fix:upload-task in tast TA
This commit is contained in:
parent
1669a2847a
commit
6f4f9dd531
|
|
@ -364,7 +364,7 @@ export default function FormTaskTa() {
|
||||||
assignmentTypeId: type,
|
assignmentTypeId: type,
|
||||||
expertCompetencies: Array.from(selectedCompetencies).join(","),
|
expertCompetencies: Array.from(selectedCompetencies).join(","),
|
||||||
title: data.title,
|
title: data.title,
|
||||||
attachmentUrl: links,
|
attachmentUrl: cleanedLinks,
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await createTaskTa(requestData);
|
const response = await createTaskTa(requestData);
|
||||||
|
|
|
||||||
|
|
@ -296,17 +296,109 @@ export default function FormTaskTaNew() {
|
||||||
initState();
|
initState();
|
||||||
}, [id, refresh]);
|
}, [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) => {
|
const save = async (data: ImageSchema) => {
|
||||||
loading();
|
loading();
|
||||||
|
|
||||||
const finalTags = tags.join(", ");
|
const finalTags = tags.join(", ");
|
||||||
const finalTitle = data.title || detail?.title || "";
|
const finalTitle = data.title || detail?.title || "";
|
||||||
const finalDescription = articleBody || data.description;
|
const finalDescription = articleBody || data.description;
|
||||||
|
|
||||||
if (!finalDescription.trim()) {
|
|
||||||
MySwal.fire("Error", "Deskripsi tidak boleh kosong.", "error");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let requestData: {
|
let requestData: {
|
||||||
assignmentExpertId: any;
|
assignmentExpertId: any;
|
||||||
title: string;
|
title: string;
|
||||||
|
|
@ -322,9 +414,8 @@ export default function FormTaskTaNew() {
|
||||||
tags: string;
|
tags: string;
|
||||||
isYoutube: boolean;
|
isYoutube: boolean;
|
||||||
isInternationalMedia: boolean;
|
isInternationalMedia: boolean;
|
||||||
attachFromScheduleId?: number; // ✅ Tambahkan properti ini
|
attachFromScheduleId?: number;
|
||||||
} = {
|
} = {
|
||||||
...data,
|
|
||||||
assignmentExpertId: detail?.id || null,
|
assignmentExpertId: detail?.id || null,
|
||||||
title: finalTitle,
|
title: finalTitle,
|
||||||
description: finalDescription,
|
description: finalDescription,
|
||||||
|
|
@ -341,55 +432,35 @@ export default function FormTaskTaNew() {
|
||||||
isInternationalMedia: false,
|
isInternationalMedia: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let id = Cookies.get("idCreate");
|
|
||||||
|
|
||||||
if (scheduleId !== undefined) {
|
if (scheduleId !== undefined) {
|
||||||
requestData.attachFromScheduleId = Number(scheduleId); // ✅ Tambahkan nilai ini
|
requestData.attachFromScheduleId = Number(scheduleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == undefined) {
|
// SELALU create baru
|
||||||
const response = await createMedia(requestData);
|
const response = await createMedia(requestData);
|
||||||
console.log("Form Data Submitted:", requestData);
|
const id = String(response?.data?.data);
|
||||||
|
|
||||||
Cookies.set("idCreate", response?.data?.data, { expires: 1 });
|
const allUploads: Promise<any>[] = [];
|
||||||
id = response?.data?.data;
|
|
||||||
|
|
||||||
// Upload Thumbnail
|
imageFiles.forEach((file, idx) =>
|
||||||
loading();
|
allUploads.push(uploadResumableFile(idx, id, file, "1", "0"))
|
||||||
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) {
|
videoFiles.forEach((file, idx) =>
|
||||||
setIsVideoUploadFinish(true);
|
allUploads.push(uploadResumableFile(idx, id, file, "2", "0"))
|
||||||
}
|
);
|
||||||
videoFiles?.map(async (item: any, index: number) => {
|
|
||||||
await uploadResumableFile(index, String(id), item, "2", "0");
|
|
||||||
});
|
|
||||||
|
|
||||||
if (textFiles?.length == 0) {
|
textFiles.forEach((file, idx) =>
|
||||||
setIsTextUploadFinish(true);
|
allUploads.push(uploadResumableFile(idx, id, file, "3", "0"))
|
||||||
}
|
);
|
||||||
textFiles?.map(async (item: any, index: number) => {
|
|
||||||
await uploadResumableFile(index, String(id), item, "3", "0");
|
|
||||||
});
|
|
||||||
|
|
||||||
if (audioFiles?.length == 0) {
|
audioFiles.forEach((file, idx) =>
|
||||||
setIsAudioUploadFinish(true);
|
allUploads.push(uploadResumableFile(idx, id, file, "4", "0"))
|
||||||
}
|
);
|
||||||
audioFiles.map(async (item: FileWithPreview, index: number) => {
|
|
||||||
await uploadResumableFile(
|
await Promise.all(allUploads);
|
||||||
index,
|
|
||||||
String(id),
|
successSubmit("/in/contributor/task-ta");
|
||||||
item, // Use .file to access the actual File object
|
|
||||||
"4",
|
|
||||||
"0" // Optional: Replace with actual duration if available
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = (data: ImageSchema) => {
|
const onSubmit = (data: ImageSchema) => {
|
||||||
|
|
@ -419,7 +490,6 @@ export default function FormTaskTaNew() {
|
||||||
|
|
||||||
const resCsrf = await getCsrfToken();
|
const resCsrf = await getCsrfToken();
|
||||||
const csrfToken = resCsrf?.data?.token;
|
const csrfToken = resCsrf?.data?.token;
|
||||||
console.log("CSRF TOKEN : ", csrfToken);
|
|
||||||
const headers = {
|
const headers = {
|
||||||
"X-XSRF-TOKEN": csrfToken,
|
"X-XSRF-TOKEN": csrfToken,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue