ingeniuscliq-core 0.5.42 → 0.5.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -58,28 +58,26 @@ function FormPhone({
|
|
|
58
58
|
const phoneNumberField = phoneNumberFieldName || "phone_number";
|
|
59
59
|
const selectedCountryField = "selected_country_iso";
|
|
60
60
|
useEffect(() => {
|
|
61
|
-
if (initialCountryCode && !watch(countryCodeField)
|
|
61
|
+
if (initialCountryCode && !watch(countryCodeField)) {
|
|
62
62
|
const country = countryCodes.find((c) => c.countryCode === initialCountryCode);
|
|
63
63
|
if (country) {
|
|
64
64
|
setValue(countryCodeField, country.callingCode);
|
|
65
65
|
setValue(selectedCountryField, country.countryCode);
|
|
66
|
-
setValue(
|
|
66
|
+
setValue(phoneNumberField, "");
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
}, [initialCountryCode, countryCodes
|
|
69
|
+
}, [initialCountryCode, countryCodes]);
|
|
70
70
|
useEffect(() => {
|
|
71
71
|
const fullPhone = watch(name);
|
|
72
72
|
const currentCountryCode = watch(countryCodeField);
|
|
73
|
-
if (fullPhone && typeof fullPhone === "string" && !currentCountryCode) {
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
76
|
-
const callingCode =
|
|
73
|
+
if (fullPhone && typeof fullPhone === "string" && fullPhone.length >= 8 && !currentCountryCode) {
|
|
74
|
+
const matchedCountry = countryCodes.find((c) => fullPhone.startsWith(c.callingCode));
|
|
75
|
+
if (matchedCountry) {
|
|
76
|
+
const callingCode = matchedCountry.callingCode;
|
|
77
|
+
const phoneNumber = fullPhone.substring(callingCode.length);
|
|
77
78
|
setValue(countryCodeField, callingCode);
|
|
78
|
-
setValue(phoneNumberField,
|
|
79
|
-
|
|
80
|
-
if (country) {
|
|
81
|
-
setValue(selectedCountryField, country.countryCode);
|
|
82
|
-
}
|
|
79
|
+
setValue(phoneNumberField, phoneNumber);
|
|
80
|
+
setValue(selectedCountryField, matchedCountry.countryCode);
|
|
83
81
|
}
|
|
84
82
|
}
|
|
85
83
|
}, [watch(name), countryCodes]);
|