@@ -4,14 +4,15 @@ import { useSuspenseQuery, useMutation, useQueryClient } from '@tanstack/react-q
44import { axiosInstance } from '@/services/common/axiosInstance' ;
55import { API_URLS } from '@/constants/urls' ;
66import { ALERT_MESSAGES } from '@/constants/alertMessage' ;
7+ import { ERROR_MESSAGES } from '@/constants/errors' ;
78
89export const usePostEdit = ( id : string , userId : string | undefined , accessToken : string ) => {
910 const [ title , setTitle ] = useState ( '' ) ;
1011 const [ content , setContent ] = useState ( '' ) ;
1112 const router = useRouter ( ) ;
1213 const queryClient = useQueryClient ( ) ;
1314
14- // 게시글 조회 - useSuspenseQuery 사용 (enabled 옵션 제거)
15+ // 게시글 데이터 가져오기
1516 const { data } = useSuspenseQuery ( {
1617 queryKey : [ 'post-edit' , id ] ,
1718 queryFn : async ( ) => {
@@ -21,7 +22,7 @@ export const usePostEdit = (id: string, userId: string | undefined, accessToken:
2122 if ( post . userId !== userId ) {
2223 alert ( ALERT_MESSAGES . ERROR . POST . POST_PERMISSION_DENIED ) ;
2324 router . push ( '/community' ) ;
24- throw new Error ( 'Permission denied' ) ;
25+ throw new Error ( ERROR_MESSAGES . PERMISSION_DENIED ) ;
2526 }
2627
2728 return post ;
@@ -43,7 +44,7 @@ export const usePostEdit = (id: string, userId: string | undefined, accessToken:
4344 mutationFn : async ( ) => {
4445 if ( ! title . trim ( ) || ! content . trim ( ) ) {
4546 alert ( ALERT_MESSAGES . ERROR . POST . POST_EMPTY_FIELDS ) ;
46- throw new Error ( 'Empty fields' ) ;
47+ throw new Error ( ERROR_MESSAGES . EMPTY_FIELDS ) ;
4748 }
4849
4950 return axiosInstance . put (
@@ -67,7 +68,7 @@ export const usePostEdit = (id: string, userId: string | undefined, accessToken:
6768 const deletePostMutation = useMutation ( {
6869 mutationFn : async ( ) => {
6970 if ( ! window . confirm ( ALERT_MESSAGES . CONFIRM . CHECK_DELETE ) ) {
70- throw new Error ( 'Delete cancelled' ) ;
71+ throw new Error ( ERROR_MESSAGES . DELETE_CANCELLED ) ;
7172 }
7273
7374 return axiosInstance . delete ( `${ API_URLS . POSTS } /${ id } ` , {
0 commit comments