23 lines
722 B
TypeScript
23 lines
722 B
TypeScript
import { Grading } from "@/interfaces";
|
|
import { Code, Group, User } from "@/interfaces/user";
|
|
import axios from "axios";
|
|
import { useEffect, useState } from "react";
|
|
|
|
export default function useGradingSystem(entity: string) {
|
|
const [gradingSystem, setGradingSystem] = useState<Grading>();
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const [isError, setIsError] = useState(false);
|
|
|
|
const getData = () => {
|
|
setIsLoading(true);
|
|
axios
|
|
.get<Grading>(`/api/grading?entity=${entity}`)
|
|
.then((response) => setGradingSystem(response.data))
|
|
.finally(() => setIsLoading(false));
|
|
};
|
|
|
|
useEffect(getData, [entity]);
|
|
|
|
return { gradingSystem, isLoading, isError, reload: getData, mutate: setGradingSystem };
|
|
}
|