import Modal from 'flarum/components/Modal'; import Button from 'flarum/components/Button'; export default class SuspendUserModal extends Modal { constructor(...args) { super(...args); let until = this.props.user.suspendUntil(); let status = null; if (new Date() > until) until = null; if (until) { if (until.getFullYear() === 9999) status = 'indefinitely'; else status = 'limited'; } this.status = m.prop(status); this.daysRemaining = m.prop(status === 'limited' && -moment().diff(until, 'days') + 1); } className() { return 'SuspendUserModal Modal--small'; } title() { return 'Suspend ' + this.props.user.username(); } content() { return (
); } onsubmit(e) { e.preventDefault(); this.loading = true; let suspendUntil = null; switch (this.status()) { case 'indefinitely': suspendUntil = new Date('9999-12-31'); break; case 'limited': suspendUntil = moment().add(this.daysRemaining(), 'days').toDate(); break; default: // no default } this.props.user.save({suspendUntil}).then( () => this.hide(), () => { this.loading = false; m.redraw(); } ); } }