-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1bce3ae
commit 4e500af
Showing
5 changed files
with
285 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from "reactstrap"; | ||
|
||
import React, { Component } from "react"; | ||
import { FormattedMessage } from "react-intl"; | ||
import { connect } from "react-redux"; | ||
class ModalUser extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
email: "", | ||
password: "", | ||
firstName: "", | ||
lastName: "", | ||
address: "", | ||
}; | ||
} | ||
|
||
componentDidMount() {} | ||
|
||
toggle = () => { | ||
this.props.toggleFromParent(); | ||
}; | ||
|
||
handleOnChangeInput = (event, id) => { | ||
//console.log(event.target.value, "id: ", id); | ||
|
||
//bad code | ||
// this.state[id] =event.target.value; | ||
// this.setState({ | ||
// ...this.state | ||
// }, () => { | ||
// console.log("check bad code:", this.state); | ||
// }) | ||
|
||
//good code | ||
let copyState = { ...this.state }; | ||
copyState[id] = event.target.value; | ||
this.setState({ | ||
...copyState, | ||
}); | ||
}; | ||
checkValidInput = () => { | ||
let isValid = true; | ||
let arrInput = [ | ||
"email", | ||
"password", | ||
"firstName", | ||
"lastName", | ||
"address", | ||
]; | ||
for (let i = 0; i < arrInput.length; i++) { | ||
if (!this.state[arrInput[i]]) { | ||
isValid = false; | ||
alert("Missing parameter: " + arrInput[i]); | ||
break; | ||
} | ||
} | ||
return isValid; | ||
}; | ||
handleAddNewUser = () => { | ||
let isValid = this.checkValidInput(); | ||
if (isValid) { | ||
this.props.createNewUserFromParent(this.state); | ||
// console.log("check good state:", this.state); | ||
} | ||
}; | ||
|
||
render() { | ||
return ( | ||
<Modal | ||
isOpen={this.props.isOpen} | ||
toggle={() => { | ||
this.toggle(); | ||
}} | ||
className={"modal-user-container"} | ||
size="lg" | ||
centered | ||
> | ||
<ModalHeader | ||
toggle={() => { | ||
this.toggle(); | ||
}} | ||
> | ||
Create a new user | ||
</ModalHeader> | ||
<ModalBody> | ||
<div className="modal-user-body"> | ||
<div className="input-container"> | ||
<label>Email</label> | ||
<input | ||
type="text" | ||
onChange={(event) => { | ||
this.handleOnChangeInput(event, "email"); | ||
}} | ||
value={this.state.email} | ||
/> | ||
</div> | ||
<div className="input-container"> | ||
<label>Password</label> | ||
<input | ||
type="password" | ||
onChange={(event) => { | ||
this.handleOnChangeInput(event, "password"); | ||
}} | ||
value={this.state.password} | ||
/> | ||
</div> | ||
</div> | ||
<div className="modal-user-body"> | ||
<div className="input-container"> | ||
<label>First name</label> | ||
<input | ||
type="text" | ||
onChange={(event) => { | ||
this.handleOnChangeInput( | ||
event, | ||
"firstName" | ||
); | ||
}} | ||
value={this.state.firstName} | ||
/> | ||
</div> | ||
<div className="input-container"> | ||
<label>Last name</label> | ||
<input | ||
type="text" | ||
onChange={(event) => { | ||
this.handleOnChangeInput(event, "lastName"); | ||
}} | ||
value={this.state.lastName} | ||
/> | ||
</div> | ||
</div> | ||
<div className="modal-user-body"> | ||
<div className="input-container max-width-input"> | ||
<label>Address</label> | ||
<input | ||
type="text" | ||
onChange={(event) => { | ||
this.handleOnChangeInput(event, "address"); | ||
}} | ||
value={this.state.address} | ||
/> | ||
</div> | ||
</div> | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button | ||
color="primary" | ||
onClick={() => { | ||
this.handleAddNewUser(); | ||
}} | ||
className="px-3" | ||
> | ||
Save | ||
</Button>{" "} | ||
<Button | ||
color="secondary" | ||
onClick={() => { | ||
this.toggle(); | ||
}} | ||
className="px-3" | ||
> | ||
Close | ||
</Button> | ||
</ModalFooter> | ||
</Modal> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = (state) => { | ||
return {}; | ||
}; | ||
|
||
const mapDispatchToProps = (dispatch) => { | ||
return {}; | ||
}; | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(ModalUser); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters