File size: 1,549 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React from "react";
import "../css/Signup.css";
import { NavLink } from "react-router-dom";
import inputHook from "./custom_hooks/formHook";
import { reqToApiForSignUp } from "./RequestUser/ForSignUp";

function Signup({ DisplaySetNone }) {
	const [input, setInput] = inputHook({
		name: "",
		password: "",
		phone: "",
		email: "",
	});

	DisplaySetNone();

	const handleSubmit = async (e) => {
		e.preventDefault();

		let jwt = await reqToApiForSignUp(input);
		if (jwt) {
			localStorage.setItem("token", jwt);
			// props.history.push("/");
			window.location = "/";
		}
	};

	return (
		<div className="signup-container">
			<form className="signup-div">
				<h1>Sign Up</h1>
				<div>
					<label htmlFor="name"> Name: </label>

					<input
						type="text"
						name="name"
						value={input.name}
						onChange={setInput}
						required
					/>

					<label htmlFor="password"> Password: </label>

					<input
						type="password"
						name="password"
						value={input.password}
						onChange={setInput}
						required
					/>

					<label htmlFor="phone"> Phone no: </label>

					<input
						type="text"
						name="phone"
						value={input.phone}
						onChange={setInput}
					/>

					<label htmlFor="email"> Email: </label>

					<input
						type="email"
						name="email"
						value={input.email}
						onChange={setInput}
						required
					/>

					<button onClick={handleSubmit}>submit</button>

					<NavLink to="/login">go to sing in</NavLink>
				</div>
			</form>
		</div>
	);
}

export default Signup;