From 47e0b585dae15f66070431637510744c47022c1c Mon Sep 17 00:00:00 2001 From: Oleksandra Date: Sat, 2 Dec 2023 02:09:27 +0200 Subject: [PATCH 1/5] import pattern constants --- .../components/signup/signup-form/SignUpFormContent.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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..98433827e 100644 --- a/FrontEnd/src/components/SignUp/components/signup/signup-form/SignUpFormContent.js +++ b/FrontEnd/src/components/SignUp/components/signup/signup-form/SignUpFormContent.js @@ -7,6 +7,8 @@ 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 +29,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, @@ -127,7 +125,7 @@ export function SignUpFormContentComponent(props) { {...register('email', { required: errorMessageTemplates.required, pattern: { - value: emailPattern, + value: EMAIL_PATTERN, message: errorMessageTemplates.email, }, })} @@ -182,7 +180,7 @@ export function SignUpFormContentComponent(props) { {...register('password', { required: errorMessageTemplates.required, pattern: { - value: passwordPattern, + value: PASSWORD_PATTERN, message: errorMessageTemplates.password, }, })} From 0df03da9679db2d4017d88d154921de95aaf1048 Mon Sep 17 00:00:00 2001 From: Oleksandra Date: Sat, 2 Dec 2023 02:52:01 +0200 Subject: [PATCH 2/5] remove one checkbox restriction --- .../signup/signup-form/SignUpFormContent.js | 49 +++++++------------ 1 file changed, 19 insertions(+), 30 deletions(-) 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 98433827e..ba7504be7 100644 --- a/FrontEnd/src/components/SignUp/components/signup/signup-form/SignUpFormContent.js +++ b/FrontEnd/src/components/SignUp/components/signup/signup-form/SignUpFormContent.js @@ -3,6 +3,7 @@ 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'; @@ -40,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'), @@ -76,11 +58,11 @@ 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), }, }; - + console.log(dataToSend); axios({ method: 'post', url: `${process.env.REACT_APP_BASE_API_URL}/api/auth/users/`, @@ -299,8 +281,10 @@ export function SignUpFormContentComponent(props) {