feat: add defaultPhoneCountry prop with ISO 3166-1 alpha-2 type safety (#25204)

* feat: add defaultPhoneCountry prop to BookerPlatformWrapper

- Add defaultPhoneCountry to BookerStore type and implementation
- Add defaultPhoneCountry prop to BookerPlatformWrapper types
- Pass defaultPhoneCountry through store initialization
- Update PhoneInput to use defaultPhoneCountry from store
- Support default phone country extension for phone inputs in booker form

* feat: add strict typing for defaultPhoneCountry with ISO 3166-1 alpha-2 codes

- Define CountryCode type using ISO 3166-1 alpha-2 country codes
- Update defaultPhoneCountry prop type in BookerPlatformWrapper to use CountryCode
- Update defaultPhoneCountry type in BookerStore to use CountryCode
- Ensures type safety by only allowing valid country codes like 'us', 'gb', 'ee', etc.
- Fix lint warnings by prefixing type-only constants with underscore

Co-Authored-By: [email protected] <[email protected]>

* refactor: export CountryCode from store to avoid duplication

- Export CountryCode type from packages/features/bookings/Booker/store.ts
- Import CountryCode in packages/platform/atoms/booker/types.ts from store
- Remove duplicate CountryCode definition from types.ts
- Maintains single source of truth for country code type definition

Co-Authored-By: [email protected] <[email protected]>

* fix: add type-safe casts for CountryCode in PhoneInput

- Import CountryCode type from store
- Add explicit type annotation to useState<CountryCode>
- Add safe type casts with isSupportedCountry validation
- Validate navigator.language country code before using it
- Fixes CI type error: string not assignable to CountryCode

Co-Authored-By: [email protected] <[email protected]>

* docs: add defaultPhoneCountry prop documentation and changeset

- Add defaultPhoneCountry prop to booker.mdx documentation
- Add changeset for minor version bump
- Document ISO 3166-1 alpha-2 country code support

Co-Authored-By: [email protected] <[email protected]>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Rajiv Sahal <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-11-17 15:56:10 +00:00
1 parent f0e10129a1
commit 037cb8ee2a
6 files changed
+73 -9

No files matched your search

@@ -70,6 +70,7 @@ const BookerPlatformWrapperComponent = (
showNoAvailabilityDialog,
silentlyHandleCalendarFailures = false,
hideEventMetadata = false,
defaultPhoneCountry,
} = props;
const layout = BookerLayouts[view];
@@ -185,6 +186,7 @@ const BookerPlatformWrapperComponent = (
bookingData,
isPlatform: true,
allowUpdatingUrlParams,
defaultPhoneCountry,
});
useInitializeBookerStoreContext({
...props,
@@ -201,6 +203,7 @@ const BookerPlatformWrapperComponent = (
bookingData,
isPlatform: true,
allowUpdatingUrlParams,
defaultPhoneCountry,
});
const [dayCount] = useBookerStoreContext((state) => [state.dayCount, state.setDayCount], shallow);
const selectedDate = useBookerStoreContext((state) => state.selectedDate);
+3 -2
View File
@@ -3,7 +3,7 @@ import type React from "react";
import type { BookerProps } from "@calcom/features/bookings/Booker";
import type { BookerStore } from "@calcom/features/bookings/Booker/store";
import type { BookerStore, CountryCode } from "@calcom/features/bookings/Booker/store";
import type { Timezone, VIEW_TYPE } from "@calcom/features/bookings/Booker/types";
import type { BookingCreateBody } from "@calcom/features/bookings/lib/bookingCreateBodySchema";
import type { BookingResponse } from "@calcom/platform-libraries";
@@ -88,6 +88,7 @@ export type BookerPlatformWrapperAtomProps = Omit<
roundRobinHideOrgAndTeam?: boolean;
silentlyHandleCalendarFailures?: boolean;
hideEventMetadata?: boolean;
defaultPhoneCountry?: CountryCode;
};
export type BookerPlatformWrapperAtomPropsForIndividual = BookerPlatformWrapperAtomProps & {
@@ -101,4 +102,4 @@ export type BookerPlatformWrapperAtomPropsForTeam = BookerPlatformWrapperAtomPro
isTeamEvent: true;
teamId: number;
routingFormSearchParams?: RoutingFormSearchParams;
};
};