Skip to content

Commit

Permalink
fixup! Merge branch 'main' into lauris/cal-4932-platform-refactor-def…
Browse files Browse the repository at this point in the history
…ault-booking-fields
  • Loading branch information
ThyMinimalDev committed Dec 20, 2024
1 parent 368fbcb commit e7a0980
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ import {
} from "@calcom/platform-types";
import { SchedulingType } from "@calcom/prisma/enums";

const orderBySlug = (a: { slug: string }, b: { slug: string }) => {
if (a.slug < b.slug) return -1;
if (a.slug > b.slug) return 1;
return 0;
};

describe("Event types Endpoints", () => {
describe("Not authenticated", () => {
let app: INestApplication;
Expand Down Expand Up @@ -447,7 +453,6 @@ describe("Event types Endpoints", () => {
{ ...defaultResponseBookingFieldEmail },
{ ...defaultResponseBookingFieldLocation },
{ ...defaultResponseBookingFieldTitle },
{ ...defaultResponseBookingFieldNotes },
{ ...defaultResponseBookingFieldGuests },
{ ...defaultResponseBookingFieldRescheduleReason },
{
Expand All @@ -461,6 +466,7 @@ describe("Event types Endpoints", () => {
hidden: false,
isDefault: false,
},
{ ...defaultResponseBookingFieldNotes },
];

expect(createdEventType.bookingFields).toEqual(expectedBookingFields);
Expand Down Expand Up @@ -490,7 +496,9 @@ describe("Event types Endpoints", () => {
expect(fetchedEventType?.lengthInMinutes).toEqual(eventType.lengthInMinutes);
expect(fetchedEventType?.lengthInMinutesOptions).toEqual(eventType.lengthInMinutesOptions);
expect(fetchedEventType?.locations).toEqual(eventType.locations);
expect(fetchedEventType?.bookingFields).toEqual(eventType.bookingFields);
expect(fetchedEventType?.bookingFields.sort(orderBySlug)).toEqual(
eventType.bookingFields.sort(orderBySlug).filter((f) => ("hidden" in f ? !f?.hidden : true))
);
expect(fetchedEventType?.ownerId).toEqual(user.id);
expect(fetchedEventType.bookingLimitsCount).toEqual(eventType.bookingLimitsCount);
expect(fetchedEventType.onlyShowFirstAvailableSlot).toEqual(eventType.onlyShowFirstAvailableSlot);
Expand Down Expand Up @@ -857,7 +865,6 @@ describe("Event types Endpoints", () => {
lengthInMinutesOptions: [15, 30],
bookingFields: [
nameBookingField,
notesBookingField,
{
type: "select",
label: "select which language you want to learn",
Expand All @@ -868,6 +875,7 @@ describe("Event types Endpoints", () => {
disableOnPrefill: false,
hidden: false,
},
notesBookingField,
],
bookingLimitsCount: {
day: 4,
Expand Down Expand Up @@ -935,7 +943,6 @@ describe("Event types Endpoints", () => {
{ ...defaultResponseBookingFieldEmail },
{ ...defaultResponseBookingFieldLocation },
{ ...defaultResponseBookingFieldTitle },
{ ...defaultResponseBookingFieldNotes, ...notesBookingField },
{ ...defaultResponseBookingFieldGuests },
{ ...defaultResponseBookingFieldRescheduleReason },
{
Expand All @@ -949,6 +956,7 @@ describe("Event types Endpoints", () => {
hidden: false,
isDefault: false,
},
{ ...defaultResponseBookingFieldNotes, ...notesBookingField },
];

expect(updatedEventType.bookingFields).toEqual(expectedBookingFields);
Expand Down Expand Up @@ -1065,7 +1073,9 @@ describe("Event types Endpoints", () => {
expect(fetchedEventType?.lengthInMinutes).toEqual(eventType.lengthInMinutes);
expect(fetchedEventType?.lengthInMinutesOptions).toEqual(eventType.lengthInMinutesOptions);
expect(fetchedEventType?.locations).toEqual(eventType.locations);
expect(fetchedEventType?.bookingFields).toEqual(eventType.bookingFields);
expect(fetchedEventType?.bookingFields.sort(orderBySlug)).toEqual(
eventType.bookingFields.sort(orderBySlug).filter((f) => ("hidden" in f ? !f?.hidden : true))
);
expect(fetchedEventType?.ownerId).toEqual(user.id);
expect(fetchedEventType.bookingLimitsCount).toEqual(eventType.bookingLimitsCount);
expect(fetchedEventType.onlyShowFirstAvailableSlot).toEqual(eventType.onlyShowFirstAvailableSlot);
Expand Down Expand Up @@ -1162,28 +1172,28 @@ describe("Event types Endpoints", () => {
{
isDefault: true,
required: false,
slug: "notes",
type: "textarea",
slug: "guests",
type: "multiemail",
disableOnPrefill: false,
hidden: false,
},
{
isDefault: true,
required: false,
slug: "guests",
type: "multiemail",
slug: "rescheduleReason",
type: "textarea",
disableOnPrefill: false,
hidden: false,
},
{ isDefault: true, type: "phone", slug: "attendeePhoneNumber", required: false, hidden: true },
{
isDefault: true,
required: false,
slug: "rescheduleReason",
slug: "notes",
type: "textarea",
disableOnPrefill: false,
hidden: false,
},
{ isDefault: true, type: "phone", slug: "attendeePhoneNumber", required: false, hidden: true },
];

beforeAll(async () => {
Expand Down Expand Up @@ -1307,15 +1317,6 @@ describe("Event types Endpoints", () => {
defaultLabel: "what_is_this_meeting_about",
defaultPlaceholder: "",
},
{
name: "notes",
type: "textarea",
sources: [{ id: "default", type: "default", label: "Default" }],
editable: "system-but-optional",
required: false,
defaultLabel: "additional_notes",
defaultPlaceholder: "share_additional_notes",
},
{
name: "guests",
type: "multiemail",
Expand Down Expand Up @@ -1351,6 +1352,15 @@ describe("Event types Endpoints", () => {
required: false,
defaultLabel: "phone_number",
},
{
name: "notes",
type: "textarea",
sources: [{ id: "default", type: "default", label: "Default" }],
editable: "system-but-optional",
required: false,
defaultLabel: "additional_notes",
defaultPlaceholder: "share_additional_notes",
},
],
};
const legacyEventType = await eventTypesRepositoryFixture.create(legacyEventTypeInput, user.id);
Expand Down Expand Up @@ -1437,15 +1447,6 @@ describe("Event types Endpoints", () => {
defaultLabel: "what_is_this_meeting_about",
defaultPlaceholder: "",
},
{
name: "notes",
type: "textarea",
sources: [{ id: "default", type: "default", label: "Default" }],
editable: "system-but-optional",
required: false,
defaultLabel: "additional_notes",
defaultPlaceholder: "share_additional_notes",
},
{
name: "guests",
type: "multiemail",
Expand Down Expand Up @@ -1481,6 +1482,15 @@ describe("Event types Endpoints", () => {
required: false,
defaultLabel: "phone_number",
},
{
name: "notes",
type: "textarea",
sources: [{ id: "default", type: "default", label: "Default" }],
editable: "system-but-optional",
required: false,
defaultLabel: "additional_notes",
defaultPlaceholder: "share_additional_notes",
},
],
};
const legacyEventType = await eventTypesRepositoryFixture.create(legacyEventTypeInput, user.id);
Expand All @@ -1494,19 +1504,23 @@ describe("Event types Endpoints", () => {
const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14> = response.body;
const fetchedEventType = responseBody.data;

expect(fetchedEventType.bookingFields).toEqual([
...expectedReturnSystemFields,
{
isDefault: false,
type: userDefinedBookingField.type,
slug: userDefinedBookingField.name,
label: userDefinedBookingField.label,
required: userDefinedBookingField.required,
placeholder: userDefinedBookingField.placeholder,
disableOnPrefill: false,
hidden: false,
},
]);
console.log("HERE", fetchedEventType.bookingFields, expectedReturnSystemFields);

expect(fetchedEventType.bookingFields.sort(orderBySlug)).toEqual(
[
{
isDefault: false,
type: userDefinedBookingField.type,
slug: userDefinedBookingField.name,
label: userDefinedBookingField.label,
required: userDefinedBookingField.required,
placeholder: userDefinedBookingField.placeholder,
disableOnPrefill: false,
hidden: false,
},
...expectedReturnSystemFields,
].sort(orderBySlug)
);
});
});

Expand Down Expand Up @@ -1611,24 +1625,24 @@ describe("Event types Endpoints", () => {
},
{
isDefault: true,
type: "textarea",
slug: "notes",
type: "multiemail",
slug: "guests",
required: false,
disableOnPrefill: false,
hidden: false,
},
{
isDefault: true,
type: "multiemail",
slug: "guests",
type: "textarea",
slug: "rescheduleReason",
required: false,
disableOnPrefill: false,
hidden: false,
},
{
isDefault: true,
type: "textarea",
slug: "rescheduleReason",
slug: "notes",
required: false,
disableOnPrefill: false,
hidden: false,
Expand Down
16 changes: 10 additions & 6 deletions packages/platform/atoms/hooks/bookings/useCreateInstantBooking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ export const useCreateInstantBooking = (
) => {
const createInstantBooking = useMutation<ApiResponse<BookingResponse>, Error, BookingCreateBody>({
mutationFn: (data) => {
return http.post<ApiResponse<BookingResponse>>("/bookings/instant", data).then((res) => {
if (res.data.status === SUCCESS_STATUS) {
return res.data;
}
throw new Error(res.data.error.message);
});
return http
.post<ApiResponse<BookingResponse>>("/bookings/instant", data, {
headers: {},
})
.then((res) => {
if (res.data.status === SUCCESS_STATUS) {
return res.data;
}
throw new Error(res.data.error.message);
});
},
onSuccess: (data) => {
if (data.status === SUCCESS_STATUS) {
Expand Down

0 comments on commit e7a0980

Please sign in to comment.