From 7269b3ea6050482bd85ff4d2257bd2c68d57951b Mon Sep 17 00:00:00 2001 From: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Date: Wed, 11 Sep 2024 03:51:36 +0530 Subject: [PATCH] revert: booking rejection reason from booking success page (#16584) --- .../components/booking/BookingListItem.tsx | 51 ++++++++++- apps/web/components/booking/RejectBooking.tsx | 88 ------------------- .../bookings/views/bookings-single-view.tsx | 27 ------ .../src/templates/OrganizerRequestEmail.tsx | 4 +- 4 files changed, 48 insertions(+), 122 deletions(-) delete mode 100644 apps/web/components/booking/RejectBooking.tsx diff --git a/apps/web/components/booking/BookingListItem.tsx b/apps/web/components/booking/BookingListItem.tsx index 1d74398552..9f2a98a550 100644 --- a/apps/web/components/booking/BookingListItem.tsx +++ b/apps/web/components/booking/BookingListItem.tsx @@ -28,6 +28,10 @@ import type { ActionType } from "@calcom/ui"; import { Badge, Button, + Dialog, + DialogClose, + DialogContent, + DialogFooter, Dropdown, DropdownItem, DropdownMenuCheckboxItem, @@ -40,6 +44,7 @@ import { MeetingTimeInTimezones, showToast, TableActions, + TextAreaField, Tooltip, } from "@calcom/ui"; @@ -73,12 +78,19 @@ function BookingListItem(booking: BookingItemProps) { i18n: { language }, } = useLocale(); const utils = trpc.useUtils(); + const [rejectionReason, setRejectionReason] = useState(""); + const [rejectionDialogIsOpen, setRejectionDialogIsOpen] = useState(false); const [chargeCardDialogIsOpen, setChargeCardDialogIsOpen] = useState(false); const [viewRecordingsDialogIsOpen, setViewRecordingsDialogIsOpen] = useState(false); const cardCharged = booking?.payment[0]?.success; const mutation = trpc.viewer.bookings.confirm.useMutation({ - onSuccess: () => { - showToast(t("booking_confirmation_success"), "success"); + onSuccess: (data) => { + if (data?.status === BookingStatus.REJECTED) { + setRejectionDialogIsOpen(false); + showToast(t("booking_rejection_success"), "success"); + } else { + showToast(t("booking_confirmation_success"), "success"); + } utils.viewer.bookings.invalidate(); }, onError: () => { @@ -119,7 +131,7 @@ function BookingListItem(booking: BookingItemProps) { let body = { bookingId: booking.id, confirmed: confirm, - reason: "", + reason: rejectionReason, }; /** * Only pass down the recurring event id when we need to confirm the entire series, which happens in @@ -142,7 +154,9 @@ function BookingListItem(booking: BookingItemProps) { { id: "reject", label: (isTabRecurring || isTabUnconfirmed) && isRecurring ? t("reject_all") : t("reject"), - href: `/booking/${booking.uid}?reject=true`, + onClick: () => { + setRejectionDialogIsOpen(true); + }, icon: "ban", disabled: mutation.isPending, }, @@ -376,6 +390,35 @@ function BookingListItem(booking: BookingItemProps) { timeFormat={userTimeFormat ?? null} /> )} + + +
+ + {t("rejection_reason")} + (Optional) + + } + value={rejectionReason} + onChange={(e) => setRejectionReason(e.target.value)} + /> +
+ + + + + +
+
diff --git a/apps/web/components/booking/RejectBooking.tsx b/apps/web/components/booking/RejectBooking.tsx deleted file mode 100644 index 8d9b3f32cc..0000000000 --- a/apps/web/components/booking/RejectBooking.tsx +++ /dev/null @@ -1,88 +0,0 @@ -import { useCallback, useState } from "react"; - -import { useLocale } from "@calcom/lib/hooks/useLocale"; -import { trpc } from "@calcom/trpc/react"; -import { Button, TextArea } from "@calcom/ui"; - -type Props = { - booking: { - uid?: string | null; - id: number; - recurringEventId: string | null; - }; - setIsRejectionMode: () => void; -}; - -export default function RejectBooking(props: Props) { - const [rejectionReason, setRejectionReason] = useState(""); - const { t } = useLocale(); - const utils = trpc.useUtils(); - const { booking } = props; - const isRecurring = booking.recurringEventId !== null; - - const mutation = trpc.viewer.bookings.confirm.useMutation({ - onSuccess: () => { - props.setIsRejectionMode(); - utils.viewer.bookings.invalidate(); - }, - onError: () => { - utils.viewer.bookings.invalidate(); - }, - }); - - const bookingConfirm = async (confirm: boolean) => { - let body = { - bookingId: booking.id, - confirmed: confirm, - reason: rejectionReason, - }; - if (isRecurring) { - body = Object.assign({}, body, { recurringEventId: booking.recurringEventId }); - } - mutation.mutate(body); - }; - - const rejectBookingRef = useCallback((node: HTMLTextAreaElement) => { - if (node !== null) { - node.scrollIntoView({ behavior: "smooth" }); - node.focus(); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); - - return ( - <> -
- -