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 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'; import useLocationHash from '@/plugins/useLocationHash'; 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 { pathTo } = useLocationHash(); const actor = activity.relationships.actor; const properties = formatProperties(activity.properties); return (
{actor?.username || 'System'}  —  {activity.event}
{activity.isApi && } {children}

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