CommentForm.jsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import Button from 'react-bootstrap/es/Button';
  4. import Tab from 'react-bootstrap/es/Tab';
  5. import Tabs from 'react-bootstrap/es/Tabs';
  6. import * as toastr from 'toastr';
  7. import UserPicture from '../User/UserPicture';
  8. import ReactUtils from '../ReactUtils';
  9. /**
  10. *
  11. * @author Yuki Takei <yuki@weseek.co.jp>
  12. *
  13. * @export
  14. * @class Comment
  15. * @extends {React.Component}
  16. */
  17. export default class CommentForm extends React.Component {
  18. constructor(props) {
  19. super(props);
  20. this.state = {
  21. };
  22. // this.updateState = this.updateState.bind(this);
  23. // this.updateStateCheckbox = this.updateStateCheckbox.bind(this);
  24. // this.postComment = this.postComment.bind(this);
  25. // this.renderHtml = this.renderHtml.bind(this);
  26. // this.handleSelect = this.handleSelect.bind(this);
  27. // this.apiErrorHandler = this.apiErrorHandler.bind(this);
  28. // this.onUpload = this.onUpload.bind(this);
  29. // this.onSlackEnabledFlagChange = this.onSlackEnabledFlagChange.bind(this);
  30. // this.onSlackChannelsChange = this.onSlackChannelsChange.bind(this);
  31. // this.showCommentFormBtnClickHandler = this.showCommentFormBtnClickHandler.bind(this);
  32. }
  33. componentWillMount() {
  34. this.init();
  35. }
  36. init() {
  37. if (!this.props.data.pageId) {
  38. return;
  39. }
  40. }
  41. /**
  42. * Load data of comments and rerender <PageComments />
  43. */
  44. postComment(event) {
  45. if (event != null) {
  46. event.preventDefault();
  47. }
  48. // this.props.data.crowi.apiPost('/comments.add', {
  49. // commentForm: {
  50. // comment: this.state.comment,
  51. // _csrf: this.props.data.crowi.csrfToken,
  52. // page_id: this.props.data.pageId,
  53. // revision_id: this.props.data.revisionId,
  54. // is_markdown: this.state.isMarkdown,
  55. // replyTo: this.props.replyTo,
  56. // },
  57. // slackNotificationForm: {
  58. // isSlackEnabled: this.state.isSlackEnabled,
  59. // slackChannels: this.state.slackChannels,
  60. // },
  61. // })
  62. // .then((res) => {
  63. // if (this.props.onPostComplete != null) {
  64. // this.props.onPostComplete(res.comment);
  65. // }
  66. // this.setState({
  67. // comment: '',
  68. // isMarkdown: true,
  69. // html: '',
  70. // key: 1,
  71. // errorMessage: undefined,
  72. // isSlackEnabled: false,
  73. // });
  74. // // reset value
  75. // this.editor.setValue('');
  76. // })
  77. // .catch((err) => {
  78. // const errorMessage = err.message || 'An unknown error occured when posting comment';
  79. // this.setState({ errorMessage });
  80. // });
  81. }
  82. onUpload(file) {
  83. const endpoint = '/attachments.add';
  84. // // create a FromData instance
  85. // const formData = new FormData();
  86. // formData.append('_csrf', this.props.data.crowi.csrfToken);
  87. // formData.append('file', file);
  88. // formData.append('path', this.props.data.pagePath);
  89. // formData.append('page_id', this.props.data.pageId || 0);
  90. // // post
  91. // this.props.data.crowi.apiPost(endpoint, formData)
  92. // .then((res) => {
  93. // const attachment = res.attachment;
  94. // const fileName = attachment.originalName;
  95. // let insertText = `[${fileName}](${attachment.filePathProxied})`;
  96. // // when image
  97. // if (attachment.fileFormat.startsWith('image/')) {
  98. // // modify to "![fileName](url)" syntax
  99. // insertText = `!${insertText}`;
  100. // }
  101. // this.editor.insertText(insertText);
  102. // })
  103. // .catch(this.apiErrorHandler)
  104. // // finally
  105. // .then(() => {
  106. // this.editor.terminateUploadingState();
  107. // });
  108. }
  109. apiErrorHandler(error) {
  110. toastr.error(error.message, 'Error occured', {
  111. closeButton: true,
  112. progressBar: true,
  113. newestOnTop: false,
  114. showDuration: '100',
  115. hideDuration: '100',
  116. timeOut: '3000',
  117. });
  118. }
  119. render() {
  120. return (
  121. <div>
  122. {this.props.children}
  123. </div>
  124. );
  125. }
  126. }
  127. CommentForm.propTypes = {
  128. children: PropTypes.node.isRequired,
  129. onPostComplete: PropTypes.func,
  130. replyTo: PropTypes.string,
  131. data: PropTypes.object.isRequired,
  132. };