@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.
@@ -5756,6 +5756,9 @@ var DataTable = {
5756
5756
  emptyStateTitle: "No results found",
5757
5757
  emptyStateCaption: "Try adding a new item to the list or adjust your search terms."
5758
5758
  };
5759
+ var PhoneField = {
5760
+ malformedPhoneNumber: "Malformed phone number. Please enter a valid phone number."
5761
+ };
5759
5762
  var en = {
5760
5763
  PaginationControls: PaginationControls,
5761
5764
  AsyncSelectField: AsyncSelectField,
@@ -5763,7 +5766,8 @@ var en = {
5763
5766
  HintModal: HintModal,
5764
5767
  Calendar: Calendar,
5765
5768
  Card: Card,
5766
- DataTable: DataTable
5769
+ DataTable: DataTable,
5770
+ PhoneField: PhoneField
5767
5771
  };
5768
5772
 
5769
5773
  var initialValue = {
@@ -5933,15 +5937,33 @@ var ToastContainer = function ToastContainer(_ref2) {
5933
5937
  });
5934
5938
  };
5935
5939
 
5940
+ var initialValue$1 = {
5941
+ country: 'US'
5942
+ };
5943
+ var ProviderConfigContext = createContext(initialValue$1);
5944
+ var useProviderConfig = function useProviderConfig() {
5945
+ var context = useContext(ProviderConfigContext);
5946
+ if (!context) {
5947
+ throw Error('The `<SousChefProvider>` is not set. Please wrap your application with `<SousChefProvider>`');
5948
+ }
5949
+ return context;
5950
+ };
5951
+
5936
5952
  var SousChefProvider = function SousChefProvider(_ref) {
5937
5953
  var children = _ref.children,
5938
5954
  _ref$i18n = _ref.i18n,
5939
- i18n = _ref$i18n === void 0 ? en : _ref$i18n;
5940
- return React__default.createElement(TranslationsContext.Provider, {
5955
+ i18n = _ref$i18n === void 0 ? en : _ref$i18n,
5956
+ _ref$country = _ref.country,
5957
+ country = _ref$country === void 0 ? 'US' : _ref$country;
5958
+ return React__default.createElement(ProviderConfigContext.Provider, {
5959
+ value: {
5960
+ country: country
5961
+ }
5962
+ }, React__default.createElement(TranslationsContext.Provider, {
5941
5963
  value: {
5942
5964
  i18n: i18n
5943
5965
  }
5944
- }, React__default.createElement(ToastContainer, null), children);
5966
+ }, React__default.createElement(ToastContainer, null), children));
5945
5967
  };
5946
5968
 
5947
5969
  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"};
@@ -6150,12 +6172,12 @@ var DATA_TABLE_SCROLL_STATES = {
6150
6172
  };
6151
6173
  var AMOUNT_OF_SKELETON_ROWS = 10;
6152
6174
 
6153
- var initialValue$1 = {
6175
+ var initialValue$2 = {
6154
6176
  columns: [],
6155
6177
  numberOfRows: 0,
6156
6178
  state: DATA_TABLE_STATES.SKELETON_LOADING
6157
6179
  };
6158
- var Context = createContext(initialValue$1);
6180
+ var Context = createContext(initialValue$2);
6159
6181
  var useDataTableContext = function useDataTableContext() {
6160
6182
  var context = useContext(Context);
6161
6183
  if (!context) {
@@ -12136,16 +12158,57 @@ var usePhoneFieldControllers = function usePhoneFieldControllers(_ref) {
12136
12158
  _onChange = _ref.onChange,
12137
12159
  _onBlur = _ref.onBlur,
12138
12160
  error = _ref.error,
12139
- onMenuInputFocus = _ref.onMenuInputFocus;
12161
+ onMenuInputFocus = _ref.onMenuInputFocus,
12162
+ defaultCountry = _ref.defaultCountry;
12163
+ var __ = useTranslation('PhoneField');
12164
+ var errorMessage = __('malformedPhoneNumber');
12140
12165
  var _useFormContext = useFormContext(),
12141
12166
  formik = _useFormContext.formik;
12142
12167
  var id = useFieldId({
12143
12168
  name: name,
12144
12169
  id: inputId
12145
12170
  });
12171
+ var formikState = getFormikState(name, formik);
12172
+ var phoneFieldValue = formik && formikState && !value ? formikState.value : value;
12173
+ var _useProviderConfig = useProviderConfig(),
12174
+ country = _useProviderConfig.country;
12175
+ var parseMeta = function parseMeta(value) {
12176
+ if (value === '') {
12177
+ return {
12178
+ country: defaultCountry || country,
12179
+ phone: ''
12180
+ };
12181
+ }
12182
+ try {
12183
+ var phone = parsePhoneNumber(value);
12184
+ var formatedPhone = new AsYouType(phone.country).input(value.replace('+' + phone.countryCallingCode, ''));
12185
+ if (!phone.country) {
12186
+ return {
12187
+ country: defaultCountry || country,
12188
+ phone: formatedPhone,
12189
+ parsingError: errorMessage
12190
+ };
12191
+ }
12192
+ return {
12193
+ country: phone.country,
12194
+ phone: formatedPhone
12195
+ };
12196
+ } catch (error) {
12197
+ return {
12198
+ country: defaultCountry || country,
12199
+ phone: value,
12200
+ parsingError: errorMessage
12201
+ };
12202
+ }
12203
+ };
12204
+ var _useState = useState(function () {
12205
+ return parseMeta(phoneFieldValue || '');
12206
+ }),
12207
+ meta = _useState[0],
12208
+ setMeta = _useState[1];
12146
12209
  var controllers = {
12147
12210
  id: id,
12148
- error: error,
12211
+ error: error || meta.parsingError,
12149
12212
  value: value,
12150
12213
  onChange: function onChange(option) {
12151
12214
  if (_onChange) {
@@ -12164,10 +12227,9 @@ var usePhoneFieldControllers = function usePhoneFieldControllers(_ref) {
12164
12227
  }
12165
12228
  }
12166
12229
  };
12167
- var formikState = getFormikState(name, formik);
12168
12230
  if (formik && formikState) {
12169
12231
  controllers = _extends({}, controllers, {
12170
- error: error ? controllers.error : formikState.error,
12232
+ error: error || meta.parsingError ? controllers.error : formikState.error,
12171
12233
  value: value ? controllers.value : formikState.value,
12172
12234
  onChange: function onChange(option) {
12173
12235
  if (_onChange) {
@@ -12189,11 +12251,14 @@ var usePhoneFieldControllers = function usePhoneFieldControllers(_ref) {
12189
12251
  }
12190
12252
  });
12191
12253
  }
12192
- return controllers;
12254
+ return _extends({}, controllers, {
12255
+ metaData: meta,
12256
+ changeMeta: setMeta
12257
+ });
12193
12258
  };
12194
12259
 
12195
12260
  var usePhoneField = function usePhoneField(_ref) {
12196
- var _classnames, _controllers$value;
12261
+ var _classnames;
12197
12262
  var autoFocus = _ref.autoFocus,
12198
12263
  disabled = _ref.disabled,
12199
12264
  error = _ref.error,
@@ -12207,14 +12272,16 @@ var usePhoneField = function usePhoneField(_ref) {
12207
12272
  placeholder = _ref.placeholder,
12208
12273
  value = _ref.value,
12209
12274
  ref = _ref.ref,
12210
- testId = _ref.testId;
12275
+ testId = _ref.testId,
12276
+ defaultCountry = _ref.defaultCountry;
12211
12277
  var controllers = usePhoneFieldControllers({
12212
12278
  error: error,
12213
12279
  id: id,
12214
12280
  name: name,
12215
12281
  onChange: onChange,
12216
12282
  onBlur: onBlur,
12217
- value: value
12283
+ value: value,
12284
+ defaultCountry: defaultCountry
12218
12285
  });
12219
12286
  var hasError = !!controllers.error;
12220
12287
  var inputProps = {
@@ -12233,7 +12300,7 @@ var usePhoneField = function usePhoneField(_ref) {
12233
12300
  ref: ref,
12234
12301
  size: 1,
12235
12302
  type: 'text',
12236
- value: (_controllers$value = controllers.value) === null || _controllers$value === void 0 ? void 0 : _controllers$value.phone
12303
+ value: controllers.metaData.phone
12237
12304
  };
12238
12305
  var fieldProps = {
12239
12306
  caption: caption,
@@ -12245,7 +12312,9 @@ var usePhoneField = function usePhoneField(_ref) {
12245
12312
  return {
12246
12313
  inputProps: inputProps,
12247
12314
  fieldProps: fieldProps,
12248
- fieldValue: controllers.value
12315
+ fieldValue: controllers.value,
12316
+ metaData: controllers.metaData,
12317
+ changeMeta: controllers.changeMeta
12249
12318
  };
12250
12319
  };
12251
12320
 
@@ -13030,25 +13099,27 @@ var CountrySelector = function CountrySelector(_ref) {
13030
13099
  };
13031
13100
 
13032
13101
  var _excluded$2N = ["disabledCountry"];
13033
- var PhoneField = function PhoneField(_ref) {
13102
+ var PhoneField$1 = function PhoneField(_ref) {
13034
13103
  var _classNames;
13035
13104
  var _ref$disabledCountry = _ref.disabledCountry,
13036
13105
  disabledCountry = _ref$disabledCountry === void 0 ? false : _ref$disabledCountry,
13037
13106
  props = _objectWithoutPropertiesLoose(_ref, _excluded$2N);
13107
+ var __ = useTranslation('PhoneField');
13038
13108
  var inputRef = useRef(null);
13039
13109
  var _usePhoneField = usePhoneField(_extends({}, props, {
13040
13110
  ref: inputRef
13041
13111
  })),
13042
13112
  inputProps = _usePhoneField.inputProps,
13043
13113
  fieldProps = _usePhoneField.fieldProps,
13044
- fieldValue = _usePhoneField.fieldValue;
13045
- var selectedCountry = fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.country;
13114
+ metaData = _usePhoneField.metaData,
13115
+ changeMeta = _usePhoneField.changeMeta;
13116
+ var selectedCountry = metaData.country;
13046
13117
  var handleCountryChange = function handleCountryChange(countryCode) {
13047
- inputProps.onChange({
13118
+ changeMeta({
13048
13119
  country: countryCode,
13049
- phone: '',
13050
- internationalPhone: ''
13120
+ phone: ''
13051
13121
  });
13122
+ inputProps.onChange('');
13052
13123
  if (inputRef.current) {
13053
13124
  inputRef.current.focus();
13054
13125
  }
@@ -13056,45 +13127,44 @@ var PhoneField = function PhoneField(_ref) {
13056
13127
  var handlePhoneChange = function handlePhoneChange(e) {
13057
13128
  var formatedPhone = new AsYouType(selectedCountry).input(e.target.value);
13058
13129
  e.target.value = formatedPhone;
13059
- inputProps.onChange({
13130
+ var internationalPhone = '';
13131
+ var parseError = null;
13132
+ try {
13133
+ var phoneNumber = parsePhoneNumber(e.target.value, selectedCountry);
13134
+ internationalPhone = phoneNumber.number;
13135
+ } catch (error) {
13136
+ parseError = error;
13137
+ }
13138
+ if (parseError && parseError.message === 'TOO_LONG') {
13139
+ return;
13140
+ }
13141
+ changeMeta({
13060
13142
  country: selectedCountry,
13061
- phone: formatedPhone,
13062
- internationalPhone: ''
13143
+ phone: formatedPhone
13063
13144
  });
13145
+ inputProps.onChange(internationalPhone);
13064
13146
  };
13065
13147
  var handlePhoneBlur = function handlePhoneBlur(e) {
13066
13148
  var internationalPhone = '';
13149
+ var countryParseError = undefined;
13067
13150
  try {
13068
13151
  var phoneNumber = parsePhoneNumber(e.target.value, selectedCountry);
13069
13152
  internationalPhone = phoneNumber.number;
13153
+ var parseFromInternationalNumber = parsePhoneNumber(phoneNumber.number);
13154
+ if (!parseFromInternationalNumber.country) {
13155
+ countryParseError = __('malformedPhoneNumber');
13156
+ }
13070
13157
  } catch (error) {
13071
13158
  console.warn("PhoneField: " + error);
13072
13159
  }
13073
- var value = {
13074
- country: selectedCountry,
13075
- phone: e.target.value,
13076
- internationalPhone: internationalPhone
13077
- };
13078
- inputProps.onChange(value);
13079
- inputProps.onBlur(value);
13080
- };
13081
- useEffect(function () {
13082
- if (Boolean(fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.internationalPhone) && (fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.phone) === '') {
13083
- var formatedPhone = '';
13084
- try {
13085
- var phoneNumber = parsePhoneNumber(fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.internationalPhone);
13086
- formatedPhone = new AsYouType(selectedCountry).input(phoneNumber.nationalNumber);
13087
- } catch (error) {
13088
- console.warn("PhoneField: " + error);
13089
- }
13090
- var value = {
13091
- country: selectedCountry,
13092
- phone: formatedPhone,
13093
- internationalPhone: fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.internationalPhone
13094
- };
13095
- inputProps.onChange(value);
13160
+ inputProps.onChange(internationalPhone);
13161
+ inputProps.onBlur(internationalPhone);
13162
+ if (countryParseError !== undefined) {
13163
+ changeMeta(_extends({}, metaData, {
13164
+ parsingError: countryParseError
13165
+ }));
13096
13166
  }
13097
- }, [fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.internationalPhone]);
13167
+ };
13098
13168
  return React__default.createElement(Field, _extends({}, fieldProps), React__default.createElement("div", {
13099
13169
  className: styles$1c['phone-field']
13100
13170
  }, !disabledCountry && React__default.createElement(CountrySelector, {
@@ -13451,5 +13521,5 @@ var EmptyState = function EmptyState(props) {
13451
13521
  return emptyStateContainer;
13452
13522
  };
13453
13523
 
13454
- export { Accordion, ActionList, ActionListItem, AsyncSelectField$1 as AsyncSelectField, Avatar, Badge, Bold, BreadcrumbItem, Breadcrumbs, Button, COLORS, Calendar$1 as Calendar, CalloutCard, Card$1 as Card, CheckboxField, Chip, CircularProgress, CurrencyField, DataTable$1 as DataTable, DataTableCell, DataTableEditableCell, DataTableRow, DateField, DateFilter, DateRangeField, Dropdown, DropdownList, DropdownListDivider, DropdownListItem, EmptyState, Form, FormFeedback, FormFooter, FormRow, FormSection, HintModal$1 as HintModal, IconAnalytics, IconArrowDown, IconArrowDownWideShort, IconArrowLeft, IconArrowRight, IconArrowToTop, IconArrowTurnDownRight, IconArrowUp, IconAward, IconAwful, IconAwfulMonochromatic, IconBad, IconBadMonochromatic, IconBalanceScale, IconBalanceScaleLeft, IconBan, IconBarsH, IconBarsV, IconBell, IconBirthdayCake, IconBold, IconBolt, IconBook, IconBriefcase, IconBullseyeArrow, IconCalculator, IconCalendar, IconCalendarAlt, IconCalendarCheck, IconCalendarDay, IconCalendarExclamation, IconCalendarStar, IconCalendarTomorrow, IconCamera, IconCameraSlash, IconCashRegister, IconChartBar, IconCheck, IconCheckCircleIncomplete, IconChevronDown, IconChevronLeft, IconChevronRight, IconChevronUp, IconClipboardList, IconClock, IconClockRewind, IconCog, IconComment, IconCommentLines, IconCopy, IconCreditCard, IconCreditCardPlus, IconDecent, IconDecentMonochromatic, IconDownload, IconEdit, IconEllipsisV, IconEnvelope, IconEnvelopeOpenDollar, IconExclaimation, IconExclaimationTriangle, IconExpand, IconExternalLink, IconEye, IconEyeSlash, IconFile, IconFilePdf, IconFlag, IconFourDotsCircle, IconFourSquares, IconGavel, IconGif, IconGift, IconGood, IconGoodMonochromatic, IconGreat, IconGreatMonochromatic, IconGrinBeam, IconGripVertical, IconHandshake, IconHatChef, IconImage, IconInfoCircle, IconIslandTropical, IconItalic, IconLaptopSearch, IconLink, IconList, IconListOI as IconListOi, IconLock, IconMagicSolid, IconMapMarker, IconMegaphone, IconMessages, IconMinus, IconMinusCircle, IconMoneyBill, IconMugSaucerSolid, IconNotesMedical, IconOvertime, IconPaperPlane, IconPaperPlaneClock, IconPaperclip, IconPencil, IconPercentage, IconPhone, IconPlateUtensils, IconPlug, IconPlus, IconPrint, IconQuestionCircle, IconRepeat, IconReply, IconRocket, IconSearch, IconSignOut, IconSitemap, IconSlidersH, IconSort, IconStar, IconStarSolid, IconStickyNoteLines, IconStopwatch, IconStrikethrough, IconSync, IconSyncExclaimation, IconTable, IconTachometer, IconTimes, IconTimesOctagon, IconTrash, IconUnderline, IconUndo, IconUniversity, IconUnlock, IconUserComputer, IconUserFriends, IconUserLight, IconUserPlus, IconUserSearch, IconUserSlash, IconUserSolid, IconUserTag, IconUserTie, IconUsers, IconVideo, IconVolume, IconVolumeMute, IconWrench, Inline, InlineBanner, Italic, Link, Modal, ModalBody, ModalFooter, MultiSelectField, Page, PaginationControls$1 as PaginationControls, PasswordField, Paywall, PercentageField, PersistentBanner, PhoneField, Pill, PillSelectField, ProgressBar, RadioGroupBoxOption, RadioGroupField, RadioGroupOption, SIZE_25_PERCENT, SIZE_33_PERCENT, SIZE_50_PERCENT, SIZE_66_PERCENT, SIZE_75_PERCENT, SegmentedControl, SelectField$1 as SelectField, Skeleton, SousChefProvider, Spinner, Stack, Text, TextAreaField, TextField, TimeField, TimeRangeField, Toggle, ToolbarSelect, Tooltip, Underline, WeekField, ZINDEX, toast, useDataTableContext };
13524
+ export { Accordion, ActionList, ActionListItem, AsyncSelectField$1 as AsyncSelectField, Avatar, Badge, Bold, BreadcrumbItem, Breadcrumbs, Button, COLORS, Calendar$1 as Calendar, CalloutCard, Card$1 as Card, CheckboxField, Chip, CircularProgress, CurrencyField, DataTable$1 as DataTable, DataTableCell, DataTableEditableCell, DataTableRow, DateField, DateFilter, DateRangeField, Dropdown, DropdownList, DropdownListDivider, DropdownListItem, EmptyState, Form, FormFeedback, FormFooter, FormRow, FormSection, HintModal$1 as HintModal, IconAnalytics, IconArrowDown, IconArrowDownWideShort, IconArrowLeft, IconArrowRight, IconArrowToTop, IconArrowTurnDownRight, IconArrowUp, IconAward, IconAwful, IconAwfulMonochromatic, IconBad, IconBadMonochromatic, IconBalanceScale, IconBalanceScaleLeft, IconBan, IconBarsH, IconBarsV, IconBell, IconBirthdayCake, IconBold, IconBolt, IconBook, IconBriefcase, IconBullseyeArrow, IconCalculator, IconCalendar, IconCalendarAlt, IconCalendarCheck, IconCalendarDay, IconCalendarExclamation, IconCalendarStar, IconCalendarTomorrow, IconCamera, IconCameraSlash, IconCashRegister, IconChartBar, IconCheck, IconCheckCircleIncomplete, IconChevronDown, IconChevronLeft, IconChevronRight, IconChevronUp, IconClipboardList, IconClock, IconClockRewind, IconCog, IconComment, IconCommentLines, IconCopy, IconCreditCard, IconCreditCardPlus, IconDecent, IconDecentMonochromatic, IconDownload, IconEdit, IconEllipsisV, IconEnvelope, IconEnvelopeOpenDollar, IconExclaimation, IconExclaimationTriangle, IconExpand, IconExternalLink, IconEye, IconEyeSlash, IconFile, IconFilePdf, IconFlag, IconFourDotsCircle, IconFourSquares, IconGavel, IconGif, IconGift, IconGood, IconGoodMonochromatic, IconGreat, IconGreatMonochromatic, IconGrinBeam, IconGripVertical, IconHandshake, IconHatChef, IconImage, IconInfoCircle, IconIslandTropical, IconItalic, IconLaptopSearch, IconLink, IconList, IconListOI as IconListOi, IconLock, IconMagicSolid, IconMapMarker, IconMegaphone, IconMessages, IconMinus, IconMinusCircle, IconMoneyBill, IconMugSaucerSolid, IconNotesMedical, IconOvertime, IconPaperPlane, IconPaperPlaneClock, IconPaperclip, IconPencil, IconPercentage, IconPhone, IconPlateUtensils, IconPlug, IconPlus, IconPrint, IconQuestionCircle, IconRepeat, IconReply, IconRocket, IconSearch, IconSignOut, IconSitemap, IconSlidersH, IconSort, IconStar, IconStarSolid, IconStickyNoteLines, IconStopwatch, IconStrikethrough, IconSync, IconSyncExclaimation, IconTable, IconTachometer, IconTimes, IconTimesOctagon, IconTrash, IconUnderline, IconUndo, IconUniversity, IconUnlock, IconUserComputer, IconUserFriends, IconUserLight, IconUserPlus, IconUserSearch, IconUserSlash, IconUserSolid, IconUserTag, IconUserTie, IconUsers, IconVideo, IconVolume, IconVolumeMute, IconWrench, Inline, InlineBanner, Italic, Link, Modal, ModalBody, ModalFooter, MultiSelectField, Page, PaginationControls$1 as PaginationControls, PasswordField, Paywall, PercentageField, PersistentBanner, PhoneField$1 as PhoneField, Pill, PillSelectField, ProgressBar, RadioGroupBoxOption, RadioGroupField, RadioGroupOption, SIZE_25_PERCENT, SIZE_33_PERCENT, SIZE_50_PERCENT, SIZE_66_PERCENT, SIZE_75_PERCENT, SegmentedControl, SelectField$1 as SelectField, Skeleton, SousChefProvider, Spinner, Stack, Text, TextAreaField, TextField, TimeField, TimeRangeField, Toggle, ToolbarSelect, Tooltip, Underline, WeekField, ZINDEX, toast, useDataTableContext };
13455
13525
  //# sourceMappingURL=index.modern.js.map