2023-03-28 23:24:57 +00:00
|
|
|
import { LineChart, 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";
|
|
|
|
import { valueFormatter } from "../lib/valueFormatter";
|
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 BookingStatusLineChart = () => {
|
|
|
|
const { t } = useLocale();
|
|
|
|
const { filter } = useFilterContext();
|
2023-04-04 11:58:19 +00:00
|
|
|
const {
|
|
|
|
selectedTeamId,
|
|
|
|
selectedUserId,
|
|
|
|
selectedTimeView = "week",
|
|
|
|
dateRange,
|
|
|
|
selectedEventTypeId,
|
|
|
|
} = filter;
|
2023-03-23 22:10:01 +00:00
|
|
|
const [startDate, endDate] = dateRange;
|
|
|
|
|
|
|
|
if (!startDate || !endDate) return null;
|
|
|
|
|
2023-04-04 11:58:19 +00:00
|
|
|
const {
|
|
|
|
data: eventsTimeLine,
|
|
|
|
isSuccess,
|
|
|
|
isLoading,
|
|
|
|
} = trpc.viewer.insights.eventsTimeline.useQuery({
|
2023-03-23 22:10:01 +00:00
|
|
|
timeView: selectedTimeView,
|
|
|
|
startDate: startDate.toISOString(),
|
|
|
|
endDate: endDate.toISOString(),
|
2023-04-04 11:58:19 +00:00
|
|
|
teamId: selectedTeamId ?? undefined,
|
2023-03-23 22:10:01 +00:00
|
|
|
eventTypeId: selectedEventTypeId ?? undefined,
|
2023-04-04 11:58:19 +00:00
|
|
|
userId: selectedUserId ?? 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) return null;
|
|
|
|
|
|
|
|
return (
|
2023-03-28 23:24:57 +00:00
|
|
|
<CardInsights>
|
2023-03-23 22:10:01 +00:00
|
|
|
<Title>{t("event_trends")}</Title>
|
|
|
|
<LineChart
|
|
|
|
className="mt-4 h-80"
|
|
|
|
data={eventsTimeLine ?? []}
|
|
|
|
categories={["Created", "Completed", "Rescheduled", "Cancelled"]}
|
|
|
|
index="Month"
|
|
|
|
colors={["gray", "green", "blue", "red"]}
|
|
|
|
valueFormatter={valueFormatter}
|
|
|
|
/>
|
2023-03-28 23:24:57 +00:00
|
|
|
</CardInsights>
|
2023-03-23 22:10:01 +00:00
|
|
|
);
|
|
|
|
};
|