frontend converted to ts
This commit is contained in:
Executable
+62
@@ -0,0 +1,62 @@
|
||||
import React, { useState } from "react";
|
||||
import { Link, Navigate } from "react-router-dom";
|
||||
import { useAppDispatch, useAppSelector } from "../../utils/hooks";
|
||||
import { login } from "../../actions/auth";
|
||||
|
||||
const Login = () => {
|
||||
const [email, setEmail] = useState('')
|
||||
const [password, setPassword] = useState('')
|
||||
const dispatch = useAppDispatch();
|
||||
const isAuthenticated = useAppSelector((state) => state.auth.isAuthenticated);
|
||||
|
||||
const onChangeEmail = () =>
|
||||
setEmail(email)
|
||||
const onChangePasword = () =>
|
||||
setPassword(password)
|
||||
|
||||
const onSubmit = async (e: React.SyntheticEvent) => {
|
||||
e.preventDefault();
|
||||
await dispatch(login(email, password));
|
||||
};
|
||||
|
||||
if (isAuthenticated) {
|
||||
return <Navigate to="/dashboard" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="container">
|
||||
<h1 className="large text-primary">Sign In</h1>
|
||||
<p className="lead">
|
||||
<i className="fas fa-user" /> Sign Into Your Account
|
||||
</p>
|
||||
<form className="form" onSubmit={onSubmit}>
|
||||
<div className="form-group">
|
||||
<input
|
||||
type="email"
|
||||
placeholder="Email Address"
|
||||
name="email"
|
||||
value={email}
|
||||
onChange={onChangeEmail}
|
||||
/>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Password"
|
||||
name="password"
|
||||
value={password}
|
||||
onChange={onChangePasword}
|
||||
//used to be "6"
|
||||
minLength={6}
|
||||
/>
|
||||
</div>
|
||||
<input type="submit" className="btn btn-primary" value="Login" />
|
||||
</form>
|
||||
<p className="my-1">
|
||||
Don't have an account? <Link to="/register">Sign Up</Link>
|
||||
</p>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
||||
export default Login;
|
||||
Reference in New Issue
Block a user