From 3807e339ce95379be08d52d52af6c48490b1e6c2 Mon Sep 17 00:00:00 2001 From: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Date: Fri, 28 Jun 2024 19:09:33 +0530 Subject: [PATCH] fix: Provide event rescheduling option before the event end time (#15150) * feat: Provide event rescheduling option * update * update * add checker function * refactor and update * update * fix type error * Update bookings-single-view.tsx --------- Co-authored-by: Somay Chauhan --- .../bookings/views/bookings-single-view.tsx | 28 +++++++++++-------- apps/web/public/static/locales/en/common.json | 2 ++ packages/features/calendars/DatePicker.tsx | 27 ++++++++++++++++-- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/apps/web/modules/bookings/views/bookings-single-view.tsx b/apps/web/modules/bookings/views/bookings-single-view.tsx index ca841004d7..7cb09d7929 100644 --- a/apps/web/modules/bookings/views/bookings-single-view.tsx +++ b/apps/web/modules/bookings/views/bookings-single-view.tsx @@ -296,7 +296,7 @@ export default function Success(props: PageProps) { function getTitle(): string { const titleSuffix = props.recurringBookings ? "_recurring" : ""; const titlePrefix = isRoundRobin ? "round_robin_" : ""; - if (isCancelled) { + if (isCancelled || isBookingInPast) { return ""; } if (needsConfirmation) { @@ -340,6 +340,8 @@ export default function Success(props: PageProps) { const providerName = guessEventLocationType(location)?.label; const rescheduleProviderName = guessEventLocationType(rescheduleLocation)?.label; + const isBookingInPast = new Date(bookingInfo.endTime) < new Date(); + const isReschedulable = !isCancelled && !isBookingInPast; const bookingCancelledEventProps = { booking: bookingInfo, @@ -412,7 +414,7 @@ export default function Success(props: PageProps) { imageSrc={`${bookingInfo.user.avatarUrl}`} /> )} - {giphyImage && !needsConfirmation && !isCancelled && ( + {giphyImage && !needsConfirmation && isReschedulable && ( // eslint-disable-next-line @next/next/no-img-element Gif from Giphy )} @@ -421,17 +423,19 @@ export default function Success(props: PageProps) { "mx-auto flex h-12 w-12 items-center justify-center rounded-full", isRoundRobin && "border-cal-bg dark:border-cal-bg-muted absolute bottom-0 right-0 z-10 h-12 w-12 border-8", - !giphyImage && !isCancelled && !needsConfirmation ? "bg-success" : "", - !giphyImage && !isCancelled && needsConfirmation ? "bg-subtle" : "", - isCancelled ? "bg-error" : "" + !giphyImage && isReschedulable && !needsConfirmation ? "bg-success" : "", + !giphyImage && isReschedulable && needsConfirmation ? "bg-subtle" : "", + isCancelled || isBookingInPast ? "bg-error" : "" )}> - {!giphyImage && !needsConfirmation && !isCancelled && ( + {!giphyImage && !needsConfirmation && isReschedulable && ( )} - {needsConfirmation && !isCancelled && ( + {needsConfirmation && isReschedulable && ( )} - {isCancelled && } + {(isCancelled || isBookingInPast) && ( + + )}
@@ -439,7 +443,7 @@ export default function Success(props: PageProps) { className="text-emphasis text-2xl font-semibold leading-6" data-testid={isCancelled ? "cancelled-headline" : ""} id="modal-headline"> - {needsConfirmation && !isCancelled + {needsConfirmation && isReschedulable ? props.recurringBookings ? t("booking_submitted_recurring") : t("booking_submitted") @@ -447,6 +451,8 @@ export default function Success(props: PageProps) { ? seatReferenceUid ? t("no_longer_attending") : t("event_cancelled") + : isBookingInPast + ? t("event_expired") : props.recurringBookings ? t("meeting_is_scheduled_recurring") : t("meeting_is_scheduled")} @@ -650,7 +656,7 @@ export default function Success(props: PageProps) { )} {!requiresLoginToUpdate && (!needsConfirmation || !userIsOwner) && - !isCancelled && + isReschedulable && (!isCancellationMode ? ( <>
@@ -708,7 +714,7 @@ export default function Success(props: PageProps) { {userIsOwner && !needsConfirmation && !isCancellationMode && - !isCancelled && + isReschedulable && !!calculatedDuration && ( <>
diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index 57f3e50ea0..c27286079d 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -2484,5 +2484,7 @@ "USER_PENDING_MEMBER_OF_THE_ORG": "User is a pending member of the organization", "USER_ALREADY_INVITED_OR_MEMBER": "User is already invited or a member", "USER_MEMBER_OF_OTHER_ORGANIZATION": "User is member of an organization that this team is not a part of.", + "rescheduling_not_possible": "Rescheduling is not possible as the event has expired", + "event_expired": "This event is expired", "ADD_NEW_STRINGS_ABOVE_THIS_LINE_TO_PREVENT_MERGE_CONFLICTS": "↑↑↑↑↑↑↑↑↑↑↑↑↑ Add your new strings above here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑" } diff --git a/packages/features/calendars/DatePicker.tsx b/packages/features/calendars/DatePicker.tsx index 68dd6884b8..58f98beccf 100644 --- a/packages/features/calendars/DatePicker.tsx +++ b/packages/features/calendars/DatePicker.tsx @@ -129,6 +129,16 @@ const NoAvailabilityOverlay = ({ ); }; +const ReschedulingNotPossibleOverlay = () => { + const { t } = useLocale(); + + return ( +
+

{t("rescheduling_not_possible")}

+
+ ); +}; + const Days = ({ minDate, excludedDates = [], @@ -141,6 +151,7 @@ const Days = ({ eventSlug, slots, customClassName, + isBookingInPast, ...props }: Omit & { DayComponent?: React.FC>; @@ -153,6 +164,7 @@ const Days = ({ datePickerDateActive?: string; }; scrollToTimeSlots?: () => void; + isBookingInPast: boolean; }) => { // Create placeholder elements for empty days in first week const weekdayOfFirst = browsingDate.date(1).day(); @@ -279,7 +291,9 @@ const Days = ({
))} - {!props.isPending && includedDates && includedDates?.length === 0 && ( + {isBookingInPast && } + + {!props.isPending && !isBookingInPast && includedDates && includedDates?.length === 0 && ( )} @@ -294,6 +308,7 @@ const DatePicker = ({ onMonthChange, slots, customClassNames, + includedDates, ...passThroughProps }: DatePickerProps & Partial> & { @@ -308,6 +323,8 @@ const DatePicker = ({ }) => { const browsingDate = passThroughProps.browsingDate || dayjs().startOf("month"); const { i18n } = useLocale(); + const bookingData = useBookerStore((state) => state.bookingData); + const isBookingInPast = bookingData ? new Date(bookingData.endTime) < new Date() : false; const changeMonth = (newMonth: number) => { if (onMonthChange) { @@ -357,11 +374,13 @@ const DatePicker = ({