import React from 'react'; import { Link } from 'react-router-dom'; import Tooltip from '@/components/elements/tooltip/Tooltip'; import Translate from '@/components/elements/Translate'; import { format, formatDistanceToNowStrict } from 'date-fns'; import { ActivityLog } from '@definitions/user'; import { useLocation } from 'react-router'; import ActivityLogMetaButton from '@/components/elements/activity/ActivityLogMetaButton'; import { TerminalIcon } from '@heroicons/react/solid'; import classNames from 'classnames'; import style from './style.module.css'; import { isObject } from '@/helpers'; import Avatar from '@/components/Avatar'; interface Props { activity: ActivityLog; children?: React.ReactNode; } const formatProperties = (properties: Record): Record => { return Object.keys(properties).reduce((obj, key) => { const value = properties[key]; // noinspection SuspiciousTypeOfGuard const isCount = key === 'count' || (typeof key === 'string' && key.endsWith('_count')); return { ...obj, [key]: isCount || typeof value !== 'string' ? (isObject(value) ? formatProperties(value) : value) : `${value}`, }; }, {}); }; export default ({ activity, children }: Props) => { const location = useLocation(); const actor = activity.relationships.actor; const queryTo = (params: Record): string => { const current = new URLSearchParams(location.search); Object.keys(params).forEach(key => current.set(key, params[key])); return current.toString(); }; const properties = formatProperties(activity.properties); return (
{actor?.username || 'System'}  —  {activity.event}
{activity.isApi && } {children}

{activity.ip}  |  {formatDistanceToNowStrict(activity.timestamp, { addSuffix: true })}
{activity.hasAdditionalMetadata && }
); };