fix: placement content satker
This commit is contained in:
parent
9c997fd85d
commit
ae6e22e05f
|
|
@ -184,6 +184,10 @@ export default function FormAudioDetail() {
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [listDest, setListDest] = useState<Destination[]>([]);
|
const [listDest, setListDest] = useState<Destination[]>([]);
|
||||||
const [checkedLevels, setCheckedLevels] = useState<any>(new Set());
|
const [checkedLevels, setCheckedLevels] = useState<any>(new Set());
|
||||||
|
|
||||||
|
const isUploadedBySatkerLevel3 =
|
||||||
|
Number(detail?.uploadedBy?.userLevel?.levelNumber) === 3;
|
||||||
|
|
||||||
// State untuk setiap file secara individual - checklist levels
|
// State untuk setiap file secara individual - checklist levels
|
||||||
const [fileCheckedLevels, setFileCheckedLevels] = useState<
|
const [fileCheckedLevels, setFileCheckedLevels] = useState<
|
||||||
Array<Set<number>>
|
Array<Set<number>>
|
||||||
|
|
@ -218,16 +222,36 @@ export default function FormAudioDetail() {
|
||||||
const currentSelection = { ...newSelections[fileIndex] };
|
const currentSelection = { ...newSelections[fileIndex] };
|
||||||
|
|
||||||
if (key === "semua") {
|
if (key === "semua") {
|
||||||
// Jika klik Semua, set semua value ke true/false
|
|
||||||
currentSelection.semua = value;
|
currentSelection.semua = value;
|
||||||
currentSelection.nasional = value;
|
currentSelection.nasional = value;
|
||||||
currentSelection.wilayah = value;
|
|
||||||
currentSelection.international = value;
|
currentSelection.international = value;
|
||||||
|
|
||||||
|
if (isUploadedBySatkerLevel3) {
|
||||||
|
currentSelection.wilayah = false;
|
||||||
|
currentSelection.polda = false;
|
||||||
|
currentSelection.polres = false;
|
||||||
|
currentSelection.satker = false;
|
||||||
|
|
||||||
|
setFileCheckedLevels((prevLevels) => {
|
||||||
|
const newArray = [...prevLevels];
|
||||||
|
const currentFileLevels = new Set<number>(
|
||||||
|
newArray[fileIndex] || new Set()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!value) {
|
||||||
|
currentFileLevels.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
newArray[fileIndex] = currentFileLevels;
|
||||||
|
return newArray;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 🔁 LOGIC LAMA (TIDAK DIUBAH)
|
||||||
|
currentSelection.wilayah = value;
|
||||||
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) => {
|
setFileCheckedLevels((prevLevels) => {
|
||||||
const newArray = [...prevLevels];
|
const newArray = [...prevLevels];
|
||||||
const currentFileLevels = new Set<number>(
|
const currentFileLevels = new Set<number>(
|
||||||
|
|
@ -235,7 +259,6 @@ export default function FormAudioDetail() {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
// Checklist semua item di modal
|
|
||||||
listDest.forEach((item: any) => {
|
listDest.forEach((item: any) => {
|
||||||
currentFileLevels.add(Number(item.id));
|
currentFileLevels.add(Number(item.id));
|
||||||
if (item.subDestination) {
|
if (item.subDestination) {
|
||||||
|
|
@ -245,15 +268,14 @@ export default function FormAudioDetail() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Unchecklist semua item di modal
|
|
||||||
currentFileLevels.clear();
|
currentFileLevels.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
newArray[fileIndex] = currentFileLevels;
|
newArray[fileIndex] = currentFileLevels;
|
||||||
return newArray;
|
return newArray;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist
|
|
||||||
if (key === "polres" && value) {
|
if (key === "polres" && value) {
|
||||||
const currentFileCheckedLevels = fileCheckedLevels[fileIndex];
|
const currentFileCheckedLevels = fileCheckedLevels[fileIndex];
|
||||||
const hasSelectedPolda =
|
const hasSelectedPolda =
|
||||||
|
|
@ -269,14 +291,12 @@ export default function FormAudioDetail() {
|
||||||
alert(
|
alert(
|
||||||
"Harap pilih POLDA di Modal terlebih dahulu sebelum mengaktifkan checkbox POLRES."
|
"Harap pilih POLDA di Modal terlebih dahulu sebelum mengaktifkan checkbox POLRES."
|
||||||
);
|
);
|
||||||
return prev; // Batalkan perubahan
|
return prev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update salah satu saja
|
|
||||||
currentSelection[key] = value;
|
currentSelection[key] = value;
|
||||||
|
|
||||||
// Cek apakah semua selain "semua" sudah dicentang
|
|
||||||
const allChecked = [
|
const allChecked = [
|
||||||
"nasional",
|
"nasional",
|
||||||
"wilayah",
|
"wilayah",
|
||||||
|
|
@ -294,6 +314,92 @@ export default function FormAudioDetail() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// const handleFileUnitChange = (
|
||||||
|
// fileIndex: number,
|
||||||
|
// key: keyof typeof unitSelection,
|
||||||
|
// value: boolean
|
||||||
|
// ) => {
|
||||||
|
// setFileUnitSelections((prev) => {
|
||||||
|
// const newSelections = [...prev];
|
||||||
|
// const currentSelection = { ...newSelections[fileIndex] };
|
||||||
|
|
||||||
|
// if (key === "semua") {
|
||||||
|
// // Jika klik Semua, set semua value ke true/false
|
||||||
|
// currentSelection.semua = value;
|
||||||
|
// currentSelection.nasional = value;
|
||||||
|
// currentSelection.wilayah = value;
|
||||||
|
// currentSelection.international = value;
|
||||||
|
// currentSelection.polda = value;
|
||||||
|
// currentSelection.polres = 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 {
|
||||||
|
// // Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist
|
||||||
|
// if (key === "polres" && value) {
|
||||||
|
// const currentFileCheckedLevels = fileCheckedLevels[fileIndex];
|
||||||
|
// const hasSelectedPolda =
|
||||||
|
// currentFileCheckedLevels &&
|
||||||
|
// listDest.some(
|
||||||
|
// (item: any) =>
|
||||||
|
// item.levelNumber === 2 &&
|
||||||
|
// item.name !== "SATKER POLRI" &&
|
||||||
|
// currentFileCheckedLevels.has(Number(item.id))
|
||||||
|
// );
|
||||||
|
|
||||||
|
// if (!hasSelectedPolda) {
|
||||||
|
// alert(
|
||||||
|
// "Harap pilih POLDA di Modal terlebih dahulu sebelum mengaktifkan checkbox POLRES."
|
||||||
|
// );
|
||||||
|
// return prev; // Batalkan perubahan
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Update salah satu saja
|
||||||
|
// currentSelection[key] = value;
|
||||||
|
|
||||||
|
// // Cek apakah semua selain "semua" sudah dicentang
|
||||||
|
// const allChecked = [
|
||||||
|
// "nasional",
|
||||||
|
// "wilayah",
|
||||||
|
// "international",
|
||||||
|
// "polda",
|
||||||
|
// "polres",
|
||||||
|
// "satker",
|
||||||
|
// ].every((k) => currentSelection[k as keyof typeof unitSelection]);
|
||||||
|
|
||||||
|
// currentSelection.semua = allChecked;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// newSelections[fileIndex] = currentSelection;
|
||||||
|
// return newSelections;
|
||||||
|
// });
|
||||||
|
// };
|
||||||
|
|
||||||
const toggleExpand = (id: number) => {
|
const toggleExpand = (id: number) => {
|
||||||
setExpandedPolda((prev) => ({
|
setExpandedPolda((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
|
|
@ -718,8 +824,15 @@ export default function FormAudioDetail() {
|
||||||
) => {
|
) => {
|
||||||
let temp = [...filePlacements];
|
let temp = [...filePlacements];
|
||||||
if (checked) {
|
if (checked) {
|
||||||
|
// if (placement === "all") {
|
||||||
|
// temp[index] = ["all", "mabes", "polda", "international"];
|
||||||
|
|
||||||
if (placement === "all") {
|
if (placement === "all") {
|
||||||
|
if (isUploadedBySatkerLevel3) {
|
||||||
|
temp[index] = ["mabes", "international"];
|
||||||
|
} else {
|
||||||
temp[index] = ["all", "mabes", "polda", "international"];
|
temp[index] = ["all", "mabes", "polda", "international"];
|
||||||
|
}
|
||||||
|
|
||||||
// Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik
|
// Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik
|
||||||
setFileCheckedLevels((prevLevels) => {
|
setFileCheckedLevels((prevLevels) => {
|
||||||
|
|
@ -1477,7 +1590,15 @@ export default function FormAudioDetail() {
|
||||||
key: "international",
|
key: "international",
|
||||||
label: "Internasional",
|
label: "Internasional",
|
||||||
},
|
},
|
||||||
].map((item, idx) => (
|
]
|
||||||
|
.filter(
|
||||||
|
(item) =>
|
||||||
|
!(
|
||||||
|
isUploadedBySatkerLevel3 &&
|
||||||
|
item.key === "wilayah"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.map((item) => (
|
||||||
<div
|
<div
|
||||||
key={item.key}
|
key={item.key}
|
||||||
className="flex items-center gap-2 p-2 border border-gray-200 rounded-md hover:bg-gray-50"
|
className="flex items-center gap-2 p-2 border border-gray-200 rounded-md hover:bg-gray-50"
|
||||||
|
|
@ -1510,6 +1631,48 @@ export default function FormAudioDetail() {
|
||||||
</Label>
|
</Label>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
{/* {[
|
||||||
|
{ key: "semua", label: "Semua" },
|
||||||
|
{ key: "nasional", label: "Nasional" },
|
||||||
|
{ key: "wilayah", label: "Wilayah" },
|
||||||
|
{
|
||||||
|
key: "international",
|
||||||
|
label: "Internasional",
|
||||||
|
},
|
||||||
|
].map((item, idx) => (
|
||||||
|
<div
|
||||||
|
key={item.key}
|
||||||
|
className="flex items-center gap-2 p-2 border border-gray-200 rounded-md hover:bg-gray-50"
|
||||||
|
>
|
||||||
|
<Checkbox
|
||||||
|
id={`${item.key}-${index}`}
|
||||||
|
checked={
|
||||||
|
fileUnitSelections[index]?.[
|
||||||
|
item.key as keyof typeof unitSelection
|
||||||
|
] || false
|
||||||
|
}
|
||||||
|
onCheckedChange={(value) => {
|
||||||
|
handleFileUnitChange(
|
||||||
|
index,
|
||||||
|
item.key as keyof typeof unitSelection,
|
||||||
|
value as boolean
|
||||||
|
);
|
||||||
|
setupPlacement(
|
||||||
|
index,
|
||||||
|
item.key,
|
||||||
|
Boolean(value)
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Label
|
||||||
|
htmlFor={`${item.key}-${index}`}
|
||||||
|
className="text-sm font-medium cursor-pointer"
|
||||||
|
>
|
||||||
|
{item.label}
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
))} */}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -474,16 +474,42 @@ export default function FormImageDetail() {
|
||||||
const currentSelection = { ...newSelections[fileIndex] };
|
const currentSelection = { ...newSelections[fileIndex] };
|
||||||
|
|
||||||
if (key === "semua") {
|
if (key === "semua") {
|
||||||
// Jika klik Semua, set semua value ke true/false
|
// Jika klik Semua
|
||||||
currentSelection.semua = value;
|
currentSelection.semua = value;
|
||||||
|
|
||||||
|
// ✅ Tetap berlaku untuk semua kondisi
|
||||||
currentSelection.nasional = value;
|
currentSelection.nasional = value;
|
||||||
currentSelection.wilayah = value;
|
|
||||||
currentSelection.international = value;
|
currentSelection.international = value;
|
||||||
|
|
||||||
|
if (isUploadedBySatkerLevel3) {
|
||||||
|
// 🔹 TAMBAHAN: KHUSUS SATKER level 3
|
||||||
|
currentSelection.wilayah = false;
|
||||||
|
currentSelection.polda = false;
|
||||||
|
currentSelection.polres = false;
|
||||||
|
currentSelection.satker = false;
|
||||||
|
|
||||||
|
// 🔹 Sinkronisasi modal: JANGAN checklist wilayah
|
||||||
|
setFileCheckedLevels((prevLevels) => {
|
||||||
|
const newArray = [...prevLevels];
|
||||||
|
const currentFileLevels = new Set<number>(
|
||||||
|
newArray[fileIndex] || new Set()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!value) {
|
||||||
|
currentFileLevels.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
newArray[fileIndex] = currentFileLevels;
|
||||||
|
return newArray;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 🔁 LOGIC LAMA (TIDAK DIUBAH)
|
||||||
|
currentSelection.wilayah = value;
|
||||||
currentSelection.polda = value;
|
currentSelection.polda = value;
|
||||||
currentSelection.polres = value;
|
currentSelection.polres = value;
|
||||||
currentSelection.satker = value;
|
currentSelection.satker = value;
|
||||||
|
|
||||||
// Update fileCheckedLevels untuk sinkronisasi dengan modal
|
// LOGIC LAMA modal
|
||||||
setFileCheckedLevels((prevLevels) => {
|
setFileCheckedLevels((prevLevels) => {
|
||||||
const newArray = [...prevLevels];
|
const newArray = [...prevLevels];
|
||||||
const currentFileLevels = new Set<number>(
|
const currentFileLevels = new Set<number>(
|
||||||
|
|
@ -491,7 +517,6 @@ export default function FormImageDetail() {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
// Checklist semua item di modal
|
|
||||||
listDest.forEach((item: any) => {
|
listDest.forEach((item: any) => {
|
||||||
currentFileLevels.add(Number(item.id));
|
currentFileLevels.add(Number(item.id));
|
||||||
if (item.subDestination) {
|
if (item.subDestination) {
|
||||||
|
|
@ -501,15 +526,17 @@ export default function FormImageDetail() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Unchecklist semua item di modal
|
|
||||||
currentFileLevels.clear();
|
currentFileLevels.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
newArray[fileIndex] = currentFileLevels;
|
newArray[fileIndex] = currentFileLevels;
|
||||||
return newArray;
|
return newArray;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist
|
// 🔁 SELURUH LOGIC LAMA — TIDAK DISENTUH
|
||||||
|
|
||||||
|
// Validasi khusus untuk POLRES
|
||||||
if (key === "polres" && value) {
|
if (key === "polres" && value) {
|
||||||
const currentFileCheckedLevels = fileCheckedLevels[fileIndex];
|
const currentFileCheckedLevels = fileCheckedLevels[fileIndex];
|
||||||
const hasSelectedPolda =
|
const hasSelectedPolda =
|
||||||
|
|
@ -525,14 +552,12 @@ export default function FormImageDetail() {
|
||||||
alert(
|
alert(
|
||||||
"Harap pilih POLDA di Modal terlebih dahulu sebelum mengaktifkan checkbox POLRES."
|
"Harap pilih POLDA di Modal terlebih dahulu sebelum mengaktifkan checkbox POLRES."
|
||||||
);
|
);
|
||||||
return prev; // Batalkan perubahan
|
return prev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update salah satu saja
|
|
||||||
currentSelection[key] = value;
|
currentSelection[key] = value;
|
||||||
|
|
||||||
// Cek apakah semua selain "semua" sudah dicentang
|
|
||||||
const allChecked = [
|
const allChecked = [
|
||||||
"nasional",
|
"nasional",
|
||||||
"wilayah",
|
"wilayah",
|
||||||
|
|
@ -550,6 +575,92 @@ export default function FormImageDetail() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// const handleFileUnitChange = (
|
||||||
|
// fileIndex: number,
|
||||||
|
// key: keyof typeof unitSelection,
|
||||||
|
// value: boolean
|
||||||
|
// ) => {
|
||||||
|
// setFileUnitSelections((prev) => {
|
||||||
|
// const newSelections = [...prev];
|
||||||
|
// const currentSelection = { ...newSelections[fileIndex] };
|
||||||
|
|
||||||
|
// if (key === "semua") {
|
||||||
|
// // Jika klik Semua, set semua value ke true/false
|
||||||
|
// currentSelection.semua = value;
|
||||||
|
// currentSelection.nasional = value;
|
||||||
|
// currentSelection.wilayah = value;
|
||||||
|
// currentSelection.international = value;
|
||||||
|
// currentSelection.polda = value;
|
||||||
|
// currentSelection.polres = 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 {
|
||||||
|
// // Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist
|
||||||
|
// if (key === "polres" && value) {
|
||||||
|
// const currentFileCheckedLevels = fileCheckedLevels[fileIndex];
|
||||||
|
// const hasSelectedPolda =
|
||||||
|
// currentFileCheckedLevels &&
|
||||||
|
// listDest.some(
|
||||||
|
// (item: any) =>
|
||||||
|
// item.levelNumber === 2 &&
|
||||||
|
// item.name !== "SATKER POLRI" &&
|
||||||
|
// currentFileCheckedLevels.has(Number(item.id))
|
||||||
|
// );
|
||||||
|
|
||||||
|
// if (!hasSelectedPolda) {
|
||||||
|
// alert(
|
||||||
|
// "Harap pilih POLDA di Modal terlebih dahulu sebelum mengaktifkan checkbox POLRES."
|
||||||
|
// );
|
||||||
|
// return prev; // Batalkan perubahan
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Update salah satu saja
|
||||||
|
// currentSelection[key] = value;
|
||||||
|
|
||||||
|
// // Cek apakah semua selain "semua" sudah dicentang
|
||||||
|
// const allChecked = [
|
||||||
|
// "nasional",
|
||||||
|
// "wilayah",
|
||||||
|
// "international",
|
||||||
|
// "polda",
|
||||||
|
// "polres",
|
||||||
|
// "satker",
|
||||||
|
// ].every((k) => currentSelection[k as keyof typeof unitSelection]);
|
||||||
|
|
||||||
|
// currentSelection.semua = allChecked;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// newSelections[fileIndex] = currentSelection;
|
||||||
|
// return newSelections;
|
||||||
|
// });
|
||||||
|
// };
|
||||||
|
|
||||||
// Fungsi lama untuk kompatibilitas (akan dihapus nanti)
|
// Fungsi lama untuk kompatibilitas (akan dihapus nanti)
|
||||||
const handleUnitChange = (
|
const handleUnitChange = (
|
||||||
key: keyof typeof unitSelection,
|
key: keyof typeof unitSelection,
|
||||||
|
|
@ -1088,8 +1199,14 @@ export default function FormImageDetail() {
|
||||||
) => {
|
) => {
|
||||||
let temp = [...filePlacements];
|
let temp = [...filePlacements];
|
||||||
if (checked) {
|
if (checked) {
|
||||||
|
// if (placement === "all") {
|
||||||
|
// temp[index] = ["all", "mabes", "polda", "international"];
|
||||||
if (placement === "all") {
|
if (placement === "all") {
|
||||||
|
if (isUploadedBySatkerLevel3) {
|
||||||
|
temp[index] = ["mabes", "international"];
|
||||||
|
} else {
|
||||||
temp[index] = ["all", "mabes", "polda", "international"];
|
temp[index] = ["all", "mabes", "polda", "international"];
|
||||||
|
}
|
||||||
|
|
||||||
// Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik
|
// Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik
|
||||||
setFileCheckedLevels((prevLevels) => {
|
setFileCheckedLevels((prevLevels) => {
|
||||||
|
|
@ -1359,6 +1476,9 @@ export default function FormImageDetail() {
|
||||||
// console.log("portrai", portraitMap);
|
// console.log("portrai", portraitMap);
|
||||||
}, [portraitMap]);
|
}, [portraitMap]);
|
||||||
|
|
||||||
|
const isUploadedBySatkerLevel3 =
|
||||||
|
Number(detail?.uploadedBy?.userLevel?.levelNumber) === 3;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form>
|
<form>
|
||||||
{detail !== undefined ? (
|
{detail !== undefined ? (
|
||||||
|
|
@ -1741,7 +1861,15 @@ export default function FormImageDetail() {
|
||||||
key: "international",
|
key: "international",
|
||||||
label: "Internasional",
|
label: "Internasional",
|
||||||
},
|
},
|
||||||
].map((item, idx) => (
|
]
|
||||||
|
.filter(
|
||||||
|
(item) =>
|
||||||
|
!(
|
||||||
|
isUploadedBySatkerLevel3 &&
|
||||||
|
item.key === "wilayah"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.map((item) => (
|
||||||
<div
|
<div
|
||||||
key={item.key}
|
key={item.key}
|
||||||
className="flex items-center gap-2 p-2 border border-gray-200 rounded-md hover:bg-gray-50"
|
className="flex items-center gap-2 p-2 border border-gray-200 rounded-md hover:bg-gray-50"
|
||||||
|
|
@ -1774,11 +1902,54 @@ export default function FormImageDetail() {
|
||||||
</Label>
|
</Label>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
{/* {[
|
||||||
|
{ key: "semua", label: "Semua" },
|
||||||
|
{ key: "nasional", label: "Nasional" },
|
||||||
|
{ key: "wilayah", label: "Wilayah" },
|
||||||
|
{
|
||||||
|
key: "international",
|
||||||
|
label: "Internasional",
|
||||||
|
},
|
||||||
|
].map((item, idx) => (
|
||||||
|
<div
|
||||||
|
key={item.key}
|
||||||
|
className="flex items-center gap-2 p-2 border border-gray-200 rounded-md hover:bg-gray-50"
|
||||||
|
>
|
||||||
|
<Checkbox
|
||||||
|
id={`${item.key}-${index}`}
|
||||||
|
checked={
|
||||||
|
fileUnitSelections[index]?.[
|
||||||
|
item.key as keyof typeof unitSelection
|
||||||
|
] || false
|
||||||
|
}
|
||||||
|
onCheckedChange={(value) => {
|
||||||
|
handleFileUnitChange(
|
||||||
|
index,
|
||||||
|
item.key as keyof typeof unitSelection,
|
||||||
|
value as boolean
|
||||||
|
);
|
||||||
|
setupPlacement(
|
||||||
|
index,
|
||||||
|
item.key,
|
||||||
|
Boolean(value)
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Label
|
||||||
|
htmlFor={`${item.key}-${index}`}
|
||||||
|
className="text-sm font-medium cursor-pointer"
|
||||||
|
>
|
||||||
|
{item.label}
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
))} */}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Detail Wilayah */}
|
{/* Detail Wilayah */}
|
||||||
{fileUnitSelections[index]?.wilayah && (
|
{fileUnitSelections[index]?.wilayah &&
|
||||||
|
!isUploadedBySatkerLevel3 && (
|
||||||
<div className="border-t border-gray-200 pt-2">
|
<div className="border-t border-gray-200 pt-2">
|
||||||
<p className="text-sm font-medium text-gray-700 mb-2">
|
<p className="text-sm font-medium text-gray-700 mb-2">
|
||||||
Detail Wilayah:
|
Detail Wilayah:
|
||||||
|
|
@ -1846,7 +2017,8 @@ export default function FormImageDetail() {
|
||||||
<DialogContent className="max-w-[95vw] lg:max-w-[1400px] max-h-[90vh]">
|
<DialogContent className="max-w-[95vw] lg:max-w-[1400px] max-h-[90vh]">
|
||||||
<DialogHeader className="border-b border-gray-200 pb-4">
|
<DialogHeader className="border-b border-gray-200 pb-4">
|
||||||
<DialogTitle className="text-lg font-semibold">
|
<DialogTitle className="text-lg font-semibold">
|
||||||
Daftar Wilayah POLDA dan POLRES
|
Daftar Wilayah POLDA dan
|
||||||
|
POLRES
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-4 max-h-[70vh] overflow-y-auto p-1">
|
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-4 max-h-[70vh] overflow-y-auto p-1">
|
||||||
|
|
@ -1905,7 +2077,9 @@ export default function FormImageDetail() {
|
||||||
|
|
||||||
{/* Sub-items */}
|
{/* Sub-items */}
|
||||||
{polda.subDestination &&
|
{polda.subDestination &&
|
||||||
expandedPolda[polda.id] && (
|
expandedPolda[
|
||||||
|
polda.id
|
||||||
|
] && (
|
||||||
<div className="max-h-[200px] overflow-y-auto border-t border-gray-100 pt-2">
|
<div className="max-h-[200px] overflow-y-auto border-t border-gray-100 pt-2">
|
||||||
{/* Tombol Pilih Semua untuk sub-items */}
|
{/* Tombol Pilih Semua untuk sub-items */}
|
||||||
<div className="mb-2 flex justify-start">
|
<div className="mb-2 flex justify-start">
|
||||||
|
|
@ -1937,25 +2111,31 @@ export default function FormImageDetail() {
|
||||||
<>
|
<>
|
||||||
<Icon
|
<Icon
|
||||||
icon="material-symbols:check-indeterminate-small"
|
icon="material-symbols:check-indeterminate-small"
|
||||||
width={12}
|
width={
|
||||||
|
12
|
||||||
|
}
|
||||||
height={
|
height={
|
||||||
12
|
12
|
||||||
}
|
}
|
||||||
className="mr-1"
|
className="mr-1"
|
||||||
/>
|
/>
|
||||||
Batal Semua
|
Batal
|
||||||
|
Semua
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<Icon
|
<Icon
|
||||||
icon="material-symbols:check-all"
|
icon="material-symbols:check-all"
|
||||||
width={12}
|
width={
|
||||||
|
12
|
||||||
|
}
|
||||||
height={
|
height={
|
||||||
12
|
12
|
||||||
}
|
}
|
||||||
className="mr-1"
|
className="mr-1"
|
||||||
/>
|
/>
|
||||||
Pilih Semua
|
Pilih
|
||||||
|
Semua
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
||||||
|
|
@ -207,16 +207,36 @@ export default function FormTeksDetail() {
|
||||||
const currentSelection = { ...newSelections[fileIndex] };
|
const currentSelection = { ...newSelections[fileIndex] };
|
||||||
|
|
||||||
if (key === "semua") {
|
if (key === "semua") {
|
||||||
// Jika klik Semua, set semua value ke true/false
|
|
||||||
currentSelection.semua = value;
|
currentSelection.semua = value;
|
||||||
currentSelection.nasional = value;
|
currentSelection.nasional = value;
|
||||||
currentSelection.wilayah = value;
|
|
||||||
currentSelection.international = value;
|
currentSelection.international = value;
|
||||||
|
|
||||||
|
if (isUploadedBySatkerLevel3) {
|
||||||
|
currentSelection.wilayah = false;
|
||||||
|
currentSelection.polda = false;
|
||||||
|
currentSelection.polres = false;
|
||||||
|
currentSelection.satker = false;
|
||||||
|
|
||||||
|
setFileCheckedLevels((prevLevels) => {
|
||||||
|
const newArray = [...prevLevels];
|
||||||
|
const currentFileLevels = new Set<number>(
|
||||||
|
newArray[fileIndex] || new Set()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!value) {
|
||||||
|
currentFileLevels.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
newArray[fileIndex] = currentFileLevels;
|
||||||
|
return newArray;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 🔁 LOGIC LAMA (TIDAK DIUBAH)
|
||||||
|
currentSelection.wilayah = value;
|
||||||
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) => {
|
setFileCheckedLevels((prevLevels) => {
|
||||||
const newArray = [...prevLevels];
|
const newArray = [...prevLevels];
|
||||||
const currentFileLevels = new Set<number>(
|
const currentFileLevels = new Set<number>(
|
||||||
|
|
@ -224,7 +244,6 @@ export default function FormTeksDetail() {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
// Checklist semua item di modal
|
|
||||||
listDest.forEach((item: any) => {
|
listDest.forEach((item: any) => {
|
||||||
currentFileLevels.add(Number(item.id));
|
currentFileLevels.add(Number(item.id));
|
||||||
if (item.subDestination) {
|
if (item.subDestination) {
|
||||||
|
|
@ -234,15 +253,14 @@ export default function FormTeksDetail() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Unchecklist semua item di modal
|
|
||||||
currentFileLevels.clear();
|
currentFileLevels.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
newArray[fileIndex] = currentFileLevels;
|
newArray[fileIndex] = currentFileLevels;
|
||||||
return newArray;
|
return newArray;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist
|
|
||||||
if (key === "polres" && value) {
|
if (key === "polres" && value) {
|
||||||
const currentFileCheckedLevels = fileCheckedLevels[fileIndex];
|
const currentFileCheckedLevels = fileCheckedLevels[fileIndex];
|
||||||
const hasSelectedPolda =
|
const hasSelectedPolda =
|
||||||
|
|
@ -258,14 +276,12 @@ export default function FormTeksDetail() {
|
||||||
alert(
|
alert(
|
||||||
"Harap pilih POLDA di Modal terlebih dahulu sebelum mengaktifkan checkbox POLRES."
|
"Harap pilih POLDA di Modal terlebih dahulu sebelum mengaktifkan checkbox POLRES."
|
||||||
);
|
);
|
||||||
return prev; // Batalkan perubahan
|
return prev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update salah satu saja
|
|
||||||
currentSelection[key] = value;
|
currentSelection[key] = value;
|
||||||
|
|
||||||
// Cek apakah semua selain "semua" sudah dicentang
|
|
||||||
const allChecked = [
|
const allChecked = [
|
||||||
"nasional",
|
"nasional",
|
||||||
"wilayah",
|
"wilayah",
|
||||||
|
|
@ -283,6 +299,92 @@ export default function FormTeksDetail() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// const handleFileUnitChange = (
|
||||||
|
// fileIndex: number,
|
||||||
|
// key: keyof typeof unitSelection,
|
||||||
|
// value: boolean
|
||||||
|
// ) => {
|
||||||
|
// setFileUnitSelections((prev) => {
|
||||||
|
// const newSelections = [...prev];
|
||||||
|
// const currentSelection = { ...newSelections[fileIndex] };
|
||||||
|
|
||||||
|
// if (key === "semua") {
|
||||||
|
// // Jika klik Semua, set semua value ke true/false
|
||||||
|
// currentSelection.semua = value;
|
||||||
|
// currentSelection.nasional = value;
|
||||||
|
// currentSelection.wilayah = value;
|
||||||
|
// currentSelection.international = value;
|
||||||
|
// currentSelection.polda = value;
|
||||||
|
// currentSelection.polres = 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 {
|
||||||
|
// // Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist
|
||||||
|
// if (key === "polres" && value) {
|
||||||
|
// const currentFileCheckedLevels = fileCheckedLevels[fileIndex];
|
||||||
|
// const hasSelectedPolda =
|
||||||
|
// currentFileCheckedLevels &&
|
||||||
|
// listDest.some(
|
||||||
|
// (item: any) =>
|
||||||
|
// item.levelNumber === 2 &&
|
||||||
|
// item.name !== "SATKER POLRI" &&
|
||||||
|
// currentFileCheckedLevels.has(Number(item.id))
|
||||||
|
// );
|
||||||
|
|
||||||
|
// if (!hasSelectedPolda) {
|
||||||
|
// alert(
|
||||||
|
// "Harap pilih POLDA di Modal terlebih dahulu sebelum mengaktifkan checkbox POLRES."
|
||||||
|
// );
|
||||||
|
// return prev; // Batalkan perubahan
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Update salah satu saja
|
||||||
|
// currentSelection[key] = value;
|
||||||
|
|
||||||
|
// // Cek apakah semua selain "semua" sudah dicentang
|
||||||
|
// const allChecked = [
|
||||||
|
// "nasional",
|
||||||
|
// "wilayah",
|
||||||
|
// "international",
|
||||||
|
// "polda",
|
||||||
|
// "polres",
|
||||||
|
// "satker",
|
||||||
|
// ].every((k) => currentSelection[k as keyof typeof unitSelection]);
|
||||||
|
|
||||||
|
// currentSelection.semua = allChecked;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// newSelections[fileIndex] = currentSelection;
|
||||||
|
// return newSelections;
|
||||||
|
// });
|
||||||
|
// };
|
||||||
|
|
||||||
let fileTypeId = "3";
|
let fileTypeId = "3";
|
||||||
|
|
||||||
const toggleExpand = (id: number) => {
|
const toggleExpand = (id: number) => {
|
||||||
|
|
@ -725,8 +827,15 @@ export default function FormTeksDetail() {
|
||||||
) => {
|
) => {
|
||||||
let temp = [...filePlacements];
|
let temp = [...filePlacements];
|
||||||
if (checked) {
|
if (checked) {
|
||||||
|
// if (placement === "all") {
|
||||||
|
// temp[index] = ["all", "mabes", "polda", "international"];
|
||||||
|
|
||||||
if (placement === "all") {
|
if (placement === "all") {
|
||||||
|
if (isUploadedBySatkerLevel3) {
|
||||||
|
temp[index] = ["mabes", "international"];
|
||||||
|
} else {
|
||||||
temp[index] = ["all", "mabes", "polda", "international"];
|
temp[index] = ["all", "mabes", "polda", "international"];
|
||||||
|
}
|
||||||
|
|
||||||
// Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik
|
// Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik
|
||||||
setFileCheckedLevels((prevLevels) => {
|
setFileCheckedLevels((prevLevels) => {
|
||||||
|
|
@ -1126,6 +1235,9 @@ export default function FormTeksDetail() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isUploadedBySatkerLevel3 =
|
||||||
|
Number(detail?.uploadedBy?.userLevel?.levelNumber) === 3;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form>
|
<form>
|
||||||
{detail !== undefined ? (
|
{detail !== undefined ? (
|
||||||
|
|
@ -1471,7 +1583,15 @@ export default function FormTeksDetail() {
|
||||||
key: "international",
|
key: "international",
|
||||||
label: "Internasional",
|
label: "Internasional",
|
||||||
},
|
},
|
||||||
].map((item, idx) => (
|
]
|
||||||
|
.filter(
|
||||||
|
(item) =>
|
||||||
|
!(
|
||||||
|
isUploadedBySatkerLevel3 &&
|
||||||
|
item.key === "wilayah"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.map((item) => (
|
||||||
<div
|
<div
|
||||||
key={item.key}
|
key={item.key}
|
||||||
className="flex items-center gap-2 p-2 border border-gray-200 rounded-md hover:bg-gray-50"
|
className="flex items-center gap-2 p-2 border border-gray-200 rounded-md hover:bg-gray-50"
|
||||||
|
|
@ -1504,6 +1624,48 @@ export default function FormTeksDetail() {
|
||||||
</Label>
|
</Label>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
{/* {[
|
||||||
|
{ key: "semua", label: "Semua" },
|
||||||
|
{ key: "nasional", label: "Nasional" },
|
||||||
|
{ key: "wilayah", label: "Wilayah" },
|
||||||
|
{
|
||||||
|
key: "international",
|
||||||
|
label: "Internasional",
|
||||||
|
},
|
||||||
|
].map((item, idx) => (
|
||||||
|
<div
|
||||||
|
key={item.key}
|
||||||
|
className="flex items-center gap-2 p-2 border border-gray-200 rounded-md hover:bg-gray-50"
|
||||||
|
>
|
||||||
|
<Checkbox
|
||||||
|
id={`${item.key}-${index}`}
|
||||||
|
checked={
|
||||||
|
fileUnitSelections[index]?.[
|
||||||
|
item.key as keyof typeof unitSelection
|
||||||
|
] || false
|
||||||
|
}
|
||||||
|
onCheckedChange={(value) => {
|
||||||
|
handleFileUnitChange(
|
||||||
|
index,
|
||||||
|
item.key as keyof typeof unitSelection,
|
||||||
|
value as boolean
|
||||||
|
);
|
||||||
|
setupPlacement(
|
||||||
|
index,
|
||||||
|
item.key,
|
||||||
|
Boolean(value)
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Label
|
||||||
|
htmlFor={`${item.key}-${index}`}
|
||||||
|
className="text-sm font-medium cursor-pointer"
|
||||||
|
>
|
||||||
|
{item.label}
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
))} */}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -210,16 +210,36 @@ export default function FormVideoDetail() {
|
||||||
const currentSelection = { ...newSelections[fileIndex] };
|
const currentSelection = { ...newSelections[fileIndex] };
|
||||||
|
|
||||||
if (key === "semua") {
|
if (key === "semua") {
|
||||||
// Jika klik Semua, set semua value ke true/false
|
|
||||||
currentSelection.semua = value;
|
currentSelection.semua = value;
|
||||||
currentSelection.nasional = value;
|
currentSelection.nasional = value;
|
||||||
currentSelection.wilayah = value;
|
|
||||||
currentSelection.international = value;
|
currentSelection.international = value;
|
||||||
|
|
||||||
|
if (isUploadedBySatkerLevel3) {
|
||||||
|
currentSelection.wilayah = false;
|
||||||
|
currentSelection.polda = false;
|
||||||
|
currentSelection.polres = false;
|
||||||
|
currentSelection.satker = false;
|
||||||
|
|
||||||
|
setFileCheckedLevels((prevLevels) => {
|
||||||
|
const newArray = [...prevLevels];
|
||||||
|
const currentFileLevels = new Set<number>(
|
||||||
|
newArray[fileIndex] || new Set()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!value) {
|
||||||
|
currentFileLevels.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
newArray[fileIndex] = currentFileLevels;
|
||||||
|
return newArray;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 🔁 LOGIC LAMA (TIDAK DIUBAH)
|
||||||
|
currentSelection.wilayah = value;
|
||||||
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) => {
|
setFileCheckedLevels((prevLevels) => {
|
||||||
const newArray = [...prevLevels];
|
const newArray = [...prevLevels];
|
||||||
const currentFileLevels = new Set<number>(
|
const currentFileLevels = new Set<number>(
|
||||||
|
|
@ -227,7 +247,6 @@ export default function FormVideoDetail() {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
// Checklist semua item di modal
|
|
||||||
listDest.forEach((item: any) => {
|
listDest.forEach((item: any) => {
|
||||||
currentFileLevels.add(Number(item.id));
|
currentFileLevels.add(Number(item.id));
|
||||||
if (item.subDestination) {
|
if (item.subDestination) {
|
||||||
|
|
@ -237,15 +256,14 @@ export default function FormVideoDetail() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Unchecklist semua item di modal
|
|
||||||
currentFileLevels.clear();
|
currentFileLevels.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
newArray[fileIndex] = currentFileLevels;
|
newArray[fileIndex] = currentFileLevels;
|
||||||
return newArray;
|
return newArray;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist
|
|
||||||
if (key === "polres" && value) {
|
if (key === "polres" && value) {
|
||||||
const currentFileCheckedLevels = fileCheckedLevels[fileIndex];
|
const currentFileCheckedLevels = fileCheckedLevels[fileIndex];
|
||||||
const hasSelectedPolda =
|
const hasSelectedPolda =
|
||||||
|
|
@ -261,14 +279,12 @@ export default function FormVideoDetail() {
|
||||||
alert(
|
alert(
|
||||||
"Harap pilih POLDA di Modal terlebih dahulu sebelum mengaktifkan checkbox POLRES."
|
"Harap pilih POLDA di Modal terlebih dahulu sebelum mengaktifkan checkbox POLRES."
|
||||||
);
|
);
|
||||||
return prev; // Batalkan perubahan
|
return prev;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update salah satu saja
|
|
||||||
currentSelection[key] = value;
|
currentSelection[key] = value;
|
||||||
|
|
||||||
// Cek apakah semua selain "semua" sudah dicentang
|
|
||||||
const allChecked = [
|
const allChecked = [
|
||||||
"nasional",
|
"nasional",
|
||||||
"wilayah",
|
"wilayah",
|
||||||
|
|
@ -286,6 +302,92 @@ export default function FormVideoDetail() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// const handleFileUnitChange = (
|
||||||
|
// fileIndex: number,
|
||||||
|
// key: keyof typeof unitSelection,
|
||||||
|
// value: boolean
|
||||||
|
// ) => {
|
||||||
|
// setFileUnitSelections((prev) => {
|
||||||
|
// const newSelections = [...prev];
|
||||||
|
// const currentSelection = { ...newSelections[fileIndex] };
|
||||||
|
|
||||||
|
// if (key === "semua") {
|
||||||
|
// // Jika klik Semua, set semua value ke true/false
|
||||||
|
// currentSelection.semua = value;
|
||||||
|
// currentSelection.nasional = value;
|
||||||
|
// currentSelection.wilayah = value;
|
||||||
|
// currentSelection.international = value;
|
||||||
|
// currentSelection.polda = value;
|
||||||
|
// currentSelection.polres = 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 {
|
||||||
|
// // Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist
|
||||||
|
// if (key === "polres" && value) {
|
||||||
|
// const currentFileCheckedLevels = fileCheckedLevels[fileIndex];
|
||||||
|
// const hasSelectedPolda =
|
||||||
|
// currentFileCheckedLevels &&
|
||||||
|
// listDest.some(
|
||||||
|
// (item: any) =>
|
||||||
|
// item.levelNumber === 2 &&
|
||||||
|
// item.name !== "SATKER POLRI" &&
|
||||||
|
// currentFileCheckedLevels.has(Number(item.id))
|
||||||
|
// );
|
||||||
|
|
||||||
|
// if (!hasSelectedPolda) {
|
||||||
|
// alert(
|
||||||
|
// "Harap pilih POLDA di Modal terlebih dahulu sebelum mengaktifkan checkbox POLRES."
|
||||||
|
// );
|
||||||
|
// return prev; // Batalkan perubahan
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Update salah satu saja
|
||||||
|
// currentSelection[key] = value;
|
||||||
|
|
||||||
|
// // Cek apakah semua selain "semua" sudah dicentang
|
||||||
|
// const allChecked = [
|
||||||
|
// "nasional",
|
||||||
|
// "wilayah",
|
||||||
|
// "international",
|
||||||
|
// "polda",
|
||||||
|
// "polres",
|
||||||
|
// "satker",
|
||||||
|
// ].every((k) => currentSelection[k as keyof typeof unitSelection]);
|
||||||
|
|
||||||
|
// currentSelection.semua = allChecked;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// newSelections[fileIndex] = currentSelection;
|
||||||
|
// return newSelections;
|
||||||
|
// });
|
||||||
|
// };
|
||||||
|
|
||||||
let fileTypeId = "2";
|
let fileTypeId = "2";
|
||||||
|
|
||||||
const toggleExpand = (id: number) => {
|
const toggleExpand = (id: number) => {
|
||||||
|
|
@ -690,8 +792,15 @@ export default function FormVideoDetail() {
|
||||||
) => {
|
) => {
|
||||||
let temp = [...filePlacements];
|
let temp = [...filePlacements];
|
||||||
if (checked) {
|
if (checked) {
|
||||||
|
// if (placement === "all") {
|
||||||
|
// temp[index] = ["all", "mabes", "polda", "international"];
|
||||||
|
|
||||||
if (placement === "all") {
|
if (placement === "all") {
|
||||||
|
if (isUploadedBySatkerLevel3) {
|
||||||
|
temp[index] = ["mabes", "international"];
|
||||||
|
} else {
|
||||||
temp[index] = ["all", "mabes", "polda", "international"];
|
temp[index] = ["all", "mabes", "polda", "international"];
|
||||||
|
}
|
||||||
|
|
||||||
// Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik
|
// Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik
|
||||||
setFileCheckedLevels((prevLevels) => {
|
setFileCheckedLevels((prevLevels) => {
|
||||||
|
|
@ -1128,6 +1237,9 @@ export default function FormVideoDetail() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isUploadedBySatkerLevel3 =
|
||||||
|
Number(detail?.uploadedBy?.userLevel?.levelNumber) === 3;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form>
|
<form>
|
||||||
{detail !== undefined ? (
|
{detail !== undefined ? (
|
||||||
|
|
@ -1475,7 +1587,15 @@ export default function FormVideoDetail() {
|
||||||
key: "international",
|
key: "international",
|
||||||
label: "Internasional",
|
label: "Internasional",
|
||||||
},
|
},
|
||||||
].map((item, idx) => (
|
]
|
||||||
|
.filter(
|
||||||
|
(item) =>
|
||||||
|
!(
|
||||||
|
isUploadedBySatkerLevel3 &&
|
||||||
|
item.key === "wilayah"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.map((item) => (
|
||||||
<div
|
<div
|
||||||
key={item.key}
|
key={item.key}
|
||||||
className="flex items-center gap-2 p-2 border border-gray-200 rounded-md hover:bg-gray-50"
|
className="flex items-center gap-2 p-2 border border-gray-200 rounded-md hover:bg-gray-50"
|
||||||
|
|
@ -1508,11 +1628,54 @@ export default function FormVideoDetail() {
|
||||||
</Label>
|
</Label>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
{/* {[
|
||||||
|
{ key: "semua", label: "Semua" },
|
||||||
|
{ key: "nasional", label: "Nasional" },
|
||||||
|
{ key: "wilayah", label: "Wilayah" },
|
||||||
|
{
|
||||||
|
key: "international",
|
||||||
|
label: "Internasional",
|
||||||
|
},
|
||||||
|
].map((item, idx) => (
|
||||||
|
<div
|
||||||
|
key={item.key}
|
||||||
|
className="flex items-center gap-2 p-2 border border-gray-200 rounded-md hover:bg-gray-50"
|
||||||
|
>
|
||||||
|
<Checkbox
|
||||||
|
id={`${item.key}-${index}`}
|
||||||
|
checked={
|
||||||
|
fileUnitSelections[index]?.[
|
||||||
|
item.key as keyof typeof unitSelection
|
||||||
|
] || false
|
||||||
|
}
|
||||||
|
onCheckedChange={(value) => {
|
||||||
|
handleFileUnitChange(
|
||||||
|
index,
|
||||||
|
item.key as keyof typeof unitSelection,
|
||||||
|
value as boolean
|
||||||
|
);
|
||||||
|
setupPlacement(
|
||||||
|
index,
|
||||||
|
item.key,
|
||||||
|
Boolean(value)
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Label
|
||||||
|
htmlFor={`${item.key}-${index}`}
|
||||||
|
className="text-sm font-medium cursor-pointer"
|
||||||
|
>
|
||||||
|
{item.label}
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
|
))} */}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Detail Wilayah */}
|
{/* Detail Wilayah */}
|
||||||
{fileUnitSelections[index]?.wilayah && (
|
{fileUnitSelections[index]?.wilayah &&
|
||||||
|
!isUploadedBySatkerLevel3 && (
|
||||||
<div className="border-t border-gray-200 pt-2">
|
<div className="border-t border-gray-200 pt-2">
|
||||||
<p className="text-sm font-medium text-gray-700 mb-2">
|
<p className="text-sm font-medium text-gray-700 mb-2">
|
||||||
Detail Wilayah:
|
Detail Wilayah:
|
||||||
|
|
@ -1580,7 +1743,8 @@ export default function FormVideoDetail() {
|
||||||
<DialogContent className="max-w-[95vw] lg:max-w-[1400px] max-h-[90vh]">
|
<DialogContent className="max-w-[95vw] lg:max-w-[1400px] max-h-[90vh]">
|
||||||
<DialogHeader className="border-b border-gray-200 pb-4">
|
<DialogHeader className="border-b border-gray-200 pb-4">
|
||||||
<DialogTitle className="text-lg font-semibold">
|
<DialogTitle className="text-lg font-semibold">
|
||||||
Daftar Wilayah POLDA dan POLRES
|
Daftar Wilayah POLDA dan
|
||||||
|
POLRES
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-4 max-h-[70vh] overflow-y-auto p-1">
|
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-4 max-h-[70vh] overflow-y-auto p-1">
|
||||||
|
|
@ -1639,7 +1803,9 @@ export default function FormVideoDetail() {
|
||||||
|
|
||||||
{/* Sub-items */}
|
{/* Sub-items */}
|
||||||
{polda.subDestination &&
|
{polda.subDestination &&
|
||||||
expandedPolda[polda.id] && (
|
expandedPolda[
|
||||||
|
polda.id
|
||||||
|
] && (
|
||||||
<div className="max-h-[200px] overflow-y-auto border-t border-gray-100 pt-2">
|
<div className="max-h-[200px] overflow-y-auto border-t border-gray-100 pt-2">
|
||||||
{/* Tombol Pilih Semua untuk sub-items */}
|
{/* Tombol Pilih Semua untuk sub-items */}
|
||||||
<div className="mb-2 flex justify-start">
|
<div className="mb-2 flex justify-start">
|
||||||
|
|
@ -1671,25 +1837,31 @@ export default function FormVideoDetail() {
|
||||||
<>
|
<>
|
||||||
<Icon
|
<Icon
|
||||||
icon="material-symbols:check-indeterminate-small"
|
icon="material-symbols:check-indeterminate-small"
|
||||||
width={12}
|
width={
|
||||||
|
12
|
||||||
|
}
|
||||||
height={
|
height={
|
||||||
12
|
12
|
||||||
}
|
}
|
||||||
className="mr-1"
|
className="mr-1"
|
||||||
/>
|
/>
|
||||||
Batal Semua
|
Batal
|
||||||
|
Semua
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<Icon
|
<Icon
|
||||||
icon="material-symbols:check-all"
|
icon="material-symbols:check-all"
|
||||||
width={12}
|
width={
|
||||||
|
12
|
||||||
|
}
|
||||||
height={
|
height={
|
||||||
12
|
12
|
||||||
}
|
}
|
||||||
className="mr-1"
|
className="mr-1"
|
||||||
/>
|
/>
|
||||||
Pilih Semua
|
Pilih
|
||||||
|
Semua
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue