@thecb/components 10.9.0-beta.13 → 10.9.0-beta.14
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/index.cjs.js +16 -34
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +19 -0
- package/dist/index.esm.js +16 -34
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/molecules/email-form/EmailForm.js +7 -17
- package/src/components/molecules/phone-form/PhoneForm.js +8 -18
- package/src/hooks/index.js +1 -0
- package/src/hooks/use-conditionally-add-validator/index.js +6 -19
package/dist/index.cjs.js
CHANGED
|
@@ -26403,13 +26403,26 @@ var useToastNotification = function useToastNotification() {
|
|
|
26403
26403
|
};
|
|
26404
26404
|
};
|
|
26405
26405
|
|
|
26406
|
+
function useConditionallyAddValidator(condition, validatorFn, addValidator, removeValidator) {
|
|
26407
|
+
React.useEffect(function () {
|
|
26408
|
+
if (condition) {
|
|
26409
|
+
addValidator(validatorFn());
|
|
26410
|
+
}
|
|
26411
|
+
return function () {
|
|
26412
|
+
// Remove validator when component unmounts
|
|
26413
|
+
removeValidator(validatorFn());
|
|
26414
|
+
};
|
|
26415
|
+
}, [condition, addValidator, removeValidator]);
|
|
26416
|
+
}
|
|
26417
|
+
|
|
26406
26418
|
|
|
26407
26419
|
|
|
26408
26420
|
var index$5 = /*#__PURE__*/Object.freeze({
|
|
26409
26421
|
__proto__: null,
|
|
26410
26422
|
useOutsideClick: useOutsideClickHook,
|
|
26411
26423
|
useScrollTo: useScrollTo,
|
|
26412
|
-
useToastNotification: useToastNotification
|
|
26424
|
+
useToastNotification: useToastNotification,
|
|
26425
|
+
useConditionallyAddValidator: useConditionallyAddValidator
|
|
26413
26426
|
});
|
|
26414
26427
|
|
|
26415
26428
|
var hoverColor$4 = "#116285";
|
|
@@ -41774,7 +41787,6 @@ var EmailForm = function EmailForm(_ref) {
|
|
|
41774
41787
|
walletCheckboxMarked = _ref.walletCheckboxMarked,
|
|
41775
41788
|
_ref$isRequired = _ref.isRequired,
|
|
41776
41789
|
isRequired = _ref$isRequired === void 0 ? false : _ref$isRequired;
|
|
41777
|
-
console.log("🚀 ~ isRequired:", isRequired);
|
|
41778
41790
|
if (clearOnDismount) {
|
|
41779
41791
|
React.useEffect(function () {
|
|
41780
41792
|
return function () {
|
|
@@ -41782,23 +41794,8 @@ var EmailForm = function EmailForm(_ref) {
|
|
|
41782
41794
|
};
|
|
41783
41795
|
}, []);
|
|
41784
41796
|
}
|
|
41797
|
+
useConditionallyAddValidator(isRequired, required, actions.fields.email.addValidator, actions.fields.email.removeValidator);
|
|
41785
41798
|
var emailFieldErrorMessages = _defineProperty(_defineProperty({}, required.error, "Email address is required"), isProbablyEmail.error, "Invalid email address");
|
|
41786
|
-
React.useEffect(function () {
|
|
41787
|
-
debugger;
|
|
41788
|
-
if (isRequired) {
|
|
41789
|
-
console.log('adding email validator');
|
|
41790
|
-
actions.fields.email.addValidator(required());
|
|
41791
|
-
}
|
|
41792
|
-
// else {
|
|
41793
|
-
// console.log('removing email validator')
|
|
41794
|
-
// actions.fields.email.removeValidator(required());
|
|
41795
|
-
// }
|
|
41796
|
-
return function () {
|
|
41797
|
-
console.log('removing email validator');
|
|
41798
|
-
// If the form is not rendered it should not be required.
|
|
41799
|
-
actions.fields.email.removeValidator(required());
|
|
41800
|
-
};
|
|
41801
|
-
}, [isRequired]);
|
|
41802
41799
|
return /*#__PURE__*/React__default.createElement(FormContainer$1, {
|
|
41803
41800
|
variant: variant,
|
|
41804
41801
|
role: "form",
|
|
@@ -49033,23 +49030,8 @@ var PhoneForm = function PhoneForm(_ref) {
|
|
|
49033
49030
|
};
|
|
49034
49031
|
}, []);
|
|
49035
49032
|
}
|
|
49033
|
+
useConditionallyAddValidator(isRequired, required, actions.fields.phone.addValidator, actions.fields.phone.removeValidator);
|
|
49036
49034
|
var phoneErrorMessage = _defineProperty(_defineProperty({}, required.error, "Phone number is required"), hasLength.error, "Phone number must be 10 digits");
|
|
49037
|
-
React.useEffect(function () {
|
|
49038
|
-
if (isRequired) {
|
|
49039
|
-
console.log("adding phone validator");
|
|
49040
|
-
actions.fields.phone.addValidator(required());
|
|
49041
|
-
}
|
|
49042
|
-
// else {
|
|
49043
|
-
// debugger;
|
|
49044
|
-
// console.log('removing phone validator 1')
|
|
49045
|
-
// actions.fields.phone.removeValidator(required());
|
|
49046
|
-
// }
|
|
49047
|
-
return function () {
|
|
49048
|
-
console.log("removing phone validator 2");
|
|
49049
|
-
// If the form is not rendered it should not be required.
|
|
49050
|
-
actions.fields.phone.removeValidator(required());
|
|
49051
|
-
};
|
|
49052
|
-
}, [isRequired]);
|
|
49053
49035
|
return /*#__PURE__*/React__default.createElement(FormContainer$1, {
|
|
49054
49036
|
variant: variant,
|
|
49055
49037
|
role: "form",
|