From 9b20dc4847975f70bf736931f5a0ad22a9a97aea Mon Sep 17 00:00:00 2001 From: bicochan Date: Fri, 2 May 2025 14:40:35 +0900 Subject: [PATCH] =?UTF-8?q?WIP:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D,=20=EC=88=98=EC=A0=95=20=EC=9E=91=EC=97=85=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pst/bbsnotice/[bbsId]/register/page.tsx | 2 + .../src/app/providers/app-provider.tsx | 9 +- .../features/src/entities/auth/index.ts | 1 + .../src/entities/auth/lib/auth-wrapper.tsx | 40 ++ .../src/entities/code/ui/code-select.tsx | 10 +- .../entities/posting/ui/posting-dialog.tsx | 19 +- .../common/features/src/pages/notice/index.ts | 1 + .../src/pages/notice/ui/create-page.tsx | 11 +- .../src/pages/notice/ui/notice-form.tsx | 356 ++++++++++-------- .../src/pages/notice/ui/notice-page.tsx | 24 +- apps/common/features/src/shared/lib/index.ts | 1 + .../common/features/src/shared/lib/use-tus.ts | 2 +- 12 files changed, 290 insertions(+), 186 deletions(-) create mode 100644 apps/common/features/app/(with-base-layout)/pst/bbsnotice/[bbsId]/register/page.tsx create mode 100644 apps/common/features/src/entities/auth/lib/auth-wrapper.tsx diff --git a/apps/common/features/app/(with-base-layout)/pst/bbsnotice/[bbsId]/register/page.tsx b/apps/common/features/app/(with-base-layout)/pst/bbsnotice/[bbsId]/register/page.tsx new file mode 100644 index 000000000..e4c9b57b1 --- /dev/null +++ b/apps/common/features/app/(with-base-layout)/pst/bbsnotice/[bbsId]/register/page.tsx @@ -0,0 +1,2 @@ +import { CreatePage } from "@/pages/notice"; +export default CreatePage; diff --git a/apps/common/features/src/app/providers/app-provider.tsx b/apps/common/features/src/app/providers/app-provider.tsx index eaf0463a3..afe4ee651 100644 --- a/apps/common/features/src/app/providers/app-provider.tsx +++ b/apps/common/features/src/app/providers/app-provider.tsx @@ -2,6 +2,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { ConfirmProvider } from "@frontend-opensource/use-react-hooks"; +import { AuthWrapper } from "@/entities/auth"; import { MenuWrapper } from "@/entities/menu"; import { StoreProvider } from "@/shared/providers"; import { AlertDialog } from "@/shared/ui/alert-dialog"; @@ -17,9 +18,11 @@ const AppProvider = ({ children }: Readonly<{ children: React.ReactNode }>) => { - {children} - - + + {children} + + + diff --git a/apps/common/features/src/entities/auth/index.ts b/apps/common/features/src/entities/auth/index.ts index 8c7981ac9..97e142225 100644 --- a/apps/common/features/src/entities/auth/index.ts +++ b/apps/common/features/src/entities/auth/index.ts @@ -1 +1,2 @@ export { LoginApi } from "./api/login-service"; +export { AuthWrapper } from "./lib/auth-wrapper"; diff --git a/apps/common/features/src/entities/auth/lib/auth-wrapper.tsx b/apps/common/features/src/entities/auth/lib/auth-wrapper.tsx new file mode 100644 index 000000000..6af88ae96 --- /dev/null +++ b/apps/common/features/src/entities/auth/lib/auth-wrapper.tsx @@ -0,0 +1,40 @@ +"use client"; + +import { useEffect } from "react"; +import { client } from "@/shared/api"; +import type { IUserInfo } from "@/shared/store"; +import { getCookie, useUserStore } from "@/shared/lib"; +import { ENDPOINT, AUTH_USER_ID } from "@/shared/config"; +import { LoginApi } from "../api/login-service"; + +const AuthWrapper = ({ children }: { children: React.ReactNode }) => { + const { userInfo, setUserInfo } = useUserStore((state) => state); + + async function authCheck() { + const userId = getCookie(AUTH_USER_ID); + if (!userId) { + throw new Error("Missing required authentication tokens"); + } + + const response = await client.get( + `${ENDPOINT.USER_SERVICE.USERS}/${userId}`, + ); + if (!userInfo) setUserInfo(response.data); + } + + useEffect(() => { + (async () => { + try { + await authCheck(); + } catch (error) { + console.error(error); + await LoginApi.silentRefresh(); + await authCheck(); + } + })(); + }, []); + + return <>{children}; +}; + +export { AuthWrapper }; diff --git a/apps/common/features/src/entities/code/ui/code-select.tsx b/apps/common/features/src/entities/code/ui/code-select.tsx index bd175a8a9..441f334e3 100644 --- a/apps/common/features/src/entities/code/ui/code-select.tsx +++ b/apps/common/features/src/entities/code/ui/code-select.tsx @@ -11,9 +11,15 @@ import { CodeApi } from "../api/code-service"; type CodeSelectProps = { upCd: string; + placeholder?: string; } & React.ComponentPropsWithoutRef; -function CodeSelect({ upCd, defaultValue, ...props }: CodeSelectProps) { +function CodeSelect({ + upCd, + defaultValue, + placeholder = "선택", + ...props +}: CodeSelectProps) { const { data: code } = useQuery({ queryKey: [ENDPOINT.CMS_SERVICE.CODE, upCd], queryFn: () => CodeApi.getCode(upCd), @@ -21,7 +27,7 @@ function CodeSelect({ upCd, defaultValue, ...props }: CodeSelectProps) { }); const defaultValueText = - code?.find((item) => item.lwpoCd === defaultValue)?.lwpoCdNm ?? "선택"; + code?.find((item) => item.lwpoCd === defaultValue)?.lwpoCdNm ?? placeholder; return ( + + + )} + /> + + + + 작성자 + + } + render={({ field }) => ( + + + + + + )} + /> + + + {!userInfo?.userUnqId && ( - 제목 - - } - render={({ field }) => ( - - - - - - )} - /> - - - - 작성자 - - } - render={({ field }) => ( - - - - - - )} - /> - 비밀번호 ({ {...field} type="password" value={field.value ?? ""} - className="!text-[1.3rem]" + className="w-[20rem] !text-[1.3rem]" placeholder="비밀번호를 입력해주세요" /> @@ -102,31 +114,33 @@ function NoticeForm({ /> - - 내용 - - } - render={({ field }) => ( - - -