* refactor: improve most booked & least booked * add 2 new charts and trpc handlers * update arg * update comment * completed booking filter * update * add change in component level and remove unused translations * current time and accepted status logic handler * resize some charts * restore some i18n * restore i18n * restore i18n --------- Co-authored-by: Eunjae Lee <[email protected]>
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import { useMemo } from "react";
|
|
|
|
import dayjs from "@calcom/dayjs";
|
|
import { useChangeTimeZoneWithPreservedLocalTime } from "@calcom/features/data-table/hooks/useChangeTimeZoneWithPreservedLocalTime";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { trpc } from "@calcom/trpc";
|
|
|
|
import { useInsightsBookingParameters } from "../../hooks/useInsightsBookingParameters";
|
|
import { ChartCard } from "../ChartCard";
|
|
import { LoadingInsight } from "../LoadingInsights";
|
|
import { UserStatsTable } from "../UserStatsTable";
|
|
|
|
export const MostCompletedTeamMembersTable = () => {
|
|
const { t } = useLocale();
|
|
let insightsBookingParams = useInsightsBookingParameters();
|
|
|
|
const currentTime = useChangeTimeZoneWithPreservedLocalTime(
|
|
useMemo(() => {
|
|
return dayjs().toISOString();
|
|
}, [])
|
|
);
|
|
|
|
// booking with endDate < now is "accepted" booking
|
|
insightsBookingParams = {
|
|
...insightsBookingParams,
|
|
endDate: currentTime,
|
|
};
|
|
|
|
const { data, isSuccess, isPending } = trpc.viewer.insights.membersWithMostCompletedBookings.useQuery(
|
|
insightsBookingParams,
|
|
{
|
|
staleTime: 180000,
|
|
refetchOnWindowFocus: false,
|
|
trpc: {
|
|
context: { skipBatch: true },
|
|
},
|
|
}
|
|
);
|
|
|
|
if (isPending) return <LoadingInsight />;
|
|
|
|
if (!isSuccess || !data) return null;
|
|
|
|
return (
|
|
<ChartCard title={t("most_bookings_completed")}>
|
|
<UserStatsTable data={data} />
|
|
</ChartCard>
|
|
);
|
|
};
|