"use client"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; import classNames from "@calcom/ui/classNames"; import { SkeletonText } from "@calcom/ui/components/skeleton"; import { useInsightsBookingParameters } from "@calcom/web/modules/insights/hooks/useInsightsBookingParameters"; import { ChartCard } from "../ChartCard"; import { KPICard } from "../KPICard"; export const BookingKPICards = () => { const { t } = useLocale(); const insightsBookingParams = useInsightsBookingParameters(); const { data, isSuccess, isPending, isError } = trpc.viewer.insights.bookingKPIStats.useQuery( insightsBookingParams, { staleTime: 180000, refetchOnWindowFocus: false, trpc: { context: { skipBatch: true }, }, } ); const eventCategories: { title: string; index: "created" | "completed" | "rescheduled" | "cancelled"; }[] = [ { title: t("events_created"), index: "created", }, { title: t("events_completed"), index: "completed", }, { title: t("events_rescheduled"), index: "rescheduled", }, { title: t("events_cancelled"), index: "cancelled", }, ]; const performanceCategories: { title: string; index: "rating" | "no_show" | "no_show_guest" | "csat"; }[] = [ { title: t("event_ratings"), index: "rating", }, { title: t("event_no_show"), index: "no_show", }, { title: t("event_no_show_guest"), index: "no_show_guest", }, { title: t("csat_score"), index: "csat", }, ]; if (isPending) { return ( ); } if (!isSuccess || !data) return null; return (
{eventCategories.map((item, index) => ( ))} {performanceCategories.map((item, index) => ( ))}
); }; const LoadingKPICards = (props: { eventCategories: { title: string; index: string }[]; performanceCategories: { title: string; index: string }[]; isPending: boolean; isError: boolean; }) => { const { eventCategories, performanceCategories, isPending, isError } = props; const { t } = useLocale(); return (
{eventCategories.map((item, index) => (
))}
{performanceCategories.map((item, index) => (
))}
); }; // StatContainer: wraps the grid function StatContainer({ children }: { children: React.ReactNode }) { return
{children}
; } // StatItem: handles border logic function StatItem({ index, children }: { index: number; children: React.ReactNode }) { return (
{children}
); }