This commit is contained in:
hanif salafi 2025-09-23 18:00:25 +07:00
commit 74acf4d894
1 changed files with 51 additions and 4 deletions

View File

@ -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",
});
}
};