2017-05-03 09:04:16 +09:00
|
|
|
import React from 'react';
|
2017-02-15 04:59:26 +09:00
|
|
|
import { connect } from 'react-redux';
|
2017-06-28 01:07:21 +09:00
|
|
|
import { changeReportComment, submitReport } from '../../../actions/reports';
|
|
|
|
import { refreshAccountTimeline } from '../../../actions/timelines';
|
2017-04-22 03:05:35 +09:00
|
|
|
import PropTypes from 'prop-types';
|
2017-02-15 04:59:26 +09:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-06-28 01:07:21 +09:00
|
|
|
import { makeGetAccount } from '../../../selectors';
|
2017-02-15 04:59:26 +09:00
|
|
|
import { defineMessages, FormattedMessage, injectIntl } from 'react-intl';
|
2017-06-28 01:07:21 +09:00
|
|
|
import StatusCheckBox from '../../report/containers/status_check_box_container';
|
2017-07-11 08:00:14 +09:00
|
|
|
import { OrderedSet } from 'immutable';
|
2017-06-28 01:07:21 +09:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
import Button from '../../../components/button';
|
2017-02-15 04:59:26 +09:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
placeholder: { id: 'report.placeholder', defaultMessage: 'Additional comments' },
|
2017-05-21 00:31:47 +09:00
|
|
|
submit: { id: 'report.submit', defaultMessage: 'Submit' },
|
2017-02-15 04:59:26 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
const makeMapStateToProps = () => {
|
|
|
|
const getAccount = makeGetAccount();
|
|
|
|
|
|
|
|
const mapStateToProps = state => {
|
|
|
|
const accountId = state.getIn(['reports', 'new', 'account_id']);
|
|
|
|
|
|
|
|
return {
|
|
|
|
isSubmitting: state.getIn(['reports', 'new', 'isSubmitting']),
|
|
|
|
account: getAccount(state, accountId),
|
|
|
|
comment: state.getIn(['reports', 'new', 'comment']),
|
2017-07-11 08:00:14 +09:00
|
|
|
statusIds: OrderedSet(state.getIn(['timelines', `account:${accountId}`, 'items'])).union(state.getIn(['reports', 'new', 'status_ids'])),
|
2017-02-15 04:59:26 +09:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
return mapStateToProps;
|
|
|
|
};
|
|
|
|
|
2017-06-24 02:36:54 +09:00
|
|
|
@connect(makeMapStateToProps)
|
|
|
|
@injectIntl
|
2017-06-28 01:07:21 +09:00
|
|
|
export default class ReportModal extends ImmutablePureComponent {
|
2017-05-12 21:44:10 +09:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
isSubmitting: PropTypes.bool,
|
|
|
|
account: ImmutablePropTypes.map,
|
|
|
|
statusIds: ImmutablePropTypes.orderedSet.isRequired,
|
|
|
|
comment: PropTypes.string.isRequired,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
2017-05-21 00:31:47 +09:00
|
|
|
intl: PropTypes.object.isRequired,
|
2017-05-12 21:44:10 +09:00
|
|
|
};
|
2017-02-15 04:59:26 +09:00
|
|
|
|
2017-06-28 01:07:21 +09:00
|
|
|
handleCommentChange = (e) => {
|
|
|
|
this.props.dispatch(changeReportComment(e.target.value));
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|
2017-02-15 04:59:26 +09:00
|
|
|
|
2017-06-28 01:07:21 +09:00
|
|
|
handleSubmit = () => {
|
|
|
|
this.props.dispatch(submitReport());
|
|
|
|
}
|
2017-02-15 04:59:26 +09:00
|
|
|
|
2017-06-28 01:07:21 +09:00
|
|
|
componentDidMount () {
|
2017-06-12 00:07:35 +09:00
|
|
|
this.props.dispatch(refreshAccountTimeline(this.props.account.get('id')));
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|
2017-02-15 04:59:26 +09:00
|
|
|
|
|
|
|
componentWillReceiveProps (nextProps) {
|
|
|
|
if (this.props.account !== nextProps.account && nextProps.account) {
|
2017-06-12 00:07:35 +09:00
|
|
|
this.props.dispatch(refreshAccountTimeline(nextProps.account.get('id')));
|
2017-02-15 04:59:26 +09:00
|
|
|
}
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|
2017-02-15 04:59:26 +09:00
|
|
|
|
|
|
|
render () {
|
|
|
|
const { account, comment, intl, statusIds, isSubmitting } = this.props;
|
|
|
|
|
|
|
|
if (!account) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2017-06-28 01:07:21 +09:00
|
|
|
<div className='modal-root__modal report-modal'>
|
|
|
|
<div className='report-modal__target'>
|
|
|
|
<FormattedMessage id='report.target' defaultMessage='Report {target}' values={{ target: <strong>{account.get('acct')}</strong> }} />
|
|
|
|
</div>
|
2017-02-15 04:59:26 +09:00
|
|
|
|
2017-06-28 01:07:21 +09:00
|
|
|
<div className='report-modal__container'>
|
|
|
|
<div className='report-modal__statuses'>
|
2017-02-15 04:59:26 +09:00
|
|
|
<div>
|
|
|
|
{statusIds.map(statusId => <StatusCheckBox id={statusId} key={statusId} disabled={isSubmitting} />)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2017-06-28 01:07:21 +09:00
|
|
|
<div className='report-modal__comment'>
|
2017-02-15 04:59:26 +09:00
|
|
|
<textarea
|
2017-06-28 01:07:21 +09:00
|
|
|
className='setting-text light'
|
2017-02-15 04:59:26 +09:00
|
|
|
placeholder={intl.formatMessage(messages.placeholder)}
|
|
|
|
value={comment}
|
|
|
|
onChange={this.handleCommentChange}
|
|
|
|
disabled={isSubmitting}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-06-28 01:07:21 +09:00
|
|
|
|
|
|
|
<div className='report-modal__action-bar'>
|
|
|
|
<Button disabled={isSubmitting} text={intl.formatMessage(messages.submit)} onClick={this.handleSubmit} />
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-02-15 04:59:26 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|