diff --git a/app/pages/form-subscriptions-plan/index.tsx b/app/pages/form-subscriptions-plan/index.tsx index afa0a7a..da5c4d8 100644 --- a/app/pages/form-subscriptions-plan/index.tsx +++ b/app/pages/form-subscriptions-plan/index.tsx @@ -16,7 +16,7 @@ export const createSubscribePlanSchema = z.object({ code: z.string(), length: z.preprocess(Number, z.number().optional()), price: z.preprocess(Number, z.number().optional()), - status: z.boolean().optional(), + status: z.number().optional(), }) export type TSubscribePlanSchema = z.infer type TProperties = { diff --git a/app/routes/_admin.lg-admin._dashboard.categories.update.$id.tsx b/app/routes/_admin.lg-admin._dashboard.categories.update.$id.tsx index 5185b98..5e293c7 100644 --- a/app/routes/_admin.lg-admin._dashboard.categories.update.$id.tsx +++ b/app/routes/_admin.lg-admin._dashboard.categories.update.$id.tsx @@ -1,3 +1,5 @@ +import { isRouteErrorResponse } from 'react-router' + import { getCategories } from '~/apis/common/get-categories' import { FormCategoryPage } from '~/pages/form-category' @@ -11,6 +13,35 @@ export const loader = async ({ params }: Route.LoaderArgs) => { return { categoryData } } +export const ErrorBoundary = ({ error }: Route.ErrorBoundaryProps) => { + let message = 'Oops!' + let details = 'An unexpected error occurred.' + let stack: string | undefined + + if (isRouteErrorResponse(error)) { + message = error.status === 404 ? '404' : 'Error' + details = + error.status === 404 + ? 'The requested page could not be found.' + : error.statusText || details + } else if (import.meta.env.DEV && error && error instanceof Error) { + details = error.message + stack = error.stack + } + + return ( +
+

{message}

+

{details}

+ {stack && ( +
+          {stack}
+        
+ )} +
+ ) +} + const DashboardCategoriesUpdateLayout = ({ loaderData, }: Route.ComponentProps) => { diff --git a/app/routes/_admin.lg-admin._dashboard.contents._index.tsx b/app/routes/_admin.lg-admin._dashboard.contents._index.tsx index 4e409e3..6e55ac0 100644 --- a/app/routes/_admin.lg-admin._dashboard.contents._index.tsx +++ b/app/routes/_admin.lg-admin._dashboard.contents._index.tsx @@ -1,3 +1,5 @@ +import { isRouteErrorResponse } from 'react-router' + import { getNews } from '~/apis/common/get-news' import { ContentsPage } from '~/pages/dashboard-contents' @@ -8,5 +10,34 @@ export const loader = async ({}: Route.LoaderArgs) => { return { newsData } } +export const ErrorBoundary = ({ error }: Route.ErrorBoundaryProps) => { + let message = 'Oops!' + let details = 'An unexpected error occurred.' + let stack: string | undefined + + if (isRouteErrorResponse(error)) { + message = error.status === 404 ? '404' : 'Error' + details = + error.status === 404 + ? 'The requested page could not be found.' + : error.statusText || details + } else if (import.meta.env.DEV && error && error instanceof Error) { + details = error.message + stack = error.stack + } + + return ( +
+

{message}

+

{details}

+ {stack && ( +
+          {stack}
+        
+ )} +
+ ) +} + const DashboardContentsIndexLayout = () => export default DashboardContentsIndexLayout diff --git a/app/routes/_admin.lg-admin._dashboard.contents.update.$slug.tsx b/app/routes/_admin.lg-admin._dashboard.contents.update.$slug.tsx index ef1433e..b2ed7f8 100644 --- a/app/routes/_admin.lg-admin._dashboard.contents.update.$slug.tsx +++ b/app/routes/_admin.lg-admin._dashboard.contents.update.$slug.tsx @@ -1,3 +1,5 @@ +import { isRouteErrorResponse } from 'react-router' + import { getNewsBySlug } from '~/apis/common/get-news-by-slug' import { handleCookie } from '~/libs/cookies' import { FormContentsPage } from '~/pages/form-contents' @@ -13,6 +15,35 @@ export const loader = async ({ request, params }: Route.LoaderArgs) => { return { newsData } } +export const ErrorBoundary = ({ error }: Route.ErrorBoundaryProps) => { + let message = 'Oops!' + let details = 'An unexpected error occurred.' + let stack: string | undefined + + if (isRouteErrorResponse(error)) { + message = error.status === 404 ? '404' : 'Error' + details = + error.status === 404 + ? 'The requested page could not be found.' + : error.statusText || details + } else if (import.meta.env.DEV && error && error instanceof Error) { + details = error.message + stack = error.stack + } + + return ( +
+

{message}

+

{details}

+ {stack && ( +
+          {stack}
+        
+ )} +
+ ) +} + const DashboardContentUpdateLayout = ({ loaderData }: Route.ComponentProps) => { const { newsData } = loaderData || {} return diff --git a/app/routes/_admin.lg-admin._dashboard.subscribe-plan._index.tsx b/app/routes/_admin.lg-admin._dashboard.subscribe-plan._index.tsx index b94fc90..a8cca22 100644 --- a/app/routes/_admin.lg-admin._dashboard.subscribe-plan._index.tsx +++ b/app/routes/_admin.lg-admin._dashboard.subscribe-plan._index.tsx @@ -1,3 +1,5 @@ +import { isRouteErrorResponse } from 'react-router' + import { getSubscriptions } from '~/apis/common/get-subscriptions' import { SubscribePlanPage } from '~/pages/dashboard-plan-subscribe' @@ -7,5 +9,35 @@ export const loader = async ({}: Route.LoaderArgs) => { const { data: subscriptionsData } = await getSubscriptions() return { subscriptionsData } } + +export const ErrorBoundary = ({ error }: Route.ErrorBoundaryProps) => { + let message = 'Oops!' + let details = 'An unexpected error occurred.' + let stack: string | undefined + + if (isRouteErrorResponse(error)) { + message = error.status === 404 ? '404' : 'Error' + details = + error.status === 404 + ? 'The requested page could not be found.' + : error.statusText || details + } else if (import.meta.env.DEV && error && error instanceof Error) { + details = error.message + stack = error.stack + } + + return ( +
+

{message}

+

{details}

+ {stack && ( +
+          {stack}
+        
+ )} +
+ ) +} + const DashboardSubscriptionsSettingsLayout = () => export default DashboardSubscriptionsSettingsLayout diff --git a/app/routes/_admin.lg-admin._dashboard.subscribe-plan.update.$id.tsx b/app/routes/_admin.lg-admin._dashboard.subscribe-plan.update.$id.tsx index ffb981c..9a2f3d0 100644 --- a/app/routes/_admin.lg-admin._dashboard.subscribe-plan.update.$id.tsx +++ b/app/routes/_admin.lg-admin._dashboard.subscribe-plan.update.$id.tsx @@ -1,3 +1,5 @@ +import { isRouteErrorResponse } from 'react-router' + import { getSubscriptions } from '~/apis/common/get-subscriptions' import { FormSubscribePlanPage } from '~/pages/form-subscriptions-plan' @@ -11,6 +13,35 @@ export const loader = async ({ params }: Route.LoaderArgs) => { return { subscribePlanData } } +export const ErrorBoundary = ({ error }: Route.ErrorBoundaryProps) => { + let message = 'Oops!' + let details = 'An unexpected error occurred.' + let stack: string | undefined + + if (isRouteErrorResponse(error)) { + message = error.status === 404 ? '404' : 'Error' + details = + error.status === 404 + ? 'The requested page could not be found.' + : error.statusText || details + } else if (import.meta.env.DEV && error && error instanceof Error) { + details = error.message + stack = error.stack + } + + return ( +
+

{message}

+

{details}

+ {stack && ( +
+          {stack}
+        
+ )} +
+ ) +} + const DashboardSubscribePlanUpdateLayout = ({ loaderData, }: Route.ComponentProps) => { diff --git a/app/routes/_admin.lg-admin._dashboard.tags.update.$id.tsx b/app/routes/_admin.lg-admin._dashboard.tags.update.$id.tsx index 05f8ffe..2812f5c 100644 --- a/app/routes/_admin.lg-admin._dashboard.tags.update.$id.tsx +++ b/app/routes/_admin.lg-admin._dashboard.tags.update.$id.tsx @@ -1,3 +1,5 @@ +import { isRouteErrorResponse } from 'react-router' + import { getTags } from '~/apis/common/get-tags' import { FormTagPage } from '~/pages/form-tag' @@ -9,6 +11,35 @@ export const loader = async ({ params }: Route.LoaderArgs) => { return { tagData } } +export const ErrorBoundary = ({ error }: Route.ErrorBoundaryProps) => { + let message = 'Oops!' + let details = 'An unexpected error occurred.' + let stack: string | undefined + + if (isRouteErrorResponse(error)) { + message = error.status === 404 ? '404' : 'Error' + details = + error.status === 404 + ? 'The requested page could not be found.' + : error.statusText || details + } else if (import.meta.env.DEV && error && error instanceof Error) { + details = error.message + stack = error.stack + } + + return ( +
+

{message}

+

{details}

+ {stack && ( +
+          {stack}
+        
+ )} +
+ ) +} + const DashboardTagUpdateLayout = ({ loaderData }: Route.ComponentProps) => { const { tagData } = loaderData || {} return diff --git a/app/routes/_admin.lg-admin._dashboard.tsx b/app/routes/_admin.lg-admin._dashboard.tsx index 61edd57..adb15a1 100644 --- a/app/routes/_admin.lg-admin._dashboard.tsx +++ b/app/routes/_admin.lg-admin._dashboard.tsx @@ -1,4 +1,4 @@ -import { Outlet } from 'react-router' +import { isRouteErrorResponse, Outlet } from 'react-router' import { getCategories } from '~/apis/common/get-categories' import { getTags } from '~/apis/common/get-tags' @@ -17,6 +17,35 @@ export const loader = async ({}: Route.LoaderArgs) => { } } +export const ErrorBoundary = ({ error }: Route.ErrorBoundaryProps) => { + let message = 'Oops!' + let details = 'An unexpected error occurred.' + let stack: string | undefined + + if (isRouteErrorResponse(error)) { + message = error.status === 404 ? '404' : 'Error' + details = + error.status === 404 + ? 'The requested page could not be found.' + : error.statusText || details + } else if (import.meta.env.DEV && error && error instanceof Error) { + details = error.message + stack = error.stack + } + + return ( +
+

{message}

+

{details}

+ {stack && ( +
+          {stack}
+        
+ )} +
+ ) +} + const DashboardLayout = () => { return ( diff --git a/app/routes/_admin.lg-admin.tsx b/app/routes/_admin.lg-admin.tsx index 3beecde..c00c895 100644 --- a/app/routes/_admin.lg-admin.tsx +++ b/app/routes/_admin.lg-admin.tsx @@ -1,4 +1,4 @@ -import { Outlet, redirect } from 'react-router' +import { isRouteErrorResponse, Outlet, redirect } from 'react-router' import { XiorError } from 'xior' import { getStaff } from '~/apis/admin/get-staff' @@ -41,6 +41,35 @@ export const loader = async ({ request }: Route.LoaderArgs) => { } } +export const ErrorBoundary = ({ error }: Route.ErrorBoundaryProps) => { + let message = 'Oops!' + let details = 'An unexpected error occurred.' + let stack: string | undefined + + if (isRouteErrorResponse(error)) { + message = error.status === 404 ? '404' : 'Error' + details = + error.status === 404 + ? 'The requested page could not be found.' + : error.statusText || details + } else if (import.meta.env.DEV && error && error instanceof Error) { + details = error.message + stack = error.stack + } + + return ( +
+

{message}

+

{details}

+ {stack && ( +
+          {stack}
+        
+ )} +
+ ) +} + const AdminLayout = () => { return ( diff --git a/app/routes/_news._index.tsx b/app/routes/_news._index.tsx index 6b1e187..2a10664 100644 --- a/app/routes/_news._index.tsx +++ b/app/routes/_news._index.tsx @@ -1,3 +1,5 @@ +import { isRouteErrorResponse } from 'react-router' + import { getCategories } from '~/apis/common/get-categories' import { getNews } from '~/apis/common/get-news' import { NewsPage } from '~/pages/news' @@ -35,6 +37,35 @@ export const loader = async ({}: Route.LoaderArgs) => { } } +export const ErrorBoundary = ({ error }: Route.ErrorBoundaryProps) => { + let message = 'Oops!' + let details = 'An unexpected error occurred.' + let stack: string | undefined + + if (isRouteErrorResponse(error)) { + message = error.status === 404 ? '404' : 'Error' + details = + error.status === 404 + ? 'The requested page could not be found.' + : error.statusText || details + } else if (import.meta.env.DEV && error && error instanceof Error) { + details = error.message + stack = error.stack + } + + return ( +
+

{message}

+

{details}

+ {stack && ( +
+          {stack}
+        
+ )} +
+ ) +} + const NewsIndexLayout = () => export default NewsIndexLayout diff --git a/app/routes/_news.category.$code.tsx b/app/routes/_news.category.$code.tsx index 3aab2d1..db70c43 100644 --- a/app/routes/_news.category.$code.tsx +++ b/app/routes/_news.category.$code.tsx @@ -1,3 +1,5 @@ +import { isRouteErrorResponse } from 'react-router' + import { getCategories } from '~/apis/common/get-categories' import { getNews } from '~/apis/common/get-news' import { APP } from '~/configs/meta' @@ -26,6 +28,35 @@ export const meta = ({ data }: Route.MetaArgs) => { ] } +export const ErrorBoundary = ({ error }: Route.ErrorBoundaryProps) => { + let message = 'Oops!' + let details = 'An unexpected error occurred.' + let stack: string | undefined + + if (isRouteErrorResponse(error)) { + message = error.status === 404 ? '404' : 'Error' + details = + error.status === 404 + ? 'The requested page could not be found.' + : error.statusText || details + } else if (import.meta.env.DEV && error && error instanceof Error) { + details = error.message + stack = error.stack + } + + return ( +
+

{message}

+

{details}

+ {stack && ( +
+          {stack}
+        
+ )} +
+ ) +} + const NewsCategoriesLayout = () => export default NewsCategoriesLayout diff --git a/app/routes/_news.detail.$slug.tsx b/app/routes/_news.detail.$slug.tsx index 40b7156..5802810 100644 --- a/app/routes/_news.detail.$slug.tsx +++ b/app/routes/_news.detail.$slug.tsx @@ -1,3 +1,5 @@ +import { isRouteErrorResponse } from 'react-router' + import { getCategories } from '~/apis/common/get-categories' import { getNews } from '~/apis/common/get-news' import { getNewsBySlug } from '~/apis/common/get-news-by-slug' @@ -39,6 +41,35 @@ export const meta = ({ data }: Route.MetaArgs) => { ] } +export const ErrorBoundary = ({ error }: Route.ErrorBoundaryProps) => { + let message = 'Oops!' + let details = 'An unexpected error occurred.' + let stack: string | undefined + + if (isRouteErrorResponse(error)) { + message = error.status === 404 ? '404' : 'Error' + details = + error.status === 404 + ? 'The requested page could not be found.' + : error.statusText || details + } else if (import.meta.env.DEV && error && error instanceof Error) { + details = error.message + stack = error.stack + } + + return ( +
+

{message}

+

{details}

+ {stack && ( +
+          {stack}
+        
+ )} +
+ ) +} + const NewsDetailLayout = () => export default NewsDetailLayout diff --git a/app/routes/_news.tsx b/app/routes/_news.tsx index 2ec9028..c0e4393 100644 --- a/app/routes/_news.tsx +++ b/app/routes/_news.tsx @@ -1,4 +1,4 @@ -import { Outlet } from 'react-router' +import { isRouteErrorResponse, Outlet } from 'react-router' import { XiorError } from 'xior' import { getCategories } from '~/apis/common/get-categories' @@ -36,6 +36,35 @@ export const loader = async ({ request }: Route.LoaderArgs) => { } } +export const ErrorBoundary = ({ error }: Route.ErrorBoundaryProps) => { + let message = 'Oops!' + let details = 'An unexpected error occurred.' + let stack: string | undefined + + if (isRouteErrorResponse(error)) { + message = error.status === 404 ? '404' : 'Error' + details = + error.status === 404 + ? 'The requested page could not be found.' + : error.statusText || details + } else if (import.meta.env.DEV && error && error instanceof Error) { + details = error.message + stack = error.stack + } + + return ( +
+

{message}

+

{details}

+ {stack && ( +
+          {stack}
+        
+ )} +
+ ) +} + const NewsLayout = () => { return (