import React from 'react'; import cn from 'classnames'; import PropTypes from 'prop-types'; import capitalize from 'lodash/capitalize'; import styles from './UserDetail.css'; import UserHistory from './UserHistory'; import { Slot } from 'coral-framework/components'; import UserDetailCommentList from '../components/UserDetailCommentList'; import { getReliability, isSuspended, isBanned, } from 'coral-framework/utils/user'; import ButtonCopyToClipboard from './ButtonCopyToClipboard'; import ClickOutside from 'coral-framework/components/ClickOutside'; import { Icon, Drawer, Spinner, TabBar, Tab, TabContent, TabPane, } from 'coral-ui'; import ActionsMenu from 'coral-admin/src/components/ActionsMenu'; import ActionsMenuItem from 'coral-admin/src/components/ActionsMenuItem'; import UserInfoTooltip from './UserInfoTooltip'; import t from 'coral-framework/services/i18n'; class UserDetail extends React.Component { changeTab = tab => { this.props.changeTab(tab); }; showSuspenUserDialog = () => this.props.showSuspendUserDialog({ userId: this.props.root.user.id, username: this.props.root.user.username, }); showBanUserDialog = () => this.props.showBanUserDialog({ userId: this.props.root.user.id, username: this.props.root.user.username, }); renderLoading() { return ( ); } renderError() { return (
{this.props.data.error.message}
); } getActionMenuLabel() { const { root: { user } } = this.props; if (isBanned(user)) { return 'Banned'; } else if (isSuspended(user)) { return 'Suspended'; } return ''; } renderLoaded() { const { root, root: { me, user, totalComments, rejectedComments }, activeTab, selectedCommentIds, toggleSelect, hideUserDetail, viewUserDetail, loadMore, toggleSelectAll, unbanUser, unsuspendUser, modal, acceptComment, rejectComment, bulkAccept, bulkReject, } = this.props; console.log(rejectedComments, totalComments); // if totalComments is 0, you're dividing by zero let rejectedPercent = rejectedComments / totalComments * 100; if (rejectedPercent === Infinity || isNaN(rejectedPercent)) { rejectedPercent = 0; } const banned = isBanned(user); const suspended = isSuspended(user); const slotPassthrough = { root, user, }; return (

{user.username}

{user.id && ( {suspended ? ( unsuspendUser({ id: user.id })}> {t('user_detail.remove_suspension')} ) : ( {t('user_detail.suspend')} )} {banned ? ( unbanUser({ id: user.id })}> {t('user_detail.remove_ban')} ) : ( {t('user_detail.ban')} )} )} {(banned || suspended) && ( )}
  • {t('user_detail.member_since')}: {new Date(user.created_at).toLocaleString()}
  • {user.profiles.map(({ id }) => (
  • {t('user_detail.email')}: {id}{' '}
  • ))}
  • {t('user_detail.total_comments')} {totalComments}
  • {t('user_detail.reject_rate')} {rejectedPercent.toFixed(1)}%
  • {t('user_detail.reports')} {capitalize(getReliability(user.reliable.flagger))}

{t('user_detail.all')} {t('user_detail.rejected')} {t('user_detail.user_history')}
); } render() { if (this.props.data.error) { return this.renderError(); } if (this.props.loading) { return this.renderLoading(); } return this.renderLoaded(); } } UserDetail.propTypes = { userId: PropTypes.string.isRequired, hideUserDetail: PropTypes.func.isRequired, root: PropTypes.object.isRequired, acceptComment: PropTypes.func.isRequired, rejectComment: PropTypes.func.isRequired, changeTab: PropTypes.func.isRequired, toggleSelect: PropTypes.func.isRequired, bulkAccept: PropTypes.func.isRequired, bulkReject: PropTypes.func.isRequired, toggleSelectAll: PropTypes.func.isRequired, loading: PropTypes.bool.isRequired, data: PropTypes.object, activeTab: PropTypes.string.isRequired, selectedCommentIds: PropTypes.array.isRequired, viewUserDetail: PropTypes.any.isRequired, loadMore: PropTypes.any.isRequired, showSuspendUserDialog: PropTypes.func, showBanUserDialog: PropTypes.func, unbanUser: PropTypes.func.isRequired, unsuspendUser: PropTypes.func.isRequired, modal: PropTypes.bool, }; export default UserDetail;