Skip to content

Commit b2c8497

Browse files
committed
HOTFIX: 포스터 추가, 수정 시 작동 안되던 현상 수정
1 parent 2bd917a commit b2c8497

1 file changed

Lines changed: 50 additions & 30 deletions

File tree

src/app/(auth)/display/page.tsx

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import { useState, useRef } from 'react';
1717
import toast from 'react-hot-toast';
1818
import {
1919
useGetAllPosters,
20-
useAddPoster,
21-
useUpdatePoster,
2220
useDeletePoster,
2321
useActivatePoster,
2422
useDeactivatePoster,
@@ -29,6 +27,8 @@ import {
2927
getGetAllPostersQueryKey,
3028
getGetSchedulesQueryKey,
3129
} from '@/api-client';
30+
import { useMutation } from '@tanstack/react-query';
31+
import { customMutator } from '@/lib/axiosMutator';
3232
import type { DisplayCalendarScheduleDetail, DisplayPosterDetail } from '@/api-client/model';
3333

3434
type TabType = 'calendar' | 'poster';
@@ -117,29 +117,53 @@ export default function DisplayPage() {
117117
},
118118
});
119119

120-
const addPosterMutation = useAddPoster({
121-
mutation: {
122-
onSuccess: () => {
123-
queryClient.invalidateQueries({ queryKey: getGetAllPostersQueryKey() });
124-
toast.success('포스터가 추가되었습니다.');
125-
setIsPosterModalOpen(false);
126-
},
127-
onError: (error: any) => {
128-
toast.error(error?.response?.data?.message || '포스터 추가에 실패했습니다.');
129-
},
120+
const addPosterMutation = useMutation({
121+
mutationFn: async ({ image, title }: { image: File; title: string }) => {
122+
const formData = new FormData();
123+
formData.append('image', image);
124+
formData.append(
125+
'posterRequest',
126+
new Blob([JSON.stringify({ title })], { type: 'application/json' }),
127+
);
128+
return customMutator<void>({
129+
url: '/display/posters',
130+
method: 'POST',
131+
data: formData,
132+
});
133+
},
134+
onSuccess: () => {
135+
queryClient.invalidateQueries({ queryKey: getGetAllPostersQueryKey() });
136+
toast.success('포스터가 추가되었습니다.');
137+
setIsPosterModalOpen(false);
138+
},
139+
onError: (error: any) => {
140+
toast.error(error?.response?.data?.message || '포스터 추가에 실패했습니다.');
130141
},
131142
});
132143

133-
const updatePosterMutation = useUpdatePoster({
134-
mutation: {
135-
onSuccess: () => {
136-
queryClient.invalidateQueries({ queryKey: getGetAllPostersQueryKey() });
137-
toast.success('포스터가 수정되었습니다.');
138-
setIsPosterModalOpen(false);
139-
},
140-
onError: (error: any) => {
141-
toast.error(error?.response?.data?.message || '포스터 수정에 실패했습니다.');
142-
},
144+
const updatePosterMutation = useMutation({
145+
mutationFn: async ({ posterId, image, title }: { posterId: number; image?: File; title: string }) => {
146+
const formData = new FormData();
147+
if (image) {
148+
formData.append('image', image);
149+
}
150+
formData.append(
151+
'posterRequest',
152+
new Blob([JSON.stringify({ title })], { type: 'application/json' }),
153+
);
154+
return customMutator<void>({
155+
url: `/display/posters/${posterId}`,
156+
method: 'PATCH',
157+
data: formData,
158+
});
159+
},
160+
onSuccess: () => {
161+
queryClient.invalidateQueries({ queryKey: getGetAllPostersQueryKey() });
162+
toast.success('포스터가 수정되었습니다.');
163+
setIsPosterModalOpen(false);
164+
},
165+
onError: (error: any) => {
166+
toast.error(error?.response?.data?.message || '포스터 수정에 실패했습니다.');
143167
},
144168
});
145169

@@ -283,10 +307,8 @@ export default function DisplayPage() {
283307
// 수정
284308
updatePosterMutation.mutate({
285309
posterId: editingPoster.posterId,
286-
data: {
287-
...(posterImageFile ? { image: posterImageFile } : {}),
288-
posterRequest: { title: posterTitle },
289-
},
310+
...(posterImageFile ? { image: posterImageFile } : {}),
311+
title: posterTitle,
290312
});
291313
} else {
292314
// 추가
@@ -295,10 +317,8 @@ export default function DisplayPage() {
295317
return;
296318
}
297319
addPosterMutation.mutate({
298-
data: {
299-
image: posterImageFile,
300-
posterRequest: { title: posterTitle },
301-
},
320+
image: posterImageFile,
321+
title: posterTitle,
302322
});
303323
}
304324
};

0 commit comments

Comments
 (0)