Update the chat moderation modal with slightly better layout. Closes #2073
This commit is contained in:
parent
65b6feb40d
commit
a931fe0ddf
@ -4,13 +4,14 @@ import {
|
|||||||
EyeInvisibleOutlined,
|
EyeInvisibleOutlined,
|
||||||
SmallDashOutlined,
|
SmallDashOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { Dropdown, Menu, MenuProps, Space, Modal, message } from 'antd';
|
import { Dropdown, Menu, MenuProps, Space, message, Modal as AntModal } from 'antd';
|
||||||
import { FC, useState } from 'react';
|
import { FC, useState } from 'react';
|
||||||
|
import { Modal } from '../../ui/Modal/Modal';
|
||||||
import { ChatModerationDetailsModal } from '../ChatModerationDetailsModal/ChatModerationDetailsModal';
|
import { ChatModerationDetailsModal } from '../ChatModerationDetailsModal/ChatModerationDetailsModal';
|
||||||
import styles from './ChatModerationActionMenu.module.scss';
|
import styles from './ChatModerationActionMenu.module.scss';
|
||||||
import ChatModeration from '../../../services/moderation-service';
|
import ChatModeration from '../../../services/moderation-service';
|
||||||
|
|
||||||
const { confirm } = Modal;
|
const { confirm } = AntModal;
|
||||||
|
|
||||||
export type ChatModerationActionMenuProps = {
|
export type ChatModerationActionMenuProps = {
|
||||||
accessToken: string;
|
accessToken: string;
|
||||||
@ -119,11 +120,9 @@ export const ChatModerationActionMenu: FC<ChatModerationActionMenuProps> = ({
|
|||||||
</button>
|
</button>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
<Modal
|
<Modal
|
||||||
|
title={userDisplayName}
|
||||||
visible={showUserDetailsModal}
|
visible={showUserDetailsModal}
|
||||||
okText="Ban User"
|
handleCancel={() => {
|
||||||
okButtonProps={{ danger: true }}
|
|
||||||
onOk={handleBanUser}
|
|
||||||
onCancel={() => {
|
|
||||||
setShowUserDetailsModal(false);
|
setShowUserDetailsModal(false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -10,8 +10,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.colorBlock {
|
.colorBlock {
|
||||||
width: 50%;
|
display: inline-block;
|
||||||
|
width: 60px;
|
||||||
height: 20px;
|
height: 20px;
|
||||||
border: 1px solid #000;
|
border: 1px solid #000;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.displayName {
|
||||||
|
font-weight: bold;
|
||||||
|
padding-right: 10px;
|
||||||
|
font-size: 1.2rem;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
import { Button, Col, Row, Spin } from 'antd';
|
import { Button, Col, Collapse, Row, Spin, Table, Tag } from 'antd';
|
||||||
import { FC, useEffect, useState } from 'react';
|
import { FC, useEffect, useState } from 'react';
|
||||||
|
import format from 'date-fns/format';
|
||||||
|
import { DeleteOutlined } from '@ant-design/icons';
|
||||||
|
import { ColumnsType } from 'antd/lib/table';
|
||||||
import ChatModeration from '../../../services/moderation-service';
|
import ChatModeration from '../../../services/moderation-service';
|
||||||
import styles from './ChatModerationDetailsModal.module.scss';
|
import styles from './ChatModerationDetailsModal.module.scss';
|
||||||
|
import { formatUAstring } from '../../../utils/format';
|
||||||
|
|
||||||
|
const { Panel } = Collapse;
|
||||||
|
|
||||||
export type ChatModerationDetailsModalProps = {
|
export type ChatModerationDetailsModalProps = {
|
||||||
userId: string;
|
userId: string;
|
||||||
@ -54,48 +60,25 @@ const ValueRow = ({ label, value }: { label: string; value: string }) => (
|
|||||||
</Row>
|
</Row>
|
||||||
);
|
);
|
||||||
|
|
||||||
const ChatMessageRow = ({
|
|
||||||
id,
|
|
||||||
body,
|
|
||||||
accessToken,
|
|
||||||
}: {
|
|
||||||
id: string;
|
|
||||||
body: string;
|
|
||||||
accessToken: string;
|
|
||||||
}) => (
|
|
||||||
<Row justify="space-around" align="middle">
|
|
||||||
<Col span={18}>{body}</Col>
|
|
||||||
<Col>
|
|
||||||
<Button onClick={() => removeMessage(id, accessToken)}>X</Button>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
);
|
|
||||||
|
|
||||||
const ConnectedClient = ({ client }: { client: Client }) => {
|
const ConnectedClient = ({ client }: { client: Client }) => {
|
||||||
const { messageCount, userAgent, connectedAt, geo } = client;
|
const { messageCount, connectedAt, geo } = client;
|
||||||
|
const connectedAtDate = format(new Date(connectedAt), 'PP pp');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<ValueRow label="Messages Sent" value={`${messageCount}`} />
|
<ValueRow label="Messages Sent" value={`${messageCount}`} />
|
||||||
<ValueRow label="Geo" value={geo} />
|
{geo !== 'N/A' && <ValueRow label="Geo" value={geo} />}
|
||||||
<ValueRow label="Connected At" value={connectedAt.toString()} />
|
<ValueRow label="Connected At" value={connectedAtDate} />
|
||||||
<ValueRow label="User Agent" value={userAgent} />
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line react/prop-types
|
|
||||||
const UserColorBlock = ({ color }) => {
|
const UserColorBlock = ({ color }) => {
|
||||||
const bg = `var(--theme-color-users-${color})`;
|
const bg = `var(--theme-color-users-${color})`;
|
||||||
return (
|
return (
|
||||||
<Row justify="space-around" align="middle">
|
<div className={styles.colorBlock} style={{ backgroundColor: bg }}>
|
||||||
<Col span={12}>Color</Col>
|
Color {color}
|
||||||
<Col span={12}>
|
</div>
|
||||||
<div className={styles.colorBlock} style={{ backgroundColor: bg }}>
|
|
||||||
{color}
|
|
||||||
</div>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -108,7 +91,9 @@ export const ChatModerationDetailsModal: FC<ChatModerationDetailsModalProps> = (
|
|||||||
|
|
||||||
const getDetails = async () => {
|
const getDetails = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await (await fetch(`/api/moderation/chat/user/${userId}`)).json();
|
const response = await (
|
||||||
|
await fetch(`/api/moderation/chat/user/${userId}?accessToken=${accessToken}`)
|
||||||
|
).json();
|
||||||
setUserDetails(response);
|
setUserDetails(response);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -125,57 +110,69 @@ export const ChatModerationDetailsModal: FC<ChatModerationDetailsModalProps> = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { user, connectedClients, messages } = userDetails;
|
const { user, connectedClients, messages } = userDetails;
|
||||||
const { displayName, displayColor, createdAt, previousNames, scopes, isBot, authenticated } =
|
const { displayColor, createdAt, previousNames, scopes, isBot, authenticated } = user;
|
||||||
user;
|
|
||||||
|
const totalMessagesSent = connectedClients.reduce((acc, client) => acc + client.messageCount, 0);
|
||||||
|
const createdAtDate = format(new Date(createdAt), 'PP pp');
|
||||||
|
|
||||||
|
const chatMessageColumns: ColumnsType<Message> = [
|
||||||
|
{
|
||||||
|
title: 'Message',
|
||||||
|
dataIndex: 'body',
|
||||||
|
key: 'body',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Sent At',
|
||||||
|
dataIndex: 'timestamp',
|
||||||
|
key: 'timestamp',
|
||||||
|
render: timestamp => format(new Date(timestamp), 'PP pp'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Delete',
|
||||||
|
key: 'delete',
|
||||||
|
render: (text, record) => (
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
ghost
|
||||||
|
icon={<DeleteOutlined />}
|
||||||
|
onClick={() => removeMessage(record.id, accessToken)}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.modalContainer}>
|
<Spin spinning={loading}>
|
||||||
<Spin spinning={loading}>
|
<UserColorBlock color={displayColor} />
|
||||||
<h1>{displayName}</h1>
|
{scopes.map(scope => (
|
||||||
<Row justify="space-around" align="middle">
|
<Tag key={scope}>{scope}</Tag>
|
||||||
{scopes.map(scope => (
|
))}
|
||||||
<Col>{scope}</Col>
|
{authenticated && <Tag>Authenticated</Tag>}
|
||||||
))}
|
{isBot && <Tag>Bot</Tag>}
|
||||||
{authenticated && <Col>Authenticated</Col>}
|
<ValueRow label="Messages Sent Across Clients" value={totalMessagesSent.toString()} />
|
||||||
{isBot && <Col>Bot</Col>}
|
<ValueRow label="User Created" value={createdAtDate} />
|
||||||
</Row>
|
<ValueRow label="Known As" value={previousNames.join(',')} />
|
||||||
|
<Collapse accordion>
|
||||||
<UserColorBlock color={displayColor} />
|
<Panel header="Currently Connected Clients" key="connected-clients">
|
||||||
|
<Collapse accordion>
|
||||||
<ValueRow label="User Created" value={createdAt.toString()} />
|
|
||||||
<ValueRow label="Previous Names" value={previousNames.join(',')} />
|
|
||||||
|
|
||||||
<hr />
|
|
||||||
|
|
||||||
<h2>Currently Connected</h2>
|
|
||||||
{connectedClients.length > 0 && (
|
|
||||||
<Row gutter={[15, 15]} wrap>
|
|
||||||
{connectedClients.map(client => (
|
{connectedClients.map(client => (
|
||||||
<Col flex="auto">
|
<Panel header={formatUAstring(client.userAgent)} key={client.userAgent}>
|
||||||
<ConnectedClient client={client} />
|
<ConnectedClient client={client} />
|
||||||
</Col>
|
</Panel>
|
||||||
))}
|
))}
|
||||||
</Row>
|
</Collapse>
|
||||||
)}
|
</Panel>
|
||||||
|
<Collapse accordion>
|
||||||
<hr />
|
<Panel header="Recent Chat Messages" key="chat-messages">
|
||||||
{messages.length > 0 && (
|
<Table
|
||||||
<div>
|
size="small"
|
||||||
<h1>Recent Chat Messages</h1>
|
pagination={null}
|
||||||
|
columns={chatMessageColumns}
|
||||||
<div className={styles.chatHistory}>
|
dataSource={messages}
|
||||||
{messages.map(message => (
|
/>
|
||||||
<ChatMessageRow
|
</Panel>
|
||||||
key={message.id}
|
</Collapse>
|
||||||
id={message.id}
|
</Collapse>
|
||||||
body={message.body}
|
</Spin>
|
||||||
accessToken={accessToken}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</Spin>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user