Skip to content

Commit d8caccc

Browse files
committed
[fix]댓글 알림 수정
1 parent 2b825cb commit d8caccc

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/domains/recipe/api/useRecipeComment.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { useAuthStore } from '@/domains/shared/store/auth';
44
import { useToast } from '@/shared/hook/useToast';
55
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
66

7+
interface Comment {
8+
9+
userNickName: string
10+
}
11+
712
export const postRecipeComment = async (cocktailId: number, content: string) => {
813
const body = {
914
cocktailId,
@@ -18,6 +23,9 @@ export const postRecipeComment = async (cocktailId: number, content: string) =>
1823
body: JSON.stringify(body),
1924
});
2025

26+
27+
if (res.status === 401) throw new Error('unauth')
28+
2129
const text = await res.text();
2230
const data = JSON.parse(text);
2331
return data;
@@ -72,21 +80,20 @@ export function useRecipeComment({ cocktailId }: { cocktailId: number }) {
7280
queryFn: () => getRecipeComment(cocktailId),
7381
staleTime: 30_000,
7482
});
75-
83+
console.log(comments)
84+
console.log(user)
85+
const hasComment = comments.some((c:Comment) => c.userNickName === user?.nickname);
7686
const createMut = useMutation({
7787
mutationFn: (content: string) => {
7888
if (!user?.id) {
7989
toastInfo('로그인 후 이용 가능합니다.');
80-
return Promise.reject(new Error('unauth'));
90+
return Promise.resolve(null)
91+
} else if (hasComment) {
92+
toastInfo('댓글은 한 개만 작성 가능합니다.')
8193
}
8294
return postRecipeComment(cocktailId, content);
8395
},
8496
onSuccess: () => refetch(),
85-
onError: (e) => {
86-
if (e.message !== 'unauth') {
87-
toastInfo('댓글은 한개만 작성 가능합니다');
88-
}
89-
},
9097
});
9198

9299
const updateMut = useMutation({

0 commit comments

Comments
 (0)