From 4dd34f7144d4b09774934cff52214108600ae746 Mon Sep 17 00:00:00 2001 From: hanif salafi Date: Wed, 27 Aug 2025 08:48:38 +0700 Subject: [PATCH] update approval --- components/form/content/audio-detail-form.tsx | 272 ++++++++++++------ components/form/content/image-detail-form.tsx | 102 ++++++- components/form/content/teks-detail-form.tsx | 130 ++++++++- components/form/content/video-detail-form.tsx | 136 ++++++++- 4 files changed, 546 insertions(+), 94 deletions(-) diff --git a/components/form/content/audio-detail-form.tsx b/components/form/content/audio-detail-form.tsx index 85269ac5..2a18e849 100644 --- a/components/form/content/audio-detail-form.tsx +++ b/components/form/content/audio-detail-form.tsx @@ -223,6 +223,30 @@ export default function FormAudioDetail() { currentSelection.polda = value; currentSelection.polres = value; currentSelection.satker = value; + + // Update fileCheckedLevels untuk sinkronisasi dengan modal + setFileCheckedLevels((prevLevels) => { + const newArray = [...prevLevels]; + const currentFileLevels = new Set(newArray[fileIndex] || new Set()); + + if (value) { + // Checklist semua item di modal + listDest.forEach((item: any) => { + currentFileLevels.add(Number(item.id)); + if (item.subDestination) { + item.subDestination.forEach((sub: any) => { + currentFileLevels.add(Number(sub.id)); + }); + } + }); + } else { + // Unchecklist semua item di modal + currentFileLevels.clear(); + } + + newArray[fileIndex] = currentFileLevels; + return newArray; + }); } else { // Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist if (key === "polres" && value) { @@ -484,10 +508,28 @@ export default function FormAudioDetail() { const setupPlacementCheck = (length: number) => { const temp = []; + const unitSelections = []; + const checkedLevelsArray = []; + for (let i = 0; i < length; i++) { temp.push([]); + // Inisialisasi state untuk setiap file + unitSelections.push({ + semua: false, + nasional: false, + wilayah: false, + international: false, + polda: false, + polres: false, + satker: false, + }); + // Inisialisasi checkedLevels untuk setiap file + checkedLevelsArray.push(new Set()); } + setFilePlacements(temp); + setFileUnitSelections(unitSelections); + setFileCheckedLevels(checkedLevelsArray); }; useEffect(() => { @@ -603,7 +645,7 @@ export default function FormAudioDetail() { const data = { mediaFileId: files[i]?.id, placements: nowArr, - assignedToLevel: currentFileCheckedLevels.join(","), + customLocationPlacements: currentFileCheckedLevels.join(","), }; temp.push(data); @@ -613,13 +655,19 @@ export default function FormAudioDetail() { }; async function save() { + // Gabungkan semua checkedLevels dari semua file + const allCheckedLevels = new Set(); + fileCheckedLevels.forEach((fileLevels) => { + fileLevels.forEach((levelId) => { + allCheckedLevels.add(levelId); + }); + }); + const data = { mediaUploadId: id, statusId: status, message: description, - // files: [], files: isUserMabesApprover ? getPlacement() : [], - customLocationPlacement: Array.from(checkedLevels).join(","), }; setModalOpen(false); loading(); @@ -655,37 +703,129 @@ export default function FormAudioDetail() { setRejectedFiles(rejects); } - // const setupPlacement = ( - // index: number, - // placement: string, - // checked: boolean - // ) => { - // let temp = [...filePlacements]; - // if (checked) { - // if (placement === "all") { - // temp[index] = ["all", "mabes", "polda", "international"]; - // } else { - // const now = temp[index]; - // now?.push(placement); - // if (now?.length === 3 && !now?.includes("all")) { - // now?.push("all"); - // } - // temp[index] = now; - // } - // } else { - // if (placement === "all") { - // temp[index] = []; - // } else { - // const now = temp[index].filter((a) => a !== placement); - // temp[index] = now; - // if (now?.length === 3 && now?.includes("all")) { - // const newData = now.filter((b) => b !== "all"); - // temp[index] = newData; - // } - // } - // } - // setFilePlacements(temp); - // }; + const setupPlacement = ( + index: number, + placement: string, + checked: boolean + ) => { + let temp = [...filePlacements]; + if (checked) { + if (placement === "all") { + temp[index] = ["all", "mabes", "polda", "international"]; + + // Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik + setFileCheckedLevels((prevLevels) => { + const newArray = [...prevLevels]; + const currentFileLevels = new Set(newArray[index] || new Set()); + + // Checklist semua item di modal + listDest.forEach((item: any) => { + currentFileLevels.add(Number(item.id)); + if (item.subDestination) { + item.subDestination.forEach((sub: any) => { + currentFileLevels.add(Number(sub.id)); + }); + } + }); + + newArray[index] = currentFileLevels; + return newArray; + }); + + // Update fileUnitSelections untuk checkbox tingkat utama + setFileUnitSelections((prevSelections) => { + const newSelections = [...prevSelections]; + const currentSelection = { ...newSelections[index] }; + + // Set semua checkbox tingkat utama ke true + currentSelection.nasional = true; + currentSelection.wilayah = true; + currentSelection.international = true; + currentSelection.polda = true; + currentSelection.polres = true; + currentSelection.satker = true; + currentSelection.semua = true; + + newSelections[index] = currentSelection; + return newSelections; + }); + } else if (placement === "satker") { + // Ketika satker di-checklist, HANYA tambahkan satker saja + // JANGAN otomatis checklist polres + const now = temp[index] || []; + if (!now.includes("satker")) { + now.push("satker"); + } + temp[index] = now; + } else { + const now = temp[index] || []; + if (!now.includes(placement)) { + now.push(placement); + } + // Hanya auto-checklist "all" jika polda, polres, dan mabes ter-checklist + // JANGAN include satker dalam perhitungan auto "all" + const nonSatkerItems = now.filter( + (item) => item !== "satker" && item !== "all" + ); + if (nonSatkerItems.length === 3 && !now.includes("all")) { + now.push("all"); + } + temp[index] = now; + } + } else { + if (placement === "all") { + temp[index] = []; + + // Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" di-unchecklist + setFileCheckedLevels((prevLevels) => { + const newArray = [...prevLevels]; + const currentFileLevels = new Set(newArray[index] || new Set()); + + // Unchecklist semua item di modal + currentFileLevels.clear(); + + newArray[index] = currentFileLevels; + return newArray; + }); + + // Update fileUnitSelections untuk checkbox tingkat utama + setFileUnitSelections((prevSelections) => { + const newSelections = [...prevSelections]; + const currentSelection = { ...newSelections[index] }; + + // Set semua checkbox tingkat utama ke false + currentSelection.nasional = false; + currentSelection.wilayah = false; + currentSelection.international = false; + currentSelection.polda = false; + currentSelection.polres = false; + currentSelection.satker = false; + currentSelection.semua = false; + + newSelections[index] = currentSelection; + return newSelections; + }); + } else { + const now = temp[index]?.filter((a) => a !== placement); + console.log("now", now); + temp[index] = now; + // Hapus "all" jika tidak semua item ter-checklist + if (now.includes("all")) { + const nonSatkerItems = now.filter( + (item) => item !== "satker" && item !== "all" + ); + if (nonSatkerItems.length < 3) { + const newData = now.filter((b) => b !== "all"); + temp[index] = newData; + } + } + } + } + setFilePlacements(temp); + + // Update checklist levels di modal berdasarkan placement yang diubah + updateModalChecklistLevels(index, placement, checked); + }; const handleMain = ( type: string, @@ -723,62 +863,7 @@ export default function FormAudioDetail() { }); }; - const setupPlacement = ( - index: number, - placement: string, - checked: boolean - ) => { - let temp = [...filePlacements]; - if (checked) { - if (placement === "all") { - temp[index] = ["all", "mabes", "polda", "international"]; - } else if (placement === "satker") { - // Ketika satker di-checklist, HANYA tambahkan satker saja - // JANGAN otomatis checklist polres - const now = temp[index] || []; - if (!now.includes("satker")) { - now.push("satker"); - } - temp[index] = now; - } else { - const now = temp[index] || []; - if (!now.includes(placement)) { - now.push(placement); - } - // Hanya auto-checklist "all" jika polda, polres, dan mabes ter-checklist - // JANGAN include satker dalam perhitungan auto "all" - const nonSatkerItems = now.filter( - (item) => item !== "satker" && item !== "all" - ); - if (nonSatkerItems.length === 3 && !now.includes("all")) { - now.push("all"); - } - temp[index] = now; - } - } else { - if (placement === "all") { - temp[index] = []; - } else { - const now = temp[index]?.filter((a) => a !== placement); - console.log("now", now); - temp[index] = now; - // Hapus "all" jika tidak semua item ter-checklist - if (now.includes("all")) { - const nonSatkerItems = now.filter( - (item) => item !== "satker" && item !== "all" - ); - if (nonSatkerItems.length < 3) { - const newData = now.filter((b) => b !== "all"); - temp[index] = newData; - } - } - } - } - setFilePlacements(temp); - // Update checklist levels di modal berdasarkan placement yang diubah - updateModalChecklistLevels(index, placement, checked); - }; const updateModalChecklistLevels = ( fileIndex: number, @@ -1009,6 +1094,15 @@ export default function FormAudioDetail() { currentSelection.polres = checkedPolresCount > 0; currentSelection.satker = Boolean(isSatkerChecked); + // Update checkbox "semua" berdasarkan semua checkbox yang aktif + currentSelection.semua = + currentSelection.nasional && + currentSelection.wilayah && + currentSelection.international && + currentSelection.polda && + currentSelection.polres && + currentSelection.satker; + newSelections[fileIndex] = currentSelection; return newSelections; }); diff --git a/components/form/content/image-detail-form.tsx b/components/form/content/image-detail-form.tsx index 7d0d4305..037f2836 100644 --- a/components/form/content/image-detail-form.tsx +++ b/components/form/content/image-detail-form.tsx @@ -482,6 +482,30 @@ export default function FormImageDetail() { currentSelection.polda = value; currentSelection.polres = value; currentSelection.satker = value; + + // Update fileCheckedLevels untuk sinkronisasi dengan modal + setFileCheckedLevels((prevLevels) => { + const newArray = [...prevLevels]; + const currentFileLevels = new Set(newArray[fileIndex] || new Set()); + + if (value) { + // Checklist semua item di modal + listDest.forEach((item: any) => { + currentFileLevels.add(Number(item.id)); + if (item.subDestination) { + item.subDestination.forEach((sub: any) => { + currentFileLevels.add(Number(sub.id)); + }); + } + }); + } else { + // Unchecklist semua item di modal + currentFileLevels.clear(); + } + + newArray[fileIndex] = currentFileLevels; + return newArray; + }); } else { // Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist if (key === "polres" && value) { @@ -783,6 +807,15 @@ export default function FormImageDetail() { currentSelection.polres = checkedPolresCount > 0; currentSelection.satker = Boolean(isSatkerChecked); + // Update checkbox "semua" berdasarkan semua checkbox yang aktif + currentSelection.semua = + currentSelection.nasional && + currentSelection.wilayah && + currentSelection.international && + currentSelection.polda && + currentSelection.polres && + currentSelection.satker; + newSelections[fileIndex] = currentSelection; return newSelections; }); @@ -992,7 +1025,7 @@ export default function FormImageDetail() { const data = { mediaFileId: files[i]?.id, placements: nowArr, - assignedToLevel: currentFileCheckedLevels.join(",") + customLocationPlacements: currentFileCheckedLevels.join(",") }; temp.push(data); } @@ -1051,6 +1084,43 @@ export default function FormImageDetail() { if (checked) { if (placement === "all") { temp[index] = ["all", "mabes", "polda", "international"]; + + // Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik + setFileCheckedLevels((prevLevels) => { + const newArray = [...prevLevels]; + const currentFileLevels = new Set(newArray[index] || new Set()); + + // Checklist semua item di modal + listDest.forEach((item: any) => { + currentFileLevels.add(Number(item.id)); + if (item.subDestination) { + item.subDestination.forEach((sub: any) => { + currentFileLevels.add(Number(sub.id)); + }); + } + }); + + newArray[index] = currentFileLevels; + return newArray; + }); + + // Update fileUnitSelections untuk checkbox tingkat utama + setFileUnitSelections((prevSelections) => { + const newSelections = [...prevSelections]; + const currentSelection = { ...newSelections[index] }; + + // Set semua checkbox tingkat utama ke true + currentSelection.nasional = true; + currentSelection.wilayah = true; + currentSelection.international = true; + currentSelection.polda = true; + currentSelection.polres = true; + currentSelection.satker = true; + currentSelection.semua = true; + + newSelections[index] = currentSelection; + return newSelections; + }); } else if (placement === "satker") { // Ketika satker di-checklist, HANYA tambahkan satker saja // JANGAN otomatis checklist polres @@ -1077,6 +1147,36 @@ export default function FormImageDetail() { } else { if (placement === "all") { temp[index] = []; + + // Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" di-unchecklist + setFileCheckedLevels((prevLevels) => { + const newArray = [...prevLevels]; + const currentFileLevels = new Set(newArray[index] || new Set()); + + // Unchecklist semua item di modal + currentFileLevels.clear(); + + newArray[index] = currentFileLevels; + return newArray; + }); + + // Update fileUnitSelections untuk checkbox tingkat utama + setFileUnitSelections((prevSelections) => { + const newSelections = [...prevSelections]; + const currentSelection = { ...newSelections[index] }; + + // Set semua checkbox tingkat utama ke false + currentSelection.nasional = false; + currentSelection.wilayah = false; + currentSelection.international = false; + currentSelection.polda = false; + currentSelection.polres = false; + currentSelection.satker = false; + currentSelection.semua = false; + + newSelections[index] = currentSelection; + return newSelections; + }); } else { const now = temp[index]?.filter((a) => a !== placement); console.log("now", now); diff --git a/components/form/content/teks-detail-form.tsx b/components/form/content/teks-detail-form.tsx index 044153b3..3f2659b9 100644 --- a/components/form/content/teks-detail-form.tsx +++ b/components/form/content/teks-detail-form.tsx @@ -216,6 +216,30 @@ export default function FormTeksDetail() { currentSelection.polda = value; currentSelection.polres = value; currentSelection.satker = value; + + // Update fileCheckedLevels untuk sinkronisasi dengan modal + setFileCheckedLevels((prevLevels) => { + const newArray = [...prevLevels]; + const currentFileLevels = new Set(newArray[fileIndex] || new Set()); + + if (value) { + // Checklist semua item di modal + listDest.forEach((item: any) => { + currentFileLevels.add(Number(item.id)); + if (item.subDestination) { + item.subDestination.forEach((sub: any) => { + currentFileLevels.add(Number(sub.id)); + }); + } + }); + } else { + // Unchecklist semua item di modal + currentFileLevels.clear(); + } + + newArray[fileIndex] = currentFileLevels; + return newArray; + }); } else { // Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist if (key === "polres" && value) { @@ -448,10 +472,28 @@ export default function FormTeksDetail() { const setupPlacementCheck = (length: number) => { const temp = []; + const unitSelections = []; + const checkedLevelsArray = []; + for (let i = 0; i < length; i++) { temp.push([]); + // Inisialisasi state untuk setiap file + unitSelections.push({ + semua: false, + nasional: false, + wilayah: false, + international: false, + polda: false, + polres: false, + satker: false, + }); + // Inisialisasi checkedLevels untuk setiap file + checkedLevelsArray.push(new Set()); } + setFilePlacements(temp); + setFileUnitSelections(unitSelections); + setFileCheckedLevels(checkedLevelsArray); }; useEffect(() => { @@ -468,6 +510,7 @@ export default function FormTeksDetail() { names: details?.files[0]?.fileName, format: details?.files[0]?.format, }); + setupPlacementCheck(details?.files?.length); if (details?.assignedToLevel) { const levels = new Set( @@ -556,7 +599,7 @@ export default function FormTeksDetail() { const data = { mediaFileId: files[i]?.id, placements: nowArr, - assignedToLevel: currentFileCheckedLevels.join(","), + customLocationPlacements: currentFileCheckedLevels.join(","), }; temp.push(data); @@ -566,12 +609,19 @@ export default function FormTeksDetail() { }; async function save() { + // Gabungkan semua checkedLevels dari semua file + const allCheckedLevels = new Set(); + fileCheckedLevels.forEach((fileLevels) => { + fileLevels.forEach((levelId) => { + allCheckedLevels.add(levelId); + }); + }); + const data = { mediaUploadId: id, statusId: status, message: description, files: isUserMabesApprover ? getPlacement() : [], - customLocationPlacement: Array.from(checkedLevels).join(","), }; setModalOpen(false); @@ -676,6 +726,43 @@ export default function FormTeksDetail() { if (checked) { if (placement === "all") { temp[index] = ["all", "mabes", "polda", "international"]; + + // Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik + setFileCheckedLevels((prevLevels) => { + const newArray = [...prevLevels]; + const currentFileLevels = new Set(newArray[index] || new Set()); + + // Checklist semua item di modal + listDest.forEach((item: any) => { + currentFileLevels.add(Number(item.id)); + if (item.subDestination) { + item.subDestination.forEach((sub: any) => { + currentFileLevels.add(Number(sub.id)); + }); + } + }); + + newArray[index] = currentFileLevels; + return newArray; + }); + + // Update fileUnitSelections untuk checkbox tingkat utama + setFileUnitSelections((prevSelections) => { + const newSelections = [...prevSelections]; + const currentSelection = { ...newSelections[index] }; + + // Set semua checkbox tingkat utama ke true + currentSelection.nasional = true; + currentSelection.wilayah = true; + currentSelection.international = true; + currentSelection.polda = true; + currentSelection.polres = true; + currentSelection.satker = true; + currentSelection.semua = true; + + newSelections[index] = currentSelection; + return newSelections; + }); } else if (placement === "satker") { // Ketika satker di-checklist, HANYA tambahkan satker saja // JANGAN otomatis checklist polres @@ -702,6 +789,36 @@ export default function FormTeksDetail() { } else { if (placement === "all") { temp[index] = []; + + // Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" di-unchecklist + setFileCheckedLevels((prevLevels) => { + const newArray = [...prevLevels]; + const currentFileLevels = new Set(newArray[index] || new Set()); + + // Unchecklist semua item di modal + currentFileLevels.clear(); + + newArray[index] = currentFileLevels; + return newArray; + }); + + // Update fileUnitSelections untuk checkbox tingkat utama + setFileUnitSelections((prevSelections) => { + const newSelections = [...prevSelections]; + const currentSelection = { ...newSelections[index] }; + + // Set semua checkbox tingkat utama ke false + currentSelection.nasional = false; + currentSelection.wilayah = false; + currentSelection.international = false; + currentSelection.polda = false; + currentSelection.polres = false; + currentSelection.satker = false; + currentSelection.semua = false; + + newSelections[index] = currentSelection; + return newSelections; + }); } else { const now = temp[index]?.filter((a) => a !== placement); console.log("now", now); @@ -953,6 +1070,15 @@ export default function FormTeksDetail() { currentSelection.polres = checkedPolresCount > 0; currentSelection.satker = Boolean(isSatkerChecked); + // Update checkbox "semua" berdasarkan semua checkbox yang aktif + currentSelection.semua = + currentSelection.nasional && + currentSelection.wilayah && + currentSelection.international && + currentSelection.polda && + currentSelection.polres && + currentSelection.satker; + newSelections[fileIndex] = currentSelection; return newSelections; }); diff --git a/components/form/content/video-detail-form.tsx b/components/form/content/video-detail-form.tsx index 213bc5f9..857eec2f 100644 --- a/components/form/content/video-detail-form.tsx +++ b/components/form/content/video-detail-form.tsx @@ -215,6 +215,30 @@ export default function FormVideoDetail() { currentSelection.polda = value; currentSelection.polres = value; currentSelection.satker = value; + + // Update fileCheckedLevels untuk sinkronisasi dengan modal + setFileCheckedLevels((prevLevels) => { + const newArray = [...prevLevels]; + const currentFileLevels = new Set(newArray[fileIndex] || new Set()); + + if (value) { + // Checklist semua item di modal + listDest.forEach((item: any) => { + currentFileLevels.add(Number(item.id)); + if (item.subDestination) { + item.subDestination.forEach((sub: any) => { + currentFileLevels.add(Number(sub.id)); + }); + } + }); + } else { + // Unchecklist semua item di modal + currentFileLevels.clear(); + } + + newArray[fileIndex] = currentFileLevels; + return newArray; + }); } else { // Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist if (key === "polres" && value) { @@ -483,6 +507,31 @@ export default function FormVideoDetail() { ); setDetailVideo(fileUrls); + // Setup placement check untuk setiap file + const temp = []; + const unitSelections = []; + const checkedLevelsArray = []; + + for (let i = 0; i < details?.files?.length; i++) { + temp.push([]); + // Inisialisasi state untuk setiap file + unitSelections.push({ + semua: false, + nasional: false, + wilayah: false, + international: false, + polda: false, + polres: false, + satker: false, + }); + // Inisialisasi checkedLevels untuk setiap file + checkedLevelsArray.push(new Set()); + } + + setFilePlacements(temp); + setFileUnitSelections(unitSelections); + setFileCheckedLevels(checkedLevelsArray); + const approvals = await getDataApprovalByMediaUpload(details?.id); setApproval(approvals?.data?.data); } @@ -527,12 +576,19 @@ export default function FormVideoDetail() { }; async function save() { + // Gabungkan semua checkedLevels dari semua file + const allCheckedLevels = new Set(); + fileCheckedLevels.forEach((fileLevels) => { + fileLevels.forEach((levelId) => { + allCheckedLevels.add(levelId); + }); + }); + const data = { mediaUploadId: id, statusId: status, message: description, files: isUserMabesApprover ? getPlacement() : [], - customLocationPlacement: Array.from(checkedLevels).join(","), }; setModalOpen(false); loading(); @@ -580,7 +636,7 @@ export default function FormVideoDetail() { const data = { mediaFileId: files[i]?.id, placements: nowArr, - assignedToLevel: currentFileCheckedLevels.join(","), + customLocationPlacements: currentFileCheckedLevels.join(","), }; temp.push(data); @@ -631,6 +687,43 @@ export default function FormVideoDetail() { if (checked) { if (placement === "all") { temp[index] = ["all", "mabes", "polda", "international"]; + + // Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik + setFileCheckedLevels((prevLevels) => { + const newArray = [...prevLevels]; + const currentFileLevels = new Set(newArray[index] || new Set()); + + // Checklist semua item di modal + listDest.forEach((item: any) => { + currentFileLevels.add(Number(item.id)); + if (item.subDestination) { + item.subDestination.forEach((sub: any) => { + currentFileLevels.add(Number(sub.id)); + }); + } + }); + + newArray[index] = currentFileLevels; + return newArray; + }); + + // Update fileUnitSelections untuk checkbox tingkat utama + setFileUnitSelections((prevSelections) => { + const newSelections = [...prevSelections]; + const currentSelection = { ...newSelections[index] }; + + // Set semua checkbox tingkat utama ke true + currentSelection.nasional = true; + currentSelection.wilayah = true; + currentSelection.international = true; + currentSelection.polda = true; + currentSelection.polres = true; + currentSelection.satker = true; + currentSelection.semua = true; + + newSelections[index] = currentSelection; + return newSelections; + }); } else if (placement === "satker") { // Ketika satker di-checklist, HANYA tambahkan satker saja // JANGAN otomatis checklist polres @@ -657,6 +750,36 @@ export default function FormVideoDetail() { } else { if (placement === "all") { temp[index] = []; + + // Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" di-unchecklist + setFileCheckedLevels((prevLevels) => { + const newArray = [...prevLevels]; + const currentFileLevels = new Set(newArray[index] || new Set()); + + // Unchecklist semua item di modal + currentFileLevels.clear(); + + newArray[index] = currentFileLevels; + return newArray; + }); + + // Update fileUnitSelections untuk checkbox tingkat utama + setFileUnitSelections((prevSelections) => { + const newSelections = [...prevSelections]; + const currentSelection = { ...newSelections[index] }; + + // Set semua checkbox tingkat utama ke false + currentSelection.nasional = false; + currentSelection.wilayah = false; + currentSelection.international = false; + currentSelection.polda = false; + currentSelection.polres = false; + currentSelection.satker = false; + currentSelection.semua = false; + + newSelections[index] = currentSelection; + return newSelections; + }); } else { const now = temp[index]?.filter((a) => a !== placement); console.log("now", now); @@ -945,6 +1068,15 @@ export default function FormVideoDetail() { currentSelection.polres = checkedPolresCount > 0; currentSelection.satker = Boolean(isSatkerChecked); + // Update checkbox "semua" berdasarkan semua checkbox yang aktif + currentSelection.semua = + currentSelection.nasional && + currentSelection.wilayah && + currentSelection.international && + currentSelection.polda && + currentSelection.polres && + currentSelection.satker; + newSelections[fileIndex] = currentSelection; return newSelections; });