import { isSupportedCountry } from "libphonenumber-js"; import { useState } from "react"; import BasePhoneInput from "react-phone-number-input"; import type { Props, Country } from "react-phone-number-input"; import "react-phone-number-input/style.css"; import { trpc } from "@calcom/trpc/react"; export type PhoneInputProps = Props<{ value: string; id?: string; placeholder?: string; required?: boolean; className?: string; name?: string; }>; function PhoneInput({ name, className = "", onChange, ...rest }: PhoneInputProps) { const defaultCountry = useDefaultCountry(); return ( ); } const useDefaultCountry = () => { const [defaultCountry, setDefaultCountry] = useState("US"); const query = trpc.viewer.public.countryCode.useQuery(undefined, { onSuccess: (data) => { if (isSupportedCountry(data?.countryCode)) { setDefaultCountry(data.countryCode as Country); } }, }); return defaultCountry; }; export default PhoneInput;