diff --git a/app/[locale]/(protected)/admin/media-tracking/tracking-berita/component/table.tsx b/app/[locale]/(protected)/admin/media-tracking/tracking-berita/component/table.tsx index 33d03582..e3d3a51e 100644 --- a/app/[locale]/(protected)/admin/media-tracking/tracking-berita/component/table.tsx +++ b/app/[locale]/(protected)/admin/media-tracking/tracking-berita/component/table.tsx @@ -22,6 +22,8 @@ import { PaginationState } from "@tanstack/react-table"; import page from "../page"; import CustomPagination from "@/components/table/custom-pagination"; import { close, loading } from "@/config/swal"; +import withReactContent from "sweetalert2-react-content"; +import Swal from "sweetalert2"; export default function TrackingBeritaCard() { const [search, setSearch] = useState(""); @@ -30,6 +32,7 @@ export default function TrackingBeritaCard() { const [page, setPage] = useState(1); const [totalPage, setTotalPage] = useState(1); const [showData, setShowData] = useState("6"); + const MySwal = withReactContent(Swal); useEffect(() => { initFecth(); @@ -70,13 +73,45 @@ export default function TrackingBeritaCard() { ); }; + // const doSave = async () => { + // if (selectedItems.length === 0) { + // toast("Pilih minimal 1 berita untuk disimpan."); + // return; + // } + + // try { + // const promises = selectedItems.map((id) => + // mediaTrackingSave({ + // mediaUploadId: id, + // duration: 24, + // scrapingPeriod: 3, + // }) + // ); + // await Promise.all(promises); + + // toast("Berhasil Menambahkan", { + // description: "", + // }); + // setSelectedItems([]); + // initFecth(); + // } catch (err: any) { + // error(err?.message || "Gagal menyimpan data."); + // } + // }; + const doSave = async () => { if (selectedItems.length === 0) { - toast("Pilih minimal 1 berita untuk disimpan."); + MySwal.fire( + "Peringatan", + "Pilih minimal 1 berita untuk disimpan.", + "warning" + ); return; } try { + loading(); + const promises = selectedItems.map((id) => mediaTrackingSave({ mediaUploadId: id, @@ -86,13 +121,25 @@ export default function TrackingBeritaCard() { ); await Promise.all(promises); - toast("Berhasil Menambahkan", { - description: "", + close(); + + await MySwal.fire({ + icon: "success", + title: "Berhasil!", + text: "Tracking berita berhasil ditambahkan.", + confirmButtonColor: "#2563eb", }); + setSelectedItems([]); initFecth(); } catch (err: any) { - error(err?.message || "Gagal menyimpan data."); + close(); + MySwal.fire({ + icon: "error", + title: "Gagal!", + text: err?.message || "Terjadi kesalahan saat menyimpan data.", + confirmButtonColor: "#dc2626", + }); } };