Added the ability to create groups
This commit is contained in:
21
src/hooks/useGroups.tsx
Normal file
21
src/hooks/useGroups.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import {Group, User} from "@/interfaces/user";
|
||||
import axios from "axios";
|
||||
import {useEffect, useState} from "react";
|
||||
|
||||
export default function useGroups(admin?: string) {
|
||||
const [groups, setGroups] = useState<Group[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [isError, setIsError] = useState(false);
|
||||
|
||||
const getData = () => {
|
||||
setIsLoading(true);
|
||||
axios
|
||||
.get<Group[]>(!admin ? "/api/groups" : `/api/groups?admin=${admin}`)
|
||||
.then((response) => setGroups(response.data))
|
||||
.finally(() => setIsLoading(false));
|
||||
};
|
||||
|
||||
useEffect(getData, [admin]);
|
||||
|
||||
return {groups, isLoading, isError, reload: getData};
|
||||
}
|
||||
Reference in New Issue
Block a user