fix: taskTA from mabes to koorkurator

This commit is contained in:
Sabda Yagra 2026-01-13 09:52:29 +07:00
parent 7c721dcc96
commit ce7c343808
3 changed files with 925 additions and 317 deletions

View File

@ -22,7 +22,7 @@ import withReactContent from "sweetalert2-react-content";
import Swal from "sweetalert2"; import Swal from "sweetalert2";
import { useTranslations } from "next-intl"; import { useTranslations } from "next-intl";
const useTableColumns = (activeTab: "ta" | "daily" | "special") => { const useTableColumns = (activeTab: "ta" | "daily" | "special" |"mabes-koor") => {
const t = useTranslations("Table"); const t = useTranslations("Table");
const columns: ColumnDef<any>[] = [ const columns: ColumnDef<any>[] = [
{ {

View File

@ -186,14 +186,15 @@ export default function FormTaskTa() {
const roleId = Number(getCookiesDecrypt("urie")); const roleId = Number(getCookiesDecrypt("urie"));
const userId = Number(getCookiesDecrypt("uie")); const userId = Number(getCookiesDecrypt("uie"));
const MABES_LEVEL_ID = 216; const MABES_LEVEL_ID = 216; // userLevelId Mabes Polri
const APPROVER_ROLE_ID = 3; const APPROVER_ROLE_ID = 3; // roleId Approver
const isMabes = userLevelId === MABES_LEVEL_ID; const isMabes = userLevelId === MABES_LEVEL_ID;
const isApprover = roleId === APPROVER_ROLE_ID; const isApprover = roleId === APPROVER_ROLE_ID;
const isMabesApprover = const isMabesApprover =
userLevelId === MABES_LEVEL_ID && roleId === APPROVER_ROLE_ID; userLevelId === MABES_LEVEL_ID && roleId === APPROVER_ROLE_ID;
const shouldHideExpert = isMabes && isApprover;
useEffect(() => { useEffect(() => {
async function fetchUserLevel() { async function fetchUserLevel() {
@ -378,63 +379,126 @@ export default function FormTaskTa() {
// // }); // // });
// }; // };
// const save = async (data: TaskSchema) => {
// const cleanedLinks = links
// .map((link) => link.trim())
// .filter((link) => link.startsWith("http"));
// const requestData = {
// ...data,
// // assignedToUsers: handleExpertChange(),
// assignedToUsers: isMabesApprover ? "464" : handleExpertChange(),
// assignmentType: taskType,
// assignmentTypeId: type,
// expertCompetencies: Array.from(selectedCompetencies).join(","),
// attachmentUrl: cleanedLinks,
// };
// console.log("FINAL ASSIGNED TO:", {
// isMabesApprover,
// assignedToUsers: isMabesApprover
// ? String(roleId)
// : handleExpertChange(),
// });
// const response = await createTaskTa(requestData);
// const id = String(response?.data?.data.id);
// // Set block table TA
// localStorage.setItem("TA_UPLOAD_IN_PROGRESS", "true");
// loading(); // SHOW SWAL LOADING
// // Kumpulkan semua upload
// const allUploads: Promise<any>[] = [];
// imageFiles.forEach((item, idx) =>
// allUploads.push(uploadResumableFile(idx, id, item, "1", "0"))
// );
// videoFiles.forEach((item, idx) =>
// allUploads.push(uploadResumableFile(idx, id, item, "2", "0"))
// );
// textFiles.forEach((item, idx) =>
// allUploads.push(uploadResumableFile(idx, id, item, "3", "0"))
// );
// audioFiles.forEach((item, idx) =>
// allUploads.push(uploadResumableFile(idx, id, item, "4", "0"))
// );
// // Tunggu upload selesai
// await Promise.all(allUploads);
// // Hapus flag
// localStorage.removeItem("TA_UPLOAD_IN_PROGRESS");
// // Close loading + redirect
// successSubmit("/in/contributor/task-ta");
// };
const save = async (data: TaskSchema) => { const save = async (data: TaskSchema) => {
const cleanedLinks = links try {
.map((link) => link.trim()) loading();
.filter((link) => link.startsWith("http"));
const requestData = { const cleanedLinks = links
...data, .map((link) => link.trim())
assignedToUsers: handleExpertChange(), .filter((link) => link.startsWith("http"));
// assignedToUsers: isMabesApprover ? "464" : handleExpertChange(),
assignmentType: taskType,
assignmentTypeId: type,
expertCompetencies: Array.from(selectedCompetencies).join(","),
attachmentUrl: cleanedLinks,
};
console.log("FINAL ASSIGNED TO:", { const requestData = {
isMabesApprover, ...data,
assignedToUsers: isMabesApprover // assignedToUsers: isMabesApprover ? "464" : handleExpertChange(),
? String(roleId) assignedToUsers: isMabesApprover
: handleExpertChange(), ? ["464", "8258"]
}); : handleExpertChange(),
assignmentType: taskType,
assignmentTypeId: type,
expertCompetencies: Array.from(selectedCompetencies).join(","),
attachmentUrl: cleanedLinks,
};
const response = await createTaskTa(requestData); const response = await createTaskTa(requestData);
const id = String(response?.data?.data.id);
// Set block table TA if (!response?.data?.data?.id) {
localStorage.setItem("TA_UPLOAD_IN_PROGRESS", "true"); throw new Error("Gagal membuat task");
}
loading(); // SHOW SWAL LOADING const assignmentId = String(response.data.data.id);
// Kumpulkan semua upload const uploads: Promise<any>[] = [];
const allUploads: Promise<any>[] = [];
imageFiles.forEach((item, idx) => imageFiles.forEach((file, i) =>
allUploads.push(uploadResumableFile(idx, id, item, "1", "0")) uploads.push(uploadResumableFile(i, assignmentId, file, "1", "0"))
); );
videoFiles.forEach((item, idx) => videoFiles.forEach((file, i) =>
allUploads.push(uploadResumableFile(idx, id, item, "2", "0")) uploads.push(uploadResumableFile(i, assignmentId, file, "2", "0"))
); );
textFiles.forEach((item, idx) => textFiles.forEach((file, i) =>
allUploads.push(uploadResumableFile(idx, id, item, "3", "0")) uploads.push(uploadResumableFile(i, assignmentId, file, "3", "0"))
); );
audioFiles.forEach((item, idx) => audioFiles.forEach((file, i) =>
allUploads.push(uploadResumableFile(idx, id, item, "4", "0")) uploads.push(uploadResumableFile(i, assignmentId, file, "4", "0"))
); );
// Tunggu upload selesai await Promise.all(uploads);
await Promise.all(allUploads);
// Hapus flag successSubmit("/in/contributor/task-ta");
localStorage.removeItem("TA_UPLOAD_IN_PROGRESS"); } catch (err: any) {
console.error("SUBMIT ERROR:", err);
// Close loading + redirect Swal.fire({
successSubmit("/in/contributor/task-ta"); icon: "error",
title: "Gagal",
text:
err?.response?.data?.message ||
err?.message ||
"Terjadi kesalahan, data tidak tersimpan",
});
}
}; };
const onSubmit = (data: TaskSchema) => { const onSubmit = (data: TaskSchema) => {
@ -577,46 +641,91 @@ export default function FormTaskTa() {
// upload.start(); // upload.start();
// } // }
// function uploadResumableFile(
// idx: number,
// id: string,
// file: any,
// fileTypeId: string,
// duration: string
// ) {
// return new Promise(async (resolve, reject) => {
// const resCsrf = await getCsrfToken();
// const csrfToken = resCsrf?.data?.token;
// const upload = new Upload(file, {
// endpoint: `${process.env.NEXT_PUBLIC_API}/assignment-expert/file/upload`,
// headers: { "X-XSRF-TOKEN": csrfToken },
// retryDelays: [0, 3000, 6000, 12000],
// chunkSize: 20000,
// metadata: {
// assignmentId: id,
// filename: file.name,
// contentType: file.type,
// fileTypeId,
// duration,
// },
// onBeforeRequest(req) {
// req.getUnderlyingObject().withCredentials = true;
// },
// onError(err) {
// console.error("Upload error:", err);
// reject(err);
// },
// onSuccess() {
// console.log("Upload selesai:", file.name);
// resolve(true);
// },
// });
// upload.start();
// });
// }
function uploadResumableFile( function uploadResumableFile(
idx: number, idx: number,
id: string, id: string,
file: any, file: File,
fileTypeId: string, fileTypeId: string,
duration: string duration: string
) { ) {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
const resCsrf = await getCsrfToken(); try {
const csrfToken = resCsrf?.data?.token; const resCsrf = await getCsrfToken();
const csrfToken = resCsrf?.data?.token;
const upload = new Upload(file, { const upload = new Upload(file, {
endpoint: `${process.env.NEXT_PUBLIC_API}/assignment-expert/file/upload`, endpoint: `${process.env.NEXT_PUBLIC_API}/assignment-expert/file/upload`,
headers: { "X-XSRF-TOKEN": csrfToken }, headers: { "X-XSRF-TOKEN": csrfToken },
retryDelays: [0, 3000, 6000, 12000], retryDelays: [0, 3000, 6000],
chunkSize: 20000, chunkSize: 20000,
metadata: { metadata: {
assignmentId: id, assignmentId: id,
filename: file.name, filename: file.name,
contentType: file.type, contentType: file.type,
fileTypeId, fileTypeId,
duration, duration,
}, },
onBeforeRequest(req) { onBeforeRequest(req) {
req.getUnderlyingObject().withCredentials = true; req.getUnderlyingObject().withCredentials = true;
}, },
onError(err) { onError(error) {
console.error("Upload error:", err); reject(error);
reject(err); },
},
onSuccess() { onSuccess() {
console.log("Upload selesai:", file.name); resolve(true);
resolve(true); },
}, });
});
upload.start(); upload.start();
} catch (err) {
reject(err);
}
}); });
} }
@ -988,7 +1097,9 @@ export default function FormTaskTa() {
<Input <Input
type="url" type="url"
className="border rounded p-2 w-full" className="border rounded p-2 w-full"
placeholder={`Masukkan link berita ${index + 1}`} placeholder={`Masukkan link berita ${
index + 1
} | Contoh: https://www.detik.com`}
value={link} value={link}
onChange={(e) => onChange={(e) =>
handleLinkChange(index, e.target.value) handleLinkChange(index, e.target.value)