"use client" // ** React Imports import { ReactNode, useState, Fragment, MouseEvent } from 'react' // ** Next Import import Link from 'next/link' // ** MUI Components import Button from '@mui/material/Button' import Divider from '@mui/material/Divider' import Checkbox from '@mui/material/Checkbox' import TextField from '@mui/material/TextField' import Typography from '@mui/material/Typography' import InputLabel from '@mui/material/InputLabel' import IconButton from '@mui/material/IconButton' import Box, { BoxProps } from '@mui/material/Box' import FormControl from '@mui/material/FormControl' import useMediaQuery from '@mui/material/useMediaQuery' import OutlinedInput from '@mui/material/OutlinedInput' import { styled, useTheme } from '@mui/material/styles' import FormHelperText from '@mui/material/FormHelperText' import InputAdornment from '@mui/material/InputAdornment' import MuiFormControlLabel, { FormControlLabelProps } from '@mui/material/FormControlLabel' // ** Icon Imports import Icon from '../../src/@core/components/icon' // ** Third Party Imports import * as yup from 'yup' import { yupResolver } from '@hookform/resolvers/yup' import { useForm, Controller } from 'react-hook-form' // ** Layout Import import BlankLayout from '../../src/@core/layouts/BlankLayout' // ** Hooks import { useAuth } from '../../src/hooks/useAuth' import { useSettings } from '../../src/@core/hooks/useSettings' // ** Demo Imports import FooterIllustrationsV2 from '../../src/views/pages/auth/FooterIllustrationsV2' const defaultValues = { email: '', username: '', password: '', terms: false } interface FormData { email: string terms: boolean username: string password: string } // ** Styled Components const RegisterIllustration = styled('img')(({ theme }) => ({ zIndex: 2, maxHeight: 600, marginTop: theme.spacing(12), marginBottom: theme.spacing(12), [theme.breakpoints.down(1540)]: { maxHeight: 550 }, [theme.breakpoints.down('lg')]: { maxHeight: 500 } })) const RightWrapper = styled(Box)(({ theme }) => ({ width: '100%', [theme.breakpoints.up('md')]: { maxWidth: 450 }, [theme.breakpoints.up('lg')]: { maxWidth: 600 }, [theme.breakpoints.up('xl')]: { maxWidth: 750 } })) const LinkStyled = styled(Link)(({ theme }) => ({ fontSize: '0.875rem', textDecoration: 'none', color: theme.palette.primary.main })) const FormControlLabel = styled(MuiFormControlLabel)(({ theme }) => ({ marginTop: theme.spacing(1.5), marginBottom: theme.spacing(1.75), '& .MuiFormControlLabel-label': { fontSize: '0.875rem', color: theme.palette.text.secondary } })) const Register = () => { // ** States const [showPassword, setShowPassword] = useState(false) // ** Hooks const theme = useTheme() const { register } = useAuth() const { settings } = useSettings() const hidden = useMediaQuery(theme.breakpoints.down('md')) // ** Vars const { skin } = settings const schema = yup.object().shape({ password: yup.string().min(5).required(), username: yup.string().min(3).required(), email: yup.string().email().required(), terms: yup.bool().oneOf([true], 'You must accept the privacy policy & terms') }) const { control, setError, handleSubmit, formState: { errors } } = useForm({ defaultValues, mode: 'onBlur', resolver: yupResolver(schema) }) const onSubmit = (data: FormData) => { const { email, username, password } = data register({ email, username, password }, err => { if (err.email) { setError('email', { type: 'manual', message: err.email }) } if (err.username) { setError('username', { type: 'manual', message: err.username }) } }) } const imageSource = skin === 'bordered' ? 'auth-v2-register-illustration-bordered' : 'auth-v2-register-illustration' return ( {!hidden ? ( theme.spacing(8, 0, 8, 8) }} > ) : null} Adventure starts here 🚀 Make your app management easy and fun!
( )} /> {errors.username && ( {errors.username.message} )} ( )} /> {errors.email && {errors.email.message}} Password ( e.preventDefault()} onClick={() => setShowPassword(!showPassword)} > } /> )} /> {errors.password && ( {errors.password.message} )} { return ( } label={ I agree to{' '} ) => e.preventDefault()}> privacy policy & terms } /> ) }} /> {errors.terms && ( {errors.terms.message} )} Already have an account? Sign in instead `${theme.spacing(6)} !important` }} > or ) => e.preventDefault()} > ) => e.preventDefault()} > ) => e.preventDefault()} sx={{ color: theme => (theme.palette.mode === 'light' ? '#272727' : 'grey.300') }} > ) => e.preventDefault()} >
) } Register.getLayout = (page: ReactNode) => {page} Register.guestGuard = true export default Register