Skip to content

Commit 22d6bec

Browse files
committed
Implemented proper SignUp to FrontPage.
1 parent 1422ba1 commit 22d6bec

File tree

6 files changed

+69
-25
lines changed

6 files changed

+69
-25
lines changed

src/frontpage/FrontPage.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.button-spacer{
2+
width: 10px;
3+
}

src/frontpage/FrontPage.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ import SignIn from './signin/SignIn';
33
import SignUp from './signup/SignUp';
44
import { Navbar, NavbarBrand } from 'reactstrap';
55
import githubMarkSmall from './assets/GitHub-Mark-32px.png'
6+
import './FrontPage.css';
67

78
export default class FrontPage extends React.Component {
89
render() {
910
return (
1011
<div className="h-100 d-flex flex-column">
1112
<Navbar color="light" light>
1213
<NavbarBrand href="/" className="mr-auto"></NavbarBrand>
14+
<SignUp />
15+
<div className="button-spacer" />
16+
<SignIn />
1317
</Navbar>
1418
<div className="d-flex flex-grow-1">
1519
<div className="d-flex flex-fill justify-content-center align-items-center flex-column text-center">

src/frontpage/signin/SignIn.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class SignIn extends React.Component{
2121
render(){
2222
return (
2323
<div>
24-
<SignInForm/>
24+
<button type="button" class="btn btn-outline-primary">SignIn</button>
2525
</div>
2626
);
2727
}

src/frontpage/signup/SignUp.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import React, { Component } from 'react'
22
import { connect } from 'react-redux'
33
import SignUpForm from './SignUpForm';
4+
import SignUpModal from './SignUpModal';
45

56
export class SignUp extends Component {
7+
constructor(props){
8+
super(props);
9+
}
610

711
render() {
812
return (
913
<div>
10-
<SignUpForm />
14+
<SignUpModal ref="modal"/>
15+
<button type="button" class="btn btn-outline-secondary" onClick={() => { this.refs.modal.getWrappedInstance().toggle()}} >SignUp</button>
1116
</div>
1217
)
1318
}

src/frontpage/signup/SignUpForm.js

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { signUp } from './SignUpAPI';
55
import { setAuthStatus } from '../../redux/actions/AuthActions';
66

77
export class SignUpForm extends Component {
8-
constructor(props){
8+
constructor(props) {
99
super(props);
1010
this.state = {
1111
username: '',
@@ -21,7 +21,7 @@ export class SignUpForm extends Component {
2121
* SignUp process.
2222
*/
2323

24-
performSignUp(){
24+
performSignUp() {
2525
signUp(this.state.username, this.state.password, this.props.setAuthStatus);
2626
}
2727

@@ -30,26 +30,22 @@ export class SignUpForm extends Component {
3030
* Forms event handling.
3131
*/
3232

33-
handleUsernameChange(event){
34-
this.setState({username: event.target.value});
33+
handleUsernameChange(event) {
34+
this.setState({ username: event.target.value });
3535
}
3636

37-
handlePasswordChange(event){
38-
this.setState({password: event.target.value});
37+
handlePasswordChange(event) {
38+
this.setState({ password: event.target.value });
3939
}
4040

41-
render(){
42-
return(
43-
<form className="form-size">
44-
<div className="form-group">
45-
<label>Username</label>
46-
<input type="text" className="form-control" value={this.state.username} onChange={this.handleUsernameChange}/>
47-
<label>Password</label>
48-
<input type="password" className="form-control" value={this.state.password} onChange={this.handlePasswordChange}/>
49-
<br />
50-
<button type="button" className="btn btn-secondary" onClick={this.performSignUp} >SignUp</button>
51-
</div>
52-
</form>
41+
render() {
42+
return (
43+
<div>
44+
<label>Username</label>
45+
<input type="text" className="form-control" value={this.state.username} onChange={this.handleUsernameChange} />
46+
<label>Password</label>
47+
<input type="password" className="form-control" value={this.state.password} onChange={this.handlePasswordChange} />
48+
</div>
5349
)
5450
}
5551
}
@@ -58,12 +54,8 @@ SignUpForm.propTypes = {
5854
setAuthStatus: PropTypes.func
5955
}
6056

61-
const mapStateToProps = (state) => ({
62-
63-
})
64-
6557
const mapDispatchToProps = {
6658
setAuthStatus
6759
}
6860

69-
export default connect(mapStateToProps, mapDispatchToProps)(SignUpForm)
61+
export default connect(null, mapDispatchToProps, null, {withRef: true})(SignUpForm)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React, { Component } from 'react'
2+
import SignUpForm from './SignUpForm';
3+
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
4+
import {connect} from 'react-redux';
5+
6+
class SignUpModal extends Component {
7+
constructor(props) {
8+
super(props);
9+
10+
this.state = {
11+
modal: false
12+
}
13+
this.toggle = this.toggle.bind(this);
14+
}
15+
16+
toggle() {
17+
this.setState({
18+
modal: !this.state.modal
19+
})
20+
}
21+
22+
render() {
23+
return (
24+
<div>
25+
<Modal isOpen={this.state.modal} toggle={this.toggle}>
26+
<ModalHeader toggle={this.toggle}>SignUp</ModalHeader>
27+
<ModalBody>
28+
<SignUpForm ref="signUpForm"/>
29+
</ModalBody>
30+
<ModalFooter>
31+
<Button color="primary" onClick={() => {this.refs.signUpForm.getWrappedInstance().performSignUp()}}>SignUp</Button>{' '}
32+
<Button color="secondary" onClick={this.toggle}>Cancel</Button>
33+
</ModalFooter>
34+
</Modal>
35+
</div>
36+
)
37+
}
38+
}
39+
40+
export default connect(null, null, null, {withRef: true})(SignUpModal)

0 commit comments

Comments
 (0)