|
@@ -8,18 +8,38 @@ import {
|
|
|
resetPostForm,
|
|
|
removePost,
|
|
|
showEditForm,
|
|
|
- cancelUpdate
|
|
|
+ cancelUpdate,
|
|
|
+ update,
|
|
|
+ handleChangeEditForm
|
|
|
} from "../actions/remote-todo";
|
|
|
|
|
|
import Input from "../components/input";
|
|
|
import Button from "../components/button/button";
|
|
|
import Loder from "../components/HOC/loader";
|
|
|
+import Modal from "../components/modal";
|
|
|
|
|
|
export class RemoteTodo extends Component {
|
|
|
+ state = { open: false };
|
|
|
+
|
|
|
+ close = () => this.setState({ open: false });
|
|
|
+
|
|
|
+ open = () => this.setState({ open: true });
|
|
|
+
|
|
|
componentDidMount() {
|
|
|
this.props.getPosts();
|
|
|
}
|
|
|
|
|
|
+ showEditModalForm = id => {
|
|
|
+ this.props.showEditForm(id);
|
|
|
+ this.open();
|
|
|
+ };
|
|
|
+
|
|
|
+ udatePostHandler = () => {
|
|
|
+ const { sendDataObject, update } = this.props;
|
|
|
+ update(sendDataObject);
|
|
|
+ this.close();
|
|
|
+ };
|
|
|
+
|
|
|
render() {
|
|
|
const {
|
|
|
changeInputValue,
|
|
@@ -30,10 +50,10 @@ export class RemoteTodo extends Component {
|
|
|
sendDataObject,
|
|
|
removePost,
|
|
|
isFetching,
|
|
|
- showEditForm,
|
|
|
editForm,
|
|
|
editFormField,
|
|
|
- cancelUpdate
|
|
|
+ cancelUpdate,
|
|
|
+ handleChangeEditForm
|
|
|
} = this.props;
|
|
|
|
|
|
return (
|
|
@@ -75,7 +95,11 @@ export class RemoteTodo extends Component {
|
|
|
<div key={el.id} className="list__item">
|
|
|
<Button text="x" className="list__rm-btn" onClick={removePost.bind(null, el.id)} />
|
|
|
{el.editable && (
|
|
|
- <Button text="edit" className="list__edit-btn" onClick={showEditForm.bind(null, el.id)} />
|
|
|
+ <Button
|
|
|
+ text="edit"
|
|
|
+ className="list__edit-btn"
|
|
|
+ onClick={this.showEditModalForm.bind(null, el.id)}
|
|
|
+ />
|
|
|
)}
|
|
|
<h3>
|
|
|
{el.firstName} {el.lastName}
|
|
@@ -91,35 +115,35 @@ export class RemoteTodo extends Component {
|
|
|
width: "100%",
|
|
|
display: "flex",
|
|
|
flexDirection: "column"
|
|
|
- }}>
|
|
|
- {editFormField.map(el => {
|
|
|
- return (
|
|
|
- <Input
|
|
|
- key={el.id}
|
|
|
- id={el.id}
|
|
|
- value={el.value}
|
|
|
- checked={el.checked}
|
|
|
- type={el.type}
|
|
|
- name={el.name}
|
|
|
- label={el.label}
|
|
|
- onChange={changeInputValue}
|
|
|
- />
|
|
|
- );
|
|
|
- })}
|
|
|
- <div>
|
|
|
- <Loder flag={isFetching}>
|
|
|
- <Button
|
|
|
- text="Update Post"
|
|
|
- onClick={() => {
|
|
|
- console.log("sendDataObject", sendDataObject);
|
|
|
- }}
|
|
|
- />
|
|
|
- </Loder>
|
|
|
- <Button text="CANCEL" onClick={cancelUpdate} />
|
|
|
- </div>
|
|
|
- </div>
|
|
|
+ }}
|
|
|
+ />
|
|
|
</div>
|
|
|
)}
|
|
|
+ <Modal open={this.state.open} close={this.close}>
|
|
|
+ <div>
|
|
|
+ {editFormField.map(el => {
|
|
|
+ return (
|
|
|
+ <Input
|
|
|
+ key={el.id}
|
|
|
+ id={el.id}
|
|
|
+ value={el.value}
|
|
|
+ checked={el.checked}
|
|
|
+ type={el.type}
|
|
|
+ name={el.name}
|
|
|
+ label={el.label}
|
|
|
+ onChange={handleChangeEditForm}
|
|
|
+ />
|
|
|
+ );
|
|
|
+ })}
|
|
|
+ <div>
|
|
|
+ <Loder flag={isFetching}>
|
|
|
+ <Button text="Update Post" onClick={this.udatePostHandler} />
|
|
|
+ </Loder>
|
|
|
+ <Button text="CANCEL" onClick={cancelUpdate} />
|
|
|
+ </div>
|
|
|
+ <button onClick={this.close}>close</button>
|
|
|
+ </div>
|
|
|
+ </Modal>
|
|
|
</div>
|
|
|
);
|
|
|
}
|
|
@@ -138,5 +162,15 @@ const mapStateToProps = state => {
|
|
|
|
|
|
export default connect(
|
|
|
mapStateToProps,
|
|
|
- { changeInputValue, createPost, getPosts, resetPostForm, removePost, showEditForm, cancelUpdate }
|
|
|
+ {
|
|
|
+ changeInputValue,
|
|
|
+ createPost,
|
|
|
+ getPosts,
|
|
|
+ resetPostForm,
|
|
|
+ removePost,
|
|
|
+ showEditForm,
|
|
|
+ cancelUpdate,
|
|
|
+ handleChangeEditForm,
|
|
|
+ update
|
|
|
+ }
|
|
|
)(RemoteTodo);
|