-
Notifications
You must be signed in to change notification settings - Fork 10.4k
fix(phone input): trigger validation and formatting for prefill query… #23123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(phone input): trigger validation and formatting for prefill query… #23123
Conversation
@Vibgitcode27 is attempting to deploy a commit to the cal Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughAdded mount-time sanitization in the PhoneInput components: on mount (and when value changes) the prefill is trimmed, non-digit/non-plus characters removed, and a leading plus enforced; if the sanitized value differs and is not just "+" or empty, onChange is invoked with the sanitized value. onChange handlers were updated to accept a typed string and normalize calls to include a leading plus. Value formatting and defaultCountry logic were left unchanged. No public API signatures were modified. Assessment against linked issues
Assessment against linked issues: Out-of-scope changes
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
Graphite Automations"Add consumer team as reviewer" took an action on this PR • (08/15/25)1 reviewer was added to this PR based on Keith Williams's automation. "Add community label" took an action on this PR • (08/15/25)1 label was added to this PR based on Keith Williams's automation. |
There was a problem hiding this comment.
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)
packages/features/components/phone-input/PhoneInput.tsx (1)
98-106
: Consider dependency array for useEffect.The useEffect runs only on mount (
[]
dependency), but if thevalue
oronChange
props change after mount, the sanitization won't re-run. This might be intentional for prefill scenarios, but consider if dynamic value updates need sanitization.If dynamic updates should trigger sanitization, update the dependency array:
- }, []); + }, [value, onChange]);However, be cautious of infinite re-renders if
onChange
isn't memoized in parent components.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
packages/features/components/phone-input/PhoneInput.tsx
(4 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.tsx
📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)
Always use
t()
for text localization in frontend code; direct text embedding should trigger a warning
Files:
packages/features/components/phone-input/PhoneInput.tsx
**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)
Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js
.utc()
in hot paths like loops
Files:
packages/features/components/phone-input/PhoneInput.tsx
🧠 Learnings (1)
📓 Common learnings
Learnt from: Udit-takkar
PR: calcom/cal.com#22919
File: packages/features/calAIPhone/providers/retellAI/services/PhoneNumberService.ts:212-220
Timestamp: 2025-08-08T10:26:13.362Z
Learning: In calcom/cal.com PR #22919, packages/features/calAIPhone/providers/retellAI/services/PhoneNumberService.ts should include the phone number in client-facing HttpError messages (e.g., in updatePhoneNumber/getPhoneNumber catch blocks). Do not suggest redacting the phone number from these errors unless requirements change (per maintainer: Udit-takkar).
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Install dependencies / Yarn install & cache
🔇 Additional comments (5)
packages/features/components/phone-input/PhoneInput.tsx (5)
34-42
: LGTM! Properly addresses the core issue.The useEffect correctly sanitizes prefilled phone numbers by trimming whitespace, removing internal spaces, and ensuring a leading plus sign. This solves the issue where validation wasn't triggered on prefilled values from query parameters.
58-58
: Minor: Simplify prop syntax.Good simplification from the verbose
name: name
to shorthandname
.
62-64
: LGTM! Proper type annotation and normalization.The typed parameter
val: string
improves type safety, and the+${val}
normalization ensures consistent phone number formatting with leading plus signs.
116-116
: LGTM! Consistent prop simplification.Matches the same improvement made in the BasePhoneInput component.
120-122
: LGTM! Consistent implementation.The typed parameter and normalization logic matches the BasePhoneInput implementation, maintaining consistency across both components.
@Vibgitcode27 Thanks for the pr. Can you please address the coderabbit suggestions? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left a comment
useEffect(() => { | ||
if (value) { | ||
const sanitized = value.trim().replace(/\s+/g, "").replace(/^\+?/, "+"); | ||
if (value !== sanitized) { | ||
onChange(sanitized); | ||
} | ||
} | ||
}, []); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As suggested by coderabbit, we already do use libphonenumber-js library for phone number validation. Could you please check if we can use that to perform phone number validation here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with CodeRabbit's suggestion. I implemented the regex approach for consistency since we already use similar logic in this component:
value={value ? value.trim().replace(/^\+?/, "+") : undefined}
However, if you prefer using libphonenumber-js, I can implement it with parseIncompletePhoneNumber
something like this:
useEffect(() => {
if (!value) return;
const cleanedDigits = parseIncompletePhoneNumber(value);
if (!cleanedDigits) return;
const sanitized = cleanedDigits.startsWith("+") ? cleanedDigits : `+${cleanedDigits}`;
if (value !== sanitized) {
onChange(sanitized);
}
}, []);
I have pushed the regex approach. if you think I should implement the other one, please let me know and I’ll do it quickly.
@kart1ka I’ve made the changes. Have a look whenever you get time. |
@kart1ka Can you review this? |
@coderabbitai could you pls review it once again? |
🧩 Analysis chain |
🧩 Analysis chainI'll review the PR changes once again to ensure everything looks good. @anikdhabal I've reviewed the PR changes again. Here's my analysis: ✅ Code Review - Changes Look GoodThe implementation correctly addresses the phone input prefilling issues: Key Improvements:
Implementation Details:
Addresses Original Issues:
The changes are minimal, focused, and should resolve the reported issues without introducing side effects. The implementation follows React best practices and maintains backward compatibility. 🏁 Script executed:
Length of output: 4946 🏁 Script executed:
Length of output: 260 🏁 Script executed:
Length of output: 66 🏁 Script executed:
Length of output: 91 🏁 Script executed:
Length of output: 1107 @anikdhabal I've completed the review. Here's my detailed analysis: ✅ Code Review - Overall Good ImplementationThe phone input changes effectively address the prefilling issues. Here are my findings: Positive Aspects:
|
E2E results are ready! |
What does this PR do?
Motivation and Context
Visual Demo
Before:
After:
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
+
/%2B
prefixes.Checklist
Additional notes
The original issue report focused on space/blank character causing validation failures.
In reality, the core problem was that the input’s validation was not triggered on prefilled values.
This PR solves it by ensuring that the phone field runs internal validation and formatting immediately after prefill, not just after user input.