2023-03-28 23:24:57 +00:00
|
|
|
import { Title } from "@tremor/react";
|
2023-03-23 22:10:01 +00:00
|
|
|
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import { trpc } from "@calcom/trpc";
|
|
|
|
|
|
|
|
import { useFilterContext } from "../context/provider";
|
2023-03-28 23:24:57 +00:00
|
|
|
import { CardInsights } from "./Card";
|
2023-04-04 11:58:19 +00:00
|
|
|
import { LoadingInsight } from "./LoadingInsights";
|
2023-03-23 22:10:01 +00:00
|
|
|
import { TotalBookingUsersTable } from "./TotalBookingUsersTable";
|
|
|
|
|
|
|
|
export const LeastBookedTeamMembersTable = () => {
|
|
|
|
const { t } = useLocale();
|
|
|
|
const { filter } = useFilterContext();
|
2023-03-28 23:24:57 +00:00
|
|
|
const { dateRange, selectedEventTypeId, selectedTeamId: teamId } = filter;
|
2023-03-23 22:10:01 +00:00
|
|
|
const [startDate, endDate] = dateRange;
|
|
|
|
|
2023-04-04 11:58:19 +00:00
|
|
|
const { data, isSuccess, isLoading } = trpc.viewer.insights.membersWithLeastBookings.useQuery({
|
2023-03-23 22:10:01 +00:00
|
|
|
startDate: startDate.toISOString(),
|
|
|
|
endDate: endDate.toISOString(),
|
|
|
|
teamId,
|
2023-03-28 23:24:57 +00:00
|
|
|
eventTypeId: selectedEventTypeId ?? undefined,
|
2023-03-23 22:10:01 +00:00
|
|
|
});
|
|
|
|
|
2023-04-04 11:58:19 +00:00
|
|
|
if (isLoading) return <LoadingInsight />;
|
|
|
|
|
2023-03-23 22:10:01 +00:00
|
|
|
if (!isSuccess || !startDate || !endDate || !teamId) return null;
|
|
|
|
|
|
|
|
return (
|
2023-03-28 23:24:57 +00:00
|
|
|
<CardInsights>
|
2023-04-05 18:14:46 +00:00
|
|
|
<Title className="text-emphasis">{t("least_booked_members")}</Title>
|
2023-03-23 22:10:01 +00:00
|
|
|
<TotalBookingUsersTable data={data} />
|
2023-03-28 23:24:57 +00:00
|
|
|
</CardInsights>
|
2023-03-23 22:10:01 +00:00
|
|
|
);
|
|
|
|
};
|