2023-04-05 18:14:46 +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";
|
|
|
|
import { valueFormatter } from "../lib/valueFormatter";
|
2023-03-28 23:24:57 +00:00
|
|
|
import { CardInsights } from "./Card";
|
2023-04-05 18:14:46 +00:00
|
|
|
import { LineChart } from "./LineChart";
|
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,
|
2023-06-29 17:03:44 +00:00
|
|
|
isAll,
|
2023-09-18 23:36:07 +00:00
|
|
|
initialConfig,
|
2023-04-04 11:58:19 +00:00
|
|
|
} = filter;
|
2023-09-18 23:36:07 +00:00
|
|
|
const initialConfigIsReady = !!(initialConfig?.teamId || initialConfig?.userId || initialConfig?.isAll);
|
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,
|
2023-04-19 20:14:09 +00:00
|
|
|
} = trpc.viewer.insights.eventsTimeline.useQuery(
|
|
|
|
{
|
|
|
|
timeView: selectedTimeView,
|
|
|
|
startDate: startDate.toISOString(),
|
|
|
|
endDate: endDate.toISOString(),
|
|
|
|
teamId: selectedTeamId ?? undefined,
|
|
|
|
eventTypeId: selectedEventTypeId ?? undefined,
|
|
|
|
userId: selectedUserId ?? 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: initialConfigIsReady,
|
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 />;
|
|
|
|
|
2023-03-23 22:10:01 +00:00
|
|
|
if (!isSuccess) 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("event_trends")}</Title>
|
2023-03-23 22:10:01 +00:00
|
|
|
<LineChart
|
2023-04-05 18:14:46 +00:00
|
|
|
className="linechart mt-4 h-80"
|
2023-03-23 22:10:01 +00:00
|
|
|
data={eventsTimeLine ?? []}
|
|
|
|
categories={["Created", "Completed", "Rescheduled", "Cancelled"]}
|
|
|
|
index="Month"
|
2023-04-05 18:14:46 +00:00
|
|
|
colors={["purple", "green", "blue", "red"]}
|
2023-03-23 22:10:01 +00:00
|
|
|
valueFormatter={valueFormatter}
|
|
|
|
/>
|
2023-03-28 23:24:57 +00:00
|
|
|
</CardInsights>
|
2023-03-23 22:10:01 +00:00
|
|
|
);
|
|
|
|
};
|