feat:add checkbox all SPIT

This commit is contained in:
Anang Yusman 2025-03-03 13:59:42 +08:00
parent ca1ab00b9a
commit 6504adfcc3
2 changed files with 90 additions and 0 deletions

View File

@ -394,6 +394,33 @@ export default function FormConvertSPIT() {
return temp; return temp;
}; };
// const setupPlacement = (
// index: number,
// category: string,
// isChecked: boolean
// ) => {
// setFilePlacements((prev) =>
// prev.map((placement, i) =>
// i === index
// ? isChecked
// ? [...new Set([...placement, category])] // Tambahkan kategori jika belum ada
// : placement.filter((item) => item !== category) // Hapus kategori jika ada
// : placement
// )
// );
// };
const handleSelectAll = (category: string, isChecked: boolean) => {
setFilePlacements((prev: string[][]) =>
prev.map(
(placement: string[]) =>
isChecked
? Array.from(new Set([...placement, category])) // Konversi Set ke array dengan Array.from()
: placement.filter((item: string) => item !== category) // Hapus jika ada
)
);
};
const save = async (data: { const save = async (data: {
contentTitle: string; contentTitle: string;
contentDescription: string; contentDescription: string;
@ -785,6 +812,66 @@ export default function FormConvertSPIT() {
<div className="mt-3"> <div className="mt-3">
<Label className="text-xl">Penempatan file</Label> <Label className="text-xl">Penempatan file</Label>
</div> </div>
{files.length > 1 && (
<div className="flex flex-wrap gap-2 mt-2">
<div className="flex items-center space-x-2">
<Checkbox
id="all-content"
onCheckedChange={(e) =>
handleSelectAll("all", Boolean(e))
}
/>
<label
htmlFor="all-content"
className="text-xs font-medium"
>
All
</label>
</div>
<div className="flex items-center space-x-2">
<Checkbox
id="all-nasional"
onCheckedChange={(e) =>
handleSelectAll("mabes", Boolean(e))
}
/>
<label
htmlFor="all-nasional"
className="text-xs font-medium"
>
All Nasional
</label>
</div>
<div className="flex items-center space-x-2">
<Checkbox
id="all-wilayah"
onCheckedChange={(e) =>
handleSelectAll("polda", Boolean(e))
}
/>
<label
htmlFor="all-wilayah"
className="text-xs font-medium"
>
All Wilayah
</label>
</div>
<div className="flex items-center space-x-2">
<Checkbox
id="all-international"
onCheckedChange={(e) =>
handleSelectAll("international", Boolean(e))
}
/>
<label
htmlFor="all-international"
className="text-xs font-medium"
>
All Internasional
</label>
</div>
</div>
)}
{files?.map((file, index) => ( {files?.map((file, index) => (
<div <div
key={file.contentId} key={file.contentId}

View File

@ -150,6 +150,7 @@ export default function FormContestDetail() {
mabes: false, mabes: false,
polda: false, polda: false,
polres: false, polres: false,
satker: false,
}); });
const { const {
@ -231,6 +232,7 @@ export default function FormContestDetail() {
mabes: outputSet.has(1), mabes: outputSet.has(1),
polda: outputSet.has(2), polda: outputSet.has(2),
polres: outputSet.has(3), polres: outputSet.has(3),
satker: outputSet.has(4),
}); });
} }
}, [detail?.targetOutput]); }, [detail?.targetOutput]);
@ -265,6 +267,7 @@ export default function FormContestDetail() {
mabes: "1", mabes: "1",
polda: "2", polda: "2",
polres: "3", polres: "3",
satker: "4",
}; };
const assignmentPurposeString = Object.keys(unitSelection) const assignmentPurposeString = Object.keys(unitSelection)