Added a new card for the Corporate to show their user balance

This commit is contained in:
Tiago Ribeiro
2024-01-20 15:09:42 +00:00
parent 9773f1da72
commit 8eb8a7af46
6 changed files with 75 additions and 6 deletions

21
src/hooks/useCodes.tsx Normal file
View File

@@ -0,0 +1,21 @@
import {Code, Group, User} from "@/interfaces/user";
import axios from "axios";
import {useEffect, useState} from "react";
export default function useCodes(creator?: string) {
const [codes, setCodes] = useState<Code[]>([]);
const [isLoading, setIsLoading] = useState(false);
const [isError, setIsError] = useState(false);
const getData = () => {
setIsLoading(true);
axios
.get<Code[]>(`/api/code${creator ? `?creator=${creator}` : ""}`)
.then((response) => setCodes(response.data))
.finally(() => setIsLoading(false));
};
useEffect(getData, [creator]);
return {codes, isLoading, isError, reload: getData};
}