Update mod tools user info

This commit is contained in:
Bill 2021-10-20 02:45:04 -04:00
parent 59dfb8d9b4
commit fe6f27737c
9 changed files with 83 additions and 103 deletions

View File

@ -19,9 +19,5 @@
color: $black; color: $black;
background: rgba(0, 0, 0, .05); background: rgba(0, 0, 0, .05);
} }
td {
padding: 0px 5px;
}
} }
} }

View File

@ -1,19 +1,17 @@
import { FriendlyTime, ModeratorUserInfoData, ModtoolRequestUserInfoComposer, ModtoolUserInfoEvent } from '@nitrots/nitro-renderer'; import { FriendlyTime, ModeratorUserInfoData, ModtoolRequestUserInfoComposer, ModtoolUserInfoEvent } from '@nitrots/nitro-renderer';
import { FC, useCallback, useEffect, useState } from 'react'; import { FC, useCallback, useEffect, useMemo, useState } from 'react';
import { LocalizeText } from '../../../../../api';
import { ModToolsOpenUserChatlogEvent } from '../../../../../events/mod-tools/ModToolsOpenUserChatlogEvent'; import { ModToolsOpenUserChatlogEvent } from '../../../../../events/mod-tools/ModToolsOpenUserChatlogEvent';
import { CreateMessageHook, dispatchUiEvent, SendMessageHook } from '../../../../../hooks'; import { CreateMessageHook, dispatchUiEvent, SendMessageHook } from '../../../../../hooks';
import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../../../../layout'; import { NitroCardContentView, NitroCardHeaderView, NitroCardView, NitroLayoutButton, NitroLayoutGrid, NitroLayoutGridColumn } from '../../../../../layout';
import { AvatarImageView } from '../../../../shared/avatar-image/AvatarImageView';
import { IUserInfo } from '../../../utils/IUserInfo';
import { ModToolsUserModActionView } from '../user-mod-action/ModToolsUserModActionView'; import { ModToolsUserModActionView } from '../user-mod-action/ModToolsUserModActionView';
import { ModToolsUserRoomVisitsView } from '../user-room-visits/ModToolsUserRoomVisitsView'; import { ModToolsUserRoomVisitsView } from '../user-room-visits/ModToolsUserRoomVisitsView';
import { ModToolsSendUserMessageView } from '../user-sendmessage/ModToolsSendUserMessageView'; import { ModToolsSendUserMessageView } from '../user-sendmessage/ModToolsSendUserMessageView';
import { ModToolsUserViewProps } from './ModToolsUserView.types'; import { ModToolsUserViewProps } from './ModToolsUserView.types';
export const ModToolsUserView: FC<ModToolsUserViewProps> = props => export const ModToolsUserView: FC<ModToolsUserViewProps> = props =>
{ {
const { onCloseClick = null, userId = null, simple = true } = props; const { onCloseClick = null, userId = null } = props;
const [ userInfo, setUserInfo ] = useState<ModeratorUserInfoData>(null); const [ userInfo, setUserInfo ] = useState<ModeratorUserInfoData>(null);
const [ sendMessageVisible, setSendMessageVisible ] = useState(false); const [ sendMessageVisible, setSendMessageVisible ] = useState(false);
const [ modActionVisible, setModActionVisible ] = useState(false); const [ modActionVisible, setModActionVisible ] = useState(false);
@ -24,7 +22,6 @@ export const ModToolsUserView: FC<ModToolsUserViewProps> = props =>
SendMessageHook(new ModtoolRequestUserInfoComposer(userId)); SendMessageHook(new ModtoolRequestUserInfoComposer(userId));
}, [ userId ]); }, [ userId ]);
const onModtoolUserInfoEvent = useCallback((event: ModtoolUserInfoEvent) => const onModtoolUserInfoEvent = useCallback((event: ModtoolUserInfoEvent) =>
{ {
const parser = event.getParser(); const parser = event.getParser();
@ -36,137 +33,121 @@ export const ModToolsUserView: FC<ModToolsUserViewProps> = props =>
CreateMessageHook(ModtoolUserInfoEvent, onModtoolUserInfoEvent); CreateMessageHook(ModtoolUserInfoEvent, onModtoolUserInfoEvent);
const OnlineIcon = useCallback(() => const userProperties = useMemo(() =>
{ {
if(userInfo.online) return (<i className="icon icon-pf-online ml-1" />); if(!userInfo) return null;
else return (<i className="icon icon-pf-offline ml-1" />);
}, [userInfo]);
const userProperties = useCallback(() => return [
{ {
let properties: IUserInfo[] = []; localeKey: 'modtools.userinfo.userName',
value: userInfo.userName,
if(!userInfo) return properties; showOnline: true
properties = [
{
nameKey: 'name',
nameKeyFallback: 'Name',
value: userInfo.userName
}, },
{ {
nameKey: 'cfhs', localeKey: 'modtools.userinfo.cfhCount',
nameKeyFallback: 'CFHs',
value: userInfo.cfhCount.toString() value: userInfo.cfhCount.toString()
}, },
{ {
nameKey: 'abusive_cfhs', localeKey: 'modtools.userinfo.abusiveCfhCount',
nameKeyFallback: 'Abusive CFHs',
value: userInfo.abusiveCfhCount.toString() value: userInfo.abusiveCfhCount.toString()
}, },
{ {
nameKey: 'cautions', localeKey: 'modtools.userinfo.cautionCount',
nameKeyFallback: 'Cautions',
value: userInfo.cautionCount.toString() value: userInfo.cautionCount.toString()
}, },
{ {
nameKey: 'bans', localeKey: 'modtools.userinfo.banCount',
nameKeyFallback: 'Bans',
value: userInfo.banCount.toString() value: userInfo.banCount.toString()
}, },
{ {
nameKey: 'last_sanction', localeKey: 'modtools.userinfo.lastSanctionTime',
nameKeyFallback: 'Last sanction',
value: userInfo.lastSanctionTime value: userInfo.lastSanctionTime
}, },
{ {
nameKey: 'trade_locks', localeKey: 'modtools.userinfo.tradingLockCount',
nameKeyFallback: 'Trade locks',
value: userInfo.tradingLockCount.toString() value: userInfo.tradingLockCount.toString()
}, },
{ {
nameKey: 'lock_expires', localeKey: 'modtools.userinfo.tradingExpiryDate',
nameKeyFallback: 'Lock expires',
value: userInfo.tradingExpiryDate value: userInfo.tradingExpiryDate
}, },
{ {
nameKey: 'last_login', localeKey: 'modtools.userinfo.minutesSinceLastLogin',
nameKeyFallback: 'Last login',
value: FriendlyTime.format(userInfo.minutesSinceLastLogin * 60, '.ago', 2) value: FriendlyTime.format(userInfo.minutesSinceLastLogin * 60, '.ago', 2)
}, },
{ {
nameKey: 'purchase', localeKey: 'modtools.userinfo.lastPurchaseDate',
nameKeyFallback: 'Purchases',
value: userInfo.lastPurchaseDate value: userInfo.lastPurchaseDate
}, },
{ {
nameKey: 'email', localeKey: 'modtools.userinfo.primaryEmailAddress',
nameKeyFallback: 'Email',
value: userInfo.primaryEmailAddress value: userInfo.primaryEmailAddress
}, },
{ {
nameKey: 'acc_bans', localeKey: 'modtools.userinfo.identityRelatedBanCount',
nameKeyFallback: 'Banned Accs.',
value: userInfo.identityRelatedBanCount.toString() value: userInfo.identityRelatedBanCount.toString()
}, },
{ {
nameKey: 'registered', localeKey: 'modtools.userinfo.registrationAgeInMinutes',
nameKeyFallback: 'Registered',
value: FriendlyTime.format(userInfo.registrationAgeInMinutes * 60, '.ago', 2) value: FriendlyTime.format(userInfo.registrationAgeInMinutes * 60, '.ago', 2)
}, },
{ {
nameKey: 'rank', localeKey: 'modtools.userinfo.userClassification',
nameKeyFallback: 'Rank',
value: userInfo.userClassification value: userInfo.userClassification
} }
]; ];
return properties;
}, [ userInfo ]); }, [ userInfo ]);
if(!userInfo) return null;
return ( return (
<> <>
<NitroCardView className="nitro-mod-tools-user" simple={true}> <NitroCardView className="nitro-mod-tools-user" simple={true}>
<NitroCardHeaderView headerText={'User Info: ' + (userInfo ? userInfo.userName : '')} onCloseClick={() => onCloseClick()} /> <NitroCardHeaderView headerText={ LocalizeText('modtools.userinfo.title', [ 'username' ], [ userInfo.userName ]) } onCloseClick={ onCloseClick } />
<NitroCardContentView className="text-black"> <NitroCardContentView className="text-black">
{userInfo && <NitroLayoutGrid>
<div className="row"> <NitroLayoutGridColumn size={ 8 }>
{!simple && <table className="table table-striped table-sm table-text-small text-black m-0">
<div className="col-sm-3 px-0 d-flex align-items-center">
<AvatarImageView figure={userInfo.figure} direction={2} />
</div>
}
<div className="col-7">
<table className="d-flex flex-column table table-striped table-sm table-text-small text-black">
<tbody> <tbody>
{userProperties().map(property => { userProperties.map(property =>
{ {
return ( return (
<tr key={property.nameKey}> <tr>
<th scope="row">{property.nameKeyFallback}</th> <th scope="row">{ LocalizeText(property.localeKey) }</th>
<td className={'' + (property.nameKey === 'name' ? 'username' : '')}> <td>
{property.value} {(property.nameKey === 'name') && <OnlineIcon/>} { property.value }
{ property.showOnline && <i className={ `icon icon-pf-${ userInfo.online ? 'online' : 'offline' } ms-2` } /> }
</td> </td>
</tr> </tr>
) );
}) } }) }
</tbody> </tbody>
</table> </table>
</div> </NitroLayoutGridColumn>
<div className="col-5"> <NitroLayoutGridColumn size={ 4 }>
<button className="btn btn-sm btn-primary" onClick={() => dispatchUiEvent(new ModToolsOpenUserChatlogEvent(userId))}>Room Chat</button> <NitroLayoutButton variant="primary" size="sm" onClick={ event => dispatchUiEvent(new ModToolsOpenUserChatlogEvent(userId)) }>
<button className="btn btn-sm btn-primary mt-2" onClick={ () => setSendMessageVisible(!sendMessageVisible)}>Send Message</button> Room Chat
<button className="btn btn-sm btn-primary mt-2" onClick={ () => setRoomVisitsVisible(!roomVisitsVisible)}>Room Visits</button> </NitroLayoutButton>
<button className="btn btn-sm btn-primary mt-2" onClick={ () => setModActionVisible(!modActionVisible)}>Mod Action</button> <NitroLayoutButton variant="primary" size="sm" onClick={ event => setSendMessageVisible(!sendMessageVisible) }>
</div> Send Message
</div> </NitroLayoutButton>
} <NitroLayoutButton variant="primary" size="sm" onClick={ event => setRoomVisitsVisible(!roomVisitsVisible) }>
Room Visits
</NitroLayoutButton>
<NitroLayoutButton variant="primary" size="sm" onClick={ event => setModActionVisible(!modActionVisible) }>
Mod Action
</NitroLayoutButton>
</NitroLayoutGridColumn>
</NitroLayoutGrid>
</NitroCardContentView> </NitroCardContentView>
</NitroCardView> </NitroCardView>
{(sendMessageVisible && userInfo) && <ModToolsSendUserMessageView user={{ userId: userId, username: userInfo.userName }} onCloseClick={ () => setSendMessageVisible(false)}/>} { sendMessageVisible &&
{(userInfo && modActionVisible) && <ModToolsUserModActionView user={{ userId: userId, username: userInfo.userName }} onCloseClick={() => setModActionVisible(false)}/>} <ModToolsSendUserMessageView user={ { userId: userId, username: userInfo.userName } } onCloseClick={ event => setSendMessageVisible(false) } /> }
{(userInfo && roomVisitsVisible) && <ModToolsUserRoomVisitsView userId={userId} onCloseClick={ () => setRoomVisitsVisible(false)}/>} { modActionVisible &&
<ModToolsUserModActionView user={ { userId: userId, username: userInfo.userName } } onCloseClick={ event => setModActionVisible(false) } /> }
{ roomVisitsVisible &&
<ModToolsUserRoomVisitsView userId={ userId } onCloseClick={ event => setRoomVisitsVisible(false) } /> }
</> </>
); );
} }

View File

@ -2,5 +2,4 @@ export interface ModToolsUserViewProps
{ {
userId: number; userId: number;
onCloseClick: () => void; onCloseClick: () => void;
simple?: boolean;
} }

View File

@ -8,7 +8,7 @@ export const ModToolsUserModActionView: FC<ModToolsUserModActionViewProps> = pro
return ( return (
<NitroCardView className="nitro-mod-tools-user-action" simple={true}> <NitroCardView className="nitro-mod-tools-user-action" simple={true}>
<NitroCardHeaderView headerText={'Mod Action'} onCloseClick={() => onCloseClick()} /> <NitroCardHeaderView headerText={'Mod Action'} onCloseClick={ onCloseClick } />
<NitroCardContentView className="text-black"> <NitroCardContentView className="text-black">
{user && <div></div>} {user && <div></div>}
</NitroCardContentView> </NitroCardContentView>

View File

@ -1,7 +1,8 @@
import { MouseEvent } from 'react';
import { ISelectedUser } from '../../../utils/ISelectedUser'; import { ISelectedUser } from '../../../utils/ISelectedUser';
export interface ModToolsUserModActionViewProps export interface ModToolsUserModActionViewProps
{ {
user: ISelectedUser; user: ISelectedUser;
onCloseClick: () => void; onCloseClick: (event: MouseEvent) => void;
} }

View File

@ -39,7 +39,7 @@ export const ModToolsUserRoomVisitsView: FC<ModToolsUserRoomVisitsViewProps> = p
return ( return (
<NitroCardView className="nitro-mod-tools-user-visits" simple={true}> <NitroCardView className="nitro-mod-tools-user-visits" simple={true}>
<NitroCardHeaderView headerText={'User Visits'} onCloseClick={() => onCloseClick()} /> <NitroCardHeaderView headerText={'User Visits'} onCloseClick={ onCloseClick } />
<NitroCardContentView className="text-black"> <NitroCardContentView className="text-black">
{roomVisitData && {roomVisitData &&
<div className="row h-100 w-100 user-visits"> <div className="row h-100 w-100 user-visits">

View File

@ -1,5 +1,7 @@
import { MouseEvent } from 'react';
export interface ModToolsUserRoomVisitsViewProps export interface ModToolsUserRoomVisitsViewProps
{ {
userId: number; userId: number;
onCloseClick: () => void; onCloseClick: (event: MouseEvent) => void;
} }

View File

@ -1,7 +1,8 @@
import { MouseEvent } from 'react';
import { ISelectedUser } from '../../../utils/ISelectedUser'; import { ISelectedUser } from '../../../utils/ISelectedUser';
export interface ModToolsSendUserMessageViewProps export interface ModToolsSendUserMessageViewProps
{ {
user: ISelectedUser; user: ISelectedUser;
onCloseClick: () => void; onCloseClick: (event: MouseEvent) => void;
} }

View File

@ -19,7 +19,7 @@ export const ModToolsSendUserMessageView: FC<ModToolsSendUserMessageViewProps> =
return ( return (
<NitroCardView className="nitro-mod-tools-user-message" simple={true}> <NitroCardView className="nitro-mod-tools-user-message" simple={true}>
<NitroCardHeaderView headerText={'Send Message'} onCloseClick={() => onCloseClick()} /> <NitroCardHeaderView headerText={'Send Message'} onCloseClick={ onCloseClick } />
<NitroCardContentView className="text-black"> <NitroCardContentView className="text-black">
{user && <> {user && <>
<div>Message To: {user.username}</div> <div>Message To: {user.username}</div>