+
+ {JSON.stringify(selectedFiles)}
+
>} />
({});
const [selectAll, setSelectAll] = useState(false);
+ const [isData, setIsData] = useState([])
+ const memberGroup = useHookstate(globalMemberAnnouncement)
- const handleCheck = (group: string, division: string) => {
+ const handleCheck = (groupId: string, divisionId: string) => {
const newChecked = { ...checked };
- if (newChecked[group]) {
- if (newChecked[group].includes(division)) {
- newChecked[group] = newChecked[group].filter(item => item !== division);
+ if (newChecked[groupId]) {
+ if (newChecked[groupId].includes(divisionId)) {
+ newChecked[groupId] = newChecked[groupId].filter(item => item !== divisionId);
} else {
- newChecked[group].push(division);
+ newChecked[groupId].push(divisionId);
}
} else {
- newChecked[group] = [division];
+ newChecked[groupId] = [divisionId];
}
setChecked(newChecked);
console.log(newChecked)
};
- const handleGroupCheck = (group: string) => {
+ const handleGroupCheck = (groupId: string) => {
const newChecked = { ...checked };
- if (newChecked[group]) {
- delete newChecked[group];
+ if (newChecked[groupId]) {
+ delete newChecked[groupId];
} else {
- newChecked[group] = groupData.find(item => item.group === group)?.divisions || [];
+ newChecked[groupId] = isData.find(item => item.id === groupId)?.Division.map(item => item.id) || [];
}
setChecked(newChecked);
console.log(newChecked)
@@ -58,8 +51,8 @@ export default function CreateUsersAnnouncement() {
setSelectAll(!selectAll);
if (!selectAll) {
const newChecked: CheckedState = {};
- groupData.forEach(item => {
- newChecked[item.group] = item.divisions;
+ isData.forEach(item => {
+ newChecked[item.id] = item.Division.map(division => division.id);
});
setChecked(newChecked);
console.log(newChecked)
@@ -68,6 +61,25 @@ export default function CreateUsersAnnouncement() {
}
};
+ async function getData() {
+ const response = await funGetGroupDivision()
+ console.log(response)
+ setIsData(response.data)
+ }
+ const handleSubmit = () => {
+ const selectedGroups: GroupData[] = [];
+ Object.keys(checked).forEach((groupId) => {
+ if (checked[groupId]) {
+ selectedGroups.push();
+ }
+ });
+ memberGroup.set(selectedGroups);
+ };
+
+ useShallowEffect(() => {
+ getData()
+ }, [])
+
return (
>} />
@@ -85,42 +97,52 @@ export default function CreateUsersAnnouncement() {
Pilih Semua
- {groupData.map((item) => (
-
- handleGroupCheck(item.group)} justify='space-between' align='center'>
+ {isData.map((item) => (
+
+ handleGroupCheck(item.id)} justify='space-between' align='center'>
- {item.group}
+ {item.name}
- {checked[item.group] && checked[item.group].length === item.divisions.length ? : ""}
+ {checked[item.id] && checked[item.id].length === item.Division.length ? : ""}
-
- {item.divisions.map((division) => (
-
- handleCheck(item.group, division)}
- style={{
- cursor: 'pointer',
- display: 'flex',
- alignItems: 'center',
- paddingLeft: 20,
- }}
- >
- {checked[item.group] && checked[item.group].includes(division) ? : ""}
- {division}
-
+
+ {item.Division.map((division) => (
+
+ handleCheck(item.id, division.id)} justify='space-between' align='center'>
+
+ {division.name}
+
+
+ {checked[item.id] && checked[item.id].includes(division.id) ? : ""}
+
+
-
-
+
+
))}
@@ -131,11 +153,12 @@ export default function CreateUsersAnnouncement() {