import type { Dispatch, SetStateAction } from "react"; import { Controller, useForm } from "react-hook-form"; import { Dialog } from "@calcom/features/components/controlled-dialog"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { BookingReportReason } from "@calcom/prisma/enums"; import { trpc } from "@calcom/trpc/react"; import { Alert } from "@calcom/ui/components/alert"; import { Button } from "@calcom/ui/components/button"; import { DialogContent, DialogFooter, DialogHeader } from "@calcom/ui/components/dialog"; import { Select, Label } from "@calcom/ui/components/form"; import { TextArea } from "@calcom/ui/components/form"; import { showToast } from "@calcom/ui/components/toast"; type BookingReportStatus = "upcoming" | "past" | "cancelled" | "rejected"; interface IReportBookingDialog { isOpenDialog: boolean; setIsOpenDialog: Dispatch>; bookingUid: string; isRecurring: boolean; status: BookingReportStatus; } interface FormValues { reason: BookingReportReason; description: string; } export const ReportBookingDialog = (props: IReportBookingDialog) => { const { t } = useLocale(); const utils = trpc.useUtils(); const { isOpenDialog, setIsOpenDialog, bookingUid, status } = props; const willBeCancelled = status === "upcoming"; const { control, handleSubmit, formState: { errors }, } = useForm({ defaultValues: { reason: BookingReportReason.SPAM, description: "", }, }); const { mutate: reportBooking, isPending } = trpc.viewer.bookings.reportBooking.useMutation({ async onSuccess(data) { showToast(data.message, "success"); setIsOpenDialog(false); await utils.viewer.bookings.invalidate(); }, onError(error) { showToast(error.message || t("unexpected_error_try_again"), "error"); }, }); const onSubmit = (data: FormValues) => { reportBooking({ bookingUid, reason: data.reason, description: data.description || undefined, }); }; const reasonOptions = [ { label: t("report_reason_spam"), value: BookingReportReason.SPAM }, { label: t("report_reason_dont_know_person"), value: BookingReportReason.DONT_KNOW_PERSON }, { label: t("report_reason_other"), value: BookingReportReason.OTHER }, ]; return (
(