|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useCopy } from "@calcom/lib/hooks/useCopy"; |
| 4 | +import { useLocale } from "@calcom/lib/hooks/useLocale"; |
| 5 | +import { trpc } from "@calcom/trpc"; |
| 6 | +import { Button } from "@calcom/ui/components/button"; |
| 7 | +import { showToast } from "@calcom/ui/components/toast"; |
| 8 | + |
| 9 | +import { useInsightsBookingParameters } from "../../hooks/useInsightsBookingParameters"; |
| 10 | +import { ChartCard, ChartCardItem } from "../ChartCard"; |
| 11 | +import { LoadingInsight } from "../LoadingInsights"; |
| 12 | + |
| 13 | +export const RecentNoShowGuestsChart = () => { |
| 14 | + const { t } = useLocale(); |
| 15 | + const { copyToClipboard, isCopied } = useCopy(); |
| 16 | + const insightsBookingParams = useInsightsBookingParameters(); |
| 17 | + const timeZone = insightsBookingParams.timeZone; |
| 18 | + |
| 19 | + const { data, isSuccess, isPending } = trpc.viewer.insights.recentNoShowGuests.useQuery( |
| 20 | + insightsBookingParams, |
| 21 | + { |
| 22 | + staleTime: 180000, |
| 23 | + refetchOnWindowFocus: false, |
| 24 | + trpc: { |
| 25 | + context: { skipBatch: true }, |
| 26 | + }, |
| 27 | + } |
| 28 | + ); |
| 29 | + |
| 30 | + if (isPending) return <LoadingInsight />; |
| 31 | + |
| 32 | + if (!isSuccess || !data) return null; |
| 33 | + |
| 34 | + const handleCopyEmail = (email: string) => { |
| 35 | + copyToClipboard(email); |
| 36 | + showToast(t("email_copied"), "success"); |
| 37 | + }; |
| 38 | + |
| 39 | + return ( |
| 40 | + <ChartCard |
| 41 | + title={t("recent_no_show_guests")} |
| 42 | + titleTooltip={t("recent_no_show_guests_tooltip")} |
| 43 | + className="h-full"> |
| 44 | + <div className="sm:max-h-[30.6rem] sm:overflow-y-auto"> |
| 45 | + {data.map((item) => ( |
| 46 | + <ChartCardItem key={item.bookingId}> |
| 47 | + <div className="flex w-full items-center justify-between"> |
| 48 | + <div className="flex gap-2"> |
| 49 | + <div className="bg-subtle h-16 w-[2px] shrink-0 rounded-sm" /> |
| 50 | + <div className="flex flex-col space-y-1"> |
| 51 | + <p className="text-sm font-medium">{item.guestName}</p> |
| 52 | + <div className="text-subtle text-sm leading-tight"> |
| 53 | + <p>{item.eventTypeName}</p> |
| 54 | + <p> |
| 55 | + {Intl.DateTimeFormat(undefined, { |
| 56 | + timeZone, |
| 57 | + dateStyle: "medium", |
| 58 | + timeStyle: "short", |
| 59 | + }).format(new Date(item.startTime))} |
| 60 | + </p> |
| 61 | + </div> |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + <Button |
| 65 | + color="minimal" |
| 66 | + size="sm" |
| 67 | + StartIcon={isCopied ? "clipboard-check" : "clipboard"} |
| 68 | + onClick={() => handleCopyEmail(item.guestEmail)}> |
| 69 | + {!isCopied ? t("email") : t("copied")} |
| 70 | + </Button> |
| 71 | + </div> |
| 72 | + </ChartCardItem> |
| 73 | + ))} |
| 74 | + </div> |
| 75 | + {data.length === 0 && ( |
| 76 | + <div className="flex h-60 text-center"> |
| 77 | + <p className="m-auto text-sm font-light">{t("insights_no_data_found_for_filter")}</p> |
| 78 | + </div> |
| 79 | + )} |
| 80 | + </ChartCard> |
| 81 | + ); |
| 82 | +}; |
0 commit comments