From 661a494ce402da8e0ac3d305be85efc430595833 Mon Sep 17 00:00:00 2001 From: Amit91848 Date: Mon, 23 Dec 2024 22:29:27 +0530 Subject: [PATCH 1/5] feat: Setting for rescheduling past bookings --- .../components/booking/BookingListItem.tsx | 2 +- apps/web/lib/booking.ts | 1 + .../reschedule/[uid]/getServerSideProps.ts | 3 +- .../bookings/views/bookings-single-view.tsx | 32 +++++++++---------- apps/web/public/static/locales/en/common.json | 2 ++ .../tabs/advanced/EventAdvancedTab.tsx | 19 +++++++++++ packages/lib/defaultEvents.ts | 1 + packages/lib/server/eventTypeSelect.ts | 1 + packages/lib/server/repository/eventType.ts | 2 ++ packages/lib/test/builder.ts | 1 + .../event-types/hooks/useEventTypeForm.ts | 1 + .../migration.sql | 2 ++ packages/prisma/schema.prisma | 1 + packages/prisma/zod-utils.ts | 1 + .../routers/viewer/bookings/get.handler.ts | 1 + .../trpc/server/routers/viewer/slots/util.ts | 1 + 16 files changed, 53 insertions(+), 18 deletions(-) create mode 100644 packages/prisma/migrations/20241223163249_allow_rescheduling_past_booking_setting/migration.sql diff --git a/apps/web/components/booking/BookingListItem.tsx b/apps/web/components/booking/BookingListItem.tsx index 3cfa857580cc40..158615340bdc95 100644 --- a/apps/web/components/booking/BookingListItem.tsx +++ b/apps/web/components/booking/BookingListItem.tsx @@ -215,7 +215,7 @@ function BookingListItem(booking: BookingItemProps) { ]; const editBookingActions: ActionType[] = [ - ...(isBookingInPast + ...(isBookingInPast && !booking.eventType.reschedulingPastBookings ? [] : [ { diff --git a/apps/web/lib/booking.ts b/apps/web/lib/booking.ts index 2a5e535efcaf6c..5e1e4c9bca8800 100644 --- a/apps/web/lib/booking.ts +++ b/apps/web/lib/booking.ts @@ -37,6 +37,7 @@ export const getEventTypesFromDB = async (id: number) => { price: true, currency: true, bookingFields: true, + reschedulingPastBookings: true, disableGuests: true, timeZone: true, profile: { diff --git a/apps/web/lib/reschedule/[uid]/getServerSideProps.ts b/apps/web/lib/reschedule/[uid]/getServerSideProps.ts index 11fc4aa184e1c4..fa3bdf658f9439 100644 --- a/apps/web/lib/reschedule/[uid]/getServerSideProps.ts +++ b/apps/web/lib/reschedule/[uid]/getServerSideProps.ts @@ -54,6 +54,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) { }, }, slug: true, + reschedulingPastBookings: true, team: { select: { parentId: true, @@ -128,7 +129,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) { }); const isBookingInPast = booking.endTime && new Date(booking.endTime) < new Date(); - if (isBookingInPast) { + if (isBookingInPast && !eventType.reschedulingPastBookings) { return { redirect: { destination: eventUrl, diff --git a/apps/web/modules/bookings/views/bookings-single-view.tsx b/apps/web/modules/bookings/views/bookings-single-view.tsx index c6e45ca79dd64e..69b339c96f3686 100644 --- a/apps/web/modules/bookings/views/bookings-single-view.tsx +++ b/apps/web/modules/bookings/views/bookings-single-view.tsx @@ -19,7 +19,6 @@ import type { nameObjectSchema } from "@calcom/core/event"; import { getEventName } from "@calcom/core/event"; import type { ConfigType } from "@calcom/dayjs"; import dayjs from "@calcom/dayjs"; -import { getOrgFullOrigin } from "@calcom/ee/organizations/lib/orgDomains"; import { useEmbedNonStylesConfig, useIsBackgroundTransparent, @@ -728,22 +727,23 @@ export default function Success(props: PageProps) { <> - {!props.recurringBookings && !isBookingInPast && ( - - - - {t("reschedule")} - + {!props.recurringBookings && + (!isBookingInPast || eventType.reschedulingPastBookings) && ( + + + + {t("reschedule")} + + + {t("or_lowercase")} - {t("or_lowercase")} - - )} + )}