chore: lint

This commit is contained in:
karishmas6
2024-09-25 13:09:05 +05:30
parent 6a6bc3b811
commit 6a9b2f682a

View File

@@ -6,110 +6,110 @@ import { TextField, Button, CircularProgress, Typography, Box, Container } from
import { useGlobalInfoStore } from "../context/globalInfo"; import { useGlobalInfoStore } from "../context/globalInfo";
const Register = () => { const Register = () => {
const [form, setForm] = useState({ const [form, setForm] = useState({
email: '', email: '',
password: '', password: '',
}); });
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const { notify } = useGlobalInfoStore(); const { notify } = useGlobalInfoStore();
const { email, password } = form; const { email, password } = form;
const { state, dispatch } = useContext(AuthContext); const { state, dispatch } = useContext(AuthContext);
const { user } = state; const { user } = state;
const navigate = useNavigate(); const navigate = useNavigate();
useEffect(() => { useEffect(() => {
if (user !== null) navigate('/'); if (user !== null) navigate('/');
}, [user, navigate]); }, [user, navigate]);
const handleChange = (e: any) => { const handleChange = (e: any) => {
const { name, value } = e.target; const { name, value } = e.target;
setForm({ ...form, [name]: value }); setForm({ ...form, [name]: value });
}; };
const submitForm = async (e: any) => { const submitForm = async (e: any) => {
e.preventDefault(); e.preventDefault();
setLoading(true); setLoading(true);
try { try {
const { data } = await axios.post('http://localhost:8080/auth/register', { const { data } = await axios.post('http://localhost:8080/auth/register', {
email, email,
password, password,
}); });
dispatch({ dispatch({
type: 'LOGIN', type: 'LOGIN',
payload: data, payload: data,
}); });
notify('success', 'Welcome to Maxun!'); notify('success', 'Welcome to Maxun!');
window.localStorage.setItem('user', JSON.stringify(data)); window.localStorage.setItem('user', JSON.stringify(data));
navigate('/'); navigate('/');
} catch (err: any) { } catch (err: any) {
notify('error', err.response.data.message); notify('error', err.response.data.message);
} finally { } finally {
setLoading(false); setLoading(false);
} }
}; };
return ( return (
<Container maxWidth="sm" sx={{ mt: 8 }}> <Container maxWidth="sm" sx={{ mt: 8 }}>
<Box <Box
sx={{ sx={{
display: 'flex', display: 'flex',
flexDirection: 'column', flexDirection: 'column',
alignItems: 'center', alignItems: 'center',
}} }}
> >
<Typography component="h1" variant="h5"> <Typography component="h1" variant="h5">
Register Register
</Typography> </Typography>
<Typography sx={{ mt: 2, mb: 2 }}>OR</Typography> <Typography sx={{ mt: 2, mb: 2 }}>OR</Typography>
<Box component="form" onSubmit={submitForm} sx={{ mt: 1 }}> <Box component="form" onSubmit={submitForm} sx={{ mt: 1 }}>
<TextField <TextField
margin="normal" margin="normal"
required required
fullWidth fullWidth
id="email" id="email"
label="Email Address" label="Email Address"
name="email" name="email"
value={email} value={email}
onChange={handleChange} onChange={handleChange}
autoComplete="email" autoComplete="email"
/> />
<TextField <TextField
margin="normal" margin="normal"
required required
fullWidth fullWidth
name="password" name="password"
label="Password" label="Password"
type="password" type="password"
id="password" id="password"
value={password} value={password}
onChange={handleChange} onChange={handleChange}
autoComplete="current-password" autoComplete="current-password"
/> />
<Button <Button
type="submit" type="submit"
fullWidth fullWidth
variant="contained" variant="contained"
color="primary" color="primary"
sx={{ mt: 3, mb: 2 }} sx={{ mt: 3, mb: 2 }}
disabled={loading || !email || !password } disabled={loading || !email || !password}
> >
{loading ? ( {loading ? (
<CircularProgress size={24} sx={{ color: '#fff' }} /> <CircularProgress size={24} sx={{ color: '#fff' }} />
) : ( ) : (
'Register' 'Register'
)} )}
</Button> </Button>
<Typography variant="body2" align="center"> <Typography variant="body2" align="center">
Already have an account?{' '} Already have an account?{' '}
<Link to="/login" style={{ textDecoration: 'none', color: '#1976d2' }}> <Link to="/login" style={{ textDecoration: 'none', color: '#1976d2' }}>
Login Login
</Link> </Link>
</Typography> </Typography>
</Box> </Box>
</Box> </Box>
</Container> </Container>
); );
}; };
export default Register; export default Register;