import { yupResolver } from '@hookform/resolvers/yup'; import { Controller, useForm } from 'react-hook-form'; import Button from '@mui/material/Button'; import Checkbox from '@mui/material/Checkbox'; import FormControl from '@mui/material/FormControl'; import FormControlLabel from '@mui/material/FormControlLabel'; import TextField from '@mui/material/TextField'; import Typography from '@mui/material/Typography'; import { Link } from 'react-router-dom'; import * as yup from 'yup'; import _ from '@lodash'; import AvatarGroup from '@mui/material/AvatarGroup'; import Avatar from '@mui/material/Avatar'; import Box from '@mui/material/Box'; import Paper from '@mui/material/Paper'; import FormHelperText from '@mui/material/FormHelperText'; import jwtService from '../../auth/services/jwtService'; /** * Form Validation Schema */ const schema = yup.object().shape({ displayName: yup.string().required('You must enter display name'), email: yup.string().email('You must enter a valid email').required('You must enter a email'), password: yup .string() .required('Please enter your password.') .min(8, 'Password is too short - should be 8 chars minimum.'), passwordConfirm: yup.string().oneOf([yup.ref('password'), null], 'Passwords must match'), acceptTermsConditions: yup.boolean().oneOf([true], 'The terms and conditions must be accepted.'), }); const defaultValues = { displayName: '', email: '', password: '', passwordConfirm: '', acceptTermsConditions: false, }; function SignUpPage() { const { control, formState, handleSubmit, reset } = useForm({ mode: 'onChange', defaultValues, resolver: yupResolver(schema), }); const { isValid, dirtyFields, errors, setError } = formState; function onSubmit({ displayName, password, email }) { jwtService .createUser({ displayName, password, email, }) .then((user) => { // No need to do anything, registered user data will be set at app/auth/AuthContext }) .catch((_errors) => { _errors.forEach((error) => { setError(error.type, { type: 'manual', message: error.message, }); }); }); } return (
logo Sign up
Already have an account? Sign in
( )} /> ( )} /> ( )} /> ( )} /> ( } /> {errors?.acceptTermsConditions?.message} )} />
Welcome to
our community
Fuse helps developers to build organized and well coded dashboards full of beautiful and rich modules. Join us and start building your application today.
More than 17k people joined us, it's your turn
); } export default SignUpPage;