diff --git a/package-lock.json b/package-lock.json index b1082918..2725a8b4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "react": "^19.2.0", "react-apexcharts": "^2.0.1", "react-dom": "^19.2.0", + "react-error-boundary": "^6.1.2", "react-hook-form": "^7.71.1", "react-markdown": "^10.1.0", "react-remove-scroll": "^2.7.2", @@ -32,6 +33,7 @@ "@commitlint/cli": "^20.3.1", "@commitlint/config-conventional": "^20.3.1", "@eslint/js": "^9.39.2", + "@playwright/test": "^1.60.0", "@storybook/addon-essentials": "8.6.17", "@storybook/react": "8.6.17", "@storybook/react-vite": "8.6.17", @@ -43,6 +45,7 @@ "@typescript-eslint/eslint-plugin": "^8.53.0", "@typescript-eslint/parser": "^8.53.0", "@vitejs/plugin-react-swc": "^3.11.0", + "dotenv": "^17.4.2", "eslint": "^9.39.2", "eslint-config-prettier": "^10.1.8", "eslint-plugin-import": "^2.32.0", @@ -1508,6 +1511,22 @@ "url": "https://opencollective.com/pkgr" } }, + "node_modules/@playwright/test": { + "version": "1.61.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.61.1.tgz", + "integrity": "sha512-8nKv6+0RJSL9FE4jYOEGXnPeM/Hg12qZpmqzZjRh3qM0Y7c3z1mrOTfFLids72RDQYVh9WpLEfR5WdpNX4fkig==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright": "1.61.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/@rolldown/pluginutils": { "version": "1.0.0-beta.27", "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.0.0-beta.27.tgz", @@ -5044,6 +5063,19 @@ "node": ">=8" } }, + "node_modules/dotenv": { + "version": "17.4.2", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.4.2.tgz", + "integrity": "sha512-nI4U3TottKAcAD9LLud4Cb7b2QztQMUEfHbvhTH09bqXTxnSie8WnjPALV/WMCrJZ6UV/qHJ6L03OqO3LcdYZw==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", @@ -9215,6 +9247,53 @@ "node": ">=0.10" } }, + "node_modules/playwright": { + "version": "1.61.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.61.1.tgz", + "integrity": "sha512-DWnY5o3YbLWK4GovuAVwpqL+1VwGNdUGrRr++8j8PtQQzvAVZUIMjKQ90fY689sEJZJBbZVw1rXaOKSTitkzPQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.61.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.61.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.61.1.tgz", + "integrity": "sha512-h7Qlt6m4REp25qvIdvbDtVmD4LqVXfpRxhORv9L0jzETM05p4fuPJ3dKyuSXQxDSbXnmS79HAgi9589lGSpLkg==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/playwright/node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/polished": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/polished/-/polished-4.3.1.tgz", @@ -9476,6 +9555,15 @@ "react": "^19.2.4" } }, + "node_modules/react-error-boundary": { + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/react-error-boundary/-/react-error-boundary-6.1.2.tgz", + "integrity": "sha512-3DpCr5HVdZ0caUjYE/kIHBEJN0mNP3ZCgf16c48uJ5TbWjorKVp+YG8W3XqlJ7vJAVNw6wNIImyPXmFydwmyng==", + "license": "MIT", + "peerDependencies": { + "react": "^18.0.0 || ^19.0.0" + } + }, "node_modules/react-hook-form": { "version": "7.71.1", "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.71.1.tgz", diff --git a/package.json b/package.json index 7860646f..981de919 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "react": "^19.2.0", "react-apexcharts": "^2.0.1", "react-dom": "^19.2.0", + "react-error-boundary": "^6.1.2", "react-hook-form": "^7.71.1", "react-markdown": "^10.1.0", "react-remove-scroll": "^2.7.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 85c8cda9..1aa270f7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -38,6 +38,9 @@ importers: react-dom: specifier: ^19.2.0 version: 19.2.4(react@19.2.4) + react-error-boundary: + specifier: ^6.1.2 + version: 6.1.2(react@19.2.4) react-hook-form: specifier: ^7.71.1 version: 7.71.1(react@19.2.4) @@ -2925,6 +2928,11 @@ packages: peerDependencies: react: ^19.2.4 + react-error-boundary@6.1.2: + resolution: {integrity: sha512-3DpCr5HVdZ0caUjYE/kIHBEJN0mNP3ZCgf16c48uJ5TbWjorKVp+YG8W3XqlJ7vJAVNw6wNIImyPXmFydwmyng==} + peerDependencies: + react: ^18.0.0 || ^19.0.0 + react-hook-form@7.71.1: resolution: {integrity: sha512-9SUJKCGKo8HUSsCO+y0CtqkqI5nNuaDqTxyqPsZPqIwudpj4rCrAz/jZV+jn57bx5gtZKOh3neQu94DXMc+w5w==} engines: {node: '>=18.0.0'} @@ -6553,6 +6561,10 @@ snapshots: react: 19.2.4 scheduler: 0.27.0 + react-error-boundary@6.1.2(react@19.2.4): + dependencies: + react: 19.2.4 + react-hook-form@7.71.1(react@19.2.4): dependencies: react: 19.2.4 diff --git a/src/components/common/ComingSoonPlaceholder.tsx b/src/components/common/ComingSoonPlaceholder.tsx index 8011f96f..46957a36 100644 --- a/src/components/common/ComingSoonPlaceholder.tsx +++ b/src/components/common/ComingSoonPlaceholder.tsx @@ -52,7 +52,7 @@ const ComingSoonPlaceholder = memo(function ComingSoonPlaceholder({ )} > = { + title: "Common/Error/ChartErrorFallback", + component: ChartErrorFallback, + args: { + error: new Error("차트 데이터를 불러오지 못했습니다."), + resetErrorBoundary: fn(), + }, + parameters: { layout: "centered" }, +}; + +export default meta; +type TStory = StoryObj; + +export const Default: TStory = {}; + +export const InCard: TStory = { + render: (args) => ( +
+

실시간 트래픽 변화

+ +
+ ), +}; diff --git a/src/components/common/error/ChartErrorFallback.tsx b/src/components/common/error/ChartErrorFallback.tsx new file mode 100644 index 00000000..89751fac --- /dev/null +++ b/src/components/common/error/ChartErrorFallback.tsx @@ -0,0 +1,34 @@ +import { memo } from "react"; + +import Button from "@/components/common/button/Button"; + +import type { FallbackProps } from "./ErrorBoundary"; + +import WarnCircleIcon from "@/assets/icon/common/warn-circle.svg?react"; + +const ChartErrorFallback = memo(function ChartErrorFallback({ + resetErrorBoundary, +}: FallbackProps) { + return ( +
+
+ ); +}); + +export default ChartErrorFallback; diff --git a/src/components/common/error/ErrorBoundary.tsx b/src/components/common/error/ErrorBoundary.tsx new file mode 100644 index 00000000..496b8ff5 --- /dev/null +++ b/src/components/common/error/ErrorBoundary.tsx @@ -0,0 +1,6 @@ +export type { FallbackProps } from "react-error-boundary"; +export { + ErrorBoundary, + useErrorBoundary, + withErrorBoundary, +} from "react-error-boundary"; diff --git a/src/components/common/error/ErrorLayout.tsx b/src/components/common/error/ErrorLayout.tsx new file mode 100644 index 00000000..0c7ce050 --- /dev/null +++ b/src/components/common/error/ErrorLayout.tsx @@ -0,0 +1,62 @@ +import { type ReactNode } from "react"; +import { motion, useReducedMotion } from "framer-motion"; + +import WarningIcon from "@/assets/icon/ai/warning.svg?react"; +import { containerVariants, itemVariants } from "@/lib/animation"; + +interface IErrorLayoutProps { + title: string; + description: string; + actions: ReactNode; +} + +function ErrorLayout({ title, description, actions }: IErrorLayoutProps) { + const reduceMotion = useReducedMotion(); + + return ( +
+ + + + + + + {title} + + + + {description} + + + + {actions} + + +
+ ); +} + +export default ErrorLayout; diff --git a/src/components/common/error/MetricErrorFallback.stories.tsx b/src/components/common/error/MetricErrorFallback.stories.tsx new file mode 100644 index 00000000..123b1a36 --- /dev/null +++ b/src/components/common/error/MetricErrorFallback.stories.tsx @@ -0,0 +1,27 @@ +import type { Meta, StoryObj } from "@storybook/react"; +import { fn } from "@storybook/test"; + +import MetricErrorFallback from "./MetricErrorFallback"; + +const meta: Meta = { + title: "Common/Error/MetricErrorFallback", + component: MetricErrorFallback, + args: { + error: new Error("지표 데이터를 불러오지 못했습니다."), + resetErrorBoundary: fn(), + }, + parameters: { layout: "centered" }, +}; + +export default meta; +type TStory = StoryObj; + +export const Default: TStory = {}; + +export const InGrid: TStory = { + render: (args) => ( +
+ +
+ ), +}; diff --git a/src/components/common/error/MetricErrorFallback.tsx b/src/components/common/error/MetricErrorFallback.tsx new file mode 100644 index 00000000..01596f5d --- /dev/null +++ b/src/components/common/error/MetricErrorFallback.tsx @@ -0,0 +1,34 @@ +import { memo } from "react"; + +import Button from "@/components/common/button/Button"; + +import type { FallbackProps } from "./ErrorBoundary"; + +import WarnCircleIcon from "@/assets/icon/common/warn-circle.svg?react"; + +const MetricErrorFallback = memo(function MetricErrorFallback({ + resetErrorBoundary, +}: FallbackProps) { + return ( +
+
+ ); +}); + +export default MetricErrorFallback; diff --git a/src/lib/animation.ts b/src/lib/animation.ts new file mode 100644 index 00000000..d0842947 --- /dev/null +++ b/src/lib/animation.ts @@ -0,0 +1,23 @@ +export const easeOut = [0, 0, 0.2, 1] as const; + +export const containerVariants = { + hidden: {}, + visible: (reduce: boolean) => ({ + transition: { + staggerChildren: reduce ? 0 : 0.05, + delayChildren: 0, + }, + }), +}; + +export const itemVariants = { + hidden: (reduce: boolean) => ({ + opacity: reduce ? 1 : 0, + y: reduce ? 0 : 10, + }), + visible: (reduce: boolean) => ({ + opacity: 1, + y: 0, + transition: { duration: reduce ? 0 : 0.35, ease: easeOut }, + }), +}; diff --git a/src/pages/common/Error.tsx b/src/pages/common/Error.tsx index f3b91f58..f5cc3a07 100644 --- a/src/pages/common/Error.tsx +++ b/src/pages/common/Error.tsx @@ -1,3 +1,48 @@ -export default function Error() { - return
Error
; +import { + isRouteErrorResponse, + useNavigate, + useRouteError, +} from "react-router-dom"; + +import Button from "@/components/common/button/Button"; +import ErrorLayout from "@/components/common/error/ErrorLayout"; + +export default function ErrorPage() { + const error = useRouteError(); + const navigate = useNavigate(); + + const is404 = isRouteErrorResponse(error) && error.status === 404; + const title = is404 ? "페이지를 찾을 수 없어요" : "오류가 발생했어요"; + const description = is404 + ? "요청하신 페이지가 존재하지 않거나\n주소가 변경되었을 수 있어요." + : "일시적인 오류가 발생했습니다.\n잠시 후 다시 시도해 주세요."; + + return ( + + {!is404 && ( + + )} + + + } + /> + ); } diff --git a/src/pages/common/NotFound.tsx b/src/pages/common/NotFound.tsx new file mode 100644 index 00000000..fdbcc275 --- /dev/null +++ b/src/pages/common/NotFound.tsx @@ -0,0 +1,41 @@ +import { useNavigate } from "react-router-dom"; + +import Button from "@/components/common/button/Button"; +import ErrorLayout from "@/components/common/error/ErrorLayout"; + +export default function NotFound() { + const navigate = useNavigate(); + + return ( + + + + + } + /> + ); +} diff --git a/src/pages/dashboard/overview/OverviewDashboard.tsx b/src/pages/dashboard/overview/OverviewDashboard.tsx index 80254208..418cd9c6 100644 --- a/src/pages/dashboard/overview/OverviewDashboard.tsx +++ b/src/pages/dashboard/overview/OverviewDashboard.tsx @@ -4,6 +4,8 @@ import { useBudget } from "@/hooks/dashboard/useBudget"; import { useOverviewMetrics } from "@/hooks/dashboard/useOverviewMetrics"; import { useOverviewRoasRankings } from "@/hooks/dashboard/useOverviewRoasRankings"; +import ChartErrorFallback from "@/components/common/error/ChartErrorFallback"; +import { ErrorBoundary } from "@/components/common/error/ErrorBoundary"; import DashboardAiSummarySection from "@/components/dashboard/ai-report/components/DashboardAiSummarySection"; import { getBudgetStatus } from "@/components/dashboard/charts/BudgetGaugeChart"; @@ -64,18 +66,25 @@ export default function OverviewDashboard() { /> - navigate("/platform")} - /> + + navigate("/platform")} + /> + - + + + ); } diff --git a/src/pages/dashboard/overview/sections/OverviewBudgetSection.tsx b/src/pages/dashboard/overview/sections/OverviewBudgetSection.tsx index 0953aabb..fa68c7d7 100644 --- a/src/pages/dashboard/overview/sections/OverviewBudgetSection.tsx +++ b/src/pages/dashboard/overview/sections/OverviewBudgetSection.tsx @@ -7,6 +7,8 @@ import Card from "@/components/common/card/Card"; import ChartLegend, { type IChartLegendItem, } from "@/components/common/chart/ChartLegend"; +import ChartErrorFallback from "@/components/common/error/ChartErrorFallback"; +import { ErrorBoundary } from "@/components/common/error/ErrorBoundary"; import type { getBudgetStatus } from "@/components/dashboard/charts/BudgetGaugeChart"; import BudgetGaugeChart, { statusBadgeVariant, @@ -58,21 +60,26 @@ export function OverviewBudgetSection({ } >
- {isBudgetError ? ( -
- {budgetError?.message ?? ( - <> - 예산 데이터를 불러오지 못했습니다. -
- 잠시 후 다시 시도해 주세요. - - )} -
- ) : isBudgetLoading ? ( - - ) : budget ? ( - - ) : null} + + {isBudgetError ? ( +
+ {budgetError?.message ?? ( + <> + 예산 데이터를 불러오지 못했습니다. +
+ 잠시 후 다시 시도해 주세요. + + )} +
+ ) : isBudgetLoading ? ( + + ) : budget ? ( + + ) : null} +
diff --git a/src/pages/dashboard/overview/sections/OverviewKpiSection.tsx b/src/pages/dashboard/overview/sections/OverviewKpiSection.tsx index f8d08209..6d54e381 100644 --- a/src/pages/dashboard/overview/sections/OverviewKpiSection.tsx +++ b/src/pages/dashboard/overview/sections/OverviewKpiSection.tsx @@ -9,6 +9,9 @@ import type { useOverviewMetrics } from "@/hooks/dashboard/useOverviewMetrics"; import Card from "@/components/common/card/Card"; import StatCard from "@/components/common/card/StatCard"; import ChartLegend from "@/components/common/chart/ChartLegend"; +import ChartErrorFallback from "@/components/common/error/ChartErrorFallback"; +import { ErrorBoundary } from "@/components/common/error/ErrorBoundary"; +import MetricErrorFallback from "@/components/common/error/MetricErrorFallback"; import TrafficChart, { TrafficChartDownload, } from "@/components/dashboard/charts/TrafficChart"; @@ -32,25 +35,27 @@ export function OverviewKpiSection({ return (
- {isKpisError ? ( -
- {kpisError?.message ?? - "지표 데이터를 불러오지 못했습니다. 잠시 후 다시 시도해 주세요."} -
- ) : ( -
- {isKpisLoading - ? [0, 1, 2, 3].map((i) => ) - : kpiList.map((kpi) => ( - - ))} -
- )} + + {isKpisError ? ( +
+ {kpisError?.message ?? + "지표 데이터를 불러오지 못했습니다. 잠시 후 다시 시도해 주세요."} +
+ ) : ( +
+ {isKpisLoading + ? [0, 1, 2, 3].map((i) => ) + : kpiList.map((kpi) => ( + + ))} +
+ )} +
} >
- }> - - + + }> + + +
diff --git a/src/routes/Router.tsx b/src/routes/Router.tsx index 1d1a1421..42d39d2c 100644 --- a/src/routes/Router.tsx +++ b/src/routes/Router.tsx @@ -7,7 +7,8 @@ import MainRoutes from "./MainRoutes"; import AuthLayout from "@/layout/auth/AuthLayout"; import GlobalLayout from "@/layout/GlobalLayout"; import MainLayout from "@/layout/main/MainLayout"; -import Error from "@/pages/common/Error"; +import ErrorPage from "@/pages/common/Error"; +import NotFound from "@/pages/common/NotFound"; import useAuthStore from "@/store/useAuthStore"; const LandingPage = React.lazy(() => import("@/pages/landing/LandingPage")); @@ -35,11 +36,11 @@ export const router = createBrowserRouter([ ), - errorElement: , + errorElement: , }, { element: , - errorElement: , + errorElement: , children: [ { path: "/landing", @@ -61,6 +62,10 @@ export const router = createBrowserRouter([ ), children: MainRoutes, }, + { + path: "*", + element: , + }, ], }, ]);