@@ -1,6 +1,6 @@
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { fetchActiveSession, createSession, endSession, fetchSessions, deleteSession, updateSession } from '../api/client';
|
||||
import type { SleepSessionRead } from '../types';
|
||||
import type { SleepSessionRead, SleepSessionCreate } from '../types';
|
||||
|
||||
export function useSleepSession() {
|
||||
const queryClient = useQueryClient();
|
||||
@@ -12,7 +12,7 @@ export function useSleepSession() {
|
||||
});
|
||||
|
||||
const createMutation = useMutation({
|
||||
mutationFn: (args) => createSession(args),
|
||||
mutationFn: (args: SleepSessionCreate) => createSession(args),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['activeSession'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['sessions'] });
|
||||
@@ -20,7 +20,7 @@ export function useSleepSession() {
|
||||
});
|
||||
|
||||
const endMutation = useMutation({
|
||||
mutationFn: (args) => endSession(args.sessionId, { end_time: args.endTime }),
|
||||
mutationFn: (args: { sessionId: number; endTime: string }) => endSession(args.sessionId, { end_time: args.endTime }),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['activeSession'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['sessions'] });
|
||||
@@ -47,7 +47,7 @@ export function useSessions() {
|
||||
});
|
||||
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: (id) => deleteSession(id),
|
||||
mutationFn: (id: number) => deleteSession(id),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['sessions'] });
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user