You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
3.5 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { changeReportComment, submitReport } from '../../../actions/reports';
  4. import { refreshAccountTimeline } from '../../../actions/timelines';
  5. import PropTypes from 'prop-types';
  6. import ImmutablePropTypes from 'react-immutable-proptypes';
  7. import { makeGetAccount } from '../../../selectors';
  8. import { defineMessages, FormattedMessage, injectIntl } from 'react-intl';
  9. import StatusCheckBox from '../../report/containers/status_check_box_container';
  10. import Immutable from 'immutable';
  11. import ImmutablePureComponent from 'react-immutable-pure-component';
  12. import Button from '../../../components/button';
  13. const messages = defineMessages({
  14. placeholder: { id: 'report.placeholder', defaultMessage: 'Additional comments' },
  15. submit: { id: 'report.submit', defaultMessage: 'Submit' },
  16. });
  17. const makeMapStateToProps = () => {
  18. const getAccount = makeGetAccount();
  19. const mapStateToProps = state => {
  20. const accountId = state.getIn(['reports', 'new', 'account_id']);
  21. return {
  22. isSubmitting: state.getIn(['reports', 'new', 'isSubmitting']),
  23. account: getAccount(state, accountId),
  24. comment: state.getIn(['reports', 'new', 'comment']),
  25. statusIds: Immutable.OrderedSet(state.getIn(['timelines', `account:${accountId}`, 'items'])).union(state.getIn(['reports', 'new', 'status_ids'])),
  26. };
  27. };
  28. return mapStateToProps;
  29. };
  30. @connect(makeMapStateToProps)
  31. @injectIntl
  32. export default class ReportModal extends ImmutablePureComponent {
  33. static propTypes = {
  34. isSubmitting: PropTypes.bool,
  35. account: ImmutablePropTypes.map,
  36. statusIds: ImmutablePropTypes.orderedSet.isRequired,
  37. comment: PropTypes.string.isRequired,
  38. dispatch: PropTypes.func.isRequired,
  39. intl: PropTypes.object.isRequired,
  40. };
  41. handleCommentChange = (e) => {
  42. this.props.dispatch(changeReportComment(e.target.value));
  43. }
  44. handleSubmit = () => {
  45. this.props.dispatch(submitReport());
  46. }
  47. componentDidMount () {
  48. this.props.dispatch(refreshAccountTimeline(this.props.account.get('id')));
  49. }
  50. componentWillReceiveProps (nextProps) {
  51. if (this.props.account !== nextProps.account && nextProps.account) {
  52. this.props.dispatch(refreshAccountTimeline(nextProps.account.get('id')));
  53. }
  54. }
  55. render () {
  56. const { account, comment, intl, statusIds, isSubmitting } = this.props;
  57. if (!account) {
  58. return null;
  59. }
  60. return (
  61. <div className='modal-root__modal report-modal'>
  62. <div className='report-modal__target'>
  63. <FormattedMessage id='report.target' defaultMessage='Report {target}' values={{ target: <strong>{account.get('acct')}</strong> }} />
  64. </div>
  65. <div className='report-modal__container'>
  66. <div className='report-modal__statuses'>
  67. <div>
  68. {statusIds.map(statusId => <StatusCheckBox id={statusId} key={statusId} disabled={isSubmitting} />)}
  69. </div>
  70. </div>
  71. <div className='report-modal__comment'>
  72. <textarea
  73. className='setting-text light'
  74. placeholder={intl.formatMessage(messages.placeholder)}
  75. value={comment}
  76. onChange={this.handleCommentChange}
  77. disabled={isSubmitting}
  78. />
  79. </div>
  80. </div>
  81. <div className='report-modal__action-bar'>
  82. <Button disabled={isSubmitting} text={intl.formatMessage(messages.submit)} onClick={this.handleSubmit} />
  83. </div>
  84. </div>
  85. );
  86. }
  87. }