From 5bc8099e116a585a6b0230f3dfdc4849d1770b22 Mon Sep 17 00:00:00 2001 From: Sabda Yagra Date: Thu, 31 Jul 2025 19:58:16 +0700 Subject: [PATCH] feat: checkbox delete in content spit --- .../content/spit/table-spit/table-spit.tsx | 66 ++++++++++++++++++- service/content/content.ts | 5 ++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/app/[locale]/(protected)/contributor/content/spit/table-spit/table-spit.tsx b/app/[locale]/(protected)/contributor/content/spit/table-spit/table-spit.tsx index 93d58a4d..ebd33ba8 100644 --- a/app/[locale]/(protected)/contributor/content/spit/table-spit/table-spit.tsx +++ b/app/[locale]/(protected)/contributor/content/spit/table-spit/table-spit.tsx @@ -36,7 +36,11 @@ import { import { title } from "process"; import { getCookiesDecrypt } from "@/lib/utils"; import TablePagination from "@/components/table/table-pagination"; -import { listEnableCategory, listSPIT } from "@/service/content/content"; +import { + deleteBulkSPIT, + listEnableCategory, + listSPIT, +} from "@/service/content/content"; import { useSearchParams } from "next/navigation"; import { InputGroup, InputGroupText } from "@/components/ui/input-group"; @@ -53,6 +57,10 @@ import { Label } from "@/components/ui/label"; import { useTranslations } from "next-intl"; import { format } from "date-fns"; import useTableColumns from "./columns"; +import Swal from "sweetalert2"; +import withReactContent from "sweetalert2-react-content"; +import { close, error, loading } from "@/config/swal"; +import toast from "react-hot-toast"; // export type CompanyData = { // no: number; @@ -120,6 +128,30 @@ const TableSPIT = () => { }, }); + const MySwal = withReactContent(Swal); + + async function onSubmitDelete(ids: string[]) { + if (ids.length === 0) return; + + try { + loading(); + const response = await deleteBulkSPIT(ids); + + if (response?.error) { + error(response?.message); + return; + } + + toast.success("Konten berhasil dihapus"); + table.resetRowSelection(); + await fetchData(); + } catch (err) { + toast.error("Terjadi kesalahan saat menghapus"); + } finally { + close(); + } + } + React.useEffect(() => { const pageFromUrl = searchParams?.get("page"); if (pageFromUrl) { @@ -338,6 +370,38 @@ const TableSPIT = () => { + {table.getSelectedRowModel().rows.length > 0 && ( +
+ +
+)} + + {table.getHeaderGroups().map((headerGroup) => ( diff --git a/service/content/content.ts b/service/content/content.ts index 6a3924a1..911bbe0d 100644 --- a/service/content/content.ts +++ b/service/content/content.ts @@ -139,6 +139,11 @@ export async function listSPIT( ); } +export async function deleteBulkSPIT(ids: any) { + const url = `media/spit/bulk?ids=${ids}`; + return httpDeleteInterceptor( url ); +} + export async function listNulisAI(limit: any, page: any, title: string = "") { return await httpGetInterceptor( `media/nulis-ai/pagination?enablePage=1&page=${page}&size=${limit}&title=${title}`