diff --git a/FrontEnd/src/components/SignUp/components/signup/signup-form/SignUpFormContent.js b/FrontEnd/src/components/SignUp/components/signup/signup-form/SignUpFormContent.js index e009da983..c2e66cbce 100644 --- a/FrontEnd/src/components/SignUp/components/signup/signup-form/SignUpFormContent.js +++ b/FrontEnd/src/components/SignUp/components/signup/signup-form/SignUpFormContent.js @@ -3,10 +3,13 @@ import { useForm } from 'react-hook-form'; import { useNavigate } from 'react-router-dom'; import axios from 'axios'; + import EyeInvisible from '../../../../authorization/EyeInvisible'; import EyeVisible from '../../../../authorization/EyeVisible'; import styles from './SignUpFormContent.module.css'; +import { EMAIL_PATTERN, PASSWORD_PATTERN } from '../../../../../constants/constants'; + export function SignUpFormContentComponent(props) { const [showPassword, setShowPassword] = useState(false); const [showConfirmPassword, setShowConfirmPassword] = useState(false); @@ -27,10 +30,6 @@ export function SignUpFormContentComponent(props) { confirmPassword: 'Паролі не збігаються', }; - const emailPattern = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i; - - const passwordPattern = /^(?=.*[0-9])(?=.*[a-zA-Z])[a-zA-Z0-9]{8,20}$/; - const { register, handleSubmit, @@ -42,34 +41,15 @@ export function SignUpFormContentComponent(props) { mode: 'all', }); - const [isChecked, setIsChecked] = useState({ - startup: false, - company: false, - }); - - const onChangeCheckbox = (event) => { - if (event.target.name === 'startup') { - setIsChecked({ - startup: true, - company: false, - }); - } else if (event.target.name === 'company') { - setIsChecked({ - startup: false, - company: true, - }); - } - }; - const { setIsValid } = props; useEffect(() => { - const companyOrStartup = isChecked.company || isChecked.startup; - const formIsValid = companyOrStartup && isValid; - setIsValid(formIsValid); - }, [isValid, setIsValid, isChecked.company, isChecked.startup]); + setIsValid(isValid); + }, [isValid, setIsValid]); + const onSubmit = () => { + const dataToSend = { email: getValues('email'), password: getValues('password'), @@ -78,11 +58,10 @@ export function SignUpFormContentComponent(props) { surname: getValues('surname'), company: { name: getValues('companyName'), - is_registered: isChecked.company, - is_startup: isChecked.startup, + is_registered: (getValues('representative').indexOf('company') > -1), + is_startup: (getValues('representative').indexOf('startup') > -1), }, }; - axios({ method: 'post', url: `${process.env.REACT_APP_BASE_API_URL}/api/auth/users/`, @@ -127,7 +106,7 @@ export function SignUpFormContentComponent(props) { {...register('email', { required: errorMessageTemplates.required, pattern: { - value: emailPattern, + value: EMAIL_PATTERN, message: errorMessageTemplates.email, }, })} @@ -182,7 +161,7 @@ export function SignUpFormContentComponent(props) { {...register('password', { required: errorMessageTemplates.required, pattern: { - value: passwordPattern, + value: PASSWORD_PATTERN, message: errorMessageTemplates.password, }, })} @@ -301,8 +280,10 @@ export function SignUpFormContentComponent(props) {