-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathChangeCommentForm.jsx
More file actions
62 lines (59 loc) · 1.67 KB
/
ChangeCommentForm.jsx
File metadata and controls
62 lines (59 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React, { Component } from "react";
import styles from "./ChangeCommentForm.css";
import PropTypes from "prop-types";
class ChangeCommentForm extends Component {
state = {
formCommentText: "",
};
handleCommentText = (text) => {
this.setState({
formCommentText: text,
});
};
componentDidMount() {
this.handleCommentText(this.props.comment.text);
}
onSubmitForm = (e) => {
e.preventDefault();
this.props.onEditComment(
this.state.formCommentText,
this.props.comment.createDate
);
this.props.onShowChangeForm();
};
render() {
return (
<form onSubmit={this.onSubmitForm} className={styles["add-comment-form"]}>
<label htmlFor="text-comment">Text of Your comment</label>
<textarea
className={styles["comment-filed"]}
name=""
id="text-comment"
onChange={(e) => this.handleCommentText(e.target.value)}
value={this.state.formCommentText}
></textarea>
<div className={styles["change-commentform-btns"]}>
<button className={styles["btn-add-comment"]} type="submit">
Save
</button>
<button
onClick={this.props.onShowChangeForm}
className={styles["btn-add-comment"]}
>
Deny
</button>
</div>
</form>
);
}
}
ChangeCommentForm.propTypes = {
comment: PropTypes.shape({
createDate: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
text: PropTypes.string.isRequired,
}).isRequired,
onShowChangeForm: PropTypes.func.isRequired,
onEditComment: PropTypes.func.isRequired,
};
export default ChangeCommentForm;