import { Button, Col, Row, Spin } from 'antd';
import { useEffect, useState } from 'react';
import ChatModeration from '../../../services/moderation-service';
import s from './ChatModerationDetailsModal.module.scss';
interface Props {
userId: string;
accessToken: string;
}
export interface UserDetails {
user: User;
connectedClients: Client[];
messages: Message[];
}
export interface Client {
messageCount: number;
userAgent: string;
connectedAt: Date;
geo: string;
}
export interface Message {
id: string;
timestamp: Date;
user: null;
body: string;
}
export interface User {
id: string;
displayName: string;
displayColor: number;
createdAt: Date;
previousNames: string[];
scopes: string[];
isBot: boolean;
authenticated: boolean;
}
const removeMessage = async (messageId: string, accessToken: string) => {
try {
ChatModeration.removeMessage(messageId, accessToken);
} catch (e) {
console.error(e);
}
};
const ValueRow = ({ label, value }: { label: string; value: string }) => (
{label}
{value}
);
const ChatMessageRow = ({
id,
body,
accessToken,
}: {
id: string;
body: string;
accessToken: string;
}) => (
{body}
);
const ConnectedClient = ({ client }: { client: Client }) => {
const { messageCount, userAgent, connectedAt, geo } = client;
return (
);
};
// eslint-disable-next-line react/prop-types
const UserColorBlock = ({ color }) => {
const bg = `var(--theme-user-colors-${color})`;
return (
Color
{color}
);
};
export default function ChatModerationDetailsModal(props: Props) {
const { userId, accessToken } = props;
const [userDetails, setUserDetails] = useState(null);
const [loading, setLoading] = useState(true);
const getDetails = async () => {
try {
const response = await (await fetch(`/api/moderation/chat/user/${userId}`)).json();
setUserDetails(response);
setLoading(false);
} catch (e) {
console.error(e);
}
};
useEffect(() => {
getDetails();
}, []);
if (!userDetails) {
return null;
}
const { user, connectedClients, messages } = userDetails;
const { displayName, displayColor, createdAt, previousNames, scopes, isBot, authenticated } =
user;
return (
{displayName}
{scopes.map(scope => (
{scope}
))}
{authenticated && Authenticated}
{isBot && Bot}
Currently Connected
{connectedClients.length > 0 && (
{connectedClients.map(client => (
))}
)}
{messages.length > 0 && (
Recent Chat Messages
{messages.map(message => (
))}
)}
);
}