feat: options to disable cancelling and/or rescheduling (#20489)

* feat:disable-rescheduling

* feat:disable-cancelling

* enhancements

* enhancements-2

* enhancements-3

* revert CancelBooking.tsx

* add-test

* final-changes

* minor-change

* fix: Revert yarn.lock accidental commit

* minor-change

* fix:type checks

* fix:type check

* fix:type check

* add-test

* add-tests

* add-test

* fix:type checks

* fix:type check

* fix:clean-code

* fix:type check

* fix:type check

* fix:minor-change

* fix:tests

* fix:BookingListItem

* fix:type-check

* fix:type-check

* adding check for platform

* revert-change

---------

Co-authored-by: Alex van Andel <[email protected]>
Co-authored-by: Benny Joo <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-04-03 20:04:02 +00:00
1 parent 8d59c2fc16
commit 0465c639e6
23 files changed
+232 -16

No files matched your search

@@ -357,14 +357,27 @@ function BookingListItem(booking: BookingItemProps) {
},
];
const isDisabledCancelling = booking.eventType.disableCancelling;
const isDisabledRescheduling = booking.eventType.disableRescheduling;
if (isTabRecurring && isRecurring) {
bookedActions = bookedActions.filter((action) => action.id !== "edit_booking");
}
if (isBookingInPast && isPending && !isConfirmed) {
if (isDisabledCancelling || (isBookingInPast && isPending && !isConfirmed)) {
bookedActions = bookedActions.filter((action) => action.id !== "cancel");
}
if (isDisabledRescheduling) {
bookedActions.forEach((action) => {
if (action.id === "edit_booking") {
action.actions = action.actions?.filter(
({ id }) => id !== "reschedule" && id !== "reschedule_request"
);
}
});
}
const RequestSentMessage = () => {
return (
<Badge startIcon="send" size="md" variant="gray" data-testid="request_reschedule_sent">
+2
View File
@@ -39,6 +39,8 @@ export const getEventTypesFromDB = async (id: number) => {
currency: true,
bookingFields: true,
allowReschedulingPastBookings: true,
disableCancelling: true,
disableRescheduling: true,
disableGuests: true,
timeZone: true,
profile: {
@@ -58,6 +58,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
},
slug: true,
allowReschedulingPastBookings: true,
disableRescheduling: true,
team: {
select: {
parentId: true,
@@ -98,9 +99,11 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
// If booking is already CANCELLED or REJECTED, we can't reschedule this booking. Take the user to the booking page which would show it's correct status and other details.
// A booking that has been rescheduled to a new booking will also have a status of CANCELLED
const isDisabledRescheduling = booking.eventType?.disableRescheduling;
if (
!allowRescheduleForCancelledBooking &&
(booking.status === BookingStatus.CANCELLED || booking.status === BookingStatus.REJECTED)
isDisabledRescheduling ||
(!allowRescheduleForCancelledBooking &&
(booking.status === BookingStatus.CANCELLED || booking.status === BookingStatus.REJECTED))
) {
return {
redirect: {
@@ -47,6 +47,11 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
}
const eventData = team.eventTypes[0];
if (rescheduleUid && eventData.disableRescheduling) {
return { redirect: { destination: `/booking/${rescheduleUid}`, permanent: false } };
}
const eventTypeId = eventData.id;
const eventHostsUserData = await getUsersData(
team.isPrivate,
@@ -181,6 +186,8 @@ const getTeamWithEventsData = async (
metadata: true,
length: true,
hidden: true,
disableCancelling: true,
disableRescheduling: true,
hosts: {
take: 3,
select: {
@@ -105,7 +105,6 @@ export default function Success(props: PageProps) {
const pathname = usePathname();
const searchParams = useCompatSearchParams();
const { eventType, bookingInfo, requiresLoginToUpdate, rescheduledToUid } = props;
const {
allRemainingBookings,
isSuccessBookingPage,
@@ -116,6 +115,7 @@ export default function Success(props: PageProps) {
noShow,
rating,
} = querySchema.parse(routerQuery);
const attendeeTimeZone = bookingInfo?.attendees.find((attendee) => attendee.email === email)?.timeZone;
const isFeedbackMode = !!(noShow || rating);
@@ -367,6 +367,12 @@ export default function Success(props: PageProps) {
const isRerouting = searchParams?.get("cal.rerouting") === "true";
const isRescheduled = bookingInfo?.rescheduled;
const canCancelOrReschedule = !eventType?.disableCancelling || !eventType?.disableRescheduling;
const canCancelAndReschedule = !eventType?.disableCancelling && !eventType?.disableRescheduling;
const canCancel = !eventType?.disableCancelling;
const canReschedule = !eventType?.disableRescheduling;
const successPageHeadline = (() => {
if (needsConfirmationAndReschedulable) {
return isRecurringBooking ? t("booking_submitted_recurring") : t("booking_submitted");
@@ -708,6 +714,7 @@ export default function Success(props: PageProps) {
(!needsConfirmation || !userIsOwner) &&
isReschedulable &&
!isRerouting &&
canCancelOrReschedule &&
(!isCancellationMode ? (
<>
<hr className="border-subtle mb-8" />
@@ -718,7 +725,8 @@ export default function Success(props: PageProps) {
<>
{!props.recurringBookings &&
(!isBookingInPast || eventType.allowReschedulingPastBookings) && (
(!isBookingInPast || eventType.allowReschedulingPastBookings) &&
canReschedule && (
<span className="text-default inline">
<span className="underline" data-testid="reschedule-link">
<Link
@@ -731,19 +739,23 @@ export default function Success(props: PageProps) {
{t("reschedule")}
</Link>
</span>
<span className="mx-2">{t("or_lowercase")}</span>
{canCancelAndReschedule && (
<span className="mx-2">{t("or_lowercase")}</span>
)}
</span>
)}
<button
data-testid="cancel"
className={classNames(
"text-default underline",
props.recurringBookings && "ltr:mr-2 rtl:ml-2"
)}
onClick={() => setIsCancellationMode(true)}>
{t("cancel")}
</button>
{canCancel && (
<button
data-testid="cancel"
className={classNames(
"text-default underline",
props.recurringBookings && "ltr:mr-2 rtl:ml-2"
)}
onClick={() => setIsCancellationMode(true)}>
{t("cancel")}
</button>
)}
</>
</div>
</>
+71
View File
@@ -583,3 +583,74 @@ test.describe("Booking round robin event", () => {
expect(hostNameSecondBooking).toBe("teammate-1"); // teammate-1 should be booked again
});
});
test.describe("Event type with disabled cancellation and rescheduling", () => {
let bookingId: string;
let user: { username: string | null };
test.beforeEach(async ({ page, users }) => {
user = await users.create({
name: `Test-user-${randomString(4)}`,
eventTypes: [
{
title: "No Cancel No Reschedule",
slug: "no-cancel-no-reschedule",
length: 30,
disableCancelling: true,
disableRescheduling: true,
},
],
});
// Book the event
await page.goto(`/${user.username}/no-cancel-no-reschedule`);
await selectFirstAvailableTimeSlotNextMonth(page);
await bookTimeSlot(page, {
name: "Test-user-1",
email: "[email protected]",
});
// Verify booking was successful
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
const url = new URL(page.url());
const pathSegments = url.pathname.split("/");
bookingId = pathSegments[pathSegments.length - 1];
});
test("Reschedule and cancel buttons should be hidden on success page", async ({ page }) => {
await expect(page.locator('[data-testid="reschedule-link"]')).toBeHidden();
await expect(page.locator('[data-testid="cancel"]')).toBeHidden();
});
test("Direct access to reschedule/{bookingId} should redirect to success page", async ({ page }) => {
await page.goto(`/reschedule/${bookingId}`);
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
await page.waitForURL((url) => url.pathname === `/booking/${bookingId}`);
});
test("Using rescheduleUid query parameter should redirect to success page", async ({ page }) => {
await page.goto(`/${user.username}/no-cancel-no-reschedule?rescheduleUid=${bookingId}`);
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
await page.waitForURL((url) => url.pathname === `/booking/${bookingId}`);
});
test("Should prevent cancellation and show an error message", async ({ page }) => {
const response = await page.request.post("/api/cancel", {
data: {
uid: bookingId,
},
headers: {
"Content-Type": "application/json",
},
});
expect(response.status()).toBe(400);
const responseBody = await response.json();
expect(responseBody.message).toBe("This event type does not allow cancellations");
});
});
@@ -1152,6 +1152,10 @@
"enabled_after_update": "Enabled after update",
"enabled_after_update_description": "The private link will work after saving",
"confirm_delete_api_key": "Revoke this API key",
"disable_rescheduling":"Disable Rescheduling",
"description_disable_rescheduling":"Guests can no longer reschedule the event with calendar invite or email",
"disable_cancelling":"Disable Cancelling",
"description_disable_cancelling":"Guests can no longer cancel the event with calendar invite or email",
"revoke_api_key": "Revoke API key",
"api_key_copied": "API key copied!",
"api_key_expires_on": "The API key will expire on",
@@ -57,7 +57,18 @@ async function processReschedule({
rescheduleUid: string | string[] | undefined;
}) {
if (!rescheduleUid) return;
const booking = await getBookingForReschedule(`${rescheduleUid}`, session?.user?.id);
if (booking?.eventType?.disableRescheduling) {
return {
redirect: {
destination: `/booking/${rescheduleUid}`,
permanent: false,
},
};
}
// if no booking found, no eventTypeId (dynamic) or it matches this eventData - return void (success).
if (booking === null || !booking.eventTypeId || booking?.eventTypeId === props.eventData?.id) {
props.booking = booking;
@@ -61,6 +61,11 @@ async function getBooking(prisma: PrismaClient, uid: string, isSeatedEvent?: boo
smsReminderNumber: true,
location: true,
eventTypeId: true,
eventType: {
select: {
disableRescheduling: true,
},
},
attendees: {
select: {
email: true,
@@ -263,6 +268,9 @@ export const getBookingForSeatedEvent = async (uid: string) => {
responses: {},
smsReminderNumber: null,
location: null,
eventType: {
disableRescheduling: false,
},
// mask attendee emails for seated events
attendees: booking.attendees.map((attendee) => ({
...attendee,
@@ -69,6 +69,7 @@ export async function getBookingToDelete(id: number | undefined, uid: string | u
currency: true,
length: true,
seatsPerTimeSlot: true,
disableCancelling: true,
bookingFields: true,
seatsShowAttendees: true,
metadata: true,
@@ -88,6 +88,13 @@ async function handler(input: CancelBookingInput) {
throw new HttpError({ statusCode: 400, message: "User not found" });
}
if (bookingToDelete.eventType?.disableCancelling) {
throw new HttpError({
statusCode: 400,
message: "This event type does not allow cancellations",
});
}
if (!platformClientId && !cancellationReason && bookingToDelete.userId == userId) {
throw new HttpError({
statusCode: 400,
+2
View File
@@ -59,6 +59,8 @@ export type BookerEvent = Pick<
| "instantMeetingParameters"
| "fieldTranslations"
| "autoTranslateDescriptionEnabled"
| "disableCancelling"
| "disableRescheduling"
> & {
subsetOfUsers: BookerEventUser[];
showInstantEventConnectNowModal: boolean;
@@ -487,12 +487,20 @@ export const EventAdvancedTab = ({
const lockTimeZoneToggleOnBookingPageLocked = shouldLockDisableProps("lockTimeZoneToggleOnBookingPage");
const multiplePrivateLinksLocked = shouldLockDisableProps("multiplePrivateLinks");
const reschedulingPastBookingsLocked = shouldLockDisableProps("allowReschedulingPastBookings");
const disableCancellingLocked = shouldLockDisableProps("disableCancelling");
const disableReschedulingLocked = shouldLockDisableProps("disableRescheduling");
const { isLocked, ...eventNameLocked } = shouldLockDisableProps("eventName");
if (isManagedEventType) {
multiplePrivateLinksLocked.disabled = true;
}
const [disableCancelling, setDisableCancelling] = useState(eventType.disableCancelling || false);
const [disableRescheduling, setDisableRescheduling] = useState(eventType.disableRescheduling || false);
const closeEventNameTip = () => setShowEventNameTip(false);
const [isEventTypeColorChecked, setIsEventTypeColorChecked] = useState(!!eventType.eventTypeColor);
@@ -582,6 +590,51 @@ export const EventAdvancedTab = ({
onRequiresConfirmation={setRequiresConfirmation}
customClassNames={customClassNames?.requiresConfirmation}
/>
{!isPlatform && (
<>
<Controller
name="disableCancelling"
render={({ field: { onChange } }) => (
<SettingsToggle
labelClassName="text-sm"
toggleSwitchAtTheEnd={true}
switchContainerClassName="border-subtle rounded-lg border py-6 px-4 sm:px-6"
title={t("disable_cancelling")}
data-testid="disable-cancelling-toggle"
{...disableCancellingLocked}
description={t("description_disable_cancelling")}
checked={disableCancelling}
onCheckedChange={(val) => {
setDisableCancelling(val);
onChange(val);
}}
/>
)}
/>
<Controller
name="disableRescheduling"
render={({ field: { onChange } }) => (
<SettingsToggle
labelClassName="text-sm"
toggleSwitchAtTheEnd={true}
switchContainerClassName="border-subtle rounded-lg border py-6 px-4 sm:px-6"
title={t("disable_rescheduling")}
data-testid="disable-rescheduling-toggle"
{...disableReschedulingLocked}
description={t("description_disable_rescheduling")}
checked={disableRescheduling}
onCheckedChange={(val) => {
setDisableRescheduling(val);
onChange(val);
}}
/>
)}
/>
</>
)}
<Controller
name="canSendCalVideoTranscriptionEmails"
render={({ field: { value, onChange } }) => (
@@ -81,6 +81,8 @@ const getPublicEventSelect = (fetchAllUsers: boolean) => {
price: true,
currency: true,
seatsPerTimeSlot: true,
disableCancelling: true,
disableRescheduling: true,
seatsShowAvailabilityCount: true,
bookingFields: true,
teamId: true,
@@ -516,6 +518,8 @@ export const getPublicEvent = async (
instantMeetingParameters: eventWithUserProfiles.instantMeetingParameters,
aiPhoneCallConfig: eventWithUserProfiles.aiPhoneCallConfig,
assignAllTeamMembers: event.assignAllTeamMembers,
disableCancelling: event.disableCancelling,
disableRescheduling: event.disableRescheduling,
};
};
+2 -1
View File
@@ -95,7 +95,8 @@ export type FormValues = {
customInputs: CustomInputParsed[];
schedule: number | null;
useEventLevelSelectedCalendars: boolean;
disabledCancelling: boolean;
disabledRescheduling: boolean;
periodType: PeriodType;
/**
* Number of days(Applicable only for ROLLING period type)
+2
View File
@@ -88,6 +88,8 @@ const commons = {
seatsPerTimeSlot: null,
seatsShowAttendees: null,
seatsShowAvailabilityCount: null,
disableCancelling: false,
disableRescheduling: false,
onlyShowFirstAvailableSlot: false,
allowReschedulingPastBookings: false,
id: 0,
+2
View File
@@ -30,6 +30,8 @@ export const eventTypeSelect = Prisma.validator<Prisma.EventTypeSelect>()({
lockTimeZoneToggleOnBookingPage: true,
requiresBookerEmailVerification: true,
disableGuests: true,
disableCancelling: true,
disableRescheduling: true,
hideCalendarNotes: true,
minimumBookingNotice: true,
beforeEventBuffer: true,
@@ -503,6 +503,8 @@ export class EventTypeRepository {
hideCalendarNotes: true,
hideCalendarEventDetails: true,
disableGuests: true,
disableCancelling: true,
disableRescheduling: true,
minimumBookingNotice: true,
beforeEventBuffer: true,
afterEventBuffer: true,
+2
View File
@@ -123,6 +123,8 @@ export const buildEventType = (eventType?: Partial<EventType>): EventType => {
onlyShowFirstAvailableSlot: false,
seatsPerTimeSlot: null,
seatsShowAttendees: null,
disableCancelling: false,
disableRescheduling: false,
seatsShowAvailabilityCount: null,
maxLeadThreshold: null,
schedulingType: null,
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "EventType" ADD COLUMN "disableCancelling" BOOLEAN DEFAULT false,
ADD COLUMN "disableRescheduling" BOOLEAN DEFAULT false;
+2
View File
@@ -132,6 +132,8 @@ model EventType {
afterEventBuffer Int @default(0)
seatsPerTimeSlot Int?
onlyShowFirstAvailableSlot Boolean @default(false)
disableCancelling Boolean? @default(false)
disableRescheduling Boolean? @default(false)
seatsShowAttendees Boolean? @default(false)
seatsShowAvailabilityCount Boolean? @default(true)
schedulingType SchedulingType?
+2
View File
@@ -635,6 +635,8 @@ export const allManagedEventTypeProps: { [k in keyof Omit<Prisma.EventTypeSelect
recurringEvent: true,
customInputs: true,
disableGuests: true,
disableCancelling: true,
disableRescheduling: true,
requiresConfirmation: true,
canSendCalVideoTranscriptionEmails: true,
requiresConfirmationForFreeEmail: true,
@@ -97,6 +97,8 @@ export async function getBookings({
seatsShowAvailabilityCount: true,
eventTypeColor: true,
allowReschedulingPastBookings: true,
disableCancelling: true,
disableRescheduling: true,
schedulingType: true,
length: true,
team: {