import React, {Component} from 'react'; import PropTypes from 'prop-types'; import {Icon} from 'coral-ui'; import styles from './FlagBox.css'; import t from 'coral-framework/services/i18n'; const shortReasons = { 'This comment is offensive': t('modqueue.offensive'), 'This looks like an ad/marketing': t('modqueue.spam_ads'), 'This user is impersonating': t('modqueue.impersonating'), 'I don\'t like this username': t('modqueue.dont_like_username'), 'Other': t('modqueue.other') }; class FlagBox extends Component { constructor () { super(); this.state = { showDetail: false }; } toggleDetail = () => { this.setState((state) => ({ showDetail: !state.showDetail })); } reasonMap = (reason) => { const shortReason = shortReasons[reason]; // if the short reason isn't found, just return the long one. return shortReason ? shortReason : reason; } render() { const {actionSummaries, actions, viewUserDetail} = this.props; const {showDetail} = this.state; return (

{t('community.flags')} ({actionSummaries.length}):

    {actionSummaries.map((action, i) =>
  • {this.reasonMap(action.reason)} ({action.count})
  • )}
{showDetail ? t('modqueue.less_detail') : t('modqueue.more_detail')}
{showDetail && (
    {actionSummaries.map((summary, i) => { const actionList = actions.filter((a) => a.reason === summary.reason); return (
  • {this.reasonMap(summary.reason)} ({summary.count})
  • ); })}
)}
); } } FlagBox.propTypes = { actionSummaries: PropTypes.arrayOf(PropTypes.shape({ reason: PropTypes.string, count: PropTypes.number })).isRequired, actions: PropTypes.arrayOf(PropTypes.shape({ message: PropTypes.string, user: PropTypes.shape({username: PropTypes.string}) })).isRequired }; export default FlagBox;