import React, {PropTypes} from 'react'; import {Dialog} from 'coral-ui'; import {RadioGroup, Radio} from 'react-mdl'; import styles from './SuspendUserDialog.css'; import Button from 'coral-ui/components/Button'; import t, {timeago} from 'coral-framework/services/i18n'; import {dateAdd} from 'coral-framework/utils'; const initialState = {step: 0, duration: '3'}; function durationsToDate(hours) { // Add 1 minute more to help `timeago.js` to display the correct duration. return dateAdd(new Date(), 'minute', hours * 60 + 1); } class SuspendUserDialog extends React.Component { state = initialState; componentWillReceiveProps(next) { if (this.props.open && !next.open) { this.setState(initialState); } } handleDurationChange = (event) => { this.setState({duration: event.target.value}); } handleMessageChange = (event) => { this.setState({message: event.target.value}); } goToStep1 = () => { this.setState({ step: 1, message: t( 'suspenduser.email_message_suspend', this.props.username, this.props.organizationName, timeago(durationsToDate(this.state.duration)), ), }); } handlePerform = () => { this.props.onPerform({ message: this.state.message, // Add 1 minute more to help `timeago.js` to display the correct duration. until: durationsToDate(this.state.duration), }); }; renderStep0() { const {onCancel, username} = this.props; const {duration} = this.state; return ( {t('suspenduser.title_suspend')} {t('suspenduser.description_suspend', username)} {t('suspenduser.select_duration')} {t('suspenduser.one_hour')} {t('suspenduser.hours', 3)} {t('suspenduser.hours', 24)} {t('suspenduser.days', 7)} {t('suspenduser.cancel')} {t('suspenduser.suspend_user')} ); } renderStep1() { const {onCancel, username} = this.props; const {message} = this.state; return ( {t('suspenduser.title_notify')} {t('suspenduser.description_notify', username)} {t('suspenduser.write_message')} {t('suspenduser.cancel')} {t('suspenduser.send')} ); } render() { const {open, onCancel} = this.props; const {step} = this.state; return ( × {step === 0 && this.renderStep0()} {step === 1 && this.renderStep1()} ); } } SuspendUserDialog.propTypes = { open: PropTypes.bool.isRequired, onPerform: PropTypes.func.isRequired, onCancel: PropTypes.func.isRequired, organizationName: PropTypes.string, username: PropTypes.string, }; export default SuspendUserDialog;
{t('suspenduser.description_suspend', username)}
{t('suspenduser.description_notify', username)}