Skip to content

Commit

Permalink
Update Register.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarsh1311 authored Nov 3, 2024
1 parent e4d7bb7 commit 0523727
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions client/src/components/Register.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import pokemonGroup from '../assets/pokemonGroup.png';
import bg from '../assets/2.svg';
import { Link, useNavigate } from 'react-router-dom';
Expand All @@ -16,6 +16,7 @@ const Register = () => {
reset,
formState: { errors }
} = useForm();
const [loading, setLoading] = useState(false);

const onSubmit = async (data) => {
if (data.password !== data.confirmPassword) {
Expand All @@ -25,6 +26,8 @@ const Register = () => {

const { username, email, password } = data;
try {
setLoading(true);

await axios.post(`${import.meta.env.VITE_BASE_URI}/register`, {
username,
email,
Expand All @@ -33,9 +36,13 @@ const Register = () => {

toast.success('User registered successfully');
navigate('/login');
reset();
setLoading(false);

} catch (e) {
toast.warning(e.response.data.error);
reset();
setLoading(false);
}
};

Expand Down Expand Up @@ -162,8 +169,13 @@ const Register = () => {
onClick={handleSubmit(onSubmit)}
className=" w-full rounded-lg bg-blue-500 px-6 py-2 text-lg text-white"
type="submit"
disabled={loading}
>
Register
{
loading ? <div className='w-8 h-8 rounded-full mx-auto border-l-2 animate-spin border-white'>

</div> : 'Register'
}
</button>
</div>
</form>
Expand Down

0 comments on commit 0523727

Please sign in to comment.