diff --git a/src/app/(dashboard)/karyawan/page.tsx b/src/app/(dashboard)/karyawan/page.tsx index c53be00..cf92f61 100644 --- a/src/app/(dashboard)/karyawan/page.tsx +++ b/src/app/(dashboard)/karyawan/page.tsx @@ -1,16 +1,40 @@ "use client" import { useAppSelector } from "@/lib/hooks"; -import { useGetEmployeeSummaryQuery, useGetMonthlyEmployeeQuery } from "@/services/api"; +import { useGetEmployeeSummaryQuery, useGetMonthlyEmployeeQuery, useGetSanctionSummaryQuery } from "@/services/api"; import { ExclamationCircleIcon } from "@heroicons/react/24/outline"; import { BarChart, ChartsLegend, ChartsTooltip, ChartsXAxis, ChartsYAxis, LineChart } from "@mui/x-charts"; import { formatDate } from "date-fns"; -import { useEffect } from "react"; +import { useEffect, useState } from "react"; export default function KaryawanPage() { const filter = useAppSelector(state => state.filter.filter); - const {data: employeeSummary} = useGetEmployeeSummaryQuery(filter); - const {data: montlyEmployee} = useGetMonthlyEmployeeQuery(filter); + const {data: employeeSummary, isFetching : loadingSummary} = useGetEmployeeSummaryQuery(filter); + const {data: montlyEmployee, isFetching : loadingMonthly} = useGetMonthlyEmployeeQuery(filter); + const {data: sanctionSummary, isFetching: loadingSanction} = useGetSanctionSummaryQuery(filter); + const [totalSanctions, setTotalSanctions] = useState<{ + type: string; + count: number; + }[]>([]); + + useEffect(() => { + if (sanctionSummary) { + const tmp = sanctionSummary.reduce((acc, curr) => { + acc.push({type: "st", count: curr.st}); + acc.push({type: "sp1", count: curr.sp1}); + acc.push({type: "sp2", count: curr.sp2}); + acc.push({type: "sp3", count: curr.sp3}); + acc.push({type: "phk", count: curr.phk}); + return acc; + }, [] as {type: string; count: number}[]); + //add total + const total = tmp.reduce((acc, curr) => { + acc[curr.type] = (acc[curr.type] || 0) + curr.count; + return acc; + }, {} as {[key: string]: number}); + setTotalSanctions(Object.keys(total).map(key => ({type: key, count: total[key]}))) + } + }, [sanctionSummary]); useEffect(() => { console.log(filter); @@ -20,22 +44,32 @@ export default function KaryawanPage() {