@7shifts/sous-chef 3.52.0 → 3.53.0
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.
- package/dist/core/SousChefProvider/SousChefProvider.d.ts +3 -1
- package/dist/core/SousChefProvider/context/ProviderConfigContext.d.ts +8 -0
- package/dist/forms/PhoneField/PhoneField.d.ts +5 -4
- package/dist/forms/PhoneField/types.d.ts +0 -5
- package/dist/forms/PhoneField/usePhoneField.d.ts +15 -5
- package/dist/forms/hooks/usePhoneFieldControllers.d.ts +19 -8
- package/dist/forms/index.d.ts +1 -1
- package/dist/i18n/locales/en.json +3 -0
- package/dist/i18n/locales/es.json +3 -0
- package/dist/i18n/locales/fr.json +3 -0
- package/dist/index.js +120 -50
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +120 -50
- package/dist/index.modern.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import en from '../../i18n/locales/en.json';
|
|
3
|
+
import { CountryCode } from 'libphonenumber-js';
|
|
3
4
|
type Props = {
|
|
4
5
|
i18n?: typeof en;
|
|
6
|
+
country?: CountryCode;
|
|
5
7
|
children: React.ReactNode;
|
|
6
8
|
};
|
|
7
|
-
declare const SousChefProvider: ({ children, i18n }: Props) => React.JSX.Element;
|
|
9
|
+
declare const SousChefProvider: ({ children, i18n, country }: Props) => React.JSX.Element;
|
|
8
10
|
export default SousChefProvider;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { CountryCode } from 'libphonenumber-js';
|
|
3
|
+
export type ProviderConfigContextType = {
|
|
4
|
+
country: CountryCode;
|
|
5
|
+
};
|
|
6
|
+
declare const ProviderConfigContext: import("react").Context<ProviderConfigContextType>;
|
|
7
|
+
export declare const useProviderConfig: () => ProviderConfigContextType;
|
|
8
|
+
export default ProviderConfigContext;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { CountryCode } from 'libphonenumber-js';
|
|
3
3
|
export type Props = {
|
|
4
4
|
autoFocus?: boolean;
|
|
5
5
|
caption?: React.ReactNode;
|
|
@@ -10,12 +10,13 @@ export type Props = {
|
|
|
10
10
|
label?: React.ReactNode;
|
|
11
11
|
maxLength?: number;
|
|
12
12
|
name: string;
|
|
13
|
-
onBlur?: (value:
|
|
14
|
-
onChange?: (value:
|
|
13
|
+
onBlur?: (value: string) => void;
|
|
14
|
+
onChange?: (value: string) => void;
|
|
15
15
|
placeholder?: string;
|
|
16
|
-
value?:
|
|
16
|
+
value?: string;
|
|
17
17
|
testId?: string;
|
|
18
18
|
disabledCountry?: boolean;
|
|
19
|
+
defaultCountry?: CountryCode;
|
|
19
20
|
};
|
|
20
21
|
declare const PhoneField: ({ disabledCountry, ...props }: Props) => React.JSX.Element;
|
|
21
22
|
export default PhoneField;
|
|
@@ -4,7 +4,7 @@ import type { Props } from './PhoneField';
|
|
|
4
4
|
type UseTextFieldProps = Props & {
|
|
5
5
|
ref: RefType<HTMLInputElement>;
|
|
6
6
|
};
|
|
7
|
-
export declare const usePhoneField: ({ autoFocus, disabled, error, id, maxLength, name, caption, label, onBlur, onChange, placeholder, value, ref, testId }: UseTextFieldProps) => {
|
|
7
|
+
export declare const usePhoneField: ({ autoFocus, disabled, error, id, maxLength, name, caption, label, onBlur, onChange, placeholder, value, ref, testId, defaultCountry }: UseTextFieldProps) => {
|
|
8
8
|
inputProps: {
|
|
9
9
|
'aria-describedby': string;
|
|
10
10
|
'aria-invalid': boolean;
|
|
@@ -15,13 +15,13 @@ export declare const usePhoneField: ({ autoFocus, disabled, error, id, maxLength
|
|
|
15
15
|
id: string;
|
|
16
16
|
maxLength: number | undefined;
|
|
17
17
|
name: string;
|
|
18
|
-
onBlur: (e:
|
|
19
|
-
onChange: (e:
|
|
18
|
+
onBlur: (e: string) => void;
|
|
19
|
+
onChange: (e: string) => void;
|
|
20
20
|
placeholder: string | undefined;
|
|
21
21
|
ref: RefType<HTMLInputElement>;
|
|
22
22
|
size: number;
|
|
23
23
|
type: string;
|
|
24
|
-
value: string
|
|
24
|
+
value: string;
|
|
25
25
|
};
|
|
26
26
|
fieldProps: {
|
|
27
27
|
caption: import("react").ReactNode;
|
|
@@ -30,6 +30,16 @@ export declare const usePhoneField: ({ autoFocus, disabled, error, id, maxLength
|
|
|
30
30
|
id: string;
|
|
31
31
|
name: string;
|
|
32
32
|
};
|
|
33
|
-
fieldValue:
|
|
33
|
+
fieldValue: string | undefined;
|
|
34
|
+
metaData: {
|
|
35
|
+
country: import("libphonenumber-js").CountryCode;
|
|
36
|
+
phone: string;
|
|
37
|
+
parsingError?: string | undefined;
|
|
38
|
+
};
|
|
39
|
+
changeMeta: (data: {
|
|
40
|
+
country: import("libphonenumber-js").CountryCode;
|
|
41
|
+
phone: string;
|
|
42
|
+
parsingError?: string | undefined;
|
|
43
|
+
}) => void;
|
|
34
44
|
};
|
|
35
45
|
export {};
|
|
@@ -1,20 +1,31 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
2
|
+
import { CountryCode } from 'libphonenumber-js';
|
|
3
3
|
type FieldControls = {
|
|
4
4
|
id: string;
|
|
5
5
|
error?: React.ReactNode;
|
|
6
|
-
value?:
|
|
7
|
-
onChange: (e:
|
|
8
|
-
onBlur: (e:
|
|
6
|
+
value?: string;
|
|
7
|
+
onChange: (e: string) => void;
|
|
8
|
+
onBlur: (e: string) => void;
|
|
9
|
+
metaData: {
|
|
10
|
+
country: CountryCode;
|
|
11
|
+
phone: string;
|
|
12
|
+
parsingError?: string;
|
|
13
|
+
};
|
|
14
|
+
changeMeta: (data: {
|
|
15
|
+
country: CountryCode;
|
|
16
|
+
phone: string;
|
|
17
|
+
parsingError?: string;
|
|
18
|
+
}) => void;
|
|
9
19
|
};
|
|
10
20
|
type Props = {
|
|
11
21
|
name: string;
|
|
12
22
|
id?: string;
|
|
13
|
-
value?:
|
|
14
|
-
onChange?: (e:
|
|
15
|
-
onBlur?: (e:
|
|
23
|
+
value?: string;
|
|
24
|
+
onChange?: (e: string) => void;
|
|
25
|
+
onBlur?: (e: string) => void;
|
|
16
26
|
error?: React.ReactNode;
|
|
17
27
|
onMenuInputFocus?: (isFocused: boolean) => void;
|
|
28
|
+
defaultCountry?: CountryCode;
|
|
18
29
|
};
|
|
19
|
-
export declare const usePhoneFieldControllers: ({ name, id: inputId, value, onChange, onBlur, error, onMenuInputFocus }: Props) => FieldControls;
|
|
30
|
+
export declare const usePhoneFieldControllers: ({ name, id: inputId, value, onChange, onBlur, error, onMenuInputFocus, defaultCountry }: Props) => FieldControls;
|
|
20
31
|
export {};
|
package/dist/forms/index.d.ts
CHANGED
|
@@ -27,4 +27,4 @@ export type { PasswordCriteria } from './PasswordField/types';
|
|
|
27
27
|
export type { SelectOption, SelectOptions, GroupOption, CustomOptionProps, SelectedOptionPrefixProps } from './SelectField/types';
|
|
28
28
|
export type { AsyncSelectOptions } from './AsyncSelectField/types';
|
|
29
29
|
export type { FormikType } from './Form/types';
|
|
30
|
-
export type {
|
|
30
|
+
export type { PhoneFieldCountryCode } from './PhoneField/types';
|
|
@@ -40,5 +40,8 @@
|
|
|
40
40
|
"DataTable": {
|
|
41
41
|
"emptyStateTitle": "No results found",
|
|
42
42
|
"emptyStateCaption": "Try adding a new item to the list or adjust your search terms."
|
|
43
|
+
},
|
|
44
|
+
"PhoneField": {
|
|
45
|
+
"malformedPhoneNumber": "Malformed phone number. Please enter a valid phone number."
|
|
43
46
|
}
|
|
44
47
|
}
|
|
@@ -40,5 +40,8 @@
|
|
|
40
40
|
"DataTable": {
|
|
41
41
|
"emptyStateTitle": "No se encontraron resultados",
|
|
42
42
|
"emptyStateCaption": "Intenta agregar un nuevo elemento a la lista o ajusta tus términos de búsqueda."
|
|
43
|
+
},
|
|
44
|
+
"PhoneField": {
|
|
45
|
+
"malformedPhoneNumber": "Número de teléfono mal formado. Por favor, ingresa un número de teléfono válido."
|
|
43
46
|
}
|
|
44
47
|
}
|
|
@@ -40,5 +40,8 @@
|
|
|
40
40
|
"DataTable": {
|
|
41
41
|
"emptyStateTitle": "Aucun résultat trouvé",
|
|
42
42
|
"emptyStateCaption": "Essayez d'ajouter un nouvel élément à la liste ou ajustez vos termes de recherche."
|
|
43
|
+
},
|
|
44
|
+
"PhoneField": {
|
|
45
|
+
"malformedPhoneNumber": "Numéro de téléphone mal formé. Veuillez entrer un numéro de téléphone valide."
|
|
43
46
|
}
|
|
44
47
|
}
|
package/dist/index.js
CHANGED
|
@@ -5760,6 +5760,9 @@ var DataTable = {
|
|
|
5760
5760
|
emptyStateTitle: "No results found",
|
|
5761
5761
|
emptyStateCaption: "Try adding a new item to the list or adjust your search terms."
|
|
5762
5762
|
};
|
|
5763
|
+
var PhoneField = {
|
|
5764
|
+
malformedPhoneNumber: "Malformed phone number. Please enter a valid phone number."
|
|
5765
|
+
};
|
|
5763
5766
|
var en = {
|
|
5764
5767
|
PaginationControls: PaginationControls,
|
|
5765
5768
|
AsyncSelectField: AsyncSelectField,
|
|
@@ -5767,7 +5770,8 @@ var en = {
|
|
|
5767
5770
|
HintModal: HintModal,
|
|
5768
5771
|
Calendar: Calendar,
|
|
5769
5772
|
Card: Card,
|
|
5770
|
-
DataTable: DataTable
|
|
5773
|
+
DataTable: DataTable,
|
|
5774
|
+
PhoneField: PhoneField
|
|
5771
5775
|
};
|
|
5772
5776
|
|
|
5773
5777
|
var initialValue = {
|
|
@@ -5937,15 +5941,33 @@ var ToastContainer = function ToastContainer(_ref2) {
|
|
|
5937
5941
|
});
|
|
5938
5942
|
};
|
|
5939
5943
|
|
|
5944
|
+
var initialValue$1 = {
|
|
5945
|
+
country: 'US'
|
|
5946
|
+
};
|
|
5947
|
+
var ProviderConfigContext = React.createContext(initialValue$1);
|
|
5948
|
+
var useProviderConfig = function useProviderConfig() {
|
|
5949
|
+
var context = React.useContext(ProviderConfigContext);
|
|
5950
|
+
if (!context) {
|
|
5951
|
+
throw Error('The `<SousChefProvider>` is not set. Please wrap your application with `<SousChefProvider>`');
|
|
5952
|
+
}
|
|
5953
|
+
return context;
|
|
5954
|
+
};
|
|
5955
|
+
|
|
5940
5956
|
var SousChefProvider = function SousChefProvider(_ref) {
|
|
5941
5957
|
var children = _ref.children,
|
|
5942
5958
|
_ref$i18n = _ref.i18n,
|
|
5943
|
-
i18n = _ref$i18n === void 0 ? en : _ref$i18n
|
|
5944
|
-
|
|
5959
|
+
i18n = _ref$i18n === void 0 ? en : _ref$i18n,
|
|
5960
|
+
_ref$country = _ref.country,
|
|
5961
|
+
country = _ref$country === void 0 ? 'US' : _ref$country;
|
|
5962
|
+
return React__default.createElement(ProviderConfigContext.Provider, {
|
|
5963
|
+
value: {
|
|
5964
|
+
country: country
|
|
5965
|
+
}
|
|
5966
|
+
}, React__default.createElement(TranslationsContext.Provider, {
|
|
5945
5967
|
value: {
|
|
5946
5968
|
i18n: i18n
|
|
5947
5969
|
}
|
|
5948
|
-
}, React__default.createElement(ToastContainer, null), children);
|
|
5970
|
+
}, React__default.createElement(ToastContainer, null), children));
|
|
5949
5971
|
};
|
|
5950
5972
|
|
|
5951
5973
|
var styles$a = {"data-table-header":"_1vpCK","data-table-header__item":"_dJWps","data-table-header__item--sortable":"_14AEw","data-table-header__itemfocus":"_2JSFR","data-table-header__item--action":"_29TM7","data-table-header__item-content":"_2Zpt5","data-table-header__item-content--right-align":"_3WtwH","data-table-header__sort-icon":"_3codU"};
|
|
@@ -6154,12 +6176,12 @@ var DATA_TABLE_SCROLL_STATES = {
|
|
|
6154
6176
|
};
|
|
6155
6177
|
var AMOUNT_OF_SKELETON_ROWS = 10;
|
|
6156
6178
|
|
|
6157
|
-
var initialValue$
|
|
6179
|
+
var initialValue$2 = {
|
|
6158
6180
|
columns: [],
|
|
6159
6181
|
numberOfRows: 0,
|
|
6160
6182
|
state: DATA_TABLE_STATES.SKELETON_LOADING
|
|
6161
6183
|
};
|
|
6162
|
-
var Context = React.createContext(initialValue$
|
|
6184
|
+
var Context = React.createContext(initialValue$2);
|
|
6163
6185
|
var useDataTableContext = function useDataTableContext() {
|
|
6164
6186
|
var context = React.useContext(Context);
|
|
6165
6187
|
if (!context) {
|
|
@@ -12140,16 +12162,57 @@ var usePhoneFieldControllers = function usePhoneFieldControllers(_ref) {
|
|
|
12140
12162
|
_onChange = _ref.onChange,
|
|
12141
12163
|
_onBlur = _ref.onBlur,
|
|
12142
12164
|
error = _ref.error,
|
|
12143
|
-
onMenuInputFocus = _ref.onMenuInputFocus
|
|
12165
|
+
onMenuInputFocus = _ref.onMenuInputFocus,
|
|
12166
|
+
defaultCountry = _ref.defaultCountry;
|
|
12167
|
+
var __ = useTranslation('PhoneField');
|
|
12168
|
+
var errorMessage = __('malformedPhoneNumber');
|
|
12144
12169
|
var _useFormContext = useFormContext(),
|
|
12145
12170
|
formik = _useFormContext.formik;
|
|
12146
12171
|
var id = useFieldId({
|
|
12147
12172
|
name: name,
|
|
12148
12173
|
id: inputId
|
|
12149
12174
|
});
|
|
12175
|
+
var formikState = getFormikState(name, formik);
|
|
12176
|
+
var phoneFieldValue = formik && formikState && !value ? formikState.value : value;
|
|
12177
|
+
var _useProviderConfig = useProviderConfig(),
|
|
12178
|
+
country = _useProviderConfig.country;
|
|
12179
|
+
var parseMeta = function parseMeta(value) {
|
|
12180
|
+
if (value === '') {
|
|
12181
|
+
return {
|
|
12182
|
+
country: defaultCountry || country,
|
|
12183
|
+
phone: ''
|
|
12184
|
+
};
|
|
12185
|
+
}
|
|
12186
|
+
try {
|
|
12187
|
+
var phone = libphonenumberJs.parsePhoneNumber(value);
|
|
12188
|
+
var formatedPhone = new libphonenumberJs.AsYouType(phone.country).input(value.replace('+' + phone.countryCallingCode, ''));
|
|
12189
|
+
if (!phone.country) {
|
|
12190
|
+
return {
|
|
12191
|
+
country: defaultCountry || country,
|
|
12192
|
+
phone: formatedPhone,
|
|
12193
|
+
parsingError: errorMessage
|
|
12194
|
+
};
|
|
12195
|
+
}
|
|
12196
|
+
return {
|
|
12197
|
+
country: phone.country,
|
|
12198
|
+
phone: formatedPhone
|
|
12199
|
+
};
|
|
12200
|
+
} catch (error) {
|
|
12201
|
+
return {
|
|
12202
|
+
country: defaultCountry || country,
|
|
12203
|
+
phone: value,
|
|
12204
|
+
parsingError: errorMessage
|
|
12205
|
+
};
|
|
12206
|
+
}
|
|
12207
|
+
};
|
|
12208
|
+
var _useState = React.useState(function () {
|
|
12209
|
+
return parseMeta(phoneFieldValue || '');
|
|
12210
|
+
}),
|
|
12211
|
+
meta = _useState[0],
|
|
12212
|
+
setMeta = _useState[1];
|
|
12150
12213
|
var controllers = {
|
|
12151
12214
|
id: id,
|
|
12152
|
-
error: error,
|
|
12215
|
+
error: error || meta.parsingError,
|
|
12153
12216
|
value: value,
|
|
12154
12217
|
onChange: function onChange(option) {
|
|
12155
12218
|
if (_onChange) {
|
|
@@ -12168,10 +12231,9 @@ var usePhoneFieldControllers = function usePhoneFieldControllers(_ref) {
|
|
|
12168
12231
|
}
|
|
12169
12232
|
}
|
|
12170
12233
|
};
|
|
12171
|
-
var formikState = getFormikState(name, formik);
|
|
12172
12234
|
if (formik && formikState) {
|
|
12173
12235
|
controllers = _extends({}, controllers, {
|
|
12174
|
-
error: error ? controllers.error : formikState.error,
|
|
12236
|
+
error: error || meta.parsingError ? controllers.error : formikState.error,
|
|
12175
12237
|
value: value ? controllers.value : formikState.value,
|
|
12176
12238
|
onChange: function onChange(option) {
|
|
12177
12239
|
if (_onChange) {
|
|
@@ -12193,11 +12255,14 @@ var usePhoneFieldControllers = function usePhoneFieldControllers(_ref) {
|
|
|
12193
12255
|
}
|
|
12194
12256
|
});
|
|
12195
12257
|
}
|
|
12196
|
-
return controllers
|
|
12258
|
+
return _extends({}, controllers, {
|
|
12259
|
+
metaData: meta,
|
|
12260
|
+
changeMeta: setMeta
|
|
12261
|
+
});
|
|
12197
12262
|
};
|
|
12198
12263
|
|
|
12199
12264
|
var usePhoneField = function usePhoneField(_ref) {
|
|
12200
|
-
var _classnames
|
|
12265
|
+
var _classnames;
|
|
12201
12266
|
var autoFocus = _ref.autoFocus,
|
|
12202
12267
|
disabled = _ref.disabled,
|
|
12203
12268
|
error = _ref.error,
|
|
@@ -12211,14 +12276,16 @@ var usePhoneField = function usePhoneField(_ref) {
|
|
|
12211
12276
|
placeholder = _ref.placeholder,
|
|
12212
12277
|
value = _ref.value,
|
|
12213
12278
|
ref = _ref.ref,
|
|
12214
|
-
testId = _ref.testId
|
|
12279
|
+
testId = _ref.testId,
|
|
12280
|
+
defaultCountry = _ref.defaultCountry;
|
|
12215
12281
|
var controllers = usePhoneFieldControllers({
|
|
12216
12282
|
error: error,
|
|
12217
12283
|
id: id,
|
|
12218
12284
|
name: name,
|
|
12219
12285
|
onChange: onChange,
|
|
12220
12286
|
onBlur: onBlur,
|
|
12221
|
-
value: value
|
|
12287
|
+
value: value,
|
|
12288
|
+
defaultCountry: defaultCountry
|
|
12222
12289
|
});
|
|
12223
12290
|
var hasError = !!controllers.error;
|
|
12224
12291
|
var inputProps = {
|
|
@@ -12237,7 +12304,7 @@ var usePhoneField = function usePhoneField(_ref) {
|
|
|
12237
12304
|
ref: ref,
|
|
12238
12305
|
size: 1,
|
|
12239
12306
|
type: 'text',
|
|
12240
|
-
value:
|
|
12307
|
+
value: controllers.metaData.phone
|
|
12241
12308
|
};
|
|
12242
12309
|
var fieldProps = {
|
|
12243
12310
|
caption: caption,
|
|
@@ -12249,7 +12316,9 @@ var usePhoneField = function usePhoneField(_ref) {
|
|
|
12249
12316
|
return {
|
|
12250
12317
|
inputProps: inputProps,
|
|
12251
12318
|
fieldProps: fieldProps,
|
|
12252
|
-
fieldValue: controllers.value
|
|
12319
|
+
fieldValue: controllers.value,
|
|
12320
|
+
metaData: controllers.metaData,
|
|
12321
|
+
changeMeta: controllers.changeMeta
|
|
12253
12322
|
};
|
|
12254
12323
|
};
|
|
12255
12324
|
|
|
@@ -13034,25 +13103,27 @@ var CountrySelector = function CountrySelector(_ref) {
|
|
|
13034
13103
|
};
|
|
13035
13104
|
|
|
13036
13105
|
var _excluded$2N = ["disabledCountry"];
|
|
13037
|
-
var PhoneField = function PhoneField(_ref) {
|
|
13106
|
+
var PhoneField$1 = function PhoneField(_ref) {
|
|
13038
13107
|
var _classNames;
|
|
13039
13108
|
var _ref$disabledCountry = _ref.disabledCountry,
|
|
13040
13109
|
disabledCountry = _ref$disabledCountry === void 0 ? false : _ref$disabledCountry,
|
|
13041
13110
|
props = _objectWithoutPropertiesLoose(_ref, _excluded$2N);
|
|
13111
|
+
var __ = useTranslation('PhoneField');
|
|
13042
13112
|
var inputRef = React.useRef(null);
|
|
13043
13113
|
var _usePhoneField = usePhoneField(_extends({}, props, {
|
|
13044
13114
|
ref: inputRef
|
|
13045
13115
|
})),
|
|
13046
13116
|
inputProps = _usePhoneField.inputProps,
|
|
13047
13117
|
fieldProps = _usePhoneField.fieldProps,
|
|
13048
|
-
|
|
13049
|
-
|
|
13118
|
+
metaData = _usePhoneField.metaData,
|
|
13119
|
+
changeMeta = _usePhoneField.changeMeta;
|
|
13120
|
+
var selectedCountry = metaData.country;
|
|
13050
13121
|
var handleCountryChange = function handleCountryChange(countryCode) {
|
|
13051
|
-
|
|
13122
|
+
changeMeta({
|
|
13052
13123
|
country: countryCode,
|
|
13053
|
-
phone: ''
|
|
13054
|
-
internationalPhone: ''
|
|
13124
|
+
phone: ''
|
|
13055
13125
|
});
|
|
13126
|
+
inputProps.onChange('');
|
|
13056
13127
|
if (inputRef.current) {
|
|
13057
13128
|
inputRef.current.focus();
|
|
13058
13129
|
}
|
|
@@ -13060,45 +13131,44 @@ var PhoneField = function PhoneField(_ref) {
|
|
|
13060
13131
|
var handlePhoneChange = function handlePhoneChange(e) {
|
|
13061
13132
|
var formatedPhone = new libphonenumberJs.AsYouType(selectedCountry).input(e.target.value);
|
|
13062
13133
|
e.target.value = formatedPhone;
|
|
13063
|
-
|
|
13134
|
+
var internationalPhone = '';
|
|
13135
|
+
var parseError = null;
|
|
13136
|
+
try {
|
|
13137
|
+
var phoneNumber = libphonenumberJs.parsePhoneNumber(e.target.value, selectedCountry);
|
|
13138
|
+
internationalPhone = phoneNumber.number;
|
|
13139
|
+
} catch (error) {
|
|
13140
|
+
parseError = error;
|
|
13141
|
+
}
|
|
13142
|
+
if (parseError && parseError.message === 'TOO_LONG') {
|
|
13143
|
+
return;
|
|
13144
|
+
}
|
|
13145
|
+
changeMeta({
|
|
13064
13146
|
country: selectedCountry,
|
|
13065
|
-
phone: formatedPhone
|
|
13066
|
-
internationalPhone: ''
|
|
13147
|
+
phone: formatedPhone
|
|
13067
13148
|
});
|
|
13149
|
+
inputProps.onChange(internationalPhone);
|
|
13068
13150
|
};
|
|
13069
13151
|
var handlePhoneBlur = function handlePhoneBlur(e) {
|
|
13070
13152
|
var internationalPhone = '';
|
|
13153
|
+
var countryParseError = undefined;
|
|
13071
13154
|
try {
|
|
13072
13155
|
var phoneNumber = libphonenumberJs.parsePhoneNumber(e.target.value, selectedCountry);
|
|
13073
13156
|
internationalPhone = phoneNumber.number;
|
|
13157
|
+
var parseFromInternationalNumber = libphonenumberJs.parsePhoneNumber(phoneNumber.number);
|
|
13158
|
+
if (!parseFromInternationalNumber.country) {
|
|
13159
|
+
countryParseError = __('malformedPhoneNumber');
|
|
13160
|
+
}
|
|
13074
13161
|
} catch (error) {
|
|
13075
13162
|
console.warn("PhoneField: " + error);
|
|
13076
13163
|
}
|
|
13077
|
-
|
|
13078
|
-
|
|
13079
|
-
|
|
13080
|
-
|
|
13081
|
-
|
|
13082
|
-
|
|
13083
|
-
inputProps.onBlur(value);
|
|
13084
|
-
};
|
|
13085
|
-
React.useEffect(function () {
|
|
13086
|
-
if (Boolean(fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.internationalPhone) && (fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.phone) === '') {
|
|
13087
|
-
var formatedPhone = '';
|
|
13088
|
-
try {
|
|
13089
|
-
var phoneNumber = libphonenumberJs.parsePhoneNumber(fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.internationalPhone);
|
|
13090
|
-
formatedPhone = new libphonenumberJs.AsYouType(selectedCountry).input(phoneNumber.nationalNumber);
|
|
13091
|
-
} catch (error) {
|
|
13092
|
-
console.warn("PhoneField: " + error);
|
|
13093
|
-
}
|
|
13094
|
-
var value = {
|
|
13095
|
-
country: selectedCountry,
|
|
13096
|
-
phone: formatedPhone,
|
|
13097
|
-
internationalPhone: fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.internationalPhone
|
|
13098
|
-
};
|
|
13099
|
-
inputProps.onChange(value);
|
|
13164
|
+
inputProps.onChange(internationalPhone);
|
|
13165
|
+
inputProps.onBlur(internationalPhone);
|
|
13166
|
+
if (countryParseError !== undefined) {
|
|
13167
|
+
changeMeta(_extends({}, metaData, {
|
|
13168
|
+
parsingError: countryParseError
|
|
13169
|
+
}));
|
|
13100
13170
|
}
|
|
13101
|
-
}
|
|
13171
|
+
};
|
|
13102
13172
|
return React__default.createElement(Field, _extends({}, fieldProps), React__default.createElement("div", {
|
|
13103
13173
|
className: styles$1c['phone-field']
|
|
13104
13174
|
}, !disabledCountry && React__default.createElement(CountrySelector, {
|
|
@@ -13654,7 +13724,7 @@ exports.PasswordField = PasswordField;
|
|
|
13654
13724
|
exports.Paywall = Paywall;
|
|
13655
13725
|
exports.PercentageField = PercentageField;
|
|
13656
13726
|
exports.PersistentBanner = PersistentBanner;
|
|
13657
|
-
exports.PhoneField = PhoneField;
|
|
13727
|
+
exports.PhoneField = PhoneField$1;
|
|
13658
13728
|
exports.Pill = Pill;
|
|
13659
13729
|
exports.PillSelectField = PillSelectField;
|
|
13660
13730
|
exports.ProgressBar = ProgressBar;
|