diff --git a/components/form/task-ta/task-ta-form.tsx b/components/form/task-ta/task-ta-form.tsx index 42a0a3a1..21ff778b 100644 --- a/components/form/task-ta/task-ta-form.tsx +++ b/components/form/task-ta/task-ta-form.tsx @@ -364,7 +364,7 @@ export default function FormTaskTa() { assignmentTypeId: type, expertCompetencies: Array.from(selectedCompetencies).join(","), title: data.title, - attachmentUrl: links, + attachmentUrl: cleanedLinks, }; const response = await createTaskTa(requestData); diff --git a/components/form/task-ta/task-ta-upload-form.tsx b/components/form/task-ta/task-ta-upload-form.tsx index 469eac18..91a99783 100644 --- a/components/form/task-ta/task-ta-upload-form.tsx +++ b/components/form/task-ta/task-ta-upload-form.tsx @@ -296,17 +296,109 @@ export default function FormTaskTaNew() { initState(); }, [id, refresh]); + // const save = async (data: ImageSchema) => { + // loading(); + // const finalTags = tags.join(", "); + // const finalTitle = data.title || detail?.title || ""; + // const finalDescription = articleBody || data.description; + + // if (!finalDescription.trim()) { + // MySwal.fire("Error", "Deskripsi tidak boleh kosong.", "error"); + // return; + // } + + // let requestData: { + // assignmentExpertId: any; + // title: string; + // description: string; + // htmlDescription: string; + // fileTypeId: string; + // categoryId: any; + // subCategoryId: any; + // uploadedBy: string; + // statusId: string; + // publishedFor: string; + // creatorName: string; + // tags: string; + // isYoutube: boolean; + // isInternationalMedia: boolean; + // attachFromScheduleId?: number; // ✅ Tambahkan properti ini + // } = { + // ...data, + // assignmentExpertId: detail?.id || null, + // title: finalTitle, + // description: finalDescription, + // htmlDescription: finalDescription, + // fileTypeId: fileTypeId, + // categoryId: "235", + // subCategoryId: "171", + // uploadedBy: "2b7c8d83-d298-4b19-9f74-b07924506b58", + // statusId: "1", + // publishedFor: "7", + // creatorName: "Penugasan-Ta", + // tags: "penugasan-Ta", + // isYoutube: false, + // isInternationalMedia: false, + // }; + + // let id = Cookies.get("idCreate"); + + // if (scheduleId !== undefined) { + // requestData.attachFromScheduleId = Number(scheduleId); // ✅ Tambahkan nilai ini + // } + + // if (id == undefined) { + // const response = await createMedia(requestData); + // console.log("Form Data Submitted:", requestData); + + // Cookies.set("idCreate", response?.data?.data, { expires: 1 }); + // id = response?.data?.data; + + // // Upload Thumbnail + // loading(); + // if (imageFiles?.length == 0) { + // setIsImageUploadFinish(true); + // } + // imageFiles?.map(async (item: any, index: number) => { + // await uploadResumableFile(index, String(id), item, "1", "0"); + // }); + + // if (videoFiles?.length == 0) { + // setIsVideoUploadFinish(true); + // } + // videoFiles?.map(async (item: any, index: number) => { + // await uploadResumableFile(index, String(id), item, "2", "0"); + // }); + + // if (textFiles?.length == 0) { + // setIsTextUploadFinish(true); + // } + // textFiles?.map(async (item: any, index: number) => { + // await uploadResumableFile(index, String(id), item, "3", "0"); + // }); + + // if (audioFiles?.length == 0) { + // setIsAudioUploadFinish(true); + // } + // audioFiles.map(async (item: FileWithPreview, index: number) => { + // await uploadResumableFile( + // index, + // String(id), + // item, // Use .file to access the actual File object + // "4", + // "0" // Optional: Replace with actual duration if available + // ); + // }); + // } + // }; + const save = async (data: ImageSchema) => { loading(); + const finalTags = tags.join(", "); const finalTitle = data.title || detail?.title || ""; const finalDescription = articleBody || data.description; - if (!finalDescription.trim()) { - MySwal.fire("Error", "Deskripsi tidak boleh kosong.", "error"); - return; - } - let requestData: { assignmentExpertId: any; title: string; @@ -322,9 +414,8 @@ export default function FormTaskTaNew() { tags: string; isYoutube: boolean; isInternationalMedia: boolean; - attachFromScheduleId?: number; // ✅ Tambahkan properti ini + attachFromScheduleId?: number; } = { - ...data, assignmentExpertId: detail?.id || null, title: finalTitle, description: finalDescription, @@ -341,55 +432,35 @@ export default function FormTaskTaNew() { isInternationalMedia: false, }; - let id = Cookies.get("idCreate"); - if (scheduleId !== undefined) { - requestData.attachFromScheduleId = Number(scheduleId); // ✅ Tambahkan nilai ini + requestData.attachFromScheduleId = Number(scheduleId); } - if (id == undefined) { - const response = await createMedia(requestData); - console.log("Form Data Submitted:", requestData); + // SELALU create baru + const response = await createMedia(requestData); + const id = String(response?.data?.data); - Cookies.set("idCreate", response?.data?.data, { expires: 1 }); - id = response?.data?.data; + const allUploads: Promise[] = []; - // Upload Thumbnail - loading(); - if (imageFiles?.length == 0) { - setIsImageUploadFinish(true); - } - imageFiles?.map(async (item: any, index: number) => { - await uploadResumableFile(index, String(id), item, "1", "0"); - }); + imageFiles.forEach((file, idx) => + allUploads.push(uploadResumableFile(idx, id, file, "1", "0")) + ); - if (videoFiles?.length == 0) { - setIsVideoUploadFinish(true); - } - videoFiles?.map(async (item: any, index: number) => { - await uploadResumableFile(index, String(id), item, "2", "0"); - }); + videoFiles.forEach((file, idx) => + allUploads.push(uploadResumableFile(idx, id, file, "2", "0")) + ); - if (textFiles?.length == 0) { - setIsTextUploadFinish(true); - } - textFiles?.map(async (item: any, index: number) => { - await uploadResumableFile(index, String(id), item, "3", "0"); - }); + textFiles.forEach((file, idx) => + allUploads.push(uploadResumableFile(idx, id, file, "3", "0")) + ); - if (audioFiles?.length == 0) { - setIsAudioUploadFinish(true); - } - audioFiles.map(async (item: FileWithPreview, index: number) => { - await uploadResumableFile( - index, - String(id), - item, // Use .file to access the actual File object - "4", - "0" // Optional: Replace with actual duration if available - ); - }); - } + audioFiles.forEach((file, idx) => + allUploads.push(uploadResumableFile(idx, id, file, "4", "0")) + ); + + await Promise.all(allUploads); + + successSubmit("/in/contributor/task-ta"); }; const onSubmit = (data: ImageSchema) => { @@ -419,7 +490,6 @@ export default function FormTaskTaNew() { const resCsrf = await getCsrfToken(); const csrfToken = resCsrf?.data?.token; - console.log("CSRF TOKEN : ", csrfToken); const headers = { "X-XSRF-TOKEN": csrfToken, };