Skip to content

fix(web): preserve phone country while typing international numbers#29754

Open
ronit-1404 wants to merge 2 commits into
calcom:mainfrom
ronit-1404:phin
Open

fix(web): preserve phone country while typing international numbers#29754
ronit-1404 wants to merge 2 commits into
calcom:mainfrom
ronit-1404:phin

Conversation

@ronit-1404

Copy link
Copy Markdown

Fixes #29739

PR description:
This fixes the booking phone input so typing a country calling code directly no longer resets the field back to the US flag or +1 while the user keeps typing. The input now infers and retains the matching country from the typed calling code, so cases like +91... or +371... behave like US input does today.

What changed:

Added country inference from calling-code prefixes in the phone input component.
Persisted the inferred country in component state so it does not snap back between keystrokes.
Covered the behavior with regression tests for +371, +91, and raw-digit entry flows.
Bug fixed:

Direct entry of non-US international numbers would revert to US formatting/default country when the user started typing, especially after entering a calling code or pressing space.
Prefilled calling-code-only values such as +371 now resolve to the correct country instead of defaulting to US.

@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Cal.diy, @ronit-1404! Thanks for opening this pull request.

A few things to keep in mind:

  • This is Cal.diy, not Cal.com. Cal.diy is a community-driven, fully open-source fork of Cal.com licensed under MIT. Your changes here will be part of Cal.diy — they will not be deployed to the Cal.com production app.
  • Please review our Contributing Guidelines if you haven't already.
  • Make sure your PR title follows the Conventional Commits format.

A maintainer will review your PR soon. Thanks for contributing!

@github-actions github-actions Bot added the 🐛 bug Something isn't working label Jul 11, 2026
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 44a1d26a-2324-432e-a53c-83bf1e589bd2

📥 Commits

Reviewing files that changed from the base of the PR and between 1c7a2a4 and 3ee394f.

📒 Files selected for processing (1)
  • packages/prisma/.env
💤 Files with no reviewable changes (1)
  • packages/prisma/.env

📝 Walkthrough

Walkthrough

The phone input now infers countries from unambiguous calling-code prefixes, synchronizes selected country state in platform and web variants, and normalizes changed values with a leading +. Tests cover unique and ambiguous calling codes.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The packages/prisma/.env change is unrelated to the phone-input fix and is not justified by the linked issue. Move the .env change to a separate PR or explain why it is required for the phone-input fix.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: preserving phone country selection for international number input.
Description check ✅ Passed The description is directly related to the phone input fix and the regression tests added.
Linked Issues check ✅ Passed The phone input now infers country from calling-code prefixes and handles +371-style values as required by #29739.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/web/components/phone-input/PhoneInput.tsx (1)

29-49: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Avoid recomputing getCountries() on every inference call.

getCountries() is invoked again inside inferCountryFromPhoneValue (Line 44) on top of the module-level computation, and the helper runs on every render (Lines 61, 156) and every keystroke via onChange. Precompute a calling-code → countries map once at module scope so lookups are O(1).

♻️ Proposed precomputation
-const COUNTRY_CALLING_CODES = getCountries()
-  .map((country) => getCountryCallingCode(country).toString())
-  .filter((callingCode, index, allCallingCodes) => allCallingCodes.indexOf(callingCode) === index)
-  .sort((left, right) => right.length - left.length);
+const CALLING_CODE_TO_COUNTRIES = getCountries().reduce<Record<string, CountryCode[]>>((acc, country) => {
+  const callingCode = getCountryCallingCode(country).toString();
+  (acc[callingCode] ??= []).push(country.toLowerCase() as CountryCode);
+  return acc;
+}, {});
+const COUNTRY_CALLING_CODES = Object.keys(CALLING_CODE_TO_COUNTRIES).sort(
+  (left, right) => right.length - left.length
+);
 
 export const inferCountryFromPhoneValue = (value?: string): CountryCode | undefined => {
   if (!value) return undefined;
 
   const sanitized = value.trim().replace(/[^\d+]/g, "").replace(/^\+?/, "+");
   if (!/^\+\d+$/.test(sanitized)) return undefined;
 
   const dialingCode = sanitized.slice(1);
   const matchingCallingCode = COUNTRY_CALLING_CODES.find((callingCode) => dialingCode.startsWith(callingCode));
   if (!matchingCallingCode) return undefined;
 
-  const matchingCountries = getCountries().filter(
-    (country) => getCountryCallingCode(country).toString() === matchingCallingCode
-  );
-
-  return matchingCountries.length === 1 ? (matchingCountries[0].toLowerCase() as CountryCode) : undefined;
+  const matchingCountries = CALLING_CODE_TO_COUNTRIES[matchingCallingCode];
+  return matchingCountries.length === 1 ? matchingCountries[0] : undefined;
 };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/components/phone-input/PhoneInput.tsx` around lines 29 - 49,
Precompute a calling-code-to-countries map at module scope alongside
COUNTRY_CALLING_CODES, using getCountries() once and grouping each country by
its calling code. Update inferCountryFromPhoneValue to look up matching
countries from that map instead of calling getCountries().filter on every
inference, while preserving the existing unique-country return behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/prisma/.env`:
- Around line 17-18: Remove all credential and key values from the tracked .env
file, including DATABASE_URL, DATABASE_DIRECT_URL, NEXTAUTH_SECRET,
CRON_API_KEY, CALENDSO_ENCRYPTION_KEY, and the E2E account password; replace
them with an ignored local environment-file or secret-manager workflow and
ensure the file is excluded from version control. Rotate or revoke every exposed
value if valid.

---

Nitpick comments:
In `@apps/web/components/phone-input/PhoneInput.tsx`:
- Around line 29-49: Precompute a calling-code-to-countries map at module scope
alongside COUNTRY_CALLING_CODES, using getCountries() once and grouping each
country by its calling code. Update inferCountryFromPhoneValue to look up
matching countries from that map instead of calling getCountries().filter on
every inference, while preserving the existing unique-country return behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 84a013bb-d1e6-4fad-a886-27fc39585d0c

📥 Commits

Reviewing files that changed from the base of the PR and between f004349 and 1c7a2a4.

📒 Files selected for processing (3)
  • apps/web/components/phone-input/PhoneInput.test.ts
  • apps/web/components/phone-input/PhoneInput.tsx
  • packages/prisma/.env

Comment thread packages/prisma/.env Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

attendeePhoneNumber in params can't parse country phone code

1 participant