diff --git a/client/common/FinalFormField.jsx b/client/common/FinalFormField.jsx
new file mode 100644
index 0000000000..74914cc292
--- /dev/null
+++ b/client/common/FinalFormField.jsx
@@ -0,0 +1,51 @@
+import PropTypes from 'prop-types';
+import React from 'react';
+import { Field } from 'react-final-form';
+import FormField from './FormField';
+
+function FinalFormField({
+ name,
+ validate,
+ validateFields,
+ initialValue,
+ ...rest
+}) {
+ return (
+
+ + + {hasError && {error}} +
+ ); +} + +FormField.propTypes = { + id: PropTypes.string.isRequired, + label: PropTypes.string.isRequired, + ariaLabel: PropTypes.string.isRequired, + type: PropTypes.string.isRequired, + autoComplete: PropTypes.string, + hasError: PropTypes.bool, + error: PropTypes.string +}; + +FormField.defaultProps = { + autoComplete: null, + hasError: false, + error: null +}; + +export default FormField; diff --git a/client/modules/User/components/AccountForm.jsx b/client/modules/User/components/AccountForm.jsx index 5be633b594..f26f1f3218 100644 --- a/client/modules/User/components/AccountForm.jsx +++ b/client/modules/User/components/AccountForm.jsx @@ -1,8 +1,9 @@ import React from 'react'; -import { Form, Field } from 'react-final-form'; +import { Form } from 'react-final-form'; import { useSelector, useDispatch } from 'react-redux'; import { useTranslation } from 'react-i18next'; import Button from '../../../common/Button'; +import FinalFormField from '../../../common/FinalFormField'; import { validateSettings } from '../../../utils/reduxFormUtils'; import { updateSettings, initiateVerification } from '../actions'; import apiClient from '../../../utils/apiClient'; @@ -61,31 +62,17 @@ function AccountForm() { handleSubmit(event).then(restart); }} > -- - - {field.meta.touched && field.meta.error && ( - {field.meta.error} - )} -
- )} -@@ -103,71 +90,33 @@ function AccountForm() { )}
)} -- - - {field.meta.touched && field.meta.error && ( - {field.meta.error} - )} -
- )} -- - - {field.meta.touched && field.meta.error && ( - {field.meta.error} - )} -
- )} -- - - {field.meta.touched && field.meta.error && ( - {field.meta.error} - )} -
- )} -