From aa56483f8ddaa1def8cb44082575438a865ba0bb Mon Sep 17 00:00:00 2001 From: bicochan Date: Mon, 12 May 2025 15:14:31 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=ED=8F=BC=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entities/comment/api/comment-service.ts | 3 +- .../src/pages/(pst)/normal/ui/modify-page.tsx | 4 +- .../src/pages/(pst)/notice/ui/modify-page.tsx | 4 +- .../src/widgets/post/ui/post-form.tsx | 756 +++++++++--------- .../features/src/widgets/post/ui/post.tsx | 42 +- 5 files changed, 430 insertions(+), 379 deletions(-) diff --git a/apps/common/features/src/entities/comment/api/comment-service.ts b/apps/common/features/src/entities/comment/api/comment-service.ts index a4001301d..45f300069 100644 --- a/apps/common/features/src/entities/comment/api/comment-service.ts +++ b/apps/common/features/src/entities/comment/api/comment-service.ts @@ -50,7 +50,8 @@ export class CommentApiService implements CommentService { cmntPswd: string, ): Promise { const response = await client.delete( - `${ENDPOINT.BOARD_SERVICE.POSTS_COMMENTS}/${bbsId}/${pstNo}/${cmntNo}?cmntPswd=${cmntPswd}`, + `${ENDPOINT.BOARD_SERVICE.POSTS_COMMENTS}/${bbsId}/${pstNo}/${cmntNo}`, + { params: { cmntPswd } }, ); return response.data; } diff --git a/apps/common/features/src/pages/(pst)/normal/ui/modify-page.tsx b/apps/common/features/src/pages/(pst)/normal/ui/modify-page.tsx index 897b72e62..d6114ab44 100644 --- a/apps/common/features/src/pages/(pst)/normal/ui/modify-page.tsx +++ b/apps/common/features/src/pages/(pst)/normal/ui/modify-page.tsx @@ -1,5 +1,6 @@ "use client"; +import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { useMutation, useQuery } from "@tanstack/react-query"; @@ -13,6 +14,7 @@ import { ENDPOINT } from "@/shared/config"; import { useAlertStore, useUserStore } from "@/shared/lib"; function ModifyPage({ bbsId, pstNo }: { bbsId: string; pstNo: string }) { + const router = useRouter(); const { setMessage: alert } = useAlertStore((state) => state); const { userInfo } = useUserStore((state) => state); @@ -25,7 +27,7 @@ function ModifyPage({ bbsId, pstNo }: { bbsId: string; pstNo: string }) { mutationFn: (data: PostUpdateFormData) => PostApi.updatePost(bbsId, pstNo, data), onSuccess: () => { - alert("수정되었습니다."); + alert("수정되었습니다.", router.back); }, }); diff --git a/apps/common/features/src/pages/(pst)/notice/ui/modify-page.tsx b/apps/common/features/src/pages/(pst)/notice/ui/modify-page.tsx index 897b72e62..d6114ab44 100644 --- a/apps/common/features/src/pages/(pst)/notice/ui/modify-page.tsx +++ b/apps/common/features/src/pages/(pst)/notice/ui/modify-page.tsx @@ -1,5 +1,6 @@ "use client"; +import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { useMutation, useQuery } from "@tanstack/react-query"; @@ -13,6 +14,7 @@ import { ENDPOINT } from "@/shared/config"; import { useAlertStore, useUserStore } from "@/shared/lib"; function ModifyPage({ bbsId, pstNo }: { bbsId: string; pstNo: string }) { + const router = useRouter(); const { setMessage: alert } = useAlertStore((state) => state); const { userInfo } = useUserStore((state) => state); @@ -25,7 +27,7 @@ function ModifyPage({ bbsId, pstNo }: { bbsId: string; pstNo: string }) { mutationFn: (data: PostUpdateFormData) => PostApi.updatePost(bbsId, pstNo, data), onSuccess: () => { - alert("수정되었습니다."); + alert("수정되었습니다.", router.back); }, }); diff --git a/apps/common/features/src/widgets/post/ui/post-form.tsx b/apps/common/features/src/widgets/post/ui/post-form.tsx index 84636f234..6f238ec2f 100644 --- a/apps/common/features/src/widgets/post/ui/post-form.tsx +++ b/apps/common/features/src/widgets/post/ui/post-form.tsx @@ -1,9 +1,13 @@ import dayjs from "dayjs"; +import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { useQuery } from "@tanstack/react-query"; import type { HttpResponse, Upload } from "tus-js-client"; import type { UseFormReturn, FieldPath } from "react-hook-form"; -import { useLocalStorage } from "@frontend-opensource/use-react-hooks"; +import { + useConfirm, + useLocalStorage, +} from "@frontend-opensource/use-react-hooks"; import { Input, Label, @@ -26,8 +30,7 @@ import { AttachmentApi, type Attachment } from "@/entities/attachment"; import type { Post, PostFormData, PostUpdateFormData } from "@/entities/post"; import { ENDPOINT } from "@/shared/config"; import { useUserStore, useAlertStore, setCookie } from "@/shared/lib"; -import { FormWrapper } from "@/shared/ui/form-wrapper"; -import { FormControl, FormField, FormItem } from "@/shared/ui/form"; +import { Form, FormControl, FormField, FormItem } from "@/shared/ui/form"; type PostFormProps = { form: UseFormReturn; @@ -40,6 +43,9 @@ function PostForm({ }: PostFormProps) { const atflCd = form.getValues("atflCd" as FieldPath); + const router = useRouter(); + const { confirm } = useConfirm(); + const { userInfo } = useUserStore((state) => state); const { setMessage: alert } = useAlertStore((state) => state); const [storedBbsInfo] = useLocalStorage("bbs-info", ""); @@ -81,6 +87,17 @@ function PostForm({ } }; + const onSubmit = async (data: T) => { + if (await confirm("저장하시겠습니까?")) { + if (deleteAttachments.length > 0) { + await Promise.all( + deleteAttachments.map(AttachmentApi.deleteAttachmentByAtflId), + ); + } + await handleSave(data); + } + }; + const handleUpload = (e: React.ChangeEvent) => { const atflCd = form.getValues("atflCd" as FieldPath); if (atflCd) setCookie("atfl-cd-key", atflCd as string); @@ -104,15 +121,6 @@ function PostForm({ } }; - const saveInterceptors = async (data: T) => { - if (deleteAttachments.length > 0) { - await Promise.all( - deleteAttachments.map(AttachmentApi.deleteAttachmentByAtflId), - ); - } - handleSave(data); - }; - useEffect(() => { const mapper = (data: Attachment[]) => data.reduce( @@ -134,109 +142,21 @@ function PostForm({ }, []); return ( - -
- - - - - - - - 제목 - - } - render={({ field }) => ( - - - - - - )} - /> - - - - 작성자 - - } - render={({ field }) => ( - - - - - - )} - /> - - - {!userInfo?.userUnqId && ( +
+ +
+
+ + + + + - 비밀번호 + 제목 } - render={({ field }) => ( - - - - - - )} - /> - - - )} - - 내용 - - } - render={({ field }) => ( - - -