Updated the groups section for the teachers and admins
This commit is contained in:
@@ -10,8 +10,13 @@ export default function useGroups(admin?: string) {
|
||||
const getData = () => {
|
||||
setIsLoading(true);
|
||||
axios
|
||||
.get<Group[]>(!admin ? "/api/groups" : `/api/groups?admin=${admin}`)
|
||||
.then((response) => setGroups(response.data))
|
||||
.get<Group[]>("/api/groups")
|
||||
.then((response) => {
|
||||
const filter = (g: Group) => g.admin === admin || g.participants.includes(admin || "");
|
||||
|
||||
const filteredGroups = admin ? response.data.filter(filter) : response.data;
|
||||
return setGroups(admin ? filteredGroups.map((g) => ({...g, disableEditing: g.disableEditing || g.admin !== admin})) : filteredGroups);
|
||||
})
|
||||
.finally(() => setIsLoading(false));
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user