@nuskin/shipping-address-form 1.7.7 → 1.7.8-address-fixes.2

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.
@@ -168,18 +168,29 @@ const SmartyIntlResults = ({
168
168
  return;
169
169
  }
170
170
  setShowAllRequiredErrors(true);
171
+ const currentStatus = (0, _addressStatus.buildAddressStatus)({
172
+ countryCode,
173
+ addressForm: resolvedAddressForm,
174
+ formData,
175
+ verificationStatus,
176
+ mode,
177
+ requireValidation: allowValidation
178
+ });
171
179
  onSelect === null || onSelect === void 0 || onSelect({
172
180
  type: 'validation-request',
173
181
  address: formData,
174
- status: (0, _addressStatus.buildAddressStatus)({
175
- countryCode,
176
- addressForm: resolvedAddressForm,
177
- formData,
178
- verificationStatus,
179
- mode,
180
- requireValidation: allowValidation
181
- })
182
+ status: currentStatus
182
183
  });
184
+ if (allowValidation && currentStatus.needsValidation && String(formData[lookupField] || '').trim()) {
185
+ clearServiceErrors({
186
+ lookup: false,
187
+ validation: true,
188
+ custom: false
189
+ });
190
+ setShowValidationSuggestions(true);
191
+ setValidationTriggerSource('save');
192
+ setValidationTrigger(prev => prev + 1);
193
+ }
183
194
  }, [allowValidation, validationRequestId]);
184
195
  (0, _react.useEffect)(() => {
185
196
  if (!error) {
@@ -332,7 +343,7 @@ const SmartyIntlResults = ({
332
343
  (_getLookupInputElemen = getLookupInputElement()) === null || _getLookupInputElemen === void 0 || _getLookupInputElemen.focus();
333
344
  }, [isAutocompleteMode, selectedIntlAddressId, suggestions, selectedAddress, loading]);
334
345
  (0, _react.useEffect)(() => {
335
- if (validationTrigger > 0 && ['autocomplete', 'map', 'initial'].includes(validationTriggerSource)) {
346
+ if (validationTrigger > 0 && ['autocomplete', 'map', 'initial', 'save'].includes(validationTriggerSource)) {
336
347
  autoApplyValidationStartedRef.current = false;
337
348
  }
338
349
  }, [validationTrigger, validationTriggerSource]);
@@ -340,7 +351,7 @@ const SmartyIntlResults = ({
340
351
  if (validationTriggerSource === 'map' && validationLoading) {
341
352
  mapValidationStartedRef.current = true;
342
353
  }
343
- if (validationLoading && ['autocomplete', 'map', 'initial'].includes(validationTriggerSource)) {
354
+ if (validationLoading && ['autocomplete', 'map', 'initial', 'save'].includes(validationTriggerSource)) {
344
355
  autoApplyValidationStartedRef.current = true;
345
356
  }
346
357
  }, [validationLoading, validationTriggerSource]);
@@ -491,13 +502,21 @@ const SmartyIntlResults = ({
491
502
  }
492
503
  return !(0, _validators.isValidEmail)(value);
493
504
  };
505
+ const hasIllegalCharacters = field => {
506
+ const fieldConfig = ((resolvedAddressForm === null || resolvedAddressForm === void 0 ? void 0 : resolvedAddressForm.addressElements) || []).find(el => el.field === field);
507
+ if (!(fieldConfig !== null && fieldConfig !== void 0 && fieldConfig.allowedCharacters)) {
508
+ return false;
509
+ }
510
+ const value = String(formData[field] || '').trim();
511
+ return value !== '' && !fieldConfig.allowedCharacters.test(value);
512
+ };
494
513
  const shouldShowFieldError = field => {
495
514
  const shouldShowValidation = Boolean(showAllRequiredErrors || touchedFields[field]);
496
515
  if (!shouldShowValidation) {
497
516
  return false;
498
517
  }
499
518
  const requiredError = isFieldRequired(field) && isFieldBlank(field);
500
- return requiredError || hasInvalidPostalCodeFormat(field) || hasInvalidEmailFormat(field);
519
+ return requiredError || hasInvalidPostalCodeFormat(field) || hasInvalidEmailFormat(field) || hasIllegalCharacters(field);
501
520
  };
502
521
  const handleFieldBlur = field => {
503
522
  if (readOnlyView) {
@@ -524,6 +543,9 @@ const SmartyIntlResults = ({
524
543
  if (hasInvalidEmailFormat(field)) {
525
544
  return areLabelsLoading ? '' : fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.invalidEmail;
526
545
  }
546
+ if (hasIllegalCharacters(field)) {
547
+ return areLabelsLoading ? '' : (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.illegalCharacters) || 'Contains invalid characters.';
548
+ }
527
549
  return '';
528
550
  };
529
551
  const hasVisibleFieldError = field => shouldShowFieldError(field);
@@ -631,6 +653,7 @@ const SmartyIntlResults = ({
631
653
  }
632
654
  })();
633
655
  const normalizedFormData = buildTrackedAddress(updatedFormData, currentVerificationStatus, 'smarty-intl');
656
+ const wasTriggeredBySave = validationTriggerSource === 'save';
634
657
  setShowValidationSuggestions(false);
635
658
  setValidationTriggerSource(null);
636
659
  setFormData(normalizedFormData);
@@ -645,19 +668,27 @@ const SmartyIntlResults = ({
645
668
  setShowMapModal(true);
646
669
  }
647
670
  mapValidationStartedRef.current = false;
671
+ const validationStatus = (0, _addressStatus.buildAddressStatus)({
672
+ countryCode,
673
+ addressForm: resolvedAddressForm,
674
+ formData: normalizedFormData,
675
+ verificationStatus: currentVerificationStatus,
676
+ mode,
677
+ requireValidation: allowValidation
678
+ });
648
679
  onSelect === null || onSelect === void 0 || onSelect({
649
680
  type: 'validation',
650
681
  address: normalizedFormData,
651
682
  verification: validatedAddress.analysis,
652
- status: (0, _addressStatus.buildAddressStatus)({
653
- countryCode,
654
- addressForm: resolvedAddressForm,
655
- formData: normalizedFormData,
656
- verificationStatus: currentVerificationStatus,
657
- mode,
658
- requireValidation: allowValidation
659
- })
683
+ status: validationStatus
660
684
  });
685
+ if (wasTriggeredBySave) {
686
+ onSelect === null || onSelect === void 0 || onSelect({
687
+ type: 'validation-request',
688
+ address: normalizedFormData,
689
+ status: validationStatus
690
+ });
691
+ }
661
692
  };
662
693
  const handleValidate = () => {
663
694
  if (!allowValidation) {
@@ -744,14 +775,16 @@ const SmartyIntlResults = ({
744
775
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_LocationPinIcon.default, {
745
776
  className: "ns-address-lookup__icon"
746
777
  })
747
- }), !isAutocompleteMode && allowValidation && /*#__PURE__*/(0, _jsxRuntime.jsx)(_foundationUiComponents.NsButton, {
778
+ }), !isAutocompleteMode && allowValidation && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_foundationUiComponents.NsButton, {
748
779
  type: "button",
749
780
  onClick: handleValidate,
750
781
  disabled: validationLoading || !String(formData[lookupField] || '').trim(),
751
782
  variant: "contained",
752
783
  color: "primary",
753
784
  size: "small",
754
- children: validationLoading ? (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.validatingAddress) || 'Validating...' : (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.validateAddress) || 'Validate Address'
785
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_LocationPinIcon.default, {
786
+ className: "ns-address-lookup__icon"
787
+ }), validationLoading ? (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.validatingAddress) || 'Validating...' : (fieldLabels === null || fieldLabels === void 0 ? void 0 : fieldLabels.validateAddress) || 'Validate Address']
755
788
  }), entryMode === 'both' && /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
756
789
  type: "button",
757
790
  onClick: () => {
@@ -884,7 +917,7 @@ const SmartyIntlResults = ({
884
917
  return null;
885
918
  };
886
919
  (0, _react.useEffect)(() => {
887
- if (['autocomplete', 'map'].includes(validationTriggerSource) && validationSuggestions.length === 1 && autoApplyValidationStartedRef.current) {
920
+ if (['autocomplete', 'map', 'save'].includes(validationTriggerSource) && validationSuggestions.length === 1 && autoApplyValidationStartedRef.current) {
888
921
  handleValidationSelect(validationSuggestions[0]);
889
922
  }
890
923
  if (validationTriggerSource === 'initial' && validationSuggestions.length === 1 && autoApplyValidationStartedRef.current && isAcceptableInitialValidationResult(validationSuggestions[0])) {
@@ -911,7 +944,7 @@ const SmartyIntlResults = ({
911
944
  children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
912
945
  htmlFor: fieldId,
913
946
  className: "MuiFormLabel-root MuiFormLabel-colorPrimary css-1ef1ceb-MuiFormLabel-root",
914
- children: [fieldLabel, fieldConfig.required && !areLabelsLoading && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
947
+ children: [fieldLabel, (fieldConfig.required || isFieldRequired(fieldConfig.field)) && !areLabelsLoading && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
915
948
  "aria-hidden": "true",
916
949
  className: "MuiFormLabel-asterisk",
917
950
  children: ' *'