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 e3d3a51e..2a790870 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 @@ -40,7 +40,7 @@ export default function TrackingBeritaCard() { const initFecth = async () => { loading(); - const response = await listDataTracking(showData, page - 1); + const response = await listDataTracking(Number(showData), page - 1, search); const data = response?.data?.data; const newData = data?.content; setTotalPage(data?.totalPages || 1); @@ -56,23 +56,85 @@ export default function TrackingBeritaCard() { setContent(response?.data?.data?.content || []); }; - const handleInputChange = (e: React.ChangeEvent) => { + const handleInputChange = async (e: React.ChangeEvent) => { const value = e.target.value; setSearch(value); - if (value.trim() === "") { - initFecth(); - } else { - fecthAll(value); - } + const response = await listDataTracking(Number(showData), 0, value); + setContent(response?.data?.data?.content || []); }; + // const handleInputChange = (e: React.ChangeEvent) => { + // const value = e.target.value; + // setSearch(value); + + // if (value.trim() === "") { + // initFecth(); + // } else { + // fecthAll(value); + // } + // }; + const handleSelect = (id: number) => { setSelectedItems((prev) => prev.includes(id) ? prev.filter((x) => x !== id) : [...prev, id] ); }; + const doSave = async () => { + if (selectedItems.length === 0) { + MySwal.fire( + "Peringatan", + "Pilih minimal 1 berita untuk disimpan.", + "warning" + ); + return; + } + + try { + loading(); + + const promises = selectedItems.map(async (id) => { + const res = await mediaTrackingSave({ + mediaUploadId: id, + duration: 24, + scrapingPeriod: 3, + }); + + // cek pesan API + if (!res?.data?.success) { + throw new Error( + res?.data?.message || + "Limit media tracking per hari sudah tercapai. Maksimal 5 tracking per hari." + ); + } + + return res; + }); + + await Promise.all(promises); + close(); + + await MySwal.fire({ + icon: "success", + title: "Berhasil!", + text: "Tracking berita berhasil ditambahkan.", + confirmButtonColor: "#2563eb", + }); + + setSelectedItems([]); + initFecth(); + } catch (err: any) { + close(); + MySwal.fire({ + icon: "error", + title: "Gagal!", + text: err?.message || "Terjadi kesalahan saat menyimpan data.", + confirmButtonColor: "#dc2626", + }); + } + }; + // const doSave = async () => { // if (selectedItems.length === 0) { // toast("Pilih minimal 1 berita untuk disimpan."); @@ -99,48 +161,63 @@ export default function TrackingBeritaCard() { // } // }; - const doSave = async () => { - if (selectedItems.length === 0) { - MySwal.fire( - "Peringatan", - "Pilih minimal 1 berita untuk disimpan.", - "warning" - ); - return; - } + // const doSave = async () => { + // if (selectedItems.length === 0) { + // MySwal.fire( + // "Peringatan", + // "Pilih minimal 1 berita untuk disimpan.", + // "warning" + // ); + // return; + // } - try { - loading(); + // try { + // loading(); - const promises = selectedItems.map((id) => - mediaTrackingSave({ - mediaUploadId: id, - duration: 24, - scrapingPeriod: 3, - }) - ); - await Promise.all(promises); + // const promises = selectedItems.map((id) => + // mediaTrackingSave({ + // mediaUploadId: id, + // duration: 24, + // scrapingPeriod: 3, + // }) + // ); + // await Promise.all(promises); - close(); + // close(); - await MySwal.fire({ - icon: "success", - title: "Berhasil!", - text: "Tracking berita berhasil ditambahkan.", - confirmButtonColor: "#2563eb", - }); + // await MySwal.fire({ + // icon: "success", + // title: "Berhasil!", + // text: "Tracking berita berhasil ditambahkan.", + // confirmButtonColor: "#2563eb", + // }); - setSelectedItems([]); - initFecth(); - } catch (err: any) { - close(); - MySwal.fire({ - icon: "error", - title: "Gagal!", - text: err?.message || "Terjadi kesalahan saat menyimpan data.", - confirmButtonColor: "#dc2626", - }); - } + // setSelectedItems([]); + // initFecth(); + // } catch (err: any) { + // close(); + // MySwal.fire({ + // icon: "error", + // title: "Gagal!", + // text: err?.message || "Terjadi kesalahan saat menyimpan data.", + // confirmButtonColor: "#dc2626", + // }); + // } + // }; + + const slugify = (text: string) => { + return text + .toLowerCase() + .replace(/[^a-z0-9]+/g, "-") + .replace(/(^-|-$)+/g, ""); + }; + + const goToDetail = (item: any) => { + const type = item.type || "image"; + const slug = slugify(item.title || ""); + const url = `/in/${type}/detail/${item.id}-${slug}`; + + window.location.href = url; }; return ( @@ -188,7 +265,7 @@ export default function TrackingBeritaCard() {
{selectedItems.length} Item Terpilih{" "} - / Tracking Berita tersisa {29 - selectedItems.length} + / Tracking Berita tersisa {5 - selectedItems.length}
+ + )} */} + {roleId !== 12 && roleId !== 19 && ( @@ -1009,14 +1044,17 @@ export default function FormTaskTaDetail() { onClick={() => setModalType("diterima")} className="ml-3" > - {acceptAcceptance?.length} {t("accepted", { defaultValue: "Accepted" })} + {acceptAcceptance?.length}{" "} + {t("accepted", { defaultValue: "Accepted" })} - {t("assignment-status-details", { defaultValue: "Assignment Status Details" })} + {t("assignment-status-details", { + defaultValue: "Assignment Status Details", + })} @@ -1025,7 +1063,7 @@ export default function FormTaskTaDetail() { - */} +
@@ -1255,6 +1293,38 @@ export default function FormTaskTaDetail() { ))} + {/* {videoUploadedFiles?.map((file, index) => ( +
+
+ setSelectedVideo( + `https://mediahub.polri.go.id/api/v2/assignment-expert/file/viewer?id=${file.id}` + ) + } + > + +
+
+ {file.fileName} +
+
+
+ + +
+ ))} */}
@@ -1312,12 +1382,16 @@ export default function FormTaskTaDetail() {
{selectedText && ( -