From 499cbd08ca2f2e28cd91ea64b358e013ae8a5b79 Mon Sep 17 00:00:00 2001 From: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Date: Fri, 27 Jun 2025 14:39:04 +0530 Subject: [PATCH] feat: Phone based bookings for everyone (#21320) (#22024) * Revert "Revert "feat: Phone based bookings for everyone (#21320)" (#22018)" This reverts commit 80e2118e68b18ababd08ae322e179abe406d9f3c. * chore: don't use repository * chore: create getTeamWithOrganizationSettings function --------- Co-authored-by: Hariom Balhara --- apps/web/public/static/locales/en/common.json | 4 + .../features/bookings/lib/getBookingFields.ts | 35 ++- .../tabs/advanced/EventAdvancedTab.tsx | 51 ++-- .../features/form-builder/FormBuilder.tsx | 67 ++++- packages/lib/server/repository/team.ts | 14 + packages/sms/sms-manager.ts | 84 ++++-- packages/sms/test/sms-manager.test.ts | 255 ++++++++++++++++++ 7 files changed, 444 insertions(+), 66 deletions(-) create mode 100644 packages/sms/test/sms-manager.test.ts diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index 634bd6dcae..4df124bc83 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -267,6 +267,8 @@ "guests": "Guests", "guest": "Guest", "web_conferencing_details_to_follow": "Web conferencing details to follow in the confirmation email.", + "confirmation":"Confirmation", + "what_booker_should_provide": "What your booker should provide to receive confirmations", "404_the_user": "The username", "username": "Username", "is_still_available": "is still available.", @@ -1710,6 +1712,8 @@ "show_available_seats_count": "Show the number of available seats", "how_booking_questions_as_variables": "How to use booking questions as variables?", "format": "Format", + "questions": "Questions", + "all_info_your_booker_provide": "All the info your booker should provide before booking with you.", "uppercase_for_letters": "Use uppercase for all letters", "replace_whitespaces_underscores": "Replace whitespaces with underscores", "platform_members": "Platform members", diff --git a/packages/features/bookings/lib/getBookingFields.ts b/packages/features/bookings/lib/getBookingFields.ts index 05c1d1bc35..6fce4bc9ea 100644 --- a/packages/features/bookings/lib/getBookingFields.ts +++ b/packages/features/bookings/lib/getBookingFields.ts @@ -160,7 +160,22 @@ export const ensureBookingInputsHaveSystemFields = ({ type: "email", name: "email", required: !isEmailFieldOptional, - editable: isOrgTeamEvent ? "system-but-optional" : "system", + editable: "system-but-optional", + sources: [ + { + label: "Default", + id: "default", + type: "default", + }, + ], + }, + { + defaultLabel: "phone_number", + type: "phone", + name: "attendeePhoneNumber", + required: false, + hidden: true, + editable: "system-but-optional", sources: [ { label: "Default", @@ -169,7 +184,6 @@ export const ensureBookingInputsHaveSystemFields = ({ }, ], }, - { defaultLabel: "location", type: "radioInput", @@ -204,23 +218,6 @@ export const ensureBookingInputsHaveSystemFields = ({ ], }, ]; - if (isOrgTeamEvent) { - systemBeforeFields.splice(2, 0, { - defaultLabel: "phone_number", - type: "phone", - name: "attendeePhoneNumber", - required: false, - hidden: true, - editable: "system-but-optional", - sources: [ - { - label: "Default", - id: "default", - type: "default", - }, - ], - }); - } // These fields should be added after other user fields const systemAfterFields: typeof bookingFields = [ diff --git a/packages/features/eventtypes/components/tabs/advanced/EventAdvancedTab.tsx b/packages/features/eventtypes/components/tabs/advanced/EventAdvancedTab.tsx index 62cc1e0e35..253d12e3cd 100644 --- a/packages/features/eventtypes/components/tabs/advanced/EventAdvancedTab.tsx +++ b/packages/features/eventtypes/components/tabs/advanced/EventAdvancedTab.tsx @@ -577,27 +577,38 @@ export const EventAdvancedTab = ({ /> )} -
- +
+
+ {t("booking_questions_title")} +
+

+ {t("booking_questions_description")} +

+
+
+ { - // Location field has a default value at backend so API can send no location but we don't allow it in UI and thus we want to show it as required to user - return field.name === "location" ? true : field.required; - }} - /> + }} + shouldConsiderRequired={(field: BookingField) => { + // Location field has a default value at backend so API can send no location but we don't allow it in UI and thus we want to show it as required to user + return field.name === "location" ? true : field.required; + }} + /> +
-

{description}

+
+

{description}

+ {showPhoneAndEmailToggle && ( + { + const phoneField = fields.find((field) => field.name === "attendeePhoneNumber"); + const emailField = fields.find((field) => field.name === "email"); + + if (phoneField && !phoneField.hidden && phoneField.required && !emailField?.required) { + return "phone"; + } + + return "email"; + })()} + options={[ + { + value: "email", + label: "Email", + iconLeft: , + }, + { + value: "phone", + label: "Phone", + iconLeft: , + }, + ]} + onValueChange={(value) => { + const phoneFieldIndex = fields.findIndex((field) => field.name === "attendeePhoneNumber"); + const emailFieldIndex = fields.findIndex((field) => field.name === "email"); + if (value === "email") { + update(emailFieldIndex, { + ...fields[emailFieldIndex], + hidden: false, + required: true, + }); + update(phoneFieldIndex, { + ...fields[phoneFieldIndex], + hidden: true, + required: false, + }); + } else if (value === "phone") { + update(emailFieldIndex, { + ...fields[emailFieldIndex], + hidden: true, + required: false, + }); + update(phoneFieldIndex, { + ...fields[phoneFieldIndex], + hidden: false, + required: true, + }); + } + }} + /> + )} +
+

+ {t("questions")} +

+

+ {t("all_info_your_booker_provide")} +