import { TextField, Typography, IconButton, InputAdornment, Grid, Button } from "@mui/material" import { useEffect, useState } from "react" import { actionFullRegister } from "../actions/actionLogin"; import { connect } from "react-redux"; import { Link } from "react-router-dom"; function RegisterPage ({onRegister}) { const [values, setValues] = useState({ login: '', firstPassword: '', secondPassword: '', nick: '', showPassword: '' }) const [errorValues, setErrorValues] = useState({ login: '', firstPassword: '', secondPassword: '', nick: '' }) useEffect(() => { if(Object.values(errorValues).every(item => item === false)) { onRegister(values.login, values.firstPassword, values.nick) } }, [errorValues]) function validatePassword(fp,l,n,sp) { let e = { login: '', firstPassword: '', secondPassword: '', nick: '' } let errorsP = []; let errorsL = []; let errorsN = []; let errorsSP = []; if (fp.length < 4 || fp.length > 12) { errorsP.push("Your password must be at least 4 and no more than 12 characters"); } if (!/[a-z]/.test(fp)) { errorsP.push("Your password must contain at least one letter."); } if (!/[0-9]/.test(fp)) { errorsP.push("Your password must contain at least one digit."); } if (errorsP.length > 0) { e = {...e, firstPassword: errorsP.join('/')} } else { e = {...e, firstPassword: false} } if(!/[a-z]/.test(l)){ errorsL.push("Your login must contain at least one letter"); } if (l.length < 4 || l.length > 8) { errorsL.push("Your login must be at least 4 and no more than 8 characters"); } if (errorsL.length > 0){ e = {...e, login: errorsL.join('/')} } else { e = {...e, login: false} } if(!/[a-z]/.test(n)){ errorsN.push("Your nick must contain at least one letter"); } if (n.length < 3 || n.length > 15) { errorsN.push("Your nick must be at least 3 and no more than 15 characters"); } if (errorsN.length > 0){ e = {...e, nick: errorsN.join('/')} } else { e = {...e, nick: false} } if(fp !== sp){ errorsSP.push("Password not match") } if (errorsSP.length > 0){ e = {...e, secondPassword: errorsSP.join('/')} } else { e = {...e, secondPassword: false} } setErrorValues({...errorValues, ...e}) } const handleChange = (prop) => (e) => { setValues({...values, [prop] : e.target.value}) } return (
Registration form
Login
) } export default connect(null, {onRegister: actionFullRegister})(RegisterPage)