diff --git a/src/pages/Register.tsx b/src/pages/Register.tsx index 0293e27c..76571853 100644 --- a/src/pages/Register.tsx +++ b/src/pages/Register.tsx @@ -6,110 +6,110 @@ import { TextField, Button, CircularProgress, Typography, Box, Container } from import { useGlobalInfoStore } from "../context/globalInfo"; const Register = () => { - const [form, setForm] = useState({ - email: '', - password: '', - }); - const [loading, setLoading] = useState(false); - const { notify } = useGlobalInfoStore(); - const { email, password } = form; + const [form, setForm] = useState({ + email: '', + password: '', + }); + const [loading, setLoading] = useState(false); + const { notify } = useGlobalInfoStore(); + const { email, password } = form; - const { state, dispatch } = useContext(AuthContext); - const { user } = state; - const navigate = useNavigate(); + const { state, dispatch } = useContext(AuthContext); + const { user } = state; + const navigate = useNavigate(); - useEffect(() => { - if (user !== null) navigate('/'); - }, [user, navigate]); + useEffect(() => { + if (user !== null) navigate('/'); + }, [user, navigate]); - const handleChange = (e: any) => { - const { name, value } = e.target; - setForm({ ...form, [name]: value }); - }; + const handleChange = (e: any) => { + const { name, value } = e.target; + setForm({ ...form, [name]: value }); + }; - const submitForm = async (e: any) => { - e.preventDefault(); - setLoading(true); - try { - const { data } = await axios.post('http://localhost:8080/auth/register', { - email, - password, - }); - dispatch({ - type: 'LOGIN', - payload: data, - }); - notify('success', 'Welcome to Maxun!'); - window.localStorage.setItem('user', JSON.stringify(data)); - navigate('/'); - } catch (err: any) { - notify('error', err.response.data.message); - } finally { - setLoading(false); - } - }; + const submitForm = async (e: any) => { + e.preventDefault(); + setLoading(true); + try { + const { data } = await axios.post('http://localhost:8080/auth/register', { + email, + password, + }); + dispatch({ + type: 'LOGIN', + payload: data, + }); + notify('success', 'Welcome to Maxun!'); + window.localStorage.setItem('user', JSON.stringify(data)); + navigate('/'); + } catch (err: any) { + notify('error', err.response.data.message); + } finally { + setLoading(false); + } + }; - return ( - - - - Register - - OR - - - - - - Already have an account?{' '} - - Login - - - - - - ); + return ( + + + + Register + + OR + + + + + + Already have an account?{' '} + + Login + + + + + + ); }; export default Register;