2023-03-28 23:24:57 +00:00
|
|
|
import { Table, TableBody, TableCell, TableRow, Text, 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
|
|
|
|
|
|
|
export const PopularEventsTable = () => {
|
|
|
|
const { t } = useLocale();
|
|
|
|
const { filter } = useFilterContext();
|
2023-09-18 23:36:07 +00:00
|
|
|
const { dateRange, selectedMemberUserId, selectedUserId, isAll, initialConfig } = filter;
|
2023-03-23 22:10:01 +00:00
|
|
|
const [startDate, endDate] = dateRange;
|
|
|
|
const { selectedTeamId: teamId } = filter;
|
|
|
|
|
2023-04-19 20:14:09 +00:00
|
|
|
const { data, isSuccess, isLoading } = trpc.viewer.insights.popularEventTypes.useQuery(
|
|
|
|
{
|
|
|
|
startDate: startDate.toISOString(),
|
|
|
|
endDate: endDate.toISOString(),
|
|
|
|
teamId: teamId ?? undefined,
|
|
|
|
userId: selectedUserId ?? undefined,
|
|
|
|
memberUserId: selectedMemberUserId ?? undefined,
|
2023-06-29 17:03:44 +00:00
|
|
|
isAll,
|
2023-04-19 20:14:09 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
staleTime: 30000,
|
|
|
|
trpc: {
|
|
|
|
context: { skipBatch: true },
|
|
|
|
},
|
2023-09-18 23:36:07 +00:00
|
|
|
enabled: !!(initialConfig?.teamId || initialConfig?.userId || initialConfig?.isAll),
|
2023-04-19 20:14:09 +00:00
|
|
|
}
|
|
|
|
);
|
2023-03-23 22:10:01 +00:00
|
|
|
|
2023-04-04 11:58:19 +00:00
|
|
|
if (isLoading) return <LoadingInsight />;
|
|
|
|
|
|
|
|
if (!isSuccess || !startDate || !endDate || (!teamId && !selectedUserId)) return null;
|
2023-03-23 22:10:01 +00:00
|
|
|
|
|
|
|
return (
|
2023-03-28 23:24:57 +00:00
|
|
|
<CardInsights>
|
2023-04-05 18:14:46 +00:00
|
|
|
<Title className="text-emphasis">{t("popular_events")}</Title>
|
2023-03-23 22:10:01 +00:00
|
|
|
<Table className="mt-5">
|
|
|
|
<TableBody>
|
2023-03-28 23:24:57 +00:00
|
|
|
{data.map((item) => (
|
|
|
|
<TableRow key={item.eventTypeId}>
|
2023-04-05 18:14:46 +00:00
|
|
|
<TableCell className="text-default">{item.eventTypeName}</TableCell>
|
|
|
|
<TableCell>
|
|
|
|
<Text className="text-default text-right">
|
2023-03-28 23:24:57 +00:00
|
|
|
<strong>{item.count}</strong>
|
|
|
|
</Text>
|
2023-03-23 22:10:01 +00:00
|
|
|
</TableCell>
|
|
|
|
</TableRow>
|
2023-03-28 23:24:57 +00:00
|
|
|
))}
|
2023-03-23 22:10:01 +00:00
|
|
|
</TableBody>
|
|
|
|
</Table>
|
2023-04-04 11:58:19 +00:00
|
|
|
{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>
|
|
|
|
)}
|
2023-03-28 23:24:57 +00:00
|
|
|
</CardInsights>
|
2023-03-23 22:10:01 +00:00
|
|
|
);
|
|
|
|
};
|