From 8d2fce74bba67e8378c24298cba988db5df33745 Mon Sep 17 00:00:00 2001 From: Sabda Yagra Date: Sun, 22 Feb 2026 22:38:35 +0700 Subject: [PATCH] fix: task in mabes and koorkurator --- .../tracking-berita/component/table.tsx | 40 ++++- .../task-ta/components/columns.tsx | 153 +++++++++++------- .../task-ta/components/task-ta-table.tsx | 26 +-- components/form/task-ta/task-ta-form.tsx | 2 +- 4 files changed, 145 insertions(+), 76 deletions(-) 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 2a790870..4272afb3 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 @@ -24,6 +24,7 @@ import CustomPagination from "@/components/table/custom-pagination"; import { close, loading } from "@/config/swal"; import withReactContent from "sweetalert2-react-content"; import Swal from "sweetalert2"; +import { getCookiesDecrypt } from "@/lib/utils"; export default function TrackingBeritaCard() { const [search, setSearch] = useState(""); @@ -77,7 +78,7 @@ export default function TrackingBeritaCard() { const handleSelect = (id: number) => { setSelectedItems((prev) => - prev.includes(id) ? prev.filter((x) => x !== id) : [...prev, id] + prev.includes(id) ? prev.filter((x) => x !== id) : [...prev, id], ); }; @@ -86,13 +87,24 @@ export default function TrackingBeritaCard() { MySwal.fire( "Peringatan", "Pilih minimal 1 berita untuk disimpan.", - "warning" + "warning", ); return; } try { loading(); + const levelNumber = Number(getCookiesDecrypt("ulne")); + + const levelLimitMap: Record = { + 1: 5, + 2: 2, + 3: 2, + }; + + const maxLimit = levelLimitMap[levelNumber] || 2; + + const limitMessage = `Limit media tracking per hari sudah tercapai. Maksimal ${maxLimit} tracking per hari.`; const promises = selectedItems.map(async (id) => { const res = await mediaTrackingSave({ @@ -101,17 +113,31 @@ export default function TrackingBeritaCard() { 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." - ); + throw new Error(res?.data?.message || limitMessage); } return res; }); + // 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(); diff --git a/app/[locale]/(protected)/contributor/task-ta/components/columns.tsx b/app/[locale]/(protected)/contributor/task-ta/components/columns.tsx index 4d88788c..a0ffd900 100644 --- a/app/[locale]/(protected)/contributor/task-ta/components/columns.tsx +++ b/app/[locale]/(protected)/contributor/task-ta/components/columns.tsx @@ -112,33 +112,21 @@ const useTableColumns = ( enableHiding: false, cell: ({ row }) => { const router = useRouter(); + const createdById = row.original?.createdBy?.id; + const userId = Number(getCookiesDecrypt("uie")); const MySwal = withReactContent(Swal); const roleId = Number(getCookiesDecrypt("urie")) || 0; + const isTabTA = activeTab === "ta"; + const isTabMabesKoor = activeTab === "mabes-koor"; - // ❗ jika tab = "special" - if (activeTab === "special") { - return ( - - - - + const isCreator = Number(createdById) === Number(userId); + const canView = true; - - - - - View - - - - - ); - } + const canEdit = (isTabTA || isTabMabesKoor) && isCreator; + + const canDelete = (isTabTA || isTabMabesKoor) && isCreator; + + const canUpload = activeTab === "mabes-koor"; async function deleteProcess(id: any) { loading(); @@ -181,39 +169,81 @@ const useTableColumns = ( }; return ( + // + // + // + // + // + // {/* {(roleId == 11 || roleId == 12 || roleId == 19) && ( */} + // {(roleId == 11 || + // roleId == 12 || + // roleId == 19 || + // roleId == 3) && ( + // + // + // + // View + // + // + // )} + // {roleId == 11 || + // (roleId == 3 && ( + // + // + // + // Edit + // + // + // ))} + // {(roleId == 12 || roleId == 19) && ( + // + // + // + // Upload Tugas + // + // + // )} + // {roleId == 11 || + // (roleId == 3 && ( + // TaskDelete(row.original.id)} + // className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" + // > + // + // Delete + // + // ))} + // + // - - {/* {(roleId == 11 || roleId == 12 || roleId == 19) && ( */} - {(roleId == 11 || - roleId == 12 || - roleId == 19 || - roleId == 3) && ( - - - - View - - - )} - {roleId == 11 || - (roleId == 3 && ( - - - - Edit - - - ))} - {(roleId == 12 || roleId == 19) && ( + + + {/* VIEW */} + + + + View + + + + {/* UPLOAD (MABES → KOOR TAB) */} + {activeTab === "mabes-koor" && roleId === 11 && ( @@ -223,16 +253,27 @@ const useTableColumns = ( )} - {roleId == 11 || - (roleId == 3 && ( - TaskDelete(row.original.id)} - className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" - > - - Delete + + {/* EDIT (TAB TA & CREATOR ONLY) */} + {canEdit && ( + + + + Edit - ))} + + )} + + {/* DELETE (TAB TA & CREATOR ONLY) */} + {canDelete && ( + TaskDelete(row.original.id)} + className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" + > + + Delete + + )} ); diff --git a/app/[locale]/(protected)/contributor/task-ta/components/task-ta-table.tsx b/app/[locale]/(protected)/contributor/task-ta/components/task-ta-table.tsx index d7b153a5..4a5729ad 100644 --- a/app/[locale]/(protected)/contributor/task-ta/components/task-ta-table.tsx +++ b/app/[locale]/(protected)/contributor/task-ta/components/task-ta-table.tsx @@ -59,7 +59,7 @@ export default function TaskTaTable() { const userLevelId = Number(getCookiesDecrypt("ulie")); const roleId = Number(getCookiesDecrypt("urie")); const userId = Number(getCookiesDecrypt("uie")); - + const isKoorKuratorRole11 = roleId === 11; const isMabesApprover = userLevelId === MABES_LEVEL_ID && roleId === APPROVER_ROLE_ID; @@ -92,7 +92,7 @@ export default function TaskTaTable() { const [totalPage, setTotalPage] = React.useState(1); // const KOOR_KURATOR_USER_ID = "464"; - const KOOR_KURATOR_USER_IDS = ["464", "8258"]; + const KOOR_KURATOR_USER_IDS = ["464", "8258", "11", "216"]; // ✅ columns based on tab const columns = useTableColumns(activeTab); @@ -348,16 +348,18 @@ export default function TaskTaTable() { Atensi Khusus TA - + {!isKoorKuratorRole11 && ( + + )} )} diff --git a/components/form/task-ta/task-ta-form.tsx b/components/form/task-ta/task-ta-form.tsx index 5b6702b6..1b5b35d0 100644 --- a/components/form/task-ta/task-ta-form.tsx +++ b/components/form/task-ta/task-ta-form.tsx @@ -449,7 +449,7 @@ export default function FormTaskTa() { const requestData = { ...data, // assignedToUsers: isMabesApprover ? "464" : handleExpertChange(), - assignedToUsers: isMabesApprover ? "464,8258" : handleExpertChange(), + assignedToUsers: isMabesApprover ? "8258" : handleExpertChange(), assignmentType: taskType, assignmentTypeId: type, expertCompetencies: Array.from(selectedCompetencies).join(","),