-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhook.ts
More file actions
89 lines (80 loc) · 2.28 KB
/
hook.ts
File metadata and controls
89 lines (80 loc) · 2.28 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { useQuery, useMutation } from '@tanstack/react-query';
import {
getMandalAll,
getCoreGoals,
getSubGoalIds,
postOnboardingSubGoal,
patchOnboardingSubGoal,
deleteOnboardingSubGoal,
postAiRecommendNewSubGoal,
type SubGoalIdPosition,
} from './index';
import { QUERY_KEY } from '@/api/constant/queryKey';
export const useGetMandalAll = (mandalartId: number) => {
return useQuery({
queryKey: [QUERY_KEY.ENTIRE_GOAL, mandalartId],
queryFn: () => getMandalAll(mandalartId),
enabled: !!mandalartId,
});
};
export const useGetCoreGoals = (mandalartId: number) => {
return useQuery({
queryKey: [QUERY_KEY.CORE_GOALS, mandalartId],
queryFn: () => getCoreGoals(mandalartId),
enabled: !!mandalartId,
});
};
export const useGetSubGoalIds = (coreGoalId: number) => {
return useQuery<{ subGoalIds: SubGoalIdPosition[] }>({
queryKey: QUERY_KEY.SUB_GOAL_IDS(coreGoalId),
queryFn: () => getSubGoalIds(coreGoalId),
enabled: !!coreGoalId && coreGoalId > 0,
retry: false,
});
};
export const usePostOnboardingSubGoal = () => {
return useMutation({
mutationKey: QUERY_KEY.POST_ONBOARDING_SUB_GOAL,
mutationFn: ({
coreGoalId,
title,
position,
cycle,
}: {
coreGoalId: number;
title: string;
position: number;
cycle: string;
}) => postOnboardingSubGoal(coreGoalId, { title, position, cycle }),
});
};
export const usePatchOnboardingSubGoal = () => {
return useMutation({
mutationKey: QUERY_KEY.PATCH_ONBOARDING_SUB_GOAL,
mutationFn: (params: { subGoalId: number; title: string; cycle: string }) =>
patchOnboardingSubGoal(params),
});
};
export const useDeleteOnboardingSubGoal = () => {
return useMutation({
mutationKey: QUERY_KEY.DELETE_ONBOARDING_SUB_GOAL,
mutationFn: (subGoalId: number) => deleteOnboardingSubGoal(subGoalId),
});
};
export const usePostAiRecommendNewSubGoal = () => {
return useMutation({
mutationKey: QUERY_KEY.POST_AI_RECOMMEND_NEW_SUB_GOAL,
mutationFn: async ({
coreGoalId,
coreGoal,
subGoal,
}: {
coreGoalId: number;
coreGoal: string;
subGoal: { title: string }[];
}) => {
const response = await postAiRecommendNewSubGoal(coreGoalId, { coreGoal, subGoal });
return response;
},
});
};