This repository has been archived by the owner on Jan 17, 2023. It is now read-only.
/
login.tsx
50 lines (41 loc) · 1.4 KB
/
login.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React, { useState } from "react";
import { login } from "../services/login_service";
import { Links } from "../components/links";
export type LoginInputs = {
email: string
password: string
}
function Page() {
// these values are hardcoded since our main.go api only accepts this auth combo
const initialValues: LoginInputs = { email: "", password: "", };
const [inputs, setInputs] = useState(initialValues);
const [error, setError] = useState("");
const handleSubmit = async (e: any) => {
e.preventDefault();
const res = await login(inputs);
if (res) setError(res);
};
const handleInputChange = (e: React.ChangeEvent<any>) => {
e.persist();
setInputs({
...inputs,
[e.target.name]: e.target.value,
});
};
return <>
<Links/>
{error ? <p>Error: {error}</p> : null}
<form className="container mx-auto max-w-sm" onSubmit={handleSubmit}>
<div>
<label htmlFor="email">Email</label>
<input type="email" id="email" name="email" onChange={handleInputChange} value={inputs.email} placeholder="rickety_cricket@example.com"/>
</div>
<div>
<label htmlFor="password">Password</label>
<input type="password" id="password" name="password" onChange={handleInputChange} value={inputs.password} placeholder="********"/>
</div>
<button type="submit">Login</button>
</form>
</>;
}
export default Page;