From be4d3170db464f1f8ac70458703ea321add63d6b Mon Sep 17 00:00:00 2001 From: Parteek malik <64765095+parteekmalik@users.noreply.github.com> Date: Fri, 14 Mar 2025 11:19:59 +0530 Subject: [PATCH] fix: synced no-show state after mutation (#20015) Co-authored-by: amrit --- .../components/booking/BookingListItem.tsx | 49 +++++-------------- 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/apps/web/components/booking/BookingListItem.tsx b/apps/web/components/booking/BookingListItem.tsx index 33061e0bfb..bff94754c6 100644 --- a/apps/web/components/booking/BookingListItem.tsx +++ b/apps/web/components/booking/BookingListItem.tsx @@ -903,33 +903,23 @@ type NoShowProps = { }; const Attendee = (attendeeProps: AttendeeProps & NoShowProps) => { - const { email, name, bookingUid, isBookingInPast, noShow: noShowAttendee, phoneNumber } = attendeeProps; + const { email, name, bookingUid, isBookingInPast, noShow, phoneNumber } = attendeeProps; const { t } = useLocale(); - const [noShow, setNoShow] = useState(noShowAttendee); + const utils = trpc.useUtils(); const [openDropdown, setOpenDropdown] = useState(false); const { copyToClipboard, isCopied } = useCopy(); const noShowMutation = trpc.viewer.markNoShow.useMutation({ onSuccess: async (data) => { showToast(data.message, "success"); + utils.viewer.bookings.invalidate(); }, onError: (err) => { showToast(err.message, "error"); }, }); - function toggleNoShow({ - attendee, - bookingUid, - }: { - attendee: { email: string; noShow: boolean }; - bookingUid: string; - }) { - noShowMutation.mutate({ bookingUid, attendees: [attendee] }); - setNoShow(!noShow); - } - return ( @@ -978,29 +968,16 @@ const Attendee = (attendeeProps: AttendeeProps & NoShowProps) => { {isBookingInPast && ( - {noShow ? ( - { - e.preventDefault(); - setOpenDropdown(false); - toggleNoShow({ attendee: { noShow: false, email }, bookingUid }); - }} - StartIcon="eye"> - {t("unmark_as_no_show")} - - ) : ( - { - e.preventDefault(); - setOpenDropdown(false); - toggleNoShow({ attendee: { noShow: true, email }, bookingUid }); - }} - StartIcon="eye-off"> - {t("mark_as_no_show")} - - )} + { + e.preventDefault(); + setOpenDropdown(false); + noShowMutation.mutate({ bookingUid, attendees: [{ noShow: !noShow, email }] }); + }} + StartIcon={noShow ? "eye" : "eye-off"}> + {noShow ? t("unmark_as_no_show") : t("mark_as_no_show")} + )}