category.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import { connect } from 'react-redux';
  5. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  6. import Button from 'mastodon/components/button';
  7. import Option from './components/option';
  8. import { List as ImmutableList } from 'immutable';
  9. const messages = defineMessages({
  10. dislike: { id: 'report.reasons.dislike', defaultMessage: 'I don\'t like it' },
  11. dislike_description: { id: 'report.reasons.dislike_description', defaultMessage: 'It is not something you want to see' },
  12. spam: { id: 'report.reasons.spam', defaultMessage: 'It\'s spam' },
  13. spam_description: { id: 'report.reasons.spam_description', defaultMessage: 'Malicious links, fake engagement, or repetitive replies' },
  14. violation: { id: 'report.reasons.violation', defaultMessage: 'It violates server rules' },
  15. violation_description: { id: 'report.reasons.violation_description', defaultMessage: 'You are aware that it breaks specific rules' },
  16. other: { id: 'report.reasons.other', defaultMessage: 'It\'s something else' },
  17. other_description: { id: 'report.reasons.other_description', defaultMessage: 'The issue does not fit into other categories' },
  18. status: { id: 'report.category.title_status', defaultMessage: 'post' },
  19. account: { id: 'report.category.title_account', defaultMessage: 'profile' },
  20. });
  21. const mapStateToProps = state => ({
  22. rules: state.getIn(['server', 'server', 'rules'], ImmutableList()),
  23. });
  24. export default @connect(mapStateToProps)
  25. @injectIntl
  26. class Category extends React.PureComponent {
  27. static propTypes = {
  28. onNextStep: PropTypes.func.isRequired,
  29. rules: ImmutablePropTypes.list,
  30. category: PropTypes.string,
  31. onChangeCategory: PropTypes.func.isRequired,
  32. startedFrom: PropTypes.oneOf(['status', 'account']),
  33. intl: PropTypes.object.isRequired,
  34. };
  35. handleNextClick = () => {
  36. const { onNextStep, category } = this.props;
  37. switch(category) {
  38. case 'dislike':
  39. onNextStep('thanks');
  40. break;
  41. case 'violation':
  42. onNextStep('rules');
  43. break;
  44. default:
  45. onNextStep('statuses');
  46. break;
  47. }
  48. };
  49. handleCategoryToggle = (value, checked) => {
  50. const { onChangeCategory } = this.props;
  51. if (checked) {
  52. onChangeCategory(value);
  53. }
  54. };
  55. render () {
  56. const { category, startedFrom, rules, intl } = this.props;
  57. const options = rules.size > 0 ? [
  58. 'dislike',
  59. 'spam',
  60. 'violation',
  61. 'other',
  62. ] : [
  63. 'dislike',
  64. 'spam',
  65. 'other',
  66. ];
  67. return (
  68. <React.Fragment>
  69. <h3 className='report-dialog-modal__title'><FormattedMessage id='report.category.title' defaultMessage="Tell us what's going on with this {type}" values={{ type: intl.formatMessage(messages[startedFrom]) }} /></h3>
  70. <p className='report-dialog-modal__lead'><FormattedMessage id='report.category.subtitle' defaultMessage='Choose the best match' /></p>
  71. <div>
  72. {options.map(item => (
  73. <Option
  74. key={item}
  75. name='category'
  76. value={item}
  77. checked={category === item}
  78. onToggle={this.handleCategoryToggle}
  79. label={intl.formatMessage(messages[item])}
  80. description={intl.formatMessage(messages[`${item}_description`])}
  81. />
  82. ))}
  83. </div>
  84. <div className='flex-spacer' />
  85. <div className='report-dialog-modal__actions'>
  86. <Button onClick={this.handleNextClick} disabled={category === null}><FormattedMessage id='report.next' defaultMessage='Next' /></Button>
  87. </div>
  88. </React.Fragment>
  89. );
  90. }
  91. }