update approval

This commit is contained in:
hanif salafi 2025-08-27 08:48:38 +07:00
parent bbed0c29c1
commit 4dd34f7144
4 changed files with 546 additions and 94 deletions

View File

@ -223,6 +223,30 @@ export default function FormAudioDetail() {
currentSelection.polda = value; currentSelection.polda = value;
currentSelection.polres = value; currentSelection.polres = value;
currentSelection.satker = value; currentSelection.satker = value;
// Update fileCheckedLevels untuk sinkronisasi dengan modal
setFileCheckedLevels((prevLevels) => {
const newArray = [...prevLevels];
const currentFileLevels = new Set<number>(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 { } else {
// Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist // Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist
if (key === "polres" && value) { if (key === "polres" && value) {
@ -484,10 +508,28 @@ export default function FormAudioDetail() {
const setupPlacementCheck = (length: number) => { const setupPlacementCheck = (length: number) => {
const temp = []; const temp = [];
const unitSelections = [];
const checkedLevelsArray = [];
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
temp.push([]); 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<number>());
} }
setFilePlacements(temp); setFilePlacements(temp);
setFileUnitSelections(unitSelections);
setFileCheckedLevels(checkedLevelsArray);
}; };
useEffect(() => { useEffect(() => {
@ -603,7 +645,7 @@ export default function FormAudioDetail() {
const data = { const data = {
mediaFileId: files[i]?.id, mediaFileId: files[i]?.id,
placements: nowArr, placements: nowArr,
assignedToLevel: currentFileCheckedLevels.join(","), customLocationPlacements: currentFileCheckedLevels.join(","),
}; };
temp.push(data); temp.push(data);
@ -613,13 +655,19 @@ export default function FormAudioDetail() {
}; };
async function save() { async function save() {
// Gabungkan semua checkedLevels dari semua file
const allCheckedLevels = new Set<number>();
fileCheckedLevels.forEach((fileLevels) => {
fileLevels.forEach((levelId) => {
allCheckedLevels.add(levelId);
});
});
const data = { const data = {
mediaUploadId: id, mediaUploadId: id,
statusId: status, statusId: status,
message: description, message: description,
// files: [],
files: isUserMabesApprover ? getPlacement() : [], files: isUserMabesApprover ? getPlacement() : [],
customLocationPlacement: Array.from(checkedLevels).join(","),
}; };
setModalOpen(false); setModalOpen(false);
loading(); loading();
@ -655,37 +703,129 @@ export default function FormAudioDetail() {
setRejectedFiles(rejects); setRejectedFiles(rejects);
} }
// const setupPlacement = ( const setupPlacement = (
// index: number, index: number,
// placement: string, placement: string,
// checked: boolean checked: boolean
// ) => { ) => {
// let temp = [...filePlacements]; let temp = [...filePlacements];
// if (checked) { if (checked) {
// if (placement === "all") { if (placement === "all") {
// temp[index] = ["all", "mabes", "polda", "international"]; temp[index] = ["all", "mabes", "polda", "international"];
// } else {
// const now = temp[index]; // Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik
// now?.push(placement); setFileCheckedLevels((prevLevels) => {
// if (now?.length === 3 && !now?.includes("all")) { const newArray = [...prevLevels];
// now?.push("all"); const currentFileLevels = new Set<number>(newArray[index] || new Set());
// }
// temp[index] = now; // Checklist semua item di modal
// } listDest.forEach((item: any) => {
// } else { currentFileLevels.add(Number(item.id));
// if (placement === "all") { if (item.subDestination) {
// temp[index] = []; item.subDestination.forEach((sub: any) => {
// } else { currentFileLevels.add(Number(sub.id));
// 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; newArray[index] = currentFileLevels;
// } return newArray;
// } });
// }
// setFilePlacements(temp); // 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<number>(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 = ( const handleMain = (
type: string, 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 = ( const updateModalChecklistLevels = (
fileIndex: number, fileIndex: number,
@ -1009,6 +1094,15 @@ export default function FormAudioDetail() {
currentSelection.polres = checkedPolresCount > 0; currentSelection.polres = checkedPolresCount > 0;
currentSelection.satker = Boolean(isSatkerChecked); 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; newSelections[fileIndex] = currentSelection;
return newSelections; return newSelections;
}); });

View File

@ -482,6 +482,30 @@ export default function FormImageDetail() {
currentSelection.polda = value; currentSelection.polda = value;
currentSelection.polres = value; currentSelection.polres = value;
currentSelection.satker = value; currentSelection.satker = value;
// Update fileCheckedLevels untuk sinkronisasi dengan modal
setFileCheckedLevels((prevLevels) => {
const newArray = [...prevLevels];
const currentFileLevels = new Set<number>(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 { } else {
// Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist // Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist
if (key === "polres" && value) { if (key === "polres" && value) {
@ -783,6 +807,15 @@ export default function FormImageDetail() {
currentSelection.polres = checkedPolresCount > 0; currentSelection.polres = checkedPolresCount > 0;
currentSelection.satker = Boolean(isSatkerChecked); 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; newSelections[fileIndex] = currentSelection;
return newSelections; return newSelections;
}); });
@ -992,7 +1025,7 @@ export default function FormImageDetail() {
const data = { const data = {
mediaFileId: files[i]?.id, mediaFileId: files[i]?.id,
placements: nowArr, placements: nowArr,
assignedToLevel: currentFileCheckedLevels.join(",") customLocationPlacements: currentFileCheckedLevels.join(",")
}; };
temp.push(data); temp.push(data);
} }
@ -1051,6 +1084,43 @@ export default function FormImageDetail() {
if (checked) { if (checked) {
if (placement === "all") { if (placement === "all") {
temp[index] = ["all", "mabes", "polda", "international"]; temp[index] = ["all", "mabes", "polda", "international"];
// Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik
setFileCheckedLevels((prevLevels) => {
const newArray = [...prevLevels];
const currentFileLevels = new Set<number>(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") { } else if (placement === "satker") {
// Ketika satker di-checklist, HANYA tambahkan satker saja // Ketika satker di-checklist, HANYA tambahkan satker saja
// JANGAN otomatis checklist polres // JANGAN otomatis checklist polres
@ -1077,6 +1147,36 @@ export default function FormImageDetail() {
} else { } else {
if (placement === "all") { if (placement === "all") {
temp[index] = []; temp[index] = [];
// Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" di-unchecklist
setFileCheckedLevels((prevLevels) => {
const newArray = [...prevLevels];
const currentFileLevels = new Set<number>(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 { } else {
const now = temp[index]?.filter((a) => a !== placement); const now = temp[index]?.filter((a) => a !== placement);
console.log("now", now); console.log("now", now);

View File

@ -216,6 +216,30 @@ export default function FormTeksDetail() {
currentSelection.polda = value; currentSelection.polda = value;
currentSelection.polres = value; currentSelection.polres = value;
currentSelection.satker = value; currentSelection.satker = value;
// Update fileCheckedLevels untuk sinkronisasi dengan modal
setFileCheckedLevels((prevLevels) => {
const newArray = [...prevLevels];
const currentFileLevels = new Set<number>(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 { } else {
// Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist // Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist
if (key === "polres" && value) { if (key === "polres" && value) {
@ -448,10 +472,28 @@ export default function FormTeksDetail() {
const setupPlacementCheck = (length: number) => { const setupPlacementCheck = (length: number) => {
const temp = []; const temp = [];
const unitSelections = [];
const checkedLevelsArray = [];
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
temp.push([]); 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<number>());
} }
setFilePlacements(temp); setFilePlacements(temp);
setFileUnitSelections(unitSelections);
setFileCheckedLevels(checkedLevelsArray);
}; };
useEffect(() => { useEffect(() => {
@ -468,6 +510,7 @@ export default function FormTeksDetail() {
names: details?.files[0]?.fileName, names: details?.files[0]?.fileName,
format: details?.files[0]?.format, format: details?.files[0]?.format,
}); });
setupPlacementCheck(details?.files?.length);
if (details?.assignedToLevel) { if (details?.assignedToLevel) {
const levels = new Set( const levels = new Set(
@ -556,7 +599,7 @@ export default function FormTeksDetail() {
const data = { const data = {
mediaFileId: files[i]?.id, mediaFileId: files[i]?.id,
placements: nowArr, placements: nowArr,
assignedToLevel: currentFileCheckedLevels.join(","), customLocationPlacements: currentFileCheckedLevels.join(","),
}; };
temp.push(data); temp.push(data);
@ -566,12 +609,19 @@ export default function FormTeksDetail() {
}; };
async function save() { async function save() {
// Gabungkan semua checkedLevels dari semua file
const allCheckedLevels = new Set<number>();
fileCheckedLevels.forEach((fileLevels) => {
fileLevels.forEach((levelId) => {
allCheckedLevels.add(levelId);
});
});
const data = { const data = {
mediaUploadId: id, mediaUploadId: id,
statusId: status, statusId: status,
message: description, message: description,
files: isUserMabesApprover ? getPlacement() : [], files: isUserMabesApprover ? getPlacement() : [],
customLocationPlacement: Array.from(checkedLevels).join(","),
}; };
setModalOpen(false); setModalOpen(false);
@ -676,6 +726,43 @@ export default function FormTeksDetail() {
if (checked) { if (checked) {
if (placement === "all") { if (placement === "all") {
temp[index] = ["all", "mabes", "polda", "international"]; temp[index] = ["all", "mabes", "polda", "international"];
// Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik
setFileCheckedLevels((prevLevels) => {
const newArray = [...prevLevels];
const currentFileLevels = new Set<number>(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") { } else if (placement === "satker") {
// Ketika satker di-checklist, HANYA tambahkan satker saja // Ketika satker di-checklist, HANYA tambahkan satker saja
// JANGAN otomatis checklist polres // JANGAN otomatis checklist polres
@ -702,6 +789,36 @@ export default function FormTeksDetail() {
} else { } else {
if (placement === "all") { if (placement === "all") {
temp[index] = []; temp[index] = [];
// Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" di-unchecklist
setFileCheckedLevels((prevLevels) => {
const newArray = [...prevLevels];
const currentFileLevels = new Set<number>(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 { } else {
const now = temp[index]?.filter((a) => a !== placement); const now = temp[index]?.filter((a) => a !== placement);
console.log("now", now); console.log("now", now);
@ -953,6 +1070,15 @@ export default function FormTeksDetail() {
currentSelection.polres = checkedPolresCount > 0; currentSelection.polres = checkedPolresCount > 0;
currentSelection.satker = Boolean(isSatkerChecked); 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; newSelections[fileIndex] = currentSelection;
return newSelections; return newSelections;
}); });

View File

@ -215,6 +215,30 @@ export default function FormVideoDetail() {
currentSelection.polda = value; currentSelection.polda = value;
currentSelection.polres = value; currentSelection.polres = value;
currentSelection.satker = value; currentSelection.satker = value;
// Update fileCheckedLevels untuk sinkronisasi dengan modal
setFileCheckedLevels((prevLevels) => {
const newArray = [...prevLevels];
const currentFileLevels = new Set<number>(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 { } else {
// Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist // Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist
if (key === "polres" && value) { if (key === "polres" && value) {
@ -483,6 +507,31 @@ export default function FormVideoDetail() {
); );
setDetailVideo(fileUrls); 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<number>());
}
setFilePlacements(temp);
setFileUnitSelections(unitSelections);
setFileCheckedLevels(checkedLevelsArray);
const approvals = await getDataApprovalByMediaUpload(details?.id); const approvals = await getDataApprovalByMediaUpload(details?.id);
setApproval(approvals?.data?.data); setApproval(approvals?.data?.data);
} }
@ -527,12 +576,19 @@ export default function FormVideoDetail() {
}; };
async function save() { async function save() {
// Gabungkan semua checkedLevels dari semua file
const allCheckedLevels = new Set<number>();
fileCheckedLevels.forEach((fileLevels) => {
fileLevels.forEach((levelId) => {
allCheckedLevels.add(levelId);
});
});
const data = { const data = {
mediaUploadId: id, mediaUploadId: id,
statusId: status, statusId: status,
message: description, message: description,
files: isUserMabesApprover ? getPlacement() : [], files: isUserMabesApprover ? getPlacement() : [],
customLocationPlacement: Array.from(checkedLevels).join(","),
}; };
setModalOpen(false); setModalOpen(false);
loading(); loading();
@ -580,7 +636,7 @@ export default function FormVideoDetail() {
const data = { const data = {
mediaFileId: files[i]?.id, mediaFileId: files[i]?.id,
placements: nowArr, placements: nowArr,
assignedToLevel: currentFileCheckedLevels.join(","), customLocationPlacements: currentFileCheckedLevels.join(","),
}; };
temp.push(data); temp.push(data);
@ -631,6 +687,43 @@ export default function FormVideoDetail() {
if (checked) { if (checked) {
if (placement === "all") { if (placement === "all") {
temp[index] = ["all", "mabes", "polda", "international"]; temp[index] = ["all", "mabes", "polda", "international"];
// Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik
setFileCheckedLevels((prevLevels) => {
const newArray = [...prevLevels];
const currentFileLevels = new Set<number>(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") { } else if (placement === "satker") {
// Ketika satker di-checklist, HANYA tambahkan satker saja // Ketika satker di-checklist, HANYA tambahkan satker saja
// JANGAN otomatis checklist polres // JANGAN otomatis checklist polres
@ -657,6 +750,36 @@ export default function FormVideoDetail() {
} else { } else {
if (placement === "all") { if (placement === "all") {
temp[index] = []; temp[index] = [];
// Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" di-unchecklist
setFileCheckedLevels((prevLevels) => {
const newArray = [...prevLevels];
const currentFileLevels = new Set<number>(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 { } else {
const now = temp[index]?.filter((a) => a !== placement); const now = temp[index]?.filter((a) => a !== placement);
console.log("now", now); console.log("now", now);
@ -945,6 +1068,15 @@ export default function FormVideoDetail() {
currentSelection.polres = checkedPolresCount > 0; currentSelection.polres = checkedPolresCount > 0;
currentSelection.satker = Boolean(isSatkerChecked); 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; newSelections[fileIndex] = currentSelection;
return newSelections; return newSelections;
}); });