Skip to content

Commit d1ad4ea

Browse files
fix(eventtypes): persist requiresCancellationReason selection (#29282)
Co-authored-by: Bandhan Majumder <133476557+bandhan-majumder@users.noreply.github.com>
1 parent ff184db commit d1ad4ea

5 files changed

Lines changed: 34 additions & 1 deletion

File tree

apps/web/modules/event-types/components/tabs/advanced/EventAdvancedTab.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ export const EventAdvancedTab = ({
669669
{!isPlatform && (
670670
<Controller
671671
name="requiresCancellationReason"
672+
defaultValue={eventType.requiresCancellationReason ?? CancellationReasonRequirement.MANDATORY_HOST_ONLY}
672673
render={({ field: { value, onChange } }) => {
673674
const cancellationReasonOptions = [
674675
{ value: CancellationReasonRequirement.MANDATORY_BOTH, label: t("mandatory_for_both") },

packages/features/eventtypes/lib/getEventTypeById.integration-test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { prisma } from "@calcom/prisma";
22
import type { PrismaClient } from "@calcom/prisma";
3+
import { CancellationReasonRequirement } from "@calcom/prisma/enums";
34
import i18nMock from "@calcom/testing/lib/__mocks__/libServerI18n";
45

56
// import { mockNoTranslations } from "@calcom/testing/lib/bookingScenario/bookingScenario";
@@ -46,14 +47,22 @@ describe("getRawEventType", () => {
4647
return user;
4748
};
4849

49-
const createTestEventType = async (userId: number, overrides?: { slug?: string; title?: string }) => {
50+
const createTestEventType = async (
51+
userId: number,
52+
overrides?: {
53+
slug?: string;
54+
title?: string;
55+
requiresCancellationReason?: CancellationReasonRequirement | null;
56+
}
57+
) => {
5058
const timestamp = Date.now() + Math.random();
5159
const eventType = await prisma.eventType.create({
5260
data: {
5361
title: overrides?.title ?? "Test Event Type",
5462
slug: overrides?.slug ?? `test-event-${timestamp}`,
5563
length: 30,
5664
userId,
65+
requiresCancellationReason: overrides?.requiresCancellationReason,
5766
users: {
5867
connect: [{ id: userId }],
5968
},
@@ -104,6 +113,25 @@ describe("getRawEventType", () => {
104113
expect(result?.userId).toBe(user.id);
105114
});
106115

116+
test("should fetch requiresCancellationReason when it is configured", async () => {
117+
const user = await createTestUser();
118+
const eventType = await createTestEventType(user.id, {
119+
requiresCancellationReason: CancellationReasonRequirement.MANDATORY_ATTENDEE_ONLY,
120+
});
121+
122+
const result = await getRawEventType({
123+
userId: user.id,
124+
eventTypeId: eventType.id,
125+
isUserOrganizationAdmin: false,
126+
currentOrganizationId: null,
127+
prisma: prisma as unknown as PrismaClient,
128+
});
129+
130+
expect(result?.requiresCancellationReason).toBe(
131+
CancellationReasonRequirement.MANDATORY_ATTENDEE_ONLY
132+
);
133+
});
134+
107135
test.skip("should return null when user doesn't have access to event type", async () => {
108136
// note(Lauris): test skipped because somehow when creating event type eventType.users includes otherUser
109137
const owner = await prisma.user.create({

packages/features/eventtypes/lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ export type FormValues = {
185185
calVideoSettings?: CalVideoSettings;
186186
maxActiveBookingPerBookerOfferReschedule: boolean;
187187
enablePerHostLocations: boolean;
188+
requiresCancellationReason?: CancellationReasonRequirement | null;
188189
};
189190

190191
export type LocationFormValues = Pick<FormValues, "id" | "locations" | "bookingFields" | "seatsPerTimeSlot">;

packages/features/eventtypes/repositories/eventTypeRepository.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ export class EventTypeRepository implements IEventTypesRepository {
599599
disableGuests: true,
600600
disableCancelling: true,
601601
disableRescheduling: true,
602+
requiresCancellationReason: true,
602603
minimumRescheduleNotice: true,
603604
allowReschedulingCancelledBookings: true,
604605
minimumBookingNotice: true,
@@ -878,6 +879,7 @@ export class EventTypeRepository implements IEventTypesRepository {
878879
disableGuests: true,
879880
disableCancelling: true,
880881
disableRescheduling: true,
882+
requiresCancellationReason: true,
881883
minimumRescheduleNotice: true,
882884
allowReschedulingCancelledBookings: true,
883885
minimumBookingNotice: true,

packages/platform/atoms/event-types/hooks/useEventTypeForm.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export const useEventTypeForm = ({
134134
maxActiveBookingPerBookerOfferReschedule: eventType.maxActiveBookingPerBookerOfferReschedule,
135135
showOptimizedSlots: eventType.showOptimizedSlots ?? false,
136136
enablePerHostLocations: eventType.enablePerHostLocations ?? false,
137+
requiresCancellationReason: eventType.requiresCancellationReason || null,
137138
};
138139
}, [eventType, periodDates]);
139140

0 commit comments

Comments
 (0)