33 lines
754 B
TypeScript
33 lines
754 B
TypeScript
|
|
import { useEffect, useState } from "react";
|
||
|
|
import {
|
||
|
|
QuizStatisticResponse,
|
||
|
|
getStatistic
|
||
|
|
} from "@root/api/quizStatistic";
|
||
|
|
|
||
|
|
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 | null>({ Registrations: 0, Quizes: 0, Results: 0 });
|
||
|
|
|
||
|
|
useEffect(() => {
|
||
|
|
|
||
|
|
const requestStatistics = async () => {
|
||
|
|
|
||
|
|
const gottenData = await getStatistic(Number(formatTo), Number(formatFrom));
|
||
|
|
setData(gottenData)
|
||
|
|
}
|
||
|
|
|
||
|
|
requestStatistics();
|
||
|
|
}, [to, from]);
|
||
|
|
|
||
|
|
return { ...data };
|
||
|
|
}
|