This commit is contained in:
hanif salafi 2025-07-31 20:47:12 +07:00
commit 3f2d66c426
2 changed files with 70 additions and 1 deletions

View File

@ -36,7 +36,11 @@ import {
import { title } from "process"; import { title } from "process";
import { getCookiesDecrypt } from "@/lib/utils"; import { getCookiesDecrypt } from "@/lib/utils";
import TablePagination from "@/components/table/table-pagination"; 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 { useSearchParams } from "next/navigation";
import { InputGroup, InputGroupText } from "@/components/ui/input-group"; import { InputGroup, InputGroupText } from "@/components/ui/input-group";
@ -53,6 +57,10 @@ import { Label } from "@/components/ui/label";
import { useTranslations } from "next-intl"; import { useTranslations } from "next-intl";
import { format } from "date-fns"; import { format } from "date-fns";
import useTableColumns from "./columns"; 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 = { // export type CompanyData = {
// no: number; // 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(() => { React.useEffect(() => {
const pageFromUrl = searchParams?.get("page"); const pageFromUrl = searchParams?.get("page");
if (pageFromUrl) { if (pageFromUrl) {
@ -338,6 +370,38 @@ const TableSPIT = () => {
</div> </div>
</div> </div>
{table.getSelectedRowModel().rows.length > 0 && (
<div className="mt-4 px-5">
<Button
variant="default"
size="sm"
onClick={async () => {
const ids = table
.getSelectedRowModel()
.rows.map((row) => row.original.contentId);
const confirm = await MySwal.fire({
title: "Yakin ingin menghapus?",
text: `Anda akan menghapus ${ids.length} item.`,
icon: "warning",
showCancelButton: true,
confirmButtonText: "Ya, hapus",
cancelButtonText: "Batal",
});
if (confirm.isConfirmed) {
onSubmitDelete(ids);
}
}}
className="bg-red-600 text-white"
>
<Trash2 className="w-4 h-4 mr-2" />
Hapus yang dipilih ({table.getSelectedRowModel().rows.length})
</Button>
</div>
)}
<Table className="overflow-hidden mt-3"> <Table className="overflow-hidden mt-3">
<TableHeader> <TableHeader>
{table.getHeaderGroups().map((headerGroup) => ( {table.getHeaderGroups().map((headerGroup) => (

View File

@ -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 = "") { export async function listNulisAI(limit: any, page: any, title: string = "") {
return await httpGetInterceptor( return await httpGetInterceptor(
`media/nulis-ai/pagination?enablePage=1&page=${page}&size=${limit}&title=${title}` `media/nulis-ai/pagination?enablePage=1&page=${page}&size=${limit}&title=${title}`