35 lines
770 B
TypeScript
35 lines
770 B
TypeScript
import { useEffect, useState } from "react";
|
|
import { QuizStatisticResponse, getStatistic } from "@root/api/quizStatistics";
|
|
|
|
import type { Moment } from "moment";
|
|
|
|
interface useQuizStatisticProps {
|
|
to: Moment | null;
|
|
from: Moment | null;
|
|
}
|
|
|
|
export function useQuizStatistic({ to, from }: useQuizStatisticProps) {
|
|
const formatTo = to?.unix();
|
|
const formatFrom = from?.unix();
|
|
|
|
const [data, setData] = useState<QuizStatisticResponse>({
|
|
Registrations: 0,
|
|
Quizes: 0,
|
|
Results: 0,
|
|
});
|
|
|
|
useEffect(() => {
|
|
const requestStatistics = async () => {
|
|
const [gottenData] = await getStatistic(Number(formatTo), Number(formatFrom));
|
|
|
|
if (gottenData) {
|
|
setData(gottenData);
|
|
}
|
|
};
|
|
|
|
requestStatistics();
|
|
}, [formatTo, formatFrom]);
|
|
|
|
return { ...data };
|
|
}
|