Add basic activity log view
This commit is contained in:
parent
d1da46c5aa
commit
c6e8b893c8
9 changed files with 267 additions and 17 deletions
24
resources/scripts/api/account/activity.ts
Normal file
24
resources/scripts/api/account/activity.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import useUserSWRContentKey from '@/plugins/useUserSWRContentKey';
|
||||
import useSWR, { ConfigInterface, responseInterface } from 'swr';
|
||||
import { ActivityLog, Transformers } from '@definitions/user';
|
||||
import { AxiosError } from 'axios';
|
||||
import http, { PaginatedResult } from '@/api/http';
|
||||
import { toPaginatedSet } from '@definitions/helpers';
|
||||
|
||||
const useActivityLogs = (page = 1, config?: ConfigInterface<PaginatedResult<ActivityLog>, AxiosError>): responseInterface<PaginatedResult<ActivityLog>, AxiosError> => {
|
||||
const key = useUserSWRContentKey([ 'account', 'activity', page.toString() ]);
|
||||
|
||||
return useSWR<PaginatedResult<ActivityLog>>(key, async () => {
|
||||
const { data } = await http.get('/api/client/account/activity', {
|
||||
params: {
|
||||
include: [ 'actor' ],
|
||||
sort: '-timestamp',
|
||||
page: page,
|
||||
},
|
||||
});
|
||||
|
||||
return toPaginatedSet(data, Transformers.toActivityLog);
|
||||
}, { revalidateOnMount: false, ...(config || {}) });
|
||||
};
|
||||
|
||||
export { useActivityLogs };
|
Reference in a new issue