source: my-react-app/src/components/LoginForm.js

main
Last change on this file was 8ca35dc, checked in by Aleksandar Panovski <apano77@…>, 4 months ago

Done with stupid timeslots

  • Property mode set to 100644
File size: 5.2 KB
Line 
1import * as React from "react";
2import bootstrap from 'bootstrap/dist/css/bootstrap.min.css'
3import classNames from 'classnames';
4
5export default class LoginForm extends React.Component {
6 constructor(props) {
7 super(props);
8 this.state = {
9 active: "login",
10 firstName: "",
11 lastName: "",
12 email: "",
13 password: "",
14 onLogin: props.onLogin,
15 onRegister: props.onRegister
16 }
17 }
18
19 onChangeHandler = (e) => {
20 let name = e.target.name;
21 let value = e.target.value;
22 this.setState({[name]: value})
23 }
24
25 onSubmitLogin = (e) => {
26 this.state.onLogin(e, this.state.email, this.state.password);
27 }
28
29 onSubmitRegister = (e) => {
30 this.state.onRegister(
31 e,
32 this.state.firstName,
33 this.state.lastName,
34 this.state.email,
35 this.state.password)
36 }
37
38 render() {
39 return (
40 <div className="row justify-content-center">
41 <div className="col-4">
42 <ul className="nav nav-pills nav-justified mb-3" id="ex1" role="tablist">
43 <li className="nav-item" role="presentation">
44 <button className={classNames("nav-link", this.state.active === "login" ? "active" : "")}
45 id="tab-login" onClick={() => this.setState({active: "login"})}>Login
46 </button>
47 </li>
48 <li className="nav-item" role="presentation">
49 <button className={classNames("nav-link", this.state.active === "register" ? "active" : "")}
50 id="tab-register" onClick={() => this.setState({active: "register"})}>Register
51 </button>
52 </li>
53 </ul>
54
55 <div className="tab-content">
56 <div
57 className={classNames("tab-pane", "fade", this.state.active === "login" ? "show active" : "")}
58 id="pills-login">
59 <form onSubmit={this.onSubmitLogin}>
60 <div className="form-outline mb-4">
61 <input type="email" id="email" name="email" className="form-control"
62 onChange={this.onChangeHandler}/>
63 <label className="form-label" htmlFor="email">Email</label>
64 </div>
65 <div className="form-outline mb-4">
66 <input type="password" id="loginPassword" name="password" className="form-control"
67 onChange={this.onChangeHandler}/>
68 <label className="form-label" htmlFor="loginPassword">Password</label>
69 </div>
70
71 <button type="submit" className="btn btn-primary btn-block mb-4">Sign In</button>
72 </form>
73 </div>
74
75 <div
76 className={classNames("tab-pane", "fade", this.state.active === "register" ? "show active" : "")}
77 id="pills-register">
78 <form onSubmit={this.onSubmitRegister}>
79 <div className="form-outline mb-4">
80 <input type="text" id="firstName" name="firstName" className="form-control"
81 onChange={this.onChangeHandler}/>
82 <label className="form-label" htmlFor="firstName">First Name</label>
83 </div>
84 <div className="form-outline mb-4">
85 <input type="text" id="lastName" name="lastName" className="form-control"
86 onChange={this.onChangeHandler}/>
87 <label className="form-label" htmlFor="lastName">Last Name</label>
88 </div>
89 <div className="form-outline mb-4">
90 <input type="email" id="email" name="email" className="form-control"
91 onChange={this.onChangeHandler}/>
92 <label className="form-label" htmlFor="email">Email</label>
93 </div>
94 <div className="form-outline mb-4">
95 <input type="password" id="loginPassword" name="password" className="form-control"
96 onChange={this.onChangeHandler}/>
97 <label className="form-label" htmlFor="loginPassword">Password</label>
98 </div>
99
100 <button type="submit" className="btn btn-primary btn-block mb-4">Register</button>
101 </form>
102 </div>
103 </div>
104 </div>
105 </div>
106 );
107
108 }
109}
Note: See TracBrowser for help on using the repository browser.