Files
calendar/packages/features/insights/components/PopularEventsTable.tsx
T
+1 30ba168fc3 chore: bump @trpc/* and @tanstack/react-query (#13335)
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: Omar López <zomars@me.com>
Co-authored-by: CarinaWolli <wollencarina@gmail.com>
Co-authored-by: Alex van Andel <me@alexvanandel.com>
Co-authored-by: zomars <zomars@me.com>
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
Co-authored-by: Benny Joo <sldisek783@gmail.com>
Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com>
Co-authored-by: Gergő Móricz <mo.geryy@gmail.com>
Co-authored-by: Keith Williams <keithwillcode@gmail.com>
2024-01-23 16:42:29 -07:00

64 lines
2.0 KiB
TypeScript

import { Table, TableBody, TableCell, TableRow, Text, Title } from "@tremor/react";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc";
import { useFilterContext } from "../context/provider";
import { CardInsights } from "./Card";
import { LoadingInsight } from "./LoadingInsights";
export const PopularEventsTable = () => {
const { t } = useLocale();
const { filter } = useFilterContext();
const { dateRange, selectedMemberUserId, selectedUserId, isAll, initialConfig } = filter;
const [startDate, endDate] = dateRange;
const { selectedTeamId: teamId } = filter;
const { data, isSuccess, isPending } = trpc.viewer.insights.popularEventTypes.useQuery(
{
startDate: startDate.toISOString(),
endDate: endDate.toISOString(),
teamId: teamId ?? undefined,
userId: selectedUserId ?? undefined,
memberUserId: selectedMemberUserId ?? undefined,
isAll,
},
{
staleTime: 30000,
trpc: {
context: { skipBatch: true },
},
enabled: !!(initialConfig?.teamId || initialConfig?.userId || initialConfig?.isAll),
}
);
if (isPending) return <LoadingInsight />;
if (!isSuccess || !startDate || !endDate || (!teamId && !selectedUserId)) return null;
return (
<CardInsights>
<Title className="text-emphasis">{t("popular_events")}</Title>
<Table className="mt-5">
<TableBody>
{data.map((item) => (
<TableRow key={item.eventTypeId}>
<TableCell className="text-default">{item.eventTypeName}</TableCell>
<TableCell>
<Text className="text-default text-right">
<strong>{item.count}</strong>
</Text>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
{data.length === 0 && (
<div className="flex h-60 text-center">
<p className="m-auto text-sm font-light">{t("insights_no_data_found_for_filter")}</p>
</div>
)}
</CardInsights>
);
};