From 6b09981430646943aca7e4c20461b1e8fa2ef0e6 Mon Sep 17 00:00:00 2001 From: hamo-o Date: Thu, 5 Sep 2024 01:26:05 +0900 Subject: [PATCH 1/6] =?UTF-8?q?chore:=20react-toastify=20=EC=84=A4?= =?UTF-8?q?=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/admin/package.json | 3 ++- apps/client/package.json | 1 + packages/utils/package.json | 7 ++++--- pnpm-lock.yaml | 20 ++++++++++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/apps/admin/package.json b/apps/admin/package.json index 74112600..5ec0e41a 100644 --- a/apps/admin/package.json +++ b/apps/admin/package.json @@ -17,7 +17,8 @@ "react-clock": "^5.0.0", "react-day-picker": "^9.0.8", "react-dom": "^18.3.1", - "react-hook-form": "^7.53.0" + "react-hook-form": "^7.53.0", + "react-toastify": "^10.0.5" }, "devDependencies": { "@hookform/resolvers": "^3.9.0", diff --git a/apps/client/package.json b/apps/client/package.json index d7c4fb9f..713d0d6d 100644 --- a/apps/client/package.json +++ b/apps/client/package.json @@ -14,6 +14,7 @@ "next": "^14.2.5", "react": "^18.3.1", "react-dom": "^18.3.1", + "react-toastify": "^10.0.5", "wowds-icons": "^0.1.3", "wowds-tokens": "^0.1.1" }, diff --git a/packages/utils/package.json b/packages/utils/package.json index 5410d84a..2845c1b5 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -14,10 +14,11 @@ "@wow-class/typescript-config": "workspace:*", "jest": "^29.7.0", "jest-fetch-mock": "^3.0.3", - "typescript": "^5.3.3", - "ts-jest": "^29.2.4" + "ts-jest": "^29.2.4", + "typescript": "^5.3.3" }, "dependencies": { - "next": "^14.2.5" + "next": "^14.2.5", + "react-toastify": "^10.0.5" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 92d76d02..29eca237 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -72,6 +72,9 @@ importers: react-hook-form: specifier: ^7.53.0 version: 7.53.0(react@18.3.1) + react-toastify: + specifier: ^10.0.5 + version: 10.0.5(react-dom@18.3.1)(react@18.3.1) devDependencies: '@hookform/resolvers': specifier: ^3.9.0 @@ -127,6 +130,9 @@ importers: react-dom: specifier: ^18.3.1 version: 18.3.1(react@18.3.1) + react-toastify: + specifier: ^10.0.5 + version: 10.0.5(react-dom@18.3.1)(react@18.3.1) wowds-icons: specifier: ^0.1.3 version: 0.1.3 @@ -286,6 +292,9 @@ importers: next: specifier: ^14.2.5 version: 14.2.5(@babel/core@7.25.2)(react-dom@18.3.1)(react@18.3.1) + react-toastify: + specifier: ^10.0.5 + version: 10.0.5(react-dom@18.3.1)(react@18.3.1) devDependencies: '@types/jest': specifier: ^29.5.12 @@ -11655,6 +11664,17 @@ packages: - '@types/react-dom' dev: false + /react-toastify@10.0.5(react-dom@18.3.1)(react@18.3.1): + resolution: {integrity: sha512-mNKt2jBXJg4O7pSdbNUfDdTsK9FIdikfsIE/yUCxbAEXl4HMyJaivrVFcn3Elvt5xvCQYhUZm+hqTIu1UXM3Pw==} + peerDependencies: + react: '>=18' + react-dom: '>=18' + dependencies: + clsx: 2.1.1 + react: 18.3.1 + react-dom: 18.3.1(react@18.3.1) + dev: false + /react@18.3.1: resolution: {integrity: sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==} engines: {node: '>=0.10.0'} From 0e0605a17c48f20a3ed2ed97b59929a27c67fbb0 Mon Sep 17 00:00:00 2001 From: hamo-o Date: Thu, 5 Sep 2024 01:27:13 +0900 Subject: [PATCH 2/6] =?UTF-8?q?feat:=20fetcher=EC=97=90=20=EC=9E=84?= =?UTF-8?q?=EC=8B=9C=20=EC=97=90=EB=9F=AC=EC=BD=94=EB=93=9C=20=ED=86=A0?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/utils/src/fetcher/index.ts | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/utils/src/fetcher/index.ts b/packages/utils/src/fetcher/index.ts index c91cc884..d565dd75 100644 --- a/packages/utils/src/fetcher/index.ts +++ b/packages/utils/src/fetcher/index.ts @@ -1,3 +1,5 @@ +import { toast } from "react-toastify"; + type ApiResponse = Response & { data?: T; success?: boolean }; type RequestInterceptor = ( @@ -7,6 +9,8 @@ type ResponseInterceptor = ( response: ApiResponse ) => ApiResponse | Promise>; +const isClient = typeof window !== "undefined"; + class Fetcher { private baseUrl: string; private defaultHeaders: HeadersInit; @@ -68,15 +72,19 @@ class Fetcher { return response.text(); } - private async handleError(response: Response) { + private async handleError( + response: Response, + data: { + errorCodeName: string; + errorMessage: string; + } + ) { if (!response.ok) { - const text = await response.text(); - const error = new Error( - `HTTP Error: ${response.status} ${response.statusText}` - ); - (error as any).response = response; - (error as any).responseText = text; + const error = new Error(); + error.message = data.errorMessage; + error.name = data.errorCodeName; + if (isClient) toast.error(error.message); throw error; } } @@ -96,10 +104,11 @@ class Fetcher { let response: ApiResponse = await fetch(fullUrl, fetchOptions); - await this.handleError(response); + const data = await this.parseJsonResponse(response); + await this.handleError(response, data); response = await this.interceptResponse(response); - response.data = await this.parseJsonResponse(response); + response.data = data; return response; } @@ -162,8 +171,6 @@ class Fetcher { } } -const isClient = typeof window !== "undefined"; - const fetcher = new Fetcher({ baseUrl: process.env.NEXT_PUBLIC_VERCEL_ENV === "production" From 69307d0801df63ffa0410108864c715d5b4a21d4 Mon Sep 17 00:00:00 2001 From: hamo-o Date: Thu, 5 Sep 2024 01:27:43 +0900 Subject: [PATCH 3/6] =?UTF-8?q?feat:=20=EC=96=B4=EB=93=9C=EB=AF=BC,=20?= =?UTF-8?q?=ED=81=B4=EB=9D=BC=EC=9D=B4=EC=96=B8=ED=8A=B8=EC=97=90=20css=20?= =?UTF-8?q?=EB=B0=8F=20=ED=86=A0=EC=8A=A4=ED=8A=B8=20=EC=BB=A8=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EB=84=88=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/admin/app/layout.tsx | 8 ++++++++ apps/client/app/layout.tsx | 13 ++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/apps/admin/app/layout.tsx b/apps/admin/app/layout.tsx index 2129b180..e4cac359 100644 --- a/apps/admin/app/layout.tsx +++ b/apps/admin/app/layout.tsx @@ -1,10 +1,12 @@ import "./global.css"; import "wowds-ui/styles.css"; import "@wow-class/ui/styles.css"; +import "react-toastify/dist/ReactToastify.css"; import { JotaiProvider } from "components/JotaiProvider"; import type { Metadata } from "next"; import type { ReactNode } from "react"; +import { ToastContainer } from "react-toastify"; export const metadata: Metadata = { title: { @@ -48,6 +50,12 @@ const RootLayout = ({ + {children} {modal} diff --git a/apps/client/app/layout.tsx b/apps/client/app/layout.tsx index 3ffa3ccb..8ff1edbc 100644 --- a/apps/client/app/layout.tsx +++ b/apps/client/app/layout.tsx @@ -1,8 +1,10 @@ import "./global.css"; import "wowds-ui/styles.css"; import "@wow-class/ui/styles.css"; +import "react-toastify/dist/ReactToastify.css"; import type { Metadata } from "next"; +import { ToastContainer } from "react-toastify"; import { JotaiProvider } from "../components/JotaiProvider"; @@ -53,7 +55,16 @@ const RootLayout = ({ return ( - {children} + + {" "} + + {children} + ); From 2475b103d881b0518fa055e80b0f4b147cf2429b Mon Sep 17 00:00:00 2001 From: hamo-o Date: Thu, 5 Sep 2024 01:40:03 +0900 Subject: [PATCH 4/6] =?UTF-8?q?fix:=20=EC=84=9C=EB=B2=84=EC=9D=BC=EB=95=8C?= =?UTF-8?q?=EB=A7=8C=20=EC=97=90=EB=9F=AC=20=EB=8D=98=EC=A7=80=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/utils/src/fetcher/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/utils/src/fetcher/index.ts b/packages/utils/src/fetcher/index.ts index d565dd75..451775a3 100644 --- a/packages/utils/src/fetcher/index.ts +++ b/packages/utils/src/fetcher/index.ts @@ -84,8 +84,9 @@ class Fetcher { error.message = data.errorMessage; error.name = data.errorCodeName; - if (isClient) toast.error(error.message); - throw error; + if (isClient) { + toast.error(error.message); + } else throw error; } } From 3e4490197e99c9097f46ae32032b11383907cec9 Mon Sep 17 00:00:00 2001 From: hamo-o Date: Thu, 5 Sep 2024 01:47:56 +0900 Subject: [PATCH 5/6] =?UTF-8?q?chore:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EA=B3=B5=EB=B0=B1=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/client/app/layout.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/client/app/layout.tsx b/apps/client/app/layout.tsx index 8ff1edbc..98cd700f 100644 --- a/apps/client/app/layout.tsx +++ b/apps/client/app/layout.tsx @@ -56,7 +56,6 @@ const RootLayout = ({ - {" "} Date: Thu, 5 Sep 2024 01:49:04 +0900 Subject: [PATCH 6/6] =?UTF-8?q?chore:=20JotaiProvider=20=EB=B0=96=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=ED=86=A0=EC=8A=A4=ED=8A=B8=20=EB=B9=BC=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/admin/app/layout.tsx | 12 ++++++------ apps/client/app/layout.tsx | 16 +++++++--------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/apps/admin/app/layout.tsx b/apps/admin/app/layout.tsx index e4cac359..9555b0b1 100644 --- a/apps/admin/app/layout.tsx +++ b/apps/admin/app/layout.tsx @@ -49,13 +49,13 @@ const RootLayout = ({ return ( + - {children} {modal} diff --git a/apps/client/app/layout.tsx b/apps/client/app/layout.tsx index 98cd700f..a2963883 100644 --- a/apps/client/app/layout.tsx +++ b/apps/client/app/layout.tsx @@ -55,15 +55,13 @@ const RootLayout = ({ return ( - - - {children} - + + {children} );