ingeniuscliq-core 0.5.35 → 0.5.37
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.
|
@@ -17,7 +17,8 @@ interface FormPhoneProps<T extends FieldValues = FieldValues> extends BaseStyleP
|
|
|
17
17
|
readonly watch: (name: Path<T>) => any;
|
|
18
18
|
readonly countryCodeFieldName?: string;
|
|
19
19
|
readonly phoneNumberFieldName?: string;
|
|
20
|
+
readonly initialCountryCode?: string;
|
|
20
21
|
}
|
|
21
|
-
export declare function FormPhone<T extends FieldValues = FieldValues>({ control, name, label, customLabel, placeholder, className, inputProps, withinLabel, withinMessage, withinControl, required, withoutPlaceholder, setValue, watch, countryCodeFieldName, phoneNumberFieldName }: FormPhoneProps<T>): import("react").JSX.Element;
|
|
22
|
+
export declare function FormPhone<T extends FieldValues = FieldValues>({ control, name, label, customLabel, placeholder, className, inputProps, withinLabel, withinMessage, withinControl, required, withoutPlaceholder, setValue, watch, countryCodeFieldName, phoneNumberFieldName, initialCountryCode }: FormPhoneProps<T>): import("react").JSX.Element;
|
|
22
23
|
export {};
|
|
23
24
|
//# sourceMappingURL=FormPhone.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormPhone.d.ts","sourceRoot":"","sources":["../../../../src/components/common/form/FormPhone.tsx"],"names":[],"mappings":"AACA,OAAO,EAAS,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAGlE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAWnF,UAAU,cAAc,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,CAAE,SAAQ,cAAc;IAClF,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAA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one({
|
|
|
29
29
|
setValue,
|
|
30
30
|
watch,
|
|
31
31
|
countryCodeFieldName,
|
|
32
|
-
phoneNumberFieldName
|
|
32
|
+
phoneNumberFieldName,
|
|
33
|
+
initialCountryCode
|
|
33
34
|
}) {
|
|
34
35
|
const { t, language } = useLanguage();
|
|
35
36
|
const countryCodes = useMemo(() => {
|
|
@@ -54,6 +55,16 @@ function FormPhone({
|
|
|
54
55
|
}, [language]);
|
|
55
56
|
const countryCodeField = countryCodeFieldName || "country_code";
|
|
56
57
|
const phoneNumberField = phoneNumberFieldName || "phone_number";
|
|
58
|
+
const selectedCountryField = "selected_country_iso";
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (initialCountryCode && !watch(countryCodeField) && !watch(name)) {
|
|
61
|
+
const country = countryCodes.find((c) => c.countryCode === initialCountryCode);
|
|
62
|
+
if (country) {
|
|
63
|
+
setValue(countryCodeField, country.callingCode);
|
|
64
|
+
setValue(selectedCountryField, country.countryCode);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}, [initialCountryCode, countryCodes]);
|
|
57
68
|
useEffect(() => {
|
|
58
69
|
const countryCode = watch(countryCodeField);
|
|
59
70
|
const phoneNumber = watch(phoneNumberField);
|
|
@@ -66,11 +77,16 @@ function FormPhone({
|
|
|
66
77
|
if (fullPhone && typeof fullPhone === "string" && !watch(countryCodeField)) {
|
|
67
78
|
const phoneMatch = fullPhone.match(/^(\+\d{1,3})(\d+)$/);
|
|
68
79
|
if (phoneMatch) {
|
|
69
|
-
|
|
80
|
+
const callingCode = phoneMatch[1];
|
|
81
|
+
setValue(countryCodeField, callingCode);
|
|
70
82
|
setValue(phoneNumberField, phoneMatch[2]);
|
|
83
|
+
const country = countryCodes.find((c) => c.callingCode === callingCode);
|
|
84
|
+
if (country) {
|
|
85
|
+
setValue(selectedCountryField, country.countryCode);
|
|
86
|
+
}
|
|
71
87
|
}
|
|
72
88
|
}
|
|
73
|
-
}, [watch(name)]);
|
|
89
|
+
}, [watch(name), countryCodes]);
|
|
74
90
|
const getPlaceholder = useCallback(() => {
|
|
75
91
|
if (withoutPlaceholder) return "";
|
|
76
92
|
if (placeholder) return required ? placeholder : `${placeholder} ${t("fields.optional")}`;
|
|
@@ -99,15 +115,16 @@ function FormPhone({
|
|
|
99
115
|
Select,
|
|
100
116
|
{
|
|
101
117
|
onValueChange: (value) => {
|
|
102
|
-
const callingCode = value.split("|")
|
|
118
|
+
const [isoCode, callingCode] = value.split("|");
|
|
103
119
|
setValue(countryCodeField, callingCode);
|
|
120
|
+
setValue(selectedCountryField, isoCode);
|
|
104
121
|
},
|
|
105
122
|
value: (
|
|
106
|
-
//
|
|
107
|
-
countryCodes.find((c) => c.
|
|
123
|
+
// Usar el código ISO guardado para encontrar el país exacto seleccionado
|
|
124
|
+
watch(selectedCountryField) ? countryCodes.find((c) => c.countryCode === watch(selectedCountryField))?.value || "" : ""
|
|
108
125
|
),
|
|
109
126
|
children: [
|
|
110
|
-
/* @__PURE__ */ jsx(SelectTrigger, { className: cn("
|
|
127
|
+
/* @__PURE__ */ jsx(SelectTrigger, { className: cn("!h-full", inputProps?.className), children: /* @__PURE__ */ jsx(SelectValue, { placeholder: "+53", children: watch(countryCodeField) || "+53" }) }),
|
|
111
128
|
/* @__PURE__ */ jsx(SelectContent, { children: countryCodes.map((option) => /* @__PURE__ */ jsx(
|
|
112
129
|
SelectItem,
|
|
113
130
|
{
|