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 [listDest, setListDest] = useState<Destination[]>([]);
|
||||
const [checkedLevels, setCheckedLevels] = useState<any>(new Set());
|
||||
|
||||
const isUploadedBySatkerLevel3 =
|
||||
Number(detail?.uploadedBy?.userLevel?.levelNumber) === 3;
|
||||
|
||||
// State untuk setiap file secara individual - checklist levels
|
||||
const [fileCheckedLevels, setFileCheckedLevels] = useState<
|
||||
Array<Set<number>>
|
||||
|
|
@ -218,16 +222,36 @@ export default function FormAudioDetail() {
|
|||
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;
|
||||
|
||||
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.polres = value;
|
||||
currentSelection.satker = value;
|
||||
|
||||
// Update fileCheckedLevels untuk sinkronisasi dengan modal
|
||||
setFileCheckedLevels((prevLevels) => {
|
||||
const newArray = [...prevLevels];
|
||||
const currentFileLevels = new Set<number>(
|
||||
|
|
@ -235,7 +259,6 @@ export default function FormAudioDetail() {
|
|||
);
|
||||
|
||||
if (value) {
|
||||
// Checklist semua item di modal
|
||||
listDest.forEach((item: any) => {
|
||||
currentFileLevels.add(Number(item.id));
|
||||
if (item.subDestination) {
|
||||
|
|
@ -245,15 +268,14 @@ export default function FormAudioDetail() {
|
|||
}
|
||||
});
|
||||
} 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 =
|
||||
|
|
@ -269,14 +291,12 @@ export default function FormAudioDetail() {
|
|||
alert(
|
||||
"Harap pilih POLDA di Modal terlebih dahulu sebelum mengaktifkan checkbox POLRES."
|
||||
);
|
||||
return prev; // Batalkan perubahan
|
||||
return prev;
|
||||
}
|
||||
}
|
||||
|
||||
// Update salah satu saja
|
||||
currentSelection[key] = value;
|
||||
|
||||
// Cek apakah semua selain "semua" sudah dicentang
|
||||
const allChecked = [
|
||||
"nasional",
|
||||
"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) => {
|
||||
setExpandedPolda((prev) => ({
|
||||
...prev,
|
||||
|
|
@ -718,8 +824,15 @@ export default function FormAudioDetail() {
|
|||
) => {
|
||||
let temp = [...filePlacements];
|
||||
if (checked) {
|
||||
// if (placement === "all") {
|
||||
// temp[index] = ["all", "mabes", "polda", "international"];
|
||||
|
||||
if (placement === "all") {
|
||||
if (isUploadedBySatkerLevel3) {
|
||||
temp[index] = ["mabes", "international"];
|
||||
} else {
|
||||
temp[index] = ["all", "mabes", "polda", "international"];
|
||||
}
|
||||
|
||||
// Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik
|
||||
setFileCheckedLevels((prevLevels) => {
|
||||
|
|
@ -1477,7 +1590,15 @@ export default function FormAudioDetail() {
|
|||
key: "international",
|
||||
label: "Internasional",
|
||||
},
|
||||
].map((item, idx) => (
|
||||
]
|
||||
.filter(
|
||||
(item) =>
|
||||
!(
|
||||
isUploadedBySatkerLevel3 &&
|
||||
item.key === "wilayah"
|
||||
)
|
||||
)
|
||||
.map((item) => (
|
||||
<div
|
||||
key={item.key}
|
||||
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>
|
||||
</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>
|
||||
|
||||
|
|
|
|||
|
|
@ -474,16 +474,42 @@ export default function FormImageDetail() {
|
|||
const currentSelection = { ...newSelections[fileIndex] };
|
||||
|
||||
if (key === "semua") {
|
||||
// Jika klik Semua, set semua value ke true/false
|
||||
// Jika klik Semua
|
||||
currentSelection.semua = value;
|
||||
|
||||
// ✅ Tetap berlaku untuk semua kondisi
|
||||
currentSelection.nasional = value;
|
||||
currentSelection.wilayah = 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.polres = value;
|
||||
currentSelection.satker = value;
|
||||
|
||||
// Update fileCheckedLevels untuk sinkronisasi dengan modal
|
||||
// LOGIC LAMA modal
|
||||
setFileCheckedLevels((prevLevels) => {
|
||||
const newArray = [...prevLevels];
|
||||
const currentFileLevels = new Set<number>(
|
||||
|
|
@ -491,7 +517,6 @@ export default function FormImageDetail() {
|
|||
);
|
||||
|
||||
if (value) {
|
||||
// Checklist semua item di modal
|
||||
listDest.forEach((item: any) => {
|
||||
currentFileLevels.add(Number(item.id));
|
||||
if (item.subDestination) {
|
||||
|
|
@ -501,15 +526,17 @@ export default function FormImageDetail() {
|
|||
}
|
||||
});
|
||||
} else {
|
||||
// Unchecklist semua item di modal
|
||||
currentFileLevels.clear();
|
||||
}
|
||||
|
||||
newArray[fileIndex] = currentFileLevels;
|
||||
return newArray;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Validasi khusus untuk POLRES - harus ada POLDA yang ter-checklist
|
||||
// 🔁 SELURUH LOGIC LAMA — TIDAK DISENTUH
|
||||
|
||||
// Validasi khusus untuk POLRES
|
||||
if (key === "polres" && value) {
|
||||
const currentFileCheckedLevels = fileCheckedLevels[fileIndex];
|
||||
const hasSelectedPolda =
|
||||
|
|
@ -525,14 +552,12 @@ export default function FormImageDetail() {
|
|||
alert(
|
||||
"Harap pilih POLDA di Modal terlebih dahulu sebelum mengaktifkan checkbox POLRES."
|
||||
);
|
||||
return prev; // Batalkan perubahan
|
||||
return prev;
|
||||
}
|
||||
}
|
||||
|
||||
// Update salah satu saja
|
||||
currentSelection[key] = value;
|
||||
|
||||
// Cek apakah semua selain "semua" sudah dicentang
|
||||
const allChecked = [
|
||||
"nasional",
|
||||
"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)
|
||||
const handleUnitChange = (
|
||||
key: keyof typeof unitSelection,
|
||||
|
|
@ -1088,8 +1199,14 @@ export default function FormImageDetail() {
|
|||
) => {
|
||||
let temp = [...filePlacements];
|
||||
if (checked) {
|
||||
// if (placement === "all") {
|
||||
// temp[index] = ["all", "mabes", "polda", "international"];
|
||||
if (placement === "all") {
|
||||
if (isUploadedBySatkerLevel3) {
|
||||
temp[index] = ["mabes", "international"];
|
||||
} else {
|
||||
temp[index] = ["all", "mabes", "polda", "international"];
|
||||
}
|
||||
|
||||
// Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik
|
||||
setFileCheckedLevels((prevLevels) => {
|
||||
|
|
@ -1359,6 +1476,9 @@ export default function FormImageDetail() {
|
|||
// console.log("portrai", portraitMap);
|
||||
}, [portraitMap]);
|
||||
|
||||
const isUploadedBySatkerLevel3 =
|
||||
Number(detail?.uploadedBy?.userLevel?.levelNumber) === 3;
|
||||
|
||||
return (
|
||||
<form>
|
||||
{detail !== undefined ? (
|
||||
|
|
@ -1741,7 +1861,15 @@ export default function FormImageDetail() {
|
|||
key: "international",
|
||||
label: "Internasional",
|
||||
},
|
||||
].map((item, idx) => (
|
||||
]
|
||||
.filter(
|
||||
(item) =>
|
||||
!(
|
||||
isUploadedBySatkerLevel3 &&
|
||||
item.key === "wilayah"
|
||||
)
|
||||
)
|
||||
.map((item) => (
|
||||
<div
|
||||
key={item.key}
|
||||
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>
|
||||
</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>
|
||||
|
||||
{/* Detail Wilayah */}
|
||||
{fileUnitSelections[index]?.wilayah && (
|
||||
{fileUnitSelections[index]?.wilayah &&
|
||||
!isUploadedBySatkerLevel3 && (
|
||||
<div className="border-t border-gray-200 pt-2">
|
||||
<p className="text-sm font-medium text-gray-700 mb-2">
|
||||
Detail Wilayah:
|
||||
|
|
@ -1846,7 +2017,8 @@ export default function FormImageDetail() {
|
|||
<DialogContent className="max-w-[95vw] lg:max-w-[1400px] max-h-[90vh]">
|
||||
<DialogHeader className="border-b border-gray-200 pb-4">
|
||||
<DialogTitle className="text-lg font-semibold">
|
||||
Daftar Wilayah POLDA dan POLRES
|
||||
Daftar Wilayah POLDA dan
|
||||
POLRES
|
||||
</DialogTitle>
|
||||
</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">
|
||||
|
|
@ -1905,7 +2077,9 @@ export default function FormImageDetail() {
|
|||
|
||||
{/* Sub-items */}
|
||||
{polda.subDestination &&
|
||||
expandedPolda[polda.id] && (
|
||||
expandedPolda[
|
||||
polda.id
|
||||
] && (
|
||||
<div className="max-h-[200px] overflow-y-auto border-t border-gray-100 pt-2">
|
||||
{/* Tombol Pilih Semua untuk sub-items */}
|
||||
<div className="mb-2 flex justify-start">
|
||||
|
|
@ -1937,25 +2111,31 @@ export default function FormImageDetail() {
|
|||
<>
|
||||
<Icon
|
||||
icon="material-symbols:check-indeterminate-small"
|
||||
width={12}
|
||||
width={
|
||||
12
|
||||
}
|
||||
height={
|
||||
12
|
||||
}
|
||||
className="mr-1"
|
||||
/>
|
||||
Batal Semua
|
||||
Batal
|
||||
Semua
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Icon
|
||||
icon="material-symbols:check-all"
|
||||
width={12}
|
||||
width={
|
||||
12
|
||||
}
|
||||
height={
|
||||
12
|
||||
}
|
||||
className="mr-1"
|
||||
/>
|
||||
Pilih Semua
|
||||
Pilih
|
||||
Semua
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
|
|
|
|||
|
|
@ -207,16 +207,36 @@ export default function FormTeksDetail() {
|
|||
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;
|
||||
|
||||
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.polres = value;
|
||||
currentSelection.satker = value;
|
||||
|
||||
// Update fileCheckedLevels untuk sinkronisasi dengan modal
|
||||
setFileCheckedLevels((prevLevels) => {
|
||||
const newArray = [...prevLevels];
|
||||
const currentFileLevels = new Set<number>(
|
||||
|
|
@ -224,7 +244,6 @@ export default function FormTeksDetail() {
|
|||
);
|
||||
|
||||
if (value) {
|
||||
// Checklist semua item di modal
|
||||
listDest.forEach((item: any) => {
|
||||
currentFileLevels.add(Number(item.id));
|
||||
if (item.subDestination) {
|
||||
|
|
@ -234,15 +253,14 @@ export default function FormTeksDetail() {
|
|||
}
|
||||
});
|
||||
} 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 =
|
||||
|
|
@ -258,14 +276,12 @@ export default function FormTeksDetail() {
|
|||
alert(
|
||||
"Harap pilih POLDA di Modal terlebih dahulu sebelum mengaktifkan checkbox POLRES."
|
||||
);
|
||||
return prev; // Batalkan perubahan
|
||||
return prev;
|
||||
}
|
||||
}
|
||||
|
||||
// Update salah satu saja
|
||||
currentSelection[key] = value;
|
||||
|
||||
// Cek apakah semua selain "semua" sudah dicentang
|
||||
const allChecked = [
|
||||
"nasional",
|
||||
"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";
|
||||
|
||||
const toggleExpand = (id: number) => {
|
||||
|
|
@ -725,8 +827,15 @@ export default function FormTeksDetail() {
|
|||
) => {
|
||||
let temp = [...filePlacements];
|
||||
if (checked) {
|
||||
// if (placement === "all") {
|
||||
// temp[index] = ["all", "mabes", "polda", "international"];
|
||||
|
||||
if (placement === "all") {
|
||||
if (isUploadedBySatkerLevel3) {
|
||||
temp[index] = ["mabes", "international"];
|
||||
} else {
|
||||
temp[index] = ["all", "mabes", "polda", "international"];
|
||||
}
|
||||
|
||||
// Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik
|
||||
setFileCheckedLevels((prevLevels) => {
|
||||
|
|
@ -1126,6 +1235,9 @@ export default function FormTeksDetail() {
|
|||
});
|
||||
};
|
||||
|
||||
const isUploadedBySatkerLevel3 =
|
||||
Number(detail?.uploadedBy?.userLevel?.levelNumber) === 3;
|
||||
|
||||
return (
|
||||
<form>
|
||||
{detail !== undefined ? (
|
||||
|
|
@ -1471,7 +1583,15 @@ export default function FormTeksDetail() {
|
|||
key: "international",
|
||||
label: "Internasional",
|
||||
},
|
||||
].map((item, idx) => (
|
||||
]
|
||||
.filter(
|
||||
(item) =>
|
||||
!(
|
||||
isUploadedBySatkerLevel3 &&
|
||||
item.key === "wilayah"
|
||||
)
|
||||
)
|
||||
.map((item) => (
|
||||
<div
|
||||
key={item.key}
|
||||
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>
|
||||
</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>
|
||||
|
||||
|
|
|
|||
|
|
@ -210,16 +210,36 @@ export default function FormVideoDetail() {
|
|||
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;
|
||||
|
||||
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.polres = value;
|
||||
currentSelection.satker = value;
|
||||
|
||||
// Update fileCheckedLevels untuk sinkronisasi dengan modal
|
||||
setFileCheckedLevels((prevLevels) => {
|
||||
const newArray = [...prevLevels];
|
||||
const currentFileLevels = new Set<number>(
|
||||
|
|
@ -227,7 +247,6 @@ export default function FormVideoDetail() {
|
|||
);
|
||||
|
||||
if (value) {
|
||||
// Checklist semua item di modal
|
||||
listDest.forEach((item: any) => {
|
||||
currentFileLevels.add(Number(item.id));
|
||||
if (item.subDestination) {
|
||||
|
|
@ -237,15 +256,14 @@ export default function FormVideoDetail() {
|
|||
}
|
||||
});
|
||||
} 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 =
|
||||
|
|
@ -261,14 +279,12 @@ export default function FormVideoDetail() {
|
|||
alert(
|
||||
"Harap pilih POLDA di Modal terlebih dahulu sebelum mengaktifkan checkbox POLRES."
|
||||
);
|
||||
return prev; // Batalkan perubahan
|
||||
return prev;
|
||||
}
|
||||
}
|
||||
|
||||
// Update salah satu saja
|
||||
currentSelection[key] = value;
|
||||
|
||||
// Cek apakah semua selain "semua" sudah dicentang
|
||||
const allChecked = [
|
||||
"nasional",
|
||||
"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";
|
||||
|
||||
const toggleExpand = (id: number) => {
|
||||
|
|
@ -690,8 +792,15 @@ export default function FormVideoDetail() {
|
|||
) => {
|
||||
let temp = [...filePlacements];
|
||||
if (checked) {
|
||||
// if (placement === "all") {
|
||||
// temp[index] = ["all", "mabes", "polda", "international"];
|
||||
|
||||
if (placement === "all") {
|
||||
if (isUploadedBySatkerLevel3) {
|
||||
temp[index] = ["mabes", "international"];
|
||||
} else {
|
||||
temp[index] = ["all", "mabes", "polda", "international"];
|
||||
}
|
||||
|
||||
// Update fileCheckedLevels untuk sinkronisasi dengan modal ketika "all" diklik
|
||||
setFileCheckedLevels((prevLevels) => {
|
||||
|
|
@ -1128,6 +1237,9 @@ export default function FormVideoDetail() {
|
|||
});
|
||||
};
|
||||
|
||||
const isUploadedBySatkerLevel3 =
|
||||
Number(detail?.uploadedBy?.userLevel?.levelNumber) === 3;
|
||||
|
||||
return (
|
||||
<form>
|
||||
{detail !== undefined ? (
|
||||
|
|
@ -1475,7 +1587,15 @@ export default function FormVideoDetail() {
|
|||
key: "international",
|
||||
label: "Internasional",
|
||||
},
|
||||
].map((item, idx) => (
|
||||
]
|
||||
.filter(
|
||||
(item) =>
|
||||
!(
|
||||
isUploadedBySatkerLevel3 &&
|
||||
item.key === "wilayah"
|
||||
)
|
||||
)
|
||||
.map((item) => (
|
||||
<div
|
||||
key={item.key}
|
||||
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>
|
||||
</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>
|
||||
|
||||
{/* Detail Wilayah */}
|
||||
{fileUnitSelections[index]?.wilayah && (
|
||||
{fileUnitSelections[index]?.wilayah &&
|
||||
!isUploadedBySatkerLevel3 && (
|
||||
<div className="border-t border-gray-200 pt-2">
|
||||
<p className="text-sm font-medium text-gray-700 mb-2">
|
||||
Detail Wilayah:
|
||||
|
|
@ -1580,7 +1743,8 @@ export default function FormVideoDetail() {
|
|||
<DialogContent className="max-w-[95vw] lg:max-w-[1400px] max-h-[90vh]">
|
||||
<DialogHeader className="border-b border-gray-200 pb-4">
|
||||
<DialogTitle className="text-lg font-semibold">
|
||||
Daftar Wilayah POLDA dan POLRES
|
||||
Daftar Wilayah POLDA dan
|
||||
POLRES
|
||||
</DialogTitle>
|
||||
</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">
|
||||
|
|
@ -1639,7 +1803,9 @@ export default function FormVideoDetail() {
|
|||
|
||||
{/* Sub-items */}
|
||||
{polda.subDestination &&
|
||||
expandedPolda[polda.id] && (
|
||||
expandedPolda[
|
||||
polda.id
|
||||
] && (
|
||||
<div className="max-h-[200px] overflow-y-auto border-t border-gray-100 pt-2">
|
||||
{/* Tombol Pilih Semua untuk sub-items */}
|
||||
<div className="mb-2 flex justify-start">
|
||||
|
|
@ -1671,25 +1837,31 @@ export default function FormVideoDetail() {
|
|||
<>
|
||||
<Icon
|
||||
icon="material-symbols:check-indeterminate-small"
|
||||
width={12}
|
||||
width={
|
||||
12
|
||||
}
|
||||
height={
|
||||
12
|
||||
}
|
||||
className="mr-1"
|
||||
/>
|
||||
Batal Semua
|
||||
Batal
|
||||
Semua
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Icon
|
||||
icon="material-symbols:check-all"
|
||||
width={12}
|
||||
width={
|
||||
12
|
||||
}
|
||||
height={
|
||||
12
|
||||
}
|
||||
className="mr-1"
|
||||
/>
|
||||
Pilih Semua
|
||||
Pilih
|
||||
Semua
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
|
|
|
|||
Loading…
Reference in New Issue