Skip to content

Commit

Permalink
refactor: internal-to-api/booking-fields.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
supalarry committed Jan 16, 2025
1 parent ebe6fb5 commit 6efc490
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 26 deletions.
2 changes: 1 addition & 1 deletion apps/api/v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@axiomhq/winston": "^1.2.0",
"@calcom/platform-constants": "*",
"@calcom/platform-enums": "*",
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.84",
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.85",
"@calcom/platform-libraries-0.0.2": "npm:@calcom/platform-libraries@0.0.2",
"@calcom/platform-types": "*",
"@calcom/platform-utils": "*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ describe("Event types Endpoints", () => {
slug: "location",
required: false,
hidden: false,
disableOnPrefill: false,
};

const defaultResponseBookingFieldTitle = {
Expand Down Expand Up @@ -1163,10 +1162,7 @@ describe("Event types Endpoints", () => {
type: "radioInput",
slug: "location",
required: false,
disableOnPrefill: false,
hidden: false,
label: "",
placeholder: "",
},
{ isDefault: true, required: true, slug: "title", type: "text", disableOnPrefill: false, hidden: true },
{
Expand Down Expand Up @@ -1617,7 +1613,6 @@ describe("Event types Endpoints", () => {
type: "radioInput",
slug: "location",
required: false,
disableOnPrefill: false,
hidden: false,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,6 @@ describe("Organizations Event Types Endpoints", () => {
type: "radioInput",
slug: "location",
required: false,
disableOnPrefill: false,
hidden: false,
},
{
Expand Down Expand Up @@ -787,7 +786,6 @@ describe("Organizations Event Types Endpoints", () => {
type: "radioInput",
slug: "location",
required: false,
disableOnPrefill: false,
hidden: false,
},
{
Expand Down
172 changes: 159 additions & 13 deletions packages/lib/event-types/transformers/internal-to-api/booking-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,27 @@ import { z } from "zod";

import type {
OutputBookingField_2024_06_14,
DefaultFieldOutput_2024_06_14,
CustomFieldOutput_2024_06_14,
SplitNameDefaultFieldOutput_2024_06_14,
NameDefaultFieldOutput_2024_06_14,
EmailDefaultFieldOutput_2024_06_14,
PhoneDefaultFieldOutput_2024_06_14,
LocationDefaultFieldOutput_2024_06_14,
RescheduleReasonDefaultFieldOutput_2024_06_14,
TitleDefaultFieldOutput_2024_06_14,
NotesDefaultFieldOutput_2024_06_14,
GuestsDefaultFieldOutput_2024_06_14,
OutputUnknownBookingField_2024_06_14,
AddressFieldOutput_2024_06_14,
BooleanFieldOutput_2024_06_14,
CheckboxGroupFieldOutput_2024_06_14,
MultiEmailFieldOutput_2024_06_14,
MultiSelectFieldOutput_2024_06_14,
NumberFieldOutput_2024_06_14,
PhoneFieldOutput_2024_06_14,
RadioGroupFieldOutput_2024_06_14,
SelectFieldOutput_2024_06_14,
TextAreaFieldOutput_2024_06_14,
TextFieldOutput_2024_06_14,
} from "@calcom/platform-types";

export function transformBookingFieldsInternalToApi(
Expand Down Expand Up @@ -31,7 +50,7 @@ export function transformBookingFieldsInternalToApi(
lastNamePlaceholder: lastNameField?.placeholder,
lastNameRequired: !!lastNameField?.required,
disableOnPrefill: !!field.disableOnPrefill,
};
} satisfies SplitNameDefaultFieldOutput_2024_06_14;
}

return {
Expand All @@ -42,7 +61,7 @@ export function transformBookingFieldsInternalToApi(
label: field.variantsConfig?.variants?.fullName?.fields[0]?.label,
placeholder: field.variantsConfig?.variants?.fullName?.fields[0]?.placeholder,
disableOnPrefill: !!field.disableOnPrefill,
};
} satisfies NameDefaultFieldOutput_2024_06_14;
}
case "email":
return {
Expand All @@ -53,12 +72,59 @@ export function transformBookingFieldsInternalToApi(
label: field.label,
placeholder: field.placeholder,
disableOnPrefill: !!field.disableOnPrefill,
} as DefaultFieldOutput_2024_06_14;
} satisfies EmailDefaultFieldOutput_2024_06_14;
case "location":
return {
isDefault: true,
type: "radioInput",
slug: "location",
required: !!field.required,
hidden: !!field.hidden,
} satisfies LocationDefaultFieldOutput_2024_06_14;
case "rescheduleReason":
return {
isDefault: true,
type: "textarea",
slug: "rescheduleReason",
required: !!field.required,
label: field.label,
placeholder: field.placeholder,
disableOnPrefill: !!field.disableOnPrefill,
hidden: !!field.hidden,
} satisfies RescheduleReasonDefaultFieldOutput_2024_06_14;
case "title":
return {
isDefault: true,
type: "text",
slug: "title",
required: !!field.required,
label: field.label,
placeholder: field.placeholder,
disableOnPrefill: !!field.disableOnPrefill,
hidden: !!field.hidden,
} satisfies TitleDefaultFieldOutput_2024_06_14;
case "notes":
return {
isDefault: true,
type: "textarea",
slug: "notes",
required: !!field.required,
label: field.label,
placeholder: field.placeholder,
disableOnPrefill: !!field.disableOnPrefill,
hidden: !!field.hidden,
} satisfies NotesDefaultFieldOutput_2024_06_14;
case "guests":
return {
isDefault: true,
type: "multiemail",
slug: "guests",
required: !!field.required,
label: field.label,
placeholder: field.placeholder,
disableOnPrefill: !!field.disableOnPrefill,
hidden: !!field.hidden,
} satisfies GuestsDefaultFieldOutput_2024_06_14;
case "attendeePhoneNumber":
return {
isDefault: true,
Expand All @@ -69,32 +135,82 @@ export function transformBookingFieldsInternalToApi(
placeholder: field.placeholder,
disableOnPrefill: !!field.disableOnPrefill,
hidden: !!field.hidden,
} as DefaultFieldOutput_2024_06_14;
} satisfies PhoneDefaultFieldOutput_2024_06_14;
default:
return {
type: "unknown",
slug: "unknown",
bookingField: JSON.stringify(field),
};
} satisfies OutputUnknownBookingField_2024_06_14;
}
} else {
switch (field.type) {
case "phone":
return {
isDefault: false,
type: field.type,
slug: field.name,
label: field.label || "",
required: !!field.required,
placeholder: field.placeholder,
disableOnPrefill: !!field.disableOnPrefill,
hidden: !!field.hidden,
} satisfies PhoneFieldOutput_2024_06_14;
case "address":
return {
isDefault: false,
type: field.type,
slug: field.name,
label: field.label,
required: !!field.required,
placeholder: field.placeholder,
disableOnPrefill: !!field.disableOnPrefill,
hidden: !!field.hidden,
} satisfies AddressFieldOutput_2024_06_14;
case "text":
return {
isDefault: false,
type: field.type,
slug: field.name,
label: field.label || "",
required: !!field.required,
placeholder: field.placeholder,
disableOnPrefill: !!field.disableOnPrefill,
hidden: !!field.hidden,
} satisfies TextFieldOutput_2024_06_14;
case "number":
return {
isDefault: false,
type: field.type,
slug: field.name,
label: field.label,
required: !!field.required,
placeholder: field.placeholder,
disableOnPrefill: !!field.disableOnPrefill,
hidden: !!field.hidden,
} satisfies NumberFieldOutput_2024_06_14;
case "textarea":
return {
isDefault: false,
type: field.type,
slug: field.name,
label: field.label || "",
required: !!field.required,
placeholder: field.placeholder,
disableOnPrefill: !!field.disableOnPrefill,
hidden: !!field.hidden,
} satisfies TextAreaFieldOutput_2024_06_14;
case "multiemail":
return {
isDefault: false,
type: field.type,
slug: field.name,
label: field.label,
label: field.label || "",
required: !!field.required,
placeholder: field.placeholder,
disableOnPrefill: !!field.disableOnPrefill,
hidden: !!field.hidden,
} as CustomFieldOutput_2024_06_14;
} satisfies MultiEmailFieldOutput_2024_06_14;
case "boolean":
return {
isDefault: false,
Expand All @@ -104,10 +220,41 @@ export function transformBookingFieldsInternalToApi(
required: !!field.required,
disableOnPrefill: !!field.disableOnPrefill,
hidden: !!field.hidden,
} as CustomFieldOutput_2024_06_14;
} satisfies BooleanFieldOutput_2024_06_14;
case "select":
return {
isDefault: false,
type: field.type,
slug: field.name,
label: field.label,
required: !!field.required,
placeholder: field.placeholder,
disableOnPrefill: !!field.disableOnPrefill,
options: field.options ? field.options.map((option) => option.value) : [],
hidden: !!field.hidden,
} satisfies SelectFieldOutput_2024_06_14;
case "multiselect":
return {
isDefault: false,
type: field.type,
slug: field.name,
label: field.label,
required: !!field.required,
disableOnPrefill: !!field.disableOnPrefill,
options: field.options ? field.options.map((option) => option.value) : [],
hidden: !!field.hidden,
} satisfies MultiSelectFieldOutput_2024_06_14;
case "checkbox":
return {
isDefault: false,
type: field.type,
slug: field.name,
label: field.label,
required: !!field.required,
disableOnPrefill: !!field.disableOnPrefill,
options: field.options ? field.options.map((option) => option.value) : [],
hidden: !!field.hidden,
} satisfies CheckboxGroupFieldOutput_2024_06_14;
case "radio":
return {
isDefault: false,
Expand All @@ -116,16 +263,15 @@ export function transformBookingFieldsInternalToApi(
label: field.label,
required: !!field.required,
options: field.options ? field.options.map((option) => option.value) : [],
...(field.type === "select" ? { placeholder: field.placeholder } : {}),
disableOnPrefill: !!field.disableOnPrefill,
hidden: !!field.hidden,
} as CustomFieldOutput_2024_06_14;
} satisfies RadioGroupFieldOutput_2024_06_14;
default:
return {
type: "unknown",
slug: "unknown",
bookingField: JSON.stringify(field),
};
} satisfies OutputUnknownBookingField_2024_06_14;
}
}
});
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4141,7 +4141,7 @@ __metadata:
"@axiomhq/winston": ^1.2.0
"@calcom/platform-constants": "*"
"@calcom/platform-enums": "*"
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.84"
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.85"
"@calcom/platform-libraries-0.0.2": "npm:@calcom/platform-libraries@0.0.2"
"@calcom/platform-types": "*"
"@calcom/platform-utils": "*"
Expand Down Expand Up @@ -5194,14 +5194,14 @@ __metadata:
languageName: node
linkType: hard

"@calcom/platform-libraries@npm:@calcom/platform-libraries@0.0.84":
version: 0.0.84
resolution: "@calcom/platform-libraries@npm:0.0.84"
"@calcom/platform-libraries@npm:@calcom/platform-libraries@0.0.85":
version: 0.0.85
resolution: "@calcom/platform-libraries@npm:0.0.85"
dependencies:
"@calcom/core": "*"
"@calcom/features": "*"
"@calcom/lib": "*"
checksum: 4372a4b7942ce8e13f1bb36c6b4e9193917ea1bc5322a4ca6af4176de01c70f199ff1fe707077f470df9d054a055be069a80d764cebd4ead502ac684b55ea5c9
checksum: 19e00a1de600805d800fc7027c246164f1c1ce58b837ca934313fe31c0c77e6338179e72b8045ceabcc9d754ddc3600028b8676dcf2b456696a443a3aed186ea
languageName: node
linkType: hard

Expand Down

0 comments on commit 6efc490

Please sign in to comment.