mirror of
https://github.com/wassname/talk.git
synced 2026-06-30 10:15:58 +08:00
Calculate "until"
This commit is contained in:
@@ -6,6 +6,8 @@ import {toast} from 'react-toastify';
|
||||
import key from 'keymaster';
|
||||
import isEqual from 'lodash/isEqual';
|
||||
import styles from './components/styles.css';
|
||||
import translations from 'coral-admin/src/translations';
|
||||
import I18n from 'coral-framework/modules/i18n/i18n';
|
||||
|
||||
import {modQueueQuery, getQueueCounts} from '../../graphql/queries';
|
||||
import {banUser, setCommentStatus} from '../../graphql/mutations';
|
||||
@@ -31,6 +33,8 @@ import ModerationHeader from './components/ModerationHeader';
|
||||
import NotFoundAsset from './components/NotFoundAsset';
|
||||
import ModerationKeysModal from '../../components/ModerationKeysModal';
|
||||
|
||||
const lang = new I18n(translations);
|
||||
|
||||
class ModerationContainer extends Component {
|
||||
state = {
|
||||
selectedIndex: 0,
|
||||
@@ -208,7 +212,15 @@ class ModerationContainer extends Component {
|
||||
open={moderation.suspendUserDialog.show}
|
||||
username={moderation.suspendUserDialog.username}
|
||||
onCancel={props.hideSuspendUserDialog}
|
||||
onPerform={() => toast('User admin has been suspended for 24 hours. this suspension will automatically end after 24 hours.', {type: 'success'}) && props.hideSuspendUserDialog()}
|
||||
onPerform={(result) => {
|
||||
toast(
|
||||
lang.t('suspenduser.notify_suspend_until',
|
||||
moderation.suspendUserDialog.username,
|
||||
lang.timeago(result.until)),
|
||||
{type: 'success'}
|
||||
);
|
||||
props.hideSuspendUserDialog();
|
||||
}}
|
||||
/>
|
||||
<ModerationKeysModal
|
||||
hideShortcutsNote={props.hideShortcutsNote}
|
||||
|
||||
@@ -6,6 +6,7 @@ import styles from './SuspendUserDialog.css';
|
||||
import Button from 'coral-ui/components/Button';
|
||||
|
||||
import I18n from 'coral-framework/modules/i18n/i18n';
|
||||
import {dateAdd} from 'coral-framework/utils';
|
||||
import translations from '../../../translations';
|
||||
const lang = new I18n(translations);
|
||||
|
||||
@@ -39,7 +40,7 @@ class SuspendUserDialog extends React.Component {
|
||||
|
||||
handlePerform = () => {
|
||||
this.props.onPerform({
|
||||
duration: this.state.duration,
|
||||
until: dateAdd(new Date(), 'hour', this.state.duration),
|
||||
message: this.state.message,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -161,7 +161,8 @@
|
||||
"days": "{0} days",
|
||||
"suspend_user": "Suspend User",
|
||||
"cancel": "Cancel",
|
||||
"error_email_message_empty": "You must specify an E-Mail message."
|
||||
"error_email_message_empty": "You must specify an E-Mail message.",
|
||||
"notify_suspend_until": "User {0} has been temporarily suspended. This suspension will automatically end {1}."
|
||||
},
|
||||
"dashboard": {
|
||||
"next-update": "{0} minutes until next update.",
|
||||
|
||||
@@ -61,3 +61,33 @@ export function separateDataAndRoot(
|
||||
root,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Taken from: http://stackoverflow.com/questions/1197928/how-to-add-30-minutes-to-a-javascript-date-object.
|
||||
* Adds time to a date. Modelled after MySQL DATE_ADD function.
|
||||
* Example: dateAdd(new Date(), 'minute', 30) //returns 30 minutes from now.
|
||||
*
|
||||
* @param date Date to start with
|
||||
* @param interval One of: year, quarter, month, week, day, hour, minute, second
|
||||
* @param units Number of units of the given interval to add.
|
||||
*/
|
||||
export function dateAdd(date, interval, units) {
|
||||
let ret = new Date(date); // don't change original date
|
||||
const checkRollover = () => {
|
||||
if (ret.getDate() !== date.getDate()) {
|
||||
ret.setDate(0);
|
||||
}
|
||||
};
|
||||
switch(interval.toLowerCase()) {
|
||||
case 'year' : ret.setFullYear(ret.getFullYear() + units); checkRollover(); break;
|
||||
case 'quarter': ret.setMonth(ret.getMonth() + 3 * units); checkRollover(); break;
|
||||
case 'month' : ret.setMonth(ret.getMonth() + units); checkRollover(); break;
|
||||
case 'week' : ret.setDate(ret.getDate() + 7 * units); break;
|
||||
case 'day' : ret.setDate(ret.getDate() + units); break;
|
||||
case 'hour' : ret.setTime(ret.getTime() + units * 3600000); break;
|
||||
case 'minute' : ret.setTime(ret.getTime() + units * 60000); break;
|
||||
case 'second' : ret.setTime(ret.getTime() + units * 1000); break;
|
||||
default : ret = undefined; break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user