2022-06-12 19:08:26 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { UserIcon } from '@heroicons/react/outline';
|
|
|
|
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';
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
activity: ActivityLog;
|
|
|
|
children?: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ({ activity, children }: Props) => {
|
|
|
|
const location = useLocation();
|
|
|
|
const actor = activity.relationships.actor;
|
|
|
|
|
|
|
|
const queryTo = (params: Record<string, string>): string => {
|
|
|
|
const current = new URLSearchParams(location.search);
|
|
|
|
Object.keys(params).forEach(key => current.set(key, params[key]));
|
|
|
|
|
|
|
|
return current.toString();
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={'grid grid-cols-10 py-4 border-b-2 border-gray-800 last:rounded-b last:border-0 group'}>
|
2022-06-12 19:40:14 +00:00
|
|
|
<div className={'hidden sm:flex sm:col-span-1 items-center justify-center select-none'}>
|
2022-06-12 19:08:26 +00:00
|
|
|
<div className={'flex items-center w-8 h-8 rounded-full bg-gray-600 overflow-hidden'}>
|
|
|
|
{actor ?
|
|
|
|
<img src={actor.image} alt={'User avatar'}/>
|
|
|
|
:
|
|
|
|
<UserIcon className={'w-5 h-5 mx-auto'}/>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-06-12 19:40:14 +00:00
|
|
|
<div className={'col-span-10 sm:col-span-9 flex'}>
|
|
|
|
<div className={'flex-1 px-4 sm:px-0'}>
|
2022-06-12 19:08:26 +00:00
|
|
|
<div className={'flex items-center text-gray-50'}>
|
|
|
|
<Tooltip placement={'top'} content={actor?.email || 'System User'}>
|
|
|
|
<span>{actor?.username || 'System'}</span>
|
|
|
|
</Tooltip>
|
|
|
|
<span className={'text-gray-400'}> — </span>
|
|
|
|
<Link
|
|
|
|
to={`?${queryTo({ event: activity.event })}`}
|
|
|
|
className={'transition-colors duration-75 active:text-cyan-400 hover:text-cyan-400'}
|
|
|
|
>
|
|
|
|
{activity.event}
|
|
|
|
</Link>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
<p className={'mt-1 text-sm break-words line-clamp-2 pr-4'}>
|
|
|
|
<Translate ns={'activity'} values={activity.properties}>
|
|
|
|
{activity.event.replace(':', '.')}
|
|
|
|
</Translate>
|
|
|
|
</p>
|
|
|
|
<div className={'mt-1 flex items-center text-sm'}>
|
|
|
|
<Link
|
|
|
|
to={`?${queryTo({ ip: activity.ip })}`}
|
|
|
|
className={'transition-colors duration-75 active:text-cyan-400 hover:text-cyan-400'}
|
|
|
|
>
|
|
|
|
{activity.ip}
|
|
|
|
</Link>
|
|
|
|
<span className={'text-gray-400'}> | </span>
|
|
|
|
<Tooltip
|
|
|
|
placement={'right'}
|
|
|
|
content={format(activity.timestamp, 'MMM do, yyyy h:mma')}
|
|
|
|
>
|
|
|
|
<span>
|
|
|
|
{formatDistanceToNowStrict(activity.timestamp, { addSuffix: true })}
|
|
|
|
</span>
|
|
|
|
</Tooltip>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-06-12 19:30:49 +00:00
|
|
|
{activity.hasAdditionalMetadata && <ActivityLogMetaButton meta={activity.properties}/>}
|
2022-06-12 19:08:26 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|