diff --git a/components/form/content/spit-convert-form.tsx b/components/form/content/spit-convert-form.tsx index 319dc3c3..88545a51 100644 --- a/components/form/content/spit-convert-form.tsx +++ b/components/form/content/spit-convert-form.tsx @@ -210,57 +210,10 @@ export default function FormConvertSPIT() { const roleId = getCookiesDecrypt("urie"); const [isUserMabesApprover, setIsUserMabesApprover] = useState(false); - // Gunakan channel untuk sync antar tab - const publishChannel = useRef(null); - useEffect(() => { initializeComponent(); - // Init broadcast channel - publishChannel.current = new BroadcastChannel("spit-publish-channel"); - - // Listener untuk update dari tab lain - publishChannel.current.onmessage = (event) => { - if (event.data === "SPIT_PUBLISHED") { - setIsAlreadySaved(true); - - MySwal.fire({ - title: "Konten Sudah Dipublish", - text: "Konten ini sudah dipublish dari tab lain. Halaman akan di-refresh.", - icon: "info", - confirmButtonColor: "#3085d6", - }).then(() => { - loadDetail(); // Refresh data terbaru - }); - } - }; - - return () => { - publishChannel.current?.close(); - }; }, []); - useEffect(() => { - const interval = setInterval(async () => { - if (detail?.id) { - const response = await detailSPIT(detail.id); - const latest = response?.data?.data; - - if (latest?.isPublish && !isAlreadySaved) { - setIsAlreadySaved(true); - - MySwal.fire({ - title: "Konten Sudah Dipublish", - text: "Konten ini sudah dipublish dari tab lain. Halaman akan di-refresh.", - icon: "info", - confirmButtonColor: "#3085d6", - }).then(() => loadDetail()); - } - } - }, 3000); - - return () => clearInterval(interval); - }, [detail, isAlreadySaved]); - useEffect(() => { checkUserPermissions(); }, [userLevelId, roleId]); @@ -671,9 +624,6 @@ export default function FormConvertSPIT() { await convertSPIT(requestData); - // Broadcast ke semua tab bahwa konten ini sudah publish - publishChannel.current?.postMessage("SPIT_PUBLISHED"); - MySwal.fire({ title: "Success", text: "Data saved successfully", diff --git a/components/form/task-ta/task-ta-detail-form.tsx b/components/form/task-ta/task-ta-detail-form.tsx index 7cbb60c8..83b24a56 100644 --- a/components/form/task-ta/task-ta-detail-form.tsx +++ b/components/form/task-ta/task-ta-detail-form.tsx @@ -173,9 +173,16 @@ interface UploadResult { creatorGroup: string; } +// interface FileUploaded { +// id: number; +// url: string; +// } + interface FileUploaded { id: number; url: string; + fileName: string; + fileTypeId: number; } export default function FormTaskTaDetail() { @@ -401,6 +408,19 @@ export default function FormTaskTaDetail() { fetchAcceptanceStatus(); }, [id]); + const getViewerUrl = (url: string) => { + const ext = url.split(".").pop()?.toLowerCase(); + + if (ext === "pdf") { + return url; // langsung tampilkan PDF + } + + // doc / docx → pakai Google Viewer, lebih compatible + return `https://docs.google.com/viewer?url=${encodeURIComponent( + url + )}&embedded=true`; + }; + useEffect(() => { const fetchExpertsForCompetencies = async () => { const allExperts: any[] = []; @@ -502,7 +522,7 @@ export default function FormTaskTaDetail() { const urls = details.urls.map( (urlObj: any) => urlObj.attachmentUrl || "" ); - setUrlInputs(urls); // Save the URLs to state + setUrlInputs(urls); } if (details?.assignedToLevel) { @@ -967,7 +987,13 @@ export default function FormTaskTaDetail() { wavesurfer && wavesurfer.playPause(); }; - const handleRemoveFile = (id: number) => {}; + // const handleRemoveFile = (id: number) => {}; + const handleRemoveFile = (file: FileUploaded) => { + console.log(file); + + // contoh kalau kamu mau hapus dari state: + setVideoUploadedFiles((prev) => prev.filter((f) => f.id !== file.id)); + }; const handleSearch = (e: React.ChangeEvent) => { setSearch(e.target.value); // Perbarui state search @@ -1255,6 +1281,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 +1370,16 @@ export default function FormTaskTaDetail() {
{selectedText && ( -