import React, { useState } from "react"; import { Link } from "react-router-dom"; const Register = props => { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [username, setUsername] = useState(""); const [errors, setErrors] = useState([]); const handleSubmit = event => { event.preventDefault(); if (isValid()) { props.register(email, password, username); } else { } }; const isValid = () => { const emailRegex = /[a-zA-Z0-9]{4,}@[a-zA-Z0-9]{3,}\.[a-zA-Z]{1,10}/gi; const passwordRegex = /[a-zA-Z0-9*%#@!]{6,32}/gi; const userNameRegex = /^[a-z0-9_-]{3,16}$/gi; const errors = []; if (!emailRegex.exec(email)) errors.push("email"); if (!passwordRegex.exec(password)) errors.push("password"); if (!userNameRegex.exec(username)) errors.push("username"); setErrors(errors); return errors.length === 0; }; return (

Create an account

setEmail(e.target.value)} style={{ borderColor: errors.includes("email") ? "#d72323" : "rgba(0,0,0,0.2)" }} /> setUsername(e.target.value)} style={{ borderColor: errors.includes("username") ? "#d72323" : "rgba(0,0,0,0.2)" }} /> setPassword(e.target.value)} style={{ borderColor: errors.includes("password") ? "#d72323" : "rgba(0,0,0,0.2)" }} />
{props.error ?
{props.error.message}
: ""} Already have an account?
); }; export default Register;