Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ export const EventAdvancedTab = ({
{!isPlatform && (
<Controller
name="requiresCancellationReason"
defaultValue={eventType.requiresCancellationReason ?? CancellationReasonRequirement.MANDATORY_HOST_ONLY}
render={({ field: { value, onChange } }) => {
const cancellationReasonOptions = [
{ value: CancellationReasonRequirement.MANDATORY_BOTH, label: t("mandatory_for_both") },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { prisma } from "@calcom/prisma";
import type { PrismaClient } from "@calcom/prisma";
import { CancellationReasonRequirement } from "@calcom/prisma/enums";
import i18nMock from "@calcom/testing/lib/__mocks__/libServerI18n";

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

const createTestEventType = async (userId: number, overrides?: { slug?: string; title?: string }) => {
const createTestEventType = async (
userId: number,
overrides?: {
slug?: string;
title?: string;
requiresCancellationReason?: CancellationReasonRequirement | null;
}
) => {
const timestamp = Date.now() + Math.random();
const eventType = await prisma.eventType.create({
data: {
title: overrides?.title ?? "Test Event Type",
slug: overrides?.slug ?? `test-event-${timestamp}`,
length: 30,
userId,
requiresCancellationReason: overrides?.requiresCancellationReason,
users: {
connect: [{ id: userId }],
},
Expand Down Expand Up @@ -104,6 +113,25 @@ describe("getRawEventType", () => {
expect(result?.userId).toBe(user.id);
});

test("should fetch requiresCancellationReason when it is configured", async () => {
const user = await createTestUser();
const eventType = await createTestEventType(user.id, {
requiresCancellationReason: CancellationReasonRequirement.MANDATORY_ATTENDEE_ONLY,
});

const result = await getRawEventType({
userId: user.id,
eventTypeId: eventType.id,
isUserOrganizationAdmin: false,
currentOrganizationId: null,
prisma: prisma as unknown as PrismaClient,
});

expect(result?.requiresCancellationReason).toBe(
CancellationReasonRequirement.MANDATORY_ATTENDEE_ONLY
);
});

test.skip("should return null when user doesn't have access to event type", async () => {
// note(Lauris): test skipped because somehow when creating event type eventType.users includes otherUser
const owner = await prisma.user.create({
Expand Down
1 change: 1 addition & 0 deletions packages/features/eventtypes/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export type FormValues = {
calVideoSettings?: CalVideoSettings;
maxActiveBookingPerBookerOfferReschedule: boolean;
enablePerHostLocations: boolean;
requiresCancellationReason?: CancellationReasonRequirement | null;
};

export type LocationFormValues = Pick<FormValues, "id" | "locations" | "bookingFields" | "seatsPerTimeSlot">;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ export class EventTypeRepository implements IEventTypesRepository {
disableGuests: true,
disableCancelling: true,
disableRescheduling: true,
requiresCancellationReason: true,
minimumRescheduleNotice: true,
allowReschedulingCancelledBookings: true,
minimumBookingNotice: true,
Expand Down Expand Up @@ -878,6 +879,7 @@ export class EventTypeRepository implements IEventTypesRepository {
disableGuests: true,
disableCancelling: true,
disableRescheduling: true,
requiresCancellationReason: true,
minimumRescheduleNotice: true,
allowReschedulingCancelledBookings: true,
minimumBookingNotice: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export const useEventTypeForm = ({
maxActiveBookingPerBookerOfferReschedule: eventType.maxActiveBookingPerBookerOfferReschedule,
showOptimizedSlots: eventType.showOptimizedSlots ?? false,
enablePerHostLocations: eventType.enablePerHostLocations ?? false,
requiresCancellationReason: eventType.requiresCancellationReason || null,
};
}, [eventType, periodDates]);

Expand Down
Loading