From c5c654c8795aad48dbc1455cfbfdc6f18740fac8 Mon Sep 17 00:00:00 2001 From: amrit Date: Sun, 9 Mar 2025 22:36:03 +0530 Subject: [PATCH] feat: no-show confirmation does not pop up for single attendee (#19806) * feat: no-show marking confirmation does not pop up for single attendee bookings * fix: Add toggle for no-show status * simplify logic * feat: Centralize no-show handling logic in BookingListItem * Update BookingListItem.tsx --------- Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Co-authored-by: Tushar Bhatt <95581504+TusharBhatt1@users.noreply.github.com> Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> --- .../components/booking/BookingListItem.tsx | 46 ++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/apps/web/components/booking/BookingListItem.tsx b/apps/web/components/booking/BookingListItem.tsx index c696d71bb2..33061e0bfb 100644 --- a/apps/web/components/booking/BookingListItem.tsx +++ b/apps/web/components/booking/BookingListItem.tsx @@ -120,6 +120,28 @@ function BookingListItem(booking: BookingItemProps) { const [viewRecordingsDialogIsOpen, setViewRecordingsDialogIsOpen] = useState(false); const [isNoShowDialogOpen, setIsNoShowDialogOpen] = useState(false); const cardCharged = booking?.payment[0]?.success; + + const attendeeList = booking.attendees.map((attendee) => { + return { + name: attendee.name, + email: attendee.email, + id: attendee.id, + noShow: attendee.noShow || false, + phoneNumber: attendee.phoneNumber, + }; + }); + + const noShowMutation = trpc.viewer.markNoShow.useMutation({ + onSuccess: async (data) => { + showToast(data.message, "success"); + // Invalidate and refetch the bookings query to update the UI + await utils.viewer.bookings.invalidate(); + }, + onError: (err) => { + showToast(err.message, "error"); + }, + }); + const mutation = trpc.viewer.bookings.confirm.useMutation({ onSuccess: (data) => { if (data?.status === BookingStatus.REJECTED) { @@ -287,11 +309,22 @@ function BookingListItem(booking: BookingItemProps) { if (isBookingInPast || isOngoing) { editBookingActions.push({ id: "no_show", - label: t("mark_as_no_show"), + label: + attendeeList.length === 1 && attendeeList[0].noShow ? t("unmark_as_no_show") : t("mark_as_no_show"), onClick: () => { + // If there's only one attendee, mark them as no-show directly without showing the dialog + if (attendeeList.length === 1) { + const attendee = attendeeList[0]; + noShowMutation.mutate({ + bookingUid: booking.uid, + attendees: [{ email: attendee.email, noShow: !attendee.noShow }], + }); + return; + } + setIsNoShowDialogOpen(true); }, - icon: "eye-off" as const, + icon: attendeeList.length === 1 && attendeeList[0].noShow ? "eye" : ("eye-off" as const), }); } @@ -427,15 +460,6 @@ function BookingListItem(booking: BookingItemProps) { ]; const showPendingPayment = paymentAppData.enabled && booking.payment.length && !booking.paid; - const attendeeList = booking.attendees.map((attendee) => { - return { - name: attendee.name, - email: attendee.email, - id: attendee.id, - noShow: attendee.noShow || false, - phoneNumber: attendee.phoneNumber, - }; - }); return ( <>