Files
calendar/packages/features/insights/components/BookingStatusLineChart.tsx
T
720136fcf9 fix: replace filter implementations on /insights (#19033)
* fix: replace filter implementations on /insights

* add authorization for teamIds

* replace all the implementations

* provide eventTypeId

* remove log

* fix teamId for isAll

* fix Download button

* remove legacy implementations

* clean up

* nullish check

* remove unusable filters

* revert style

* fix type error

* fix e2e test

* fix type error

* fix type error

* fix e2e

* extract util method

* fix type error

* fix type error

* fix type error

---------

Co-authored-by: Benny Joo <sldisek783@gmail.com>
2025-02-10 20:28:48 +01:00

65 lines
1.8 KiB
TypeScript

import { Title } from "@tremor/react";
import { useMemo } from "react";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc";
import { useInsightsParameters } from "../hooks/useInsightsParameters";
import { valueFormatter } from "../lib/valueFormatter";
import { CardInsights } from "./Card";
import { LineChart } from "./LineChart";
import { LoadingInsight } from "./LoadingInsights";
export const BookingStatusLineChart = () => {
const { t } = useLocale();
const { isAll, teamId, userId, startDate, endDate, dateRangePreset, eventTypeId } = useInsightsParameters();
const selectedTimeView = useMemo(() => {
if (dateRangePreset === "tdy") return "day";
else if (dateRangePreset === "w") return "week";
else if (dateRangePreset === "m") return "month";
else if (dateRangePreset === "y") return "year";
else return "week";
}, [dateRangePreset]);
const {
data: eventsTimeLine,
isSuccess,
isPending,
} = trpc.viewer.insights.eventsTimeline.useQuery(
{
timeView: selectedTimeView,
startDate,
endDate,
teamId,
eventTypeId,
userId,
isAll,
},
{
staleTime: 30000,
trpc: {
context: { skipBatch: true },
},
}
);
if (isPending) return <LoadingInsight />;
if (!isSuccess) return null;
return (
<CardInsights>
<Title className="text-emphasis">{t("event_trends")}</Title>
<LineChart
className="linechart mt-4 h-80"
data={eventsTimeLine ?? []}
categories={["Created", "Completed", "Rescheduled", "Cancelled", "No-Show (Host)", "No-Show (Guest)"]}
index="Month"
colors={["purple", "green", "blue", "red", "slate", "orange"]}
valueFormatter={valueFormatter}
/>
</CardInsights>
);
};