diff --git a/src/pages/(admin)/Lists/GroupList.tsx b/src/pages/(admin)/Lists/GroupList.tsx index 15ec371b..2c0aea9c 100644 --- a/src/pages/(admin)/Lists/GroupList.tsx +++ b/src/pages/(admin)/Lists/GroupList.tsx @@ -10,19 +10,12 @@ import {createColumnHelper, flexRender, getCoreRowModel, useReactTable} from "@t import axios from "axios"; import clsx from "clsx"; import {capitalize} from "lodash"; -import {useState} from "react"; +import {useEffect, useState} from "react"; import {BsDash, BsPlus, BsTrash} from "react-icons/bs"; import {toast} from "react-toastify"; import Select from "react-select"; import {uuidv4} from "@firebase/util"; -const CLASSES: {[key in Module]: string} = { - reading: "text-ielts-reading", - listening: "text-ielts-listening", - speaking: "text-ielts-speaking", - writing: "text-ielts-writing", -}; - const columnHelper = createColumnHelper(); interface CreateDialogProps { @@ -92,8 +85,16 @@ const CreatePanel = ({user, users, onCreate}: CreateDialogProps) => { }; export default function GroupList({user}: {user: User}) { + const [filterByUser, setFilterByUser] = useState(false); + const {users} = useUsers(); - const {groups, reload} = useGroups(user.type === "admin" || user.type === "teacher" ? user.id : undefined); + const {groups, reload} = useGroups(filterByUser ? user.id : undefined); + + useEffect(() => { + if (user && (user.type === "admin" || user.type === "teacher")) { + setFilterByUser(true); + } + }, [user]); const createGroup = (group: Group) => { return axios