diff --git a/components/modalSelectMultiple.tsx b/components/modalSelectMultiple.tsx
index ebebbd7..2d8b628 100644
--- a/components/modalSelectMultiple.tsx
+++ b/components/modalSelectMultiple.tsx
@@ -128,6 +128,35 @@ export default function ModalSelectMultiple({ open, close, title, category, choo
};
+ const groupsWithDivisions = data.filter((group: any) => group.Division?.length > 0)
+ const isAllSelected = category === 'choose-division'
+ ? groupsWithDivisions.length > 0 && groupsWithDivisions.every((group: any) =>
+ checked[group.id]?.length === group.Division?.length
+ )
+ : data.length > 0 && selectedDivision.length === data.length
+
+ const handleSelectAll = () => {
+ if (category === 'choose-division') {
+ if (isAllSelected) {
+ setChecked({})
+ } else {
+ const newChecked: CheckedState = {}
+ data.forEach((group: any) => {
+ if (group.Division?.length > 0) {
+ newChecked[group.id] = group.Division.map((d: any) => d.id)
+ }
+ })
+ setChecked(newChecked)
+ }
+ } else {
+ if (isAllSelected) {
+ setSelectedDivision([])
+ } else {
+ setSelectedDivision(data.map((d: any) => ({ id: d.id, name: d.name })))
+ }
+ }
+ }
+
const handleSubmit = () => {
if (category == "choose-division") {
const selectedGroups: GroupData[] = [];
@@ -154,25 +183,32 @@ export default function ModalSelectMultiple({ open, close, title, category, choo
{
category == 'share-division' ?
<>
- {
- data.map((item: any, index: number) => {
- return (
- {
- handleDivisionClick(index)
- }}>
- {item.name}
- {
- selectedDivision.some((i: any) => i.id == item.id)
- ?
- : <>>
- }
-
- )
- })
- }
+
+ {isAllSelected ? 'Batalkan Semua' : 'Pilih Semua'}
+ {isAllSelected && }
+
+ {data.map((item: any, index: number) => {
+ return (
+ {
+ handleDivisionClick(index)
+ }}>
+ {item.name}
+ {
+ selectedDivision.some((i: any) => i.id == item.id)
+ ?
+ : <>>
+ }
+
+ )
+ })}
>
:
- data.map((item: any, index: number) => {
+ <>
+
+ {isAllSelected ? 'Batalkan Semua' : 'Pilih Semua'}
+ {isAllSelected && }
+
+ {data.map((item: any, index: number) => {
return (
{ handleGroupCheck(item.id) }}>
@@ -199,7 +235,8 @@ export default function ModalSelectMultiple({ open, close, title, category, choo
}
)
- })
+ })}
+ >
}
@@ -207,4 +244,4 @@ export default function ModalSelectMultiple({ open, close, title, category, choo
)
-}
\ No newline at end of file
+}