mirror of
https://github.com/hex248/sprint.git
synced 2026-02-07 18:23:03 +00:00
useOrganisationMemberTimeTracking() hook
This commit is contained in:
@@ -14,6 +14,20 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { queryKeys } from "@/lib/query/keys";
|
||||
import { apiClient } from "@/lib/server";
|
||||
|
||||
export interface MemberTimeTrackingSession {
|
||||
id: number;
|
||||
userId: number;
|
||||
issueId: number;
|
||||
issueNumber: number;
|
||||
projectKey: string;
|
||||
timestamps: string[];
|
||||
endedAt: string | null;
|
||||
createdAt: string | null;
|
||||
workTimeMs: number;
|
||||
breakTimeMs: number;
|
||||
isRunning: boolean;
|
||||
}
|
||||
|
||||
export function useOrganisations() {
|
||||
return useQuery<OrganisationResponse[]>({
|
||||
queryKey: queryKeys.organisations.byUser(),
|
||||
@@ -39,6 +53,23 @@ export function useOrganisationMembers(organisationId?: number | null) {
|
||||
});
|
||||
}
|
||||
|
||||
export function useOrganisationMemberTimeTracking(organisationId?: number | null, fromDate?: Date) {
|
||||
return useQuery<MemberTimeTrackingSession[]>({
|
||||
queryKey: queryKeys.organisations.memberTimeTracking(organisationId ?? 0, fromDate?.toISOString()),
|
||||
queryFn: async () => {
|
||||
const { data, error } = await apiClient.organisationMemberTimeTracking({
|
||||
query: {
|
||||
organisationId: organisationId ?? 0,
|
||||
fromDate: fromDate,
|
||||
},
|
||||
});
|
||||
if (error) throw new Error(error);
|
||||
return (data ?? []) as MemberTimeTrackingSession[];
|
||||
},
|
||||
enabled: Boolean(organisationId),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateOrganisation() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ export const queryKeys = {
|
||||
all: ["organisations"] as const,
|
||||
byUser: () => [...queryKeys.organisations.all, "by-user"] as const,
|
||||
members: (orgId: number) => [...queryKeys.organisations.all, orgId, "members"] as const,
|
||||
memberTimeTracking: (orgId: number, fromDate?: string) =>
|
||||
[...queryKeys.organisations.all, orgId, "member-time-tracking", fromDate ?? "all"] as const,
|
||||
},
|
||||
projects: {
|
||||
all: ["projects"] as const,
|
||||
|
||||
Reference in New Issue
Block a user