-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest
89 lines (86 loc) · 2.11 KB
/
test
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
import React from "react";
import "./Signup.css";
export const Signup = () => {
const [form, setForm] = React.useState({
email: "",
password: "",
confirmPassword: "",
});
// const handleChange = (e) => {
// setForm({
// ...form,
// [e.target.name]: e.target.value,
// });
// console.log(form);
// };
const handleChange = ({ target: { name, value } }) => {
setForm({ ...form, [name]: value });
console.log(form);
};
const submitForm = () => {
if (form.password !== form.confirmPassword) {
alert("Passwords do not match");
} else if (
form.email === "" ||
form.password === "" ||
form.confirmPassword === "" ||
form.number === ""
) {
alert("Please fill in all fields");
} else {
// https://bikeapis.herokuapp.com/register
// now let's send this to the server
var sendForm = {
email: form.email,
number: 9856589568,
password: form.password,
};
console.log(sendForm);
fetch("https://bikeapis.herokuapp.com/register", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(sendForm),
})
.then((res) => res.json())
.then((data) => {
console.log(data);
});
// end call
}
};
return (
<div className="sigin">
<input
type="email"
name="email"
placeholder="Email"
onChange={handleChange}
/>
<input
type="number"
name="phone"
placeholder="Phone"
onChange={handleChange}
/>
<input
type="password"
name="password"
placeholder="Password"
onChange={handleChange}
/>
<input
type="password"
name="confirmPassword"
placeholder="Confirm Password"
onChange={handleChange}
/>
<button onClick={submitForm}>Signup</button>
{/* <input onSubmit={submitForm} type="submit" value="Sign Up" /> */}
</div>
);
};
// "email":"[email protected]",
// "number": "9999999965",
// "password": "123456"