diff --git a/FrontEnd/src/components/ProfilePage/FormComponents/FormFields/TextField.js b/FrontEnd/src/components/ProfilePage/FormComponents/FormFields/TextField.js index 79378e8af..5c5814aee 100644 --- a/FrontEnd/src/components/ProfilePage/FormComponents/FormFields/TextField.js +++ b/FrontEnd/src/components/ProfilePage/FormComponents/FormFields/TextField.js @@ -1,3 +1,4 @@ +import { PropTypes } from 'prop-types'; import preventEnterSubmit from '../../../../utils/preventEnterSubmit'; import css from './TextField.module.css'; @@ -23,6 +24,7 @@ const TextField = (props) => { onKeyDown={preventEnterSubmit} required={(props.requredField) ? 'required' : ''} disabled={(props.name === 'email') ? 'disabled' : ''} + onBlur={props.onBlur} >
@@ -38,3 +40,15 @@ const TextField = (props) => { }; export default TextField; + +TextField.propTypes = { + requredField: PropTypes.bool, + label: PropTypes.string.isRequired, + name: PropTypes.string.isRequired, + value: PropTypes.string, + fieldPlaceholder: PropTypes.string, + maxLength: PropTypes.number, + updateHandler: PropTypes.func, + error: PropTypes.string, + onBlur: PropTypes.func, + }; \ No newline at end of file diff --git a/FrontEnd/src/components/ProfilePage/FormComponents/GeneralInfo.js b/FrontEnd/src/components/ProfilePage/FormComponents/GeneralInfo.js index bcc4d0f08..967c2c416 100644 --- a/FrontEnd/src/components/ProfilePage/FormComponents/GeneralInfo.js +++ b/FrontEnd/src/components/ProfilePage/FormComponents/GeneralInfo.js @@ -102,7 +102,7 @@ const GeneralInfo = (props) => { let isValid = true; const newFormState = {}; for (const key in profile) { - if (key in ERRORS && (!profile[key] || (Array.isArray(profile[key]) && profile[key].length === 0))) { + if (key in ERRORS && (!profile[key] || (Array.isArray(profile[key]) && profile[key]?.length === 0))) { isValid = false; newFormState[key] = { 'error': true, @@ -116,10 +116,10 @@ const GeneralInfo = (props) => { } } setFormStateErr({ ...formStateErr, ...newFormState }); - if (profile.official_name.length !== 0 && profile.official_name.length < 2) { + if (profile.official_name?.length !== 0 && profile.official_name?.length < 2) { isValid = false; } - if (profile.name.length < 2) { + if (profile.name?.length < 2) { isValid = false; } if (profile.edrpou) { @@ -147,7 +147,7 @@ const GeneralInfo = (props) => { const onUpdateField = e => { const { value: fieldValue, name: fieldName } = e.target; - const symbolCount = (fieldValue.replace(/[\s]/g,'')).length; + const symbolCount = (fieldValue.replace(/[\s]/g,''))?.length; setFormStateErr({ ...formStateErr, [fieldName]: {'error': false, 'message': ''}}); if (fieldName === 'name' && symbolCount < 2) { setFormStateErr({ ...formStateErr, [fieldName]: {'error': true, 'message': 'Введіть від 2 до 100 символів'}}); @@ -220,7 +220,7 @@ const GeneralInfo = (props) => { }; const onUpdateTextAreaField = e => { - if (e.target.value.length <= TEXT_AREA_MAX_LENGTH) + if (e.target.value?.length <= TEXT_AREA_MAX_LENGTH) setProfile((prevState) => { return { ...prevState, [e.target.name]: e.target.value }; }); @@ -491,6 +491,7 @@ const GeneralInfo = (props) => { name="common_info" label={LABELS.common_info} updateHandler={onUpdateTextAreaField} + onBlur={onBlurHandler} value={profile.common_info ?? ''} maxLength={TEXT_AREA_MAX_LENGTH} /> diff --git a/FrontEnd/src/components/ProfilePage/FormComponents/UserInfo.js b/FrontEnd/src/components/ProfilePage/FormComponents/UserInfo.js index 69945472f..f614e6123 100644 --- a/FrontEnd/src/components/ProfilePage/FormComponents/UserInfo.js +++ b/FrontEnd/src/components/ProfilePage/FormComponents/UserInfo.js @@ -79,7 +79,7 @@ const UserInfo = (props) => { })); }; - const errorsInNameSurname = formStateErr['name']['message'].length > 1 || formStateErr['surname']['message'].length > 1; + const errorsInNameSurname = formStateErr['name']['message']?.length > 1 || formStateErr['surname']['message']?.length > 1; const checkRequiredFields = () => { let isValid = true; @@ -100,10 +100,10 @@ const UserInfo = (props) => { } setFormStateErr({ ...formStateErr, ...newFormState }); - if (updateUser.name.length < 2 || updateUser.surname.length < 2) { + if (updateUser.name?.length < 2 || updateUser.surname?.length < 2) { isValid = false; } - if (updateProfile.person_position.length !== 0 && updateProfile.person_position.length < 2) { + if (updateProfile.person_position?.length !== 0 && updateProfile.person_position?.length < 2) { isValid = false; }