Skip to content

Commit 02becb1

Browse files
committed
feat: Add delete post action (kookmin-sw#75)
1 parent 789f46f commit 02becb1

File tree

3 files changed

+72
-26
lines changed

3 files changed

+72
-26
lines changed

src/app/pages/shared-post-page.tsx

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import {
1515
useUnfollowUser,
1616
} from '@/features/profile';
1717
import {
18+
useDeleteSharedPost,
1819
useScrapSharedPost,
1920
useSharedPost,
2021
useSharedPostProps,
2122
} from '@/features/shared';
23+
import { useToast } from '@/features/toast';
2224
import { getAge } from '@/shared';
2325

2426
const styles = {
@@ -377,7 +379,14 @@ const styles = {
377379
font-weight: 600;
378380
line-height: 1.5rem;
379381
`,
380-
modifyPostButton: styled.button`
382+
rowForDeleteAndModify: styled.div`
383+
display: flex;
384+
flex-direction: row;
385+
gap: 1rem;
386+
387+
align-self: end;
388+
`,
389+
postModifyButton: styled.button`
381390
all: unset;
382391
cursor: pointer;
383392
@@ -398,8 +407,28 @@ const styles = {
398407
font-style: normal;
399408
font-weight: 600;
400409
line-height: 1.5rem;
410+
`,
411+
postDeleteButton: styled.div`
412+
all: unset;
413+
cursor: pointer;
401414
402-
align-self: end;
415+
display: flex;
416+
width: fit-content;
417+
height: fit-content;
418+
padding: 0.5rem 1.5rem;
419+
justify-content: center;
420+
align-items: center;
421+
422+
border-radius: 0.5rem;
423+
background: #e15637;
424+
425+
color: #fff;
426+
text-align: right;
427+
font-family: Pretendard;
428+
font-size: 1.125rem;
429+
font-style: normal;
430+
font-weight: 600;
431+
line-height: 1.5rem;
403432
`,
404433
};
405434

@@ -410,8 +439,11 @@ export function SharedPostPage({ postId }: { postId: number }) {
410439
const mapRef = useRef<HTMLDivElement>(null);
411440

412441
const router = useRouter();
442+
const { createToast } = useToast();
413443
const { setStateWithPost } = useSharedPostProps();
414444

445+
const { mutate: deleteSharedPost } = useDeleteSharedPost();
446+
415447
const [selected, setSelected] = useState<
416448
| {
417449
memberId: string;
@@ -568,14 +600,41 @@ export function SharedPostPage({ postId }: { postId: number }) {
568600
</styles.locationInfoContainer>
569601
{sharedPost.data.publisherAccount.memberId ===
570602
auth?.user?.memberId && (
571-
<styles.modifyPostButton
572-
onClick={() => {
573-
setStateWithPost(sharedPost);
574-
router.push('/shared/writing');
575-
}}
576-
>
577-
수정하기
578-
</styles.modifyPostButton>
603+
<styles.rowForDeleteAndModify>
604+
<styles.postModifyButton
605+
onClick={() => {
606+
setStateWithPost(sharedPost);
607+
router.push('/shared/writing');
608+
}}
609+
>
610+
수정하기
611+
</styles.postModifyButton>
612+
<styles.postDeleteButton
613+
onClick={() => {
614+
deleteSharedPost(postId, {
615+
onSuccess: () => {
616+
createToast({
617+
message: '정상적으로 삭제되었습니다.',
618+
option: {
619+
duration: 3000,
620+
},
621+
});
622+
router.back();
623+
},
624+
onError: () => {
625+
createToast({
626+
message: '삭제하는데 실패하였습니다.',
627+
option: {
628+
duration: 3000,
629+
},
630+
});
631+
},
632+
});
633+
}}
634+
>
635+
삭제하기
636+
</styles.postDeleteButton>
637+
</styles.rowForDeleteAndModify>
579638
)}
580639
</styles.postContainer>
581640
<styles.mateContainer>

src/app/pages/writing-post-page.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,6 @@ export function WritingPostPage() {
608608
});
609609
}, []);
610610

611-
console.log(uploadedImages);
612-
613611
if (postId == null) {
614612
createSharedPost(
615613
{

src/features/shared/shared.hook.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -347,20 +347,9 @@ export const useSharedPost = ({
347347
enabled,
348348
});
349349

350-
export const useDeleteSharedPost = ({
351-
postId,
352-
onSuccess,
353-
onError,
354-
}: {
355-
postId: number;
356-
onSuccess: (data: SuccessBaseDTO) => void;
357-
onError: (error: Error) => void;
358-
}) =>
359-
useMutation({
360-
mutationFn: async () =>
361-
await deleteSharedPost(postId).then(response => response.data),
362-
onSuccess,
363-
onError,
350+
export const useDeleteSharedPost = () =>
351+
useMutation<AxiosResponse<SuccessBaseDTO>, FailureDTO, number>({
352+
mutationFn: deleteSharedPost,
364353
});
365354

366355
export const useScrapSharedPost = () =>

0 commit comments

Comments
 (0)