@comicrelief/component-library 7.0.2 → 7.0.3
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/components/Organisms/EmailSignUp/EmailSignUpForm.js +6 -1
- package/dist/components/Organisms/EmailSignUp/_EmailSignUp.js +1 -3
- package/package.json +1 -1
- package/src/components/Organisms/EmailSignUp/EmailSignUpForm.js +3 -1
- package/src/components/Organisms/EmailSignUp/_EmailSignUp.js +5 -8
|
@@ -28,7 +28,8 @@ var EmailSignUpForm = function EmailSignUpForm() {
|
|
|
28
28
|
resolver: (0, _yup.yupResolver)(validationSchema)
|
|
29
29
|
});
|
|
30
30
|
var handleSubmit = formMethods.handleSubmit,
|
|
31
|
-
trigger = formMethods.trigger
|
|
31
|
+
trigger = formMethods.trigger,
|
|
32
|
+
setError = formMethods.setError;
|
|
32
33
|
|
|
33
34
|
function handleSubscribe(_x) {
|
|
34
35
|
return _handleSubscribe.apply(this, arguments);
|
|
@@ -50,6 +51,10 @@ var EmailSignUpForm = function EmailSignUpForm() {
|
|
|
50
51
|
if (valid) {
|
|
51
52
|
// eslint-disable-next-line no-console
|
|
52
53
|
console.log(data);
|
|
54
|
+
} else {
|
|
55
|
+
setError('formError', {
|
|
56
|
+
message: 'Error'
|
|
57
|
+
});
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
case 4:
|
|
@@ -94,9 +94,7 @@ var EmailSignUp = function EmailSignUp(_ref) {
|
|
|
94
94
|
loading: isSubmitting,
|
|
95
95
|
loadingText: "Submitting...",
|
|
96
96
|
"data-test": "subscribe-button"
|
|
97
|
-
}, /*#__PURE__*/_react.default.createElement(_Text.default, null, "Subscribe")))), isSubmitted && !isSubmitSuccessful && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null,
|
|
98
|
-
return /*#__PURE__*/_react.default.createElement(_ErrorText.default, null, error.message);
|
|
99
|
-
})), /*#__PURE__*/_react.default.createElement(_EmailSignUp.PrivacyCopyWrapper, null, /*#__PURE__*/_react.default.createElement(_Text.default, null, privacyCopy)));
|
|
97
|
+
}, /*#__PURE__*/_react.default.createElement(_Text.default, null, "Subscribe")))), isSubmitted && !isSubmitSuccessful && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, errors.formError !== undefined && /*#__PURE__*/_react.default.createElement(_ErrorText.default, null, errors.formError.message)), /*#__PURE__*/_react.default.createElement(_EmailSignUp.PrivacyCopyWrapper, null, /*#__PURE__*/_react.default.createElement(_Text.default, null, privacyCopy)));
|
|
100
98
|
};
|
|
101
99
|
|
|
102
100
|
exports.EmailSignUp = EmailSignUp;
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@ const EmailSignUpForm = () => {
|
|
|
14
14
|
mode: 'onBlur',
|
|
15
15
|
resolver: yupResolver(validationSchema)
|
|
16
16
|
});
|
|
17
|
-
const { handleSubmit, trigger } = formMethods;
|
|
17
|
+
const { handleSubmit, trigger, setError } = formMethods;
|
|
18
18
|
|
|
19
19
|
async function handleSubscribe(data) {
|
|
20
20
|
const valid = await trigger([
|
|
@@ -25,6 +25,8 @@ const EmailSignUpForm = () => {
|
|
|
25
25
|
if (valid) {
|
|
26
26
|
// eslint-disable-next-line no-console
|
|
27
27
|
console.log(data);
|
|
28
|
+
} else {
|
|
29
|
+
setError('formError', { message: 'Error' });
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
32
|
const title = 'Stay in the know!';
|
|
@@ -100,14 +100,11 @@ const EmailSignUp = ({
|
|
|
100
100
|
)}
|
|
101
101
|
{isSubmitted && !isSubmitSuccessful && (
|
|
102
102
|
<>
|
|
103
|
-
{/*
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
{Object.values(errors).map(error => (
|
|
109
|
-
<ErrorText>{error.message}</ErrorText>
|
|
110
|
-
))}
|
|
103
|
+
{/* This error can be set as part of the submit callback using RHF's `setError` function.
|
|
104
|
+
e.g. setError('formError', { message: 'Some error message'}) */}
|
|
105
|
+
{errors.formError !== undefined && (
|
|
106
|
+
<ErrorText>{errors.formError.message}</ErrorText>
|
|
107
|
+
)}
|
|
111
108
|
</>
|
|
112
109
|
)}
|
|
113
110
|
|