mirror of
https://github.com/wassname/talk.git
synced 2026-07-19 11:28:50 +08:00
updated - getUserStatusArray
This commit is contained in:
@@ -11,7 +11,6 @@ import {
|
||||
isSuspended,
|
||||
isUsernameRejected,
|
||||
isUsernameChanged,
|
||||
getActiveStatuses,
|
||||
isBanned,
|
||||
getKarma,
|
||||
} from 'coral-framework/utils/user';
|
||||
@@ -32,7 +31,6 @@ import ActionsMenuItem from 'coral-admin/src/components/ActionsMenuItem';
|
||||
import UserInfoTooltip from './UserInfoTooltip';
|
||||
import KarmaTooltip from './KarmaTooltip';
|
||||
import t from 'coral-framework/services/i18n';
|
||||
import flatten from 'lodash/flatten';
|
||||
|
||||
class UserDetail extends React.Component {
|
||||
changeTab = tab => {
|
||||
@@ -78,14 +76,29 @@ class UserDetail extends React.Component {
|
||||
}
|
||||
|
||||
getActionMenuLabel(user) {
|
||||
const activeStatuses = getActiveStatuses(user);
|
||||
const count = activeStatuses.length;
|
||||
/**
|
||||
* getUserStatusArray
|
||||
* returns an array of active status(es)
|
||||
* i.e if suspension is active, it returns suspension
|
||||
*/
|
||||
|
||||
const getUserStatusArray = user => {
|
||||
const statusMap = {
|
||||
suspended: isSuspended,
|
||||
banned: isBanned,
|
||||
usernameRejected: isUsernameRejected,
|
||||
usernameChanged: isUsernameChanged,
|
||||
};
|
||||
return Object.keys(statusMap).filter(k => statusMap[k](user));
|
||||
};
|
||||
|
||||
const userStatusArr = getUserStatusArray(user);
|
||||
const count = userStatusArr.length;
|
||||
|
||||
if (count > 1) {
|
||||
return `Status(${count})`;
|
||||
return `Status (${count})`;
|
||||
} else {
|
||||
const activeStatus = flatten(activeStatuses)[0];
|
||||
|
||||
const activeStatus = userStatusArr[0];
|
||||
switch (activeStatus) {
|
||||
case 'suspended':
|
||||
return t('user_detail.suspended');
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import get from 'lodash/get';
|
||||
import mapValues from 'lodash/mapValues';
|
||||
import toPairs from 'lodash/toPairs';
|
||||
import moment from 'moment';
|
||||
|
||||
/**
|
||||
@@ -55,23 +53,6 @@ export const isUsernameChanged = user => {
|
||||
return get(user, 'state.status.username.status') === 'CHANGED';
|
||||
};
|
||||
|
||||
/**
|
||||
* getActiveStatuses
|
||||
* returns an array of active status(es)
|
||||
* i.e if suspension is active, it returns suspension
|
||||
*/
|
||||
|
||||
export const getActiveStatuses = user => {
|
||||
const statusMap = {
|
||||
suspended: isSuspended,
|
||||
banned: isBanned,
|
||||
usernameRejected: isUsernameRejected,
|
||||
usernameChanged: isUsernameChanged,
|
||||
};
|
||||
|
||||
return toPairs(mapValues(statusMap, fn => fn(user))).filter(x => x[1]);
|
||||
};
|
||||
|
||||
/**
|
||||
* canUsernameBeUpdated
|
||||
* retrieves boolean whether a username can be updated or not
|
||||
|
||||
Reference in New Issue
Block a user