@7shifts/sous-chef 3.52.0-beta.0 → 3.52.0-beta.1

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.
@@ -34,6 +34,7 @@ export declare const usePhoneField: ({ autoFocus, disabled, error, id, maxLength
34
34
  metaData: {
35
35
  country: import("libphonenumber-js").CountryCode;
36
36
  phone: string;
37
+ parsingError?: string | undefined;
37
38
  };
38
39
  changeMeta: (data: {
39
40
  country: import("libphonenumber-js").CountryCode;
@@ -9,6 +9,7 @@ type FieldControls = {
9
9
  metaData: {
10
10
  country: CountryCode;
11
11
  phone: string;
12
+ parsingError?: string;
12
13
  };
13
14
  changeMeta: (data: {
14
15
  country: CountryCode;
@@ -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
@@ -5725,6 +5725,9 @@ var DataTable = {
5725
5725
  emptyStateTitle: "No results found",
5726
5726
  emptyStateCaption: "Try adding a new item to the list or adjust your search terms."
5727
5727
  };
5728
+ var PhoneField = {
5729
+ malformedPhoneNumber: "Malformed phone number. Please enter a valid phone number."
5730
+ };
5728
5731
  var en = {
5729
5732
  PaginationControls: PaginationControls,
5730
5733
  AsyncSelectField: AsyncSelectField,
@@ -5732,7 +5735,8 @@ var en = {
5732
5735
  HintModal: HintModal,
5733
5736
  Calendar: Calendar,
5734
5737
  Card: Card,
5735
- DataTable: DataTable
5738
+ DataTable: DataTable,
5739
+ PhoneField: PhoneField
5736
5740
  };
5737
5741
 
5738
5742
  var initialValue = {
@@ -12125,33 +12129,14 @@ var usePhoneFieldControllers = function usePhoneFieldControllers(_ref) {
12125
12129
  error = _ref.error,
12126
12130
  onMenuInputFocus = _ref.onMenuInputFocus,
12127
12131
  defaultCountry = _ref.defaultCountry;
12132
+ var __ = useTranslation('PhoneField');
12133
+ var errorMessage = __('malformedPhoneNumber');
12128
12134
  var _useFormContext = useFormContext(),
12129
12135
  formik = _useFormContext.formik;
12130
12136
  var id = useFieldId({
12131
12137
  name: name,
12132
12138
  id: inputId
12133
12139
  });
12134
- var controllers = {
12135
- id: id,
12136
- error: error,
12137
- value: value,
12138
- onChange: function onChange(option) {
12139
- if (_onChange) {
12140
- _onChange(option);
12141
- }
12142
- if (_onChange && onMenuInputFocus) {
12143
- onMenuInputFocus(false);
12144
- }
12145
- },
12146
- onBlur: function onBlur(option) {
12147
- if (_onBlur) {
12148
- _onBlur(option);
12149
- }
12150
- if (_onBlur && onMenuInputFocus) {
12151
- onMenuInputFocus(false);
12152
- }
12153
- }
12154
- };
12155
12140
  var formikState = getFormikState(name, formik);
12156
12141
  var phoneFieldValue = formik && formikState && !value ? formikState.value : value;
12157
12142
  var _useProviderConfig = useProviderConfig(),
@@ -12166,6 +12151,13 @@ var usePhoneFieldControllers = function usePhoneFieldControllers(_ref) {
12166
12151
  try {
12167
12152
  var phone = libphonenumberJs.parsePhoneNumber(value);
12168
12153
  var formatedPhone = new libphonenumberJs.AsYouType(phone.country).input(value.replace('+' + phone.countryCallingCode, ''));
12154
+ if (!phone.country) {
12155
+ return {
12156
+ country: defaultCountry || country,
12157
+ phone: formatedPhone,
12158
+ parsingError: errorMessage
12159
+ };
12160
+ }
12169
12161
  return {
12170
12162
  country: phone.country,
12171
12163
  phone: formatedPhone
@@ -12173,7 +12165,8 @@ var usePhoneFieldControllers = function usePhoneFieldControllers(_ref) {
12173
12165
  } catch (error) {
12174
12166
  return {
12175
12167
  country: defaultCountry || country,
12176
- phone: value
12168
+ phone: value,
12169
+ parsingError: errorMessage
12177
12170
  };
12178
12171
  }
12179
12172
  };
@@ -12182,9 +12175,30 @@ var usePhoneFieldControllers = function usePhoneFieldControllers(_ref) {
12182
12175
  }),
12183
12176
  meta = _useState[0],
12184
12177
  setMeta = _useState[1];
12178
+ var controllers = {
12179
+ id: id,
12180
+ error: error || meta.parsingError,
12181
+ value: value,
12182
+ onChange: function onChange(option) {
12183
+ if (_onChange) {
12184
+ _onChange(option);
12185
+ }
12186
+ if (_onChange && onMenuInputFocus) {
12187
+ onMenuInputFocus(false);
12188
+ }
12189
+ },
12190
+ onBlur: function onBlur(option) {
12191
+ if (_onBlur) {
12192
+ _onBlur(option);
12193
+ }
12194
+ if (_onBlur && onMenuInputFocus) {
12195
+ onMenuInputFocus(false);
12196
+ }
12197
+ }
12198
+ };
12185
12199
  if (formik && formikState) {
12186
12200
  controllers = _extends({}, controllers, {
12187
- error: error ? controllers.error : formikState.error,
12201
+ error: error || meta.parsingError ? controllers.error : formikState.error,
12188
12202
  value: value ? controllers.value : formikState.value,
12189
12203
  onChange: function onChange(option) {
12190
12204
  if (_onChange) {
@@ -13054,7 +13068,7 @@ var CountrySelector = function CountrySelector(_ref) {
13054
13068
  };
13055
13069
 
13056
13070
  var _excluded$2M = ["disabledCountry"];
13057
- var PhoneField = function PhoneField(_ref) {
13071
+ var PhoneField$1 = function PhoneField(_ref) {
13058
13072
  var _classNames;
13059
13073
  var _ref$disabledCountry = _ref.disabledCountry,
13060
13074
  disabledCountry = _ref$disabledCountry === void 0 ? false : _ref$disabledCountry,
@@ -13663,7 +13677,7 @@ exports.PasswordField = PasswordField;
13663
13677
  exports.Paywall = Paywall;
13664
13678
  exports.PercentageField = PercentageField;
13665
13679
  exports.PersistentBanner = PersistentBanner;
13666
- exports.PhoneField = PhoneField;
13680
+ exports.PhoneField = PhoneField$1;
13667
13681
  exports.Pill = Pill;
13668
13682
  exports.PillSelectField = PillSelectField;
13669
13683
  exports.ProgressBar = ProgressBar;