life-manager/codebase/features/scheduling/frontend/useActivityLog.ts

35 lines
1 KiB
TypeScript

import { useQuery } from '@tanstack/react-query';
import type { UseQueryResult } from '@tanstack/react-query';
import { apiClient } from '@/lib/api';
import type { DailyLogEntry } from './useScheduling';
export function useActivityLog(options?: {
types?: string[];
limit?: number;
offset?: number;
dateFrom?: string;
dateTo?: string;
}): UseQueryResult<DailyLogEntry[]> {
const limit = options?.limit ?? 100;
const types = options?.types;
const dateFrom = options?.dateFrom;
const dateTo = options?.dateTo;
const offset = options?.offset;
return useQuery({
queryKey: ['activity-log', types, limit, offset, dateFrom, dateTo],
queryFn: () =>
apiClient
.get<DailyLogEntry[]>('/scheduling/daily-log', {
params: {
...(types?.length ? { types: types.join(',') } : {}),
limit,
...(offset ? { offset } : {}),
...(dateFrom ? { dateFrom } : {}),
...(dateTo ? { dateTo } : {}),
},
})
.then((r) => r.data),
refetchInterval: 30_000,
});
}