navigate to subgroups in modal
This commit is contained in:
parent
033388bb67
commit
cbce18f5f7
1 changed files with 31 additions and 39 deletions
|
@ -63,52 +63,44 @@ export const JoinGroupDialog = ({
|
||||||
|
|
||||||
const { id } = useParams<{ id: string }>();
|
const { id } = useParams<{ id: string }>();
|
||||||
|
|
||||||
if (id) {
|
useEffect(
|
||||||
useEffect(
|
() =>
|
||||||
() =>
|
asyncStateFetch(
|
||||||
asyncStateFetch(
|
async () => {
|
||||||
async () => {
|
const allGroups = await adminClient.groups.find();
|
||||||
|
|
||||||
|
if (groupId) {
|
||||||
|
const group = await adminClient.groups.findOne({ id: groupId });
|
||||||
|
return { group, groups: group.subGroups! };
|
||||||
|
} else if (id) {
|
||||||
const existingUserGroups = await adminClient.users.listGroups({
|
const existingUserGroups = await adminClient.users.listGroups({
|
||||||
id,
|
id,
|
||||||
});
|
});
|
||||||
const allGroups = await adminClient.groups.find();
|
|
||||||
|
|
||||||
if (groupId) {
|
return {
|
||||||
const group = await adminClient.groups.findOne({ id: groupId });
|
groups: _.differenceBy(allGroups, existingUserGroups, "id"),
|
||||||
return { group, groups: group.subGroups! };
|
};
|
||||||
} else {
|
} else
|
||||||
return {
|
return {
|
||||||
groups: _.differenceBy(allGroups, existingUserGroups, "id"),
|
groups: allGroups,
|
||||||
};
|
};
|
||||||
}
|
|
||||||
},
|
|
||||||
async ({ group: selectedGroup, groups }) => {
|
|
||||||
if (selectedGroup) {
|
|
||||||
setNavigation([...navigation, selectedGroup]);
|
|
||||||
}
|
|
||||||
|
|
||||||
groups.forEach((group: Group) => {
|
|
||||||
group.checked = !!selectedRows.find((r) => r.id === group.id);
|
|
||||||
});
|
|
||||||
setGroups(groups);
|
|
||||||
},
|
|
||||||
errorHandler
|
|
||||||
),
|
|
||||||
[groupId]
|
|
||||||
);
|
|
||||||
} else if (!id) {
|
|
||||||
useEffect(() => {
|
|
||||||
return asyncStateFetch(
|
|
||||||
() => {
|
|
||||||
return Promise.resolve(adminClient.groups.find());
|
|
||||||
},
|
},
|
||||||
(groups) => {
|
async ({ group: selectedGroup, groups }) => {
|
||||||
setGroups([...groups.filter((row) => !chips.includes(row.name))]);
|
if (selectedGroup) {
|
||||||
|
setNavigation([...navigation, selectedGroup]);
|
||||||
|
}
|
||||||
|
|
||||||
|
groups.forEach((group: Group) => {
|
||||||
|
group.checked = !!selectedRows.find((r) => r.id === group.id);
|
||||||
|
});
|
||||||
|
id
|
||||||
|
? setGroups(groups)
|
||||||
|
: setGroups([...groups.filter((row) => !chips.includes(row.name))]);
|
||||||
},
|
},
|
||||||
errorHandler
|
errorHandler
|
||||||
);
|
),
|
||||||
}, []);
|
[groupId]
|
||||||
}
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
|
|
Loading…
Reference in a new issue