Scheduling infrastructure for absolutely everyone.
fix(phone input): trigger validation and formatting for prefill query… (#23123)
Vibhor Phalke882eb85a3397
diff --git a/packages/features/components/phone-input/PhoneInput.tsx b/packages/features/components/phone-input/PhoneInput.tsxindex 070eea48b28..644ef67cb84 100644--- a/packages/features/components/phone-input/PhoneInput.tsx+++ b/packages/features/components/phone-input/PhoneInput.tsx@@ -31,6 +31,22 @@ function BasePhoneInput({}: PhoneInputProps) {const isPlatform = useIsPlatform();+ // This is to trigger validation on prefill value changes+ useEffect(() => {+ if (!value) return;++ const sanitized = value+ .trim()+ .replace(/[^\d+]/g, "")+ .replace(/^\+?/, "+");++ if (sanitized === "+" || sanitized === "") return;++ if (value !== sanitized) {+ onChange(sanitized);+ }+ }, []);+if (!isPlatform) {return (<BasePhoneInputWeb name={name} className={className} onChange={onChange} value={value} {...rest} />@@ -45,12 +61,12 @@ function BasePhoneInput({disableSearchIconcountry={defaultCountry}inputProps={{- name: name,+ name,required: rest.required,placeholder: rest.placeholder,}}- onChange={(value) => {- onChange(`+${value}`);+ onChange={(val: string) => {+ onChange(`+${val}`);}}containerClass={classNames("hover:border-emphasis dark:focus:border-emphasis border-default !bg-default rounded-md border focus-within:outline-none focus-within:ring-2 focus-within:ring-brand-default disabled:cursor-not-allowed",@@ -84,6 +100,7 @@ function BasePhoneInputWeb({...rest}: Omit<PhoneInputProps, "defaultCountry">) {const defaultCountry = useDefaultCountry();+return (<PhoneInput{...rest}@@ -92,12 +109,12 @@ function BasePhoneInputWeb({enableSearchdisableSearchIconinputProps={{- name: name,+ name,required: rest.required,placeholder: rest.placeholder,}}- onChange={(value) => {- onChange(`+${value}`);+ onChange={(val: string) => {+ onChange(`+${val}`);}}containerClass={classNames("hover:border-emphasis dark:focus:border-emphasis border-default !bg-default rounded-md border focus-within:outline-none focus-within:ring-2 focus-within:ring-brand-default disabled:cursor-not-allowed",