signup.jsx
2.79 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { useState, useEffect } from "react";
import { Link } from "react-router-dom";
import { useNavigate } from "react-router-dom";
import authService from "../service/auth";
// styles
import "../styles/layout.scss";
function Signup() {
const navigate = useNavigate();
const [signupSuccess, setSignupSuccess] = useState(0);
const [userinfo, setUserInfo] = useState({
username: "",
country: "",
city: "",
email: "",
password: "",
});
useEffect(() => {
if (sessionStorage.key("user-token")) {
navigate("/", { replace: true });
}
}, [signupSuccess, setSignupSuccess, navigate]);
const onChange = (e) => {
setUserInfo((orgState) => ({
...orgState,
[e.target.id]: e.target.value,
}));
};
const handleSubmit = async (e) => {
e.preventDefault();
const answer = await authService.handleSignup(userinfo);
setSignupSuccess(answer);
};
return (
<div className="container">
<h1>Welcome to WeatherAPP/twitter/Messanger!</h1>
<h2>Stay connected to weather*stories*friends</h2>
<button>Create account with Google</button>
<button>Create account with GitHub</button>
<br />
<p>
<b>Country Code</b> and <b>City Name</b> is required for Weather
service!
</p>
<form className="authForm" onSubmit={(e) => handleSubmit(e)}>
<label htmlFor="username">
<input
placeholder="username"
onChange={(e) => onChange(e)}
value={userinfo.username}
type="text"
id="username"
/>
</label>
<label htmlFor="country">
<input
placeholder="Please use Alpha-2 Country Code"
onChange={(e) => onChange(e)}
value={userinfo.country}
type="text"
id="country"
/>
</label>
<label htmlFor="city">
<input
placeholder="City Name"
onChange={(e) => onChange(e)}
value={userinfo.city}
type="text"
id="city"
/>
</label>
<label htmlFor="email">
<input
placeholder="email"
onChange={(e) => onChange(e)}
value={userinfo.email}
type="email"
id="email"
/>
</label>
<label htmlFor="password">
<input
placeholder="password"
onChange={(e) => onChange(e)}
value={userinfo.password}
type="password"
id="password"
/>
</label>
<label htmlFor="submit">
<input type="submit" id="submit" />
</label>
</form>
<br />
<p>
Have an account? <Link to="/login">Login</Link>
</p>
</div>
);
}
export default Signup;