mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-12 10:12:17 +01:00
refactor timeentries queries and mutations, improve activitygraph, add dashboard reporting table
This commit is contained in:
51
resources/js/utils/useTimeEntriesInfiniteQuery.ts
Normal file
51
resources/js/utils/useTimeEntriesInfiniteQuery.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { useInfiniteQuery } from '@tanstack/vue-query';
|
||||
import { api } from '@/packages/api/src';
|
||||
import { getCurrentMembershipId, getCurrentOrganizationId } from '@/utils/useUser';
|
||||
import dayjs from 'dayjs';
|
||||
import { computed } from 'vue';
|
||||
|
||||
export function useTimeEntriesInfiniteQuery() {
|
||||
const organizationId = computed(() => getCurrentOrganizationId());
|
||||
const memberId = computed(() => getCurrentMembershipId());
|
||||
|
||||
return useInfiniteQuery({
|
||||
queryKey: computed(() => [
|
||||
'timeEntries',
|
||||
'infinite',
|
||||
{ organizationId: organizationId.value, memberId: memberId.value },
|
||||
]),
|
||||
queryFn: async ({ pageParam }) => {
|
||||
const orgId = organizationId.value;
|
||||
if (!orgId) return { data: [] };
|
||||
|
||||
const queries: Record<string, string | undefined> = {
|
||||
only_full_dates: 'true',
|
||||
member_id: memberId.value,
|
||||
};
|
||||
|
||||
if (pageParam) {
|
||||
queries.end = pageParam;
|
||||
}
|
||||
|
||||
const response = await api.getTimeEntries({
|
||||
params: {
|
||||
organization: orgId,
|
||||
},
|
||||
queries: queries,
|
||||
});
|
||||
|
||||
return response;
|
||||
},
|
||||
initialPageParam: undefined as string | undefined,
|
||||
getNextPageParam: (lastPage) => {
|
||||
if (!lastPage?.data || lastPage.data.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
const latestTimeEntry = lastPage.data[lastPage.data.length - 1];
|
||||
return dayjs(latestTimeEntry.start).utc().format();
|
||||
},
|
||||
enabled: computed(() => !!organizationId.value),
|
||||
staleTime: 1000 * 30, // 30 seconds
|
||||
gcTime: 1000 * 60 * 10, // 10 minutes
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user