@rh-support/components 2.1.70 → 2.1.71
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.
|
@@ -12,6 +12,17 @@ interface IProps {
|
|
|
12
12
|
isDisabled?: boolean;
|
|
13
13
|
shouldNotSetCountryCode?: boolean;
|
|
14
14
|
}
|
|
15
|
+
export declare const getExactCountry: (phoneNumber: string) => any[] | {
|
|
16
|
+
name: string | number | string[];
|
|
17
|
+
regions: string | number | string[];
|
|
18
|
+
iso2: string | number | string[];
|
|
19
|
+
countryCode: string | number | string[];
|
|
20
|
+
dialCode: string | number | string[];
|
|
21
|
+
format: string;
|
|
22
|
+
priority: string | number | string[];
|
|
23
|
+
areaCode: string | number | string[];
|
|
24
|
+
phoneInitials: string[];
|
|
25
|
+
};
|
|
15
26
|
export declare const getPhoneObj: (phoneNumber: string) => {
|
|
16
27
|
countryCode: string;
|
|
17
28
|
phoneLine: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneInput.d.ts","sourceRoot":"","sources":["../../../src/PhoneInput/PhoneInput.tsx"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAC;AAO3B,OAAO,KAA8B,MAAM,OAAO,CAAC;AAKnD,UAAU,MAAM;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,CAAC,MAAM,KAAA,KAAK,IAAI,CAAC;IACrC,WAAW,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IACtE,mBAAmB,CAAC,EAAE,CAAC,MAAM,KAAA,KAAK,IAAI,CAAC;IACvC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,CAAC,OAAO,KAAA,KAAK,IAAI,CAAC;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACrC;
|
|
1
|
+
{"version":3,"file":"PhoneInput.d.ts","sourceRoot":"","sources":["../../../src/PhoneInput/PhoneInput.tsx"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAC;AAO3B,OAAO,KAA8B,MAAM,OAAO,CAAC;AAKnD,UAAU,MAAM;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,CAAC,MAAM,KAAA,KAAK,IAAI,CAAC;IACrC,WAAW,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IACtE,mBAAmB,CAAC,EAAE,CAAC,MAAM,KAAA,KAAK,IAAI,CAAC;IACvC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,CAAC,OAAO,KAAA,KAAK,IAAI,CAAC;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACrC;AAoDD,eAAO,MAAM,eAAe,gBAAiB,MAAM;;;;;;;;;;CAmClD,CAAC;AAqCF,eAAO,MAAM,WAAW,gBAAiB,MAAM;;;CAgB9C,CAAC;AAEF,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,qBAwLvC"}
|
|
@@ -55,6 +55,30 @@ const removeAllChars = (value) => {
|
|
|
55
55
|
// to remove all chars, brackets and have only digits
|
|
56
56
|
return value === null || value === void 0 ? void 0 : value.replace(/[^0-9]/g, '');
|
|
57
57
|
};
|
|
58
|
+
// guess exact country for any given phone
|
|
59
|
+
export const getExactCountry = (phoneNumber) => {
|
|
60
|
+
let localPhone = removeAllChars(phoneNumber);
|
|
61
|
+
// Guessing countries according to user input
|
|
62
|
+
const possibleCountries = initializedCountries === null || initializedCountries === void 0 ? void 0 : initializedCountries.filter((country) => localPhone === null || localPhone === void 0 ? void 0 : localPhone.startsWith(country.dialCode.toString()));
|
|
63
|
+
const possibleCountriesPhoneInitials = possibleCountries === null || possibleCountries === void 0 ? void 0 : possibleCountries.map((country) => country.phoneInitials);
|
|
64
|
+
// Function to find the matching country index based on user phone input
|
|
65
|
+
const findMatchingIndex = (possibleCountry, phone) => {
|
|
66
|
+
for (let i = 0; i < (possibleCountry === null || possibleCountry === void 0 ? void 0 : possibleCountry.length); i++) {
|
|
67
|
+
const country = possibleCountry[i];
|
|
68
|
+
for (let j = 0; j < (country === null || country === void 0 ? void 0 : country.length); j++) {
|
|
69
|
+
if (phone.startsWith(country[j])) {
|
|
70
|
+
return i;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return -1; // Return -1 if no match is found
|
|
75
|
+
};
|
|
76
|
+
const countryMatchingIndex = findMatchingIndex(possibleCountriesPhoneInitials, localPhone);
|
|
77
|
+
const defaultCountry = possibleCountries === null || possibleCountries === void 0 ? void 0 : possibleCountries.filter((country) => (localPhone === null || localPhone === void 0 ? void 0 : localPhone.startsWith(country.dialCode.toString())) && isEqual(country.priority, 0));
|
|
78
|
+
const possibleDefaultCountry = !isEmpty(defaultCountry[0]) && !isUndefined(defaultCountry[0]) ? defaultCountry[0] : []; // default country when phone didn't match with any country's area code
|
|
79
|
+
const exactCountry = countryMatchingIndex < 0 ? possibleDefaultCountry : possibleCountries[countryMatchingIndex];
|
|
80
|
+
return exactCountry;
|
|
81
|
+
};
|
|
58
82
|
// Formatting phone numbers according to country
|
|
59
83
|
const formatNumber = (fullPhoneNumber, localFormat) => {
|
|
60
84
|
var _a;
|
|
@@ -88,21 +112,19 @@ const formatNumber = (fullPhoneNumber, localFormat) => {
|
|
|
88
112
|
};
|
|
89
113
|
// return phoneline and countrycode for any given phone
|
|
90
114
|
export const getPhoneObj = (phoneNumber) => {
|
|
91
|
-
var _a
|
|
115
|
+
var _a;
|
|
92
116
|
let localPhone = removeAllChars(phoneNumber);
|
|
93
117
|
let countryCode = '';
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (!isEmpty(exactCountry)) {
|
|
98
|
-
countryCode = PREFIX + ((_a = exactCountry[0]) === null || _a === void 0 ? void 0 : _a.dialCode.toString());
|
|
118
|
+
const exactCountry = getExactCountry(localPhone);
|
|
119
|
+
if (!isEmpty(exactCountry) && !isEmpty(exactCountry['dialCode'].toString())) {
|
|
120
|
+
countryCode = PREFIX + exactCountry['dialCode'].toString();
|
|
99
121
|
}
|
|
100
|
-
else
|
|
101
|
-
countryCode =
|
|
122
|
+
else {
|
|
123
|
+
countryCode = '';
|
|
102
124
|
}
|
|
103
125
|
return {
|
|
104
126
|
countryCode: countryCode,
|
|
105
|
-
phoneLine: localPhone === null || localPhone === void 0 ? void 0 : localPhone.substring((
|
|
127
|
+
phoneLine: localPhone === null || localPhone === void 0 ? void 0 : localPhone.substring((_a = trimAndReplacePlusFromPhone(countryCode)) === null || _a === void 0 ? void 0 : _a.length, localPhone === null || localPhone === void 0 ? void 0 : localPhone.length),
|
|
106
128
|
};
|
|
107
129
|
};
|
|
108
130
|
export function PhoneInput(props) {
|
|
@@ -117,25 +139,7 @@ export function PhoneInput(props) {
|
|
|
117
139
|
return DEFAULT_FORMAT; // default format for portal phone without country code
|
|
118
140
|
}
|
|
119
141
|
let localFormat;
|
|
120
|
-
|
|
121
|
-
const possibleCountries = initializedCountries.filter((country) => localPhone === null || localPhone === void 0 ? void 0 : localPhone.startsWith(country.dialCode.toString()));
|
|
122
|
-
const possibleCountriesPhoneInitials = possibleCountries === null || possibleCountries === void 0 ? void 0 : possibleCountries.map((country) => country.phoneInitials);
|
|
123
|
-
// Function to find the matching country index based on user phone input
|
|
124
|
-
const findMatchingIndex = (possibleCountry, phone) => {
|
|
125
|
-
for (let i = 0; i < (possibleCountry === null || possibleCountry === void 0 ? void 0 : possibleCountry.length); i++) {
|
|
126
|
-
const country = possibleCountry[i];
|
|
127
|
-
for (let j = 0; j < (country === null || country === void 0 ? void 0 : country.length); j++) {
|
|
128
|
-
if (phone.startsWith(country[j])) {
|
|
129
|
-
return i;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return -1; // Return -1 if no match is found
|
|
134
|
-
};
|
|
135
|
-
const countryMatchingIndex = findMatchingIndex(possibleCountriesPhoneInitials, localPhone);
|
|
136
|
-
const defaultCountry = possibleCountries === null || possibleCountries === void 0 ? void 0 : possibleCountries.filter((country) => (localPhone === null || localPhone === void 0 ? void 0 : localPhone.startsWith(country.dialCode.toString())) && isEqual(country.priority, 0));
|
|
137
|
-
const possibleDefaultCountry = !isUndefined(defaultCountry[0]) ? defaultCountry[0] : []; // default country when phone didn't match with any country's area code
|
|
138
|
-
const exactCountry = countryMatchingIndex < 0 ? possibleDefaultCountry : possibleCountries[countryMatchingIndex];
|
|
142
|
+
const exactCountry = getExactCountry(localPhone);
|
|
139
143
|
if (!isEmpty(exactCountry)) {
|
|
140
144
|
setIso2(exactCountry['iso2'].toString());
|
|
141
145
|
localFormat = exactCountry['format'].toString();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rh-support/components",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.71",
|
|
4
4
|
"description": "Contains all reusabel components for support app",
|
|
5
5
|
"author": "Vikas Rathee <vrathee@redhat.com>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -109,5 +109,5 @@
|
|
|
109
109
|
"defaults and supports es6-module",
|
|
110
110
|
"maintained node versions"
|
|
111
111
|
],
|
|
112
|
-
"gitHead": "
|
|
112
|
+
"gitHead": "9de4fff35aa1e2abec92656fa48e1b7b759a9e6c"
|
|
113
113
|
}
|