2022-11-25 20:25:03 +00:00
|
|
|
import { useEffect, useState } from 'react';
|
2022-06-05 23:23:25 +00:00
|
|
|
import { ActivityLogFilters, useActivityLogs } from '@/api/account/activity';
|
2022-06-05 22:35:53 +00:00
|
|
|
import { useFlashKey } from '@/plugins/useFlash';
|
|
|
|
import PageContentBlock from '@/components/elements/PageContentBlock';
|
|
|
|
import FlashMessageRender from '@/components/FlashMessageRender';
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
import PaginationFooter from '@/components/elements/table/PaginationFooter';
|
2022-06-05 23:23:25 +00:00
|
|
|
import { DesktopComputerIcon, XCircleIcon } from '@heroicons/react/solid';
|
|
|
|
import Spinner from '@/components/elements/Spinner';
|
|
|
|
import { styles as btnStyles } from '@/components/elements/button/index';
|
|
|
|
import classNames from 'classnames';
|
2022-06-12 19:08:26 +00:00
|
|
|
import ActivityLogEntry from '@/components/elements/activity/ActivityLogEntry';
|
|
|
|
import Tooltip from '@/components/elements/tooltip/Tooltip';
|
2022-06-20 17:19:40 +00:00
|
|
|
import useLocationHash from '@/plugins/useLocationHash';
|
2022-06-05 22:35:53 +00:00
|
|
|
|
|
|
|
export default () => {
|
2022-06-20 17:19:40 +00:00
|
|
|
const { hash } = useLocationHash();
|
2022-06-05 22:35:53 +00:00
|
|
|
const { clearAndAddHttpError } = useFlashKey('account');
|
2022-06-26 19:13:52 +00:00
|
|
|
const [filters, setFilters] = useState<ActivityLogFilters>({ page: 1, sorts: { timestamp: -1 } });
|
2022-06-05 23:23:25 +00:00
|
|
|
const { data, isValidating, error } = useActivityLogs(filters, {
|
2022-06-05 22:35:53 +00:00
|
|
|
revalidateOnMount: true,
|
|
|
|
revalidateOnFocus: false,
|
|
|
|
});
|
|
|
|
|
2022-06-05 23:23:25 +00:00
|
|
|
useEffect(() => {
|
2022-11-25 20:25:03 +00:00
|
|
|
setFilters(value => ({ ...value, filters: { ip: hash.ip, event: hash.event } }));
|
2022-06-26 19:13:52 +00:00
|
|
|
}, [hash]);
|
2022-06-05 23:23:25 +00:00
|
|
|
|
2022-06-05 22:35:53 +00:00
|
|
|
useEffect(() => {
|
|
|
|
clearAndAddHttpError(error);
|
2022-06-26 19:13:52 +00:00
|
|
|
}, [error]);
|
2022-06-05 22:35:53 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<PageContentBlock title={'Account Activity Log'}>
|
2022-06-26 19:13:52 +00:00
|
|
|
<FlashMessageRender byKey={'account'} />
|
|
|
|
{(filters.filters?.event || filters.filters?.ip) && (
|
2023-01-12 19:31:47 +00:00
|
|
|
<div className={'mb-2 flex justify-end'}>
|
2022-06-05 23:23:25 +00:00
|
|
|
<Link
|
|
|
|
to={'#'}
|
2022-06-12 13:09:01 +00:00
|
|
|
className={classNames(btnStyles.button, btnStyles.text, 'w-full sm:w-auto')}
|
2022-11-25 20:25:03 +00:00
|
|
|
onClick={() => setFilters(value => ({ ...value, filters: {} }))}
|
2022-06-05 22:35:53 +00:00
|
|
|
>
|
2023-01-12 19:31:47 +00:00
|
|
|
Clear Filters <XCircleIcon className={'ml-2 h-4 w-4'} />
|
2022-06-05 23:23:25 +00:00
|
|
|
</Link>
|
|
|
|
</div>
|
2022-06-26 19:13:52 +00:00
|
|
|
)}
|
|
|
|
{!data && isValidating ? (
|
|
|
|
<Spinner centered />
|
|
|
|
) : (
|
2022-12-16 02:06:14 +00:00
|
|
|
<div className={'bg-slate-700'}>
|
2022-11-25 20:25:03 +00:00
|
|
|
{data?.items.map(activity => (
|
2022-07-10 18:53:29 +00:00
|
|
|
<ActivityLogEntry key={activity.id} activity={activity}>
|
2022-06-26 19:13:52 +00:00
|
|
|
{typeof activity.properties.useragent === 'string' && (
|
2022-06-12 19:08:26 +00:00
|
|
|
<Tooltip content={activity.properties.useragent} placement={'top'}>
|
2022-06-26 19:13:52 +00:00
|
|
|
<span>
|
|
|
|
<DesktopComputerIcon />
|
|
|
|
</span>
|
2022-06-12 19:08:26 +00:00
|
|
|
</Tooltip>
|
2022-06-26 19:13:52 +00:00
|
|
|
)}
|
2022-06-12 19:08:26 +00:00
|
|
|
</ActivityLogEntry>
|
2022-06-05 23:23:25 +00:00
|
|
|
))}
|
|
|
|
</div>
|
2022-06-26 19:13:52 +00:00
|
|
|
)}
|
|
|
|
{data && (
|
|
|
|
<PaginationFooter
|
|
|
|
pagination={data.pagination}
|
2022-11-25 20:25:03 +00:00
|
|
|
onPageSelect={page => setFilters(value => ({ ...value, page }))}
|
2022-06-26 19:13:52 +00:00
|
|
|
/>
|
|
|
|
)}
|
2022-06-05 22:35:53 +00:00
|
|
|
</PageContentBlock>
|
|
|
|
);
|
|
|
|
};
|