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