Skip to content

Commit 7d8c260

Browse files
authored
Merge pull request #516 from meowzip/reese
fix: 모음집 내부 고양이 삭제 UX 개선
2 parents 5d3177b + d1436a1 commit 7d8c260

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

src/app/diary/[id]/page.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ const DiaryDetailPage = ({ params: { id } }: { params: { id: number } }) => {
8282
<h5 className="text-end text-body-4 text-gr-500">
8383
{diaryDetail?.memberNickname}{diaryDetail?.caredTime}
8484
</h5>
85-
<div className="flex h-[300px] w-full">
86-
{diaryDetail?.images && (
85+
{diaryDetail?.images.length > 0 && (
86+
<div className="flex h-[300px] w-full">
8787
<Carousel images={diaryDetail?.images} style="rounded-16" />
88-
)}
89-
</div>
88+
</div>
89+
)}
9090
<h4 className="w-full whitespace-pre-line text-body-3 text-gr-black">
9191
{diaryDetail?.content}
9292
</h4>

src/app/zip/[id]/page.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,17 @@ const ZipDiaryPage = ({ params: { id } }: { params: { id: number } }) => {
104104
heightPercent={['50%', '40%']}
105105
name={catDetail?.name}
106106
memberId={catDetail?.id}
107-
onDelete={() => {
108-
deleteCat(catDetail?.id);
109-
location.href = '/zip';
107+
onDelete={async () => {
108+
try {
109+
await deleteCat(catDetail?.id);
110+
toast({ description: '삭제되었습니다.', duration: 1000 });
111+
router.replace('/zip');
112+
} catch (e) {
113+
toast({
114+
description: '삭제에 실패했습니다. 잠시 후 다시 시도해주세요.',
115+
duration: 1500
116+
});
117+
}
110118
}}
111119
onEdit={() => {
112120
router.push(`/zip/${id}/edit?catId=${catDetail?.id}`);

src/components/diary/DiaryWriteModal.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,11 @@ const DiaryWriteModal = ({
260260
const editDiaryMutation = useMutation({
261261
mutationFn: (reqObj: { id: number; diary: DiaryRegisterReqObj }) =>
262262
editDiaryOnServer(reqObj),
263-
onSuccess: () => {
263+
onSuccess: async () => {
264264
queryClient.invalidateQueries({ queryKey: ['diaryDetail'] });
265+
queryClient.invalidateQueries({
266+
predicate: q => q.queryKey[0] === 'diaries'
267+
});
265268
toast({
266269
description: '일지가 성공적으로 수정되었습니다.'
267270
});

src/services/cat.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,19 @@ export const deleteCat = async (id: number) => {
341341

342342
try {
343343
const response = await fetchAuth(`/cats/${id}`, requestOptions);
344-
return response.body;
344+
if (!response.ok) {
345+
const msg = await (async () => {
346+
try {
347+
const body = await response.text();
348+
return body || '요청 실패';
349+
} catch {
350+
return '요청 실패';
351+
}
352+
})();
353+
354+
throw new Error(msg);
355+
}
356+
return true;
345357
} catch (error) {
346358
console.error(error);
347359
if (error instanceof Error) {

0 commit comments

Comments
 (0)