From cbce18f5f7e06150c3f227d2314a85a9d34fef0b Mon Sep 17 00:00:00 2001 From: jenny-s51 Date: Tue, 20 Apr 2021 11:08:33 -0400 Subject: [PATCH] navigate to subgroups in modal --- src/user/JoinGroupDialog.tsx | 70 ++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 39 deletions(-) diff --git a/src/user/JoinGroupDialog.tsx b/src/user/JoinGroupDialog.tsx index 318db6c744..8c473c1fce 100644 --- a/src/user/JoinGroupDialog.tsx +++ b/src/user/JoinGroupDialog.tsx @@ -63,52 +63,44 @@ export const JoinGroupDialog = ({ const { id } = useParams<{ id: string }>(); - if (id) { - useEffect( - () => - asyncStateFetch( - async () => { + useEffect( + () => + asyncStateFetch( + 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({ id, }); - const allGroups = await adminClient.groups.find(); - if (groupId) { - const group = await adminClient.groups.findOne({ id: groupId }); - return { group, groups: group.subGroups! }; - } else { - return { - groups: _.differenceBy(allGroups, existingUserGroups, "id"), - }; - } - }, - 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()); + return { + groups: _.differenceBy(allGroups, existingUserGroups, "id"), + }; + } else + return { + groups: allGroups, + }; }, - (groups) => { - setGroups([...groups.filter((row) => !chips.includes(row.name))]); + async ({ group: selectedGroup, groups }) => { + 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 - ); - }, []); - } + ), + [groupId] + ); return (