Added the ability to create groups

This commit is contained in:
Tiago Ribeiro
2023-09-28 11:40:01 +01:00
parent 7af607d476
commit 75fb6ab197
10 changed files with 755 additions and 6 deletions

21
src/hooks/useGroups.tsx Normal file
View 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};
}