1
- import getQueryKey from '@/apis/getQueryKey ' ;
1
+ import { createQueryKeyFactory } from '@/apis/createQueryKeyFactory ' ;
2
2
import { type MissionCategory , type MissionItemTypeWithRecordId , type MissionVisibility } from '@/apis/schema/mission' ;
3
3
import {
4
4
useMutation ,
@@ -81,17 +81,23 @@ interface ModifyMissionResponse {
81
81
visibility : string ;
82
82
}
83
83
84
+ const missionsQueryKey = [ 'missions' ] ;
85
+
84
86
export const useGetMissions = ( option ?: UseQueryOptions < GetMissionsResponse > ) => {
85
87
return useQuery < GetMissionsResponse > ( {
86
- queryKey : getQueryKey ( 'missions' ) ,
88
+ queryKey : missionsQueryKey ,
87
89
queryFn : MISSION_APIS . getMissions ,
88
90
...option ,
89
91
} ) ;
90
92
} ;
91
93
94
+ const getMissionDetailQueryKey = createQueryKeyFactory < {
95
+ missionId : string ;
96
+ } > ( 'missionDetail' ) ;
97
+
92
98
export const useGetMissionDetail = ( missionId : string , option ?: UseQueryOptions < MissionContentType > ) => {
93
99
return useSuspenseQuery < MissionContentType > ( {
94
- queryKey : getQueryKey ( 'missionDetail' , { missionId } ) ,
100
+ queryKey : getMissionDetailQueryKey ( { missionId } ) ,
95
101
queryFn : ( ) => MISSION_APIS . getMissionDetail ( missionId ) ,
96
102
...option ,
97
103
} ) ;
@@ -102,7 +108,7 @@ export const useGetMissionDetailNoSuspense = (
102
108
option ?: Omit < UseQueryOptions < MissionContentType > , 'enabled' > , // TODO 수정 필요, 임시 방편
103
109
) => {
104
110
return useQuery < MissionContentType > ( {
105
- queryKey : getQueryKey ( 'missionDetail' , { missionId } ) ,
111
+ queryKey : getMissionDetailQueryKey ( { missionId } ) ,
106
112
queryFn : ( ) => MISSION_APIS . getMissionDetail ( missionId ) ,
107
113
enabled : Boolean ( missionId ) ,
108
114
...option ,
@@ -124,7 +130,7 @@ export const useDeleteMissionMutation = (missionId: string, option?: UseMutation
124
130
return useMutation ( {
125
131
mutationFn : ( ) => MISSION_APIS . deleteMission ( missionId ) ,
126
132
onSuccess : async ( ...data ) => {
127
- await queryClient . invalidateQueries ( { queryKey : getQueryKey ( 'missions' ) } ) ;
133
+ await queryClient . invalidateQueries ( { queryKey : missionsQueryKey } ) ;
128
134
option ?. onSuccess ?.( ...data ) ;
129
135
} ,
130
136
...option ,
0 commit comments