source: RebuMKReact/src/Components/Register/registerPassenger.js

Last change on this file was 364f27d, checked in by MetodiMladenovski <meto.18@…>, 14 months ago

added projects and db scripts

  • Property mode set to 100644
File size: 4.6 KB
Line 
1import React from "react";
2import {useNavigate} from "react-router-dom";
3import CenteredContainer from "../UtilComponents/CenteredContainer";
4import '../UtilComponents/App.css'
5
6const registerPassenger = (props) => {
7
8 // eslint-disable-next-line react-hooks/rules-of-hooks
9 const navigate = useNavigate();
10 // eslint-disable-next-line react-hooks/rules-of-hooks
11 const [formData, updateFormData] = React.useState({
12 firstName : "",
13 surname : "",
14 email : "",
15 password : "",
16 repeatedPassword: "",
17 })
18
19 const handleChange = (e) => {
20 updateFormData({
21 ...formData,
22 [e.target.name]: e.target.value.trim()
23
24 })
25 }
26
27 const onFormSubmit = (e) => {
28 e.preventDefault();
29 const firstName = formData.firstName
30 const surname = formData.surname
31 const email = formData.email
32 const password = formData.password
33 const repetedPassword = formData.repeatedPassword
34
35 if(password !== repetedPassword)
36 alert("Passwords don't match");
37
38 props.onRegisterPassenger(firstName, surname, email, password);
39 navigate("/login")
40 }
41
42 return(
43 <CenteredContainer>
44 <h3 style={{textAlign: "center", color: "darkcyan"}}>Register Passenger</h3>
45 <br></br>
46 <form onSubmit={onFormSubmit}>
47 <div className="form-group">
48 <label htmlFor="firstName">First name</label>
49 <input type="text"
50 className="form-control"
51 id="firstName"
52 name="firstName"
53 required
54 placeholder="E.g: John"
55 style={{height: 100 + "%"}}
56 onChange={handleChange}
57 />
58 </div>
59 <br></br>
60 <div className="form-group">
61 <label htmlFor="surname">Surname</label>
62 <input type="text"
63 className="form-control"
64 id="surname"
65 name="surname"
66 required
67 placeholder="E.g: Doe"
68 style={{height: 100 + "%"}}
69 onChange={handleChange}
70 />
71 </div>
72 <br></br>
73 <div className="form-group">
74 <label htmlFor="email">Email</label>
75 <input type="text"
76 className="form-control"
77 id="email"
78 name="email"
79 placeholder="E.g: johndoe@email.com"
80 required
81 onChange={handleChange}
82 />
83 </div>
84 <br></br>
85 <div className="form-group">
86 <label htmlFor="password">Password</label>
87 <input type="password"
88 className="form-control"
89 id="password"
90 name="password"
91 placeholder="E.g: moreCharacters@123"
92 required
93 onChange={handleChange}
94 />
95 </div>
96 <br></br>
97 <div className="form-group">
98 <label htmlFor="repeatedPassword">Repeat Password</label>
99 <input type="password"
100 className="form-control"
101 id="repeatedPassword"
102 name="repeatedPassword"
103 placeholder="E.g: moreCharacters@123"
104 required
105 onChange={handleChange}
106 />
107 </div>
108 <br></br>
109 <div className="d-grid gap-2 col-6 mx-auto">
110 <button id="submit" type="submit" className="myButton btn btn-primary" style={{backgroundColor: "darkcyan", float: "center", borderColor: "black", color:'white'}}>Register</button>
111 </div>
112 </form>
113 </CenteredContainer>
114 )
115
116}
117
118export default registerPassenger;
Note: See TracBrowser for help on using the repository browser.