// This displays a clickable user name (or whatever children element you provide), and displays a simple tooltip of created time. OnClick a modal with more information about the user is displayed. import { useState, ReactNode } from 'react'; import { Divider, Modal, Tooltip, Typography, Row, Col } from 'antd'; import formatDistanceToNow from 'date-fns/formatDistanceToNow'; import format from 'date-fns/format'; import { uniq } from 'lodash'; import BlockUserbutton from './ban-user-button'; import ModeratorUserbutton from './moderator-user-button'; import { User, UserConnectionInfo } from '../types/chat'; import { formatDisplayDate } from './user-table'; import { formatUAstring } from '../utils/format'; interface UserPopoverProps { user: User; connectionInfo?: UserConnectionInfo | null; children: ReactNode; } export default function UserPopover({ user, connectionInfo, children }: UserPopoverProps) { const [isModalVisible, setIsModalVisible] = useState(false); const handleShowModal = () => { setIsModalVisible(true); }; const handleCloseModal = () => { setIsModalVisible(false); }; const { displayName, createdAt, previousNames, nameChangedAt, disabledAt } = user; const { connectedAt, messageCount, userAgent } = connectionInfo || {}; let lastNameChangeDate = null; const nameList = previousNames && [...previousNames]; if (previousNames && previousNames.length > 1 && nameChangedAt) { lastNameChangeDate = new Date(nameChangedAt); // reverse prev names for display purposes nameList.reverse(); } const dateObject = new Date(createdAt); const createdAtDate = format(dateObject, 'PP pp'); const lastNameChangeDuration = lastNameChangeDate ? formatDistanceToNow(lastNameChangeDate) : null; return ( <> Created at: {createdAtDate}. Click for more info. > } placement="bottomLeft" > {children} {displayName} User created at {createdAtDate}. {connectionInfo && ( This user is currently connected to Chat. Active for: {formatDistanceToNow(new Date(connectedAt))} Messages sent: {messageCount} User Agent: {formatUAstring(userAgent)} )} {lastNameChangeDate && ( This user is also seen as: {uniq(nameList).map((name, index) => ( {name} {index === 0 ? ` (Changed ${lastNameChangeDuration} ago)` : ''} ))} )} {disabledAt ? ( <> This user was banned on {formatDisplayDate(disabledAt)}. > ) : ( )} > ); } UserPopover.defaultProps = { connectionInfo: null, };
User created at {createdAtDate}.
{formatDisplayDate(disabledAt)}