-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuseMyMandal.ts
More file actions
55 lines (47 loc) · 1.61 KB
/
useMyMandal.ts
File metadata and controls
55 lines (47 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { useQuery } from '@tanstack/react-query';
import { useMutation } from '@tanstack/react-query';
import { uncheckSubGoal, checkSubGoal } from './../index';
import { getMandalAll } from '../../mandalAll';
import { getMandalCoreGoals } from '..';
import type { CoreGoal } from '../type/myTodo';
import { getSubGoals } from '../../edit';
import type { CycleType } from '@/page/todo/myTodo/component/CycleChip';
import type { BaseResponse } from '@/type/api';
import { QUERY_KEY } from '@/api/constant/queryKey';
type MandalCoreGoalsResponse = BaseResponse<{
coreGoals: CoreGoal[];
}>;
export const useGetMandalAll = (mandalartId: number) => {
return useQuery({
queryKey: [QUERY_KEY.ENTIRE_GOAL, mandalartId],
queryFn: () => getMandalAll(mandalartId),
});
};
export const useGetMandalCoreGoals = (mandalartId: number) => {
return useQuery<MandalCoreGoalsResponse>({
queryKey: [QUERY_KEY.CORE_GOALS, mandalartId],
queryFn: () => getMandalCoreGoals(mandalartId),
});
};
export const useGetMandalartSubGoals = (
mandalartId: number,
coreGoalId?: number,
cycle?: string,
) => {
return useQuery({
queryKey: QUERY_KEY.MANDALART_SUB_GOALS(mandalartId, coreGoalId, cycle),
queryFn: () => getSubGoals(mandalartId, coreGoalId, cycle as CycleType),
enabled: !!mandalartId,
});
};
export const useCheckSubGoal = () => {
return useMutation({
mutationFn: ({ subGoalId, date }: { subGoalId: number; date: string }) =>
checkSubGoal(subGoalId, date),
});
};
export const useUncheckSubGoal = () => {
return useMutation({
mutationFn: (subGoalId: number) => uncheckSubGoal(subGoalId),
});
};