Skip to content

Commit 2240eff

Browse files
committed
refactor: update error routes (#192)
* refactor: update error routes Move error routes to a dedicated folder and update sidebar data accordingly. * refactor: add header to error pages layout
1 parent f3d77e3 commit 2240eff

4 files changed

Lines changed: 73 additions & 7 deletions

File tree

src/components/layout/data/sidebar-data.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,27 +131,27 @@ export const sidebarData: SidebarData = {
131131
items: [
132132
{
133133
title: 'Unauthorized',
134-
url: '/401',
134+
url: '/errors/unauthorized',
135135
icon: Lock,
136136
},
137137
{
138138
title: 'Forbidden',
139-
url: '/403',
139+
url: '/errors/forbidden',
140140
icon: UserX,
141141
},
142142
{
143143
title: 'Not Found',
144-
url: '/404',
144+
url: '/errors/not-found',
145145
icon: FileX,
146146
},
147147
{
148148
title: 'Internal Server Error',
149-
url: '/500',
149+
url: '/errors/internal-server-error',
150150
icon: ServerOff,
151151
},
152152
{
153153
title: 'Maintenance Error',
154-
url: '/503',
154+
url: '/errors/maintenance-error',
155155
icon: Construction,
156156
},
157157
],

src/components/layout/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ interface BaseNavItem {
1919
}
2020

2121
type NavLink = BaseNavItem & {
22-
url: LinkProps['to']
22+
url: LinkProps['to'] | (string & {})
2323
items?: never
2424
}
2525

2626
type NavCollapsible = BaseNavItem & {
27-
items: (BaseNavItem & { url: LinkProps['to'] })[]
27+
items: (BaseNavItem & { url: LinkProps['to'] | (string & {}) })[]
2828
url?: never
2929
}
3030

src/routeTree.gen.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { Route as AuthenticatedSettingsNotificationsRouteImport } from './routes
3838
import { Route as AuthenticatedSettingsDisplayRouteImport } from './routes/_authenticated/settings/display'
3939
import { Route as AuthenticatedSettingsAppearanceRouteImport } from './routes/_authenticated/settings/appearance'
4040
import { Route as AuthenticatedSettingsAccountRouteImport } from './routes/_authenticated/settings/account'
41+
import { Route as AuthenticatedErrorsErrorRouteImport } from './routes/_authenticated/errors/$error'
4142

4243
const ClerkRouteRoute = ClerkRouteRouteImport.update({
4344
id: '/clerk',
@@ -189,6 +190,12 @@ const AuthenticatedSettingsAccountRoute =
189190
path: '/account',
190191
getParentRoute: () => AuthenticatedSettingsRouteRoute,
191192
} as any)
193+
const AuthenticatedErrorsErrorRoute =
194+
AuthenticatedErrorsErrorRouteImport.update({
195+
id: '/errors/$error',
196+
path: '/errors/$error',
197+
getParentRoute: () => AuthenticatedRouteRoute,
198+
} as any)
192199

193200
export interface FileRoutesByFullPath {
194201
'/clerk': typeof ClerkAuthenticatedRouteRouteWithChildren
@@ -205,6 +212,7 @@ export interface FileRoutesByFullPath {
205212
'/500': typeof errors500Route
206213
'/503': typeof errors503Route
207214
'/': typeof AuthenticatedIndexRoute
215+
'/errors/$error': typeof AuthenticatedErrorsErrorRoute
208216
'/settings/account': typeof AuthenticatedSettingsAccountRoute
209217
'/settings/appearance': typeof AuthenticatedSettingsAppearanceRoute
210218
'/settings/display': typeof AuthenticatedSettingsDisplayRoute
@@ -232,6 +240,7 @@ export interface FileRoutesByTo {
232240
'/500': typeof errors500Route
233241
'/503': typeof errors503Route
234242
'/': typeof AuthenticatedIndexRoute
243+
'/errors/$error': typeof AuthenticatedErrorsErrorRoute
235244
'/settings/account': typeof AuthenticatedSettingsAccountRoute
236245
'/settings/appearance': typeof AuthenticatedSettingsAppearanceRoute
237246
'/settings/display': typeof AuthenticatedSettingsDisplayRoute
@@ -264,6 +273,7 @@ export interface FileRoutesById {
264273
'/(errors)/500': typeof errors500Route
265274
'/(errors)/503': typeof errors503Route
266275
'/_authenticated/': typeof AuthenticatedIndexRoute
276+
'/_authenticated/errors/$error': typeof AuthenticatedErrorsErrorRoute
267277
'/_authenticated/settings/account': typeof AuthenticatedSettingsAccountRoute
268278
'/_authenticated/settings/appearance': typeof AuthenticatedSettingsAppearanceRoute
269279
'/_authenticated/settings/display': typeof AuthenticatedSettingsDisplayRoute
@@ -295,6 +305,7 @@ export interface FileRouteTypes {
295305
| '/500'
296306
| '/503'
297307
| '/'
308+
| '/errors/$error'
298309
| '/settings/account'
299310
| '/settings/appearance'
300311
| '/settings/display'
@@ -322,6 +333,7 @@ export interface FileRouteTypes {
322333
| '/500'
323334
| '/503'
324335
| '/'
336+
| '/errors/$error'
325337
| '/settings/account'
326338
| '/settings/appearance'
327339
| '/settings/display'
@@ -353,6 +365,7 @@ export interface FileRouteTypes {
353365
| '/(errors)/500'
354366
| '/(errors)/503'
355367
| '/_authenticated/'
368+
| '/_authenticated/errors/$error'
356369
| '/_authenticated/settings/account'
357370
| '/_authenticated/settings/appearance'
358371
| '/_authenticated/settings/display'
@@ -588,6 +601,13 @@ declare module '@tanstack/react-router' {
588601
preLoaderRoute: typeof AuthenticatedSettingsAccountRouteImport
589602
parentRoute: typeof AuthenticatedSettingsRouteRoute
590603
}
604+
'/_authenticated/errors/$error': {
605+
id: '/_authenticated/errors/$error'
606+
path: '/errors/$error'
607+
fullPath: '/errors/$error'
608+
preLoaderRoute: typeof AuthenticatedErrorsErrorRouteImport
609+
parentRoute: typeof AuthenticatedRouteRoute
610+
}
591611
}
592612
}
593613

@@ -617,6 +637,7 @@ const AuthenticatedSettingsRouteRouteWithChildren =
617637
interface AuthenticatedRouteRouteChildren {
618638
AuthenticatedSettingsRouteRoute: typeof AuthenticatedSettingsRouteRouteWithChildren
619639
AuthenticatedIndexRoute: typeof AuthenticatedIndexRoute
640+
AuthenticatedErrorsErrorRoute: typeof AuthenticatedErrorsErrorRoute
620641
AuthenticatedAppsIndexRoute: typeof AuthenticatedAppsIndexRoute
621642
AuthenticatedChatsIndexRoute: typeof AuthenticatedChatsIndexRoute
622643
AuthenticatedHelpCenterIndexRoute: typeof AuthenticatedHelpCenterIndexRoute
@@ -627,6 +648,7 @@ interface AuthenticatedRouteRouteChildren {
627648
const AuthenticatedRouteRouteChildren: AuthenticatedRouteRouteChildren = {
628649
AuthenticatedSettingsRouteRoute: AuthenticatedSettingsRouteRouteWithChildren,
629650
AuthenticatedIndexRoute: AuthenticatedIndexRoute,
651+
AuthenticatedErrorsErrorRoute: AuthenticatedErrorsErrorRoute,
630652
AuthenticatedAppsIndexRoute: AuthenticatedAppsIndexRoute,
631653
AuthenticatedChatsIndexRoute: AuthenticatedChatsIndexRoute,
632654
AuthenticatedHelpCenterIndexRoute: AuthenticatedHelpCenterIndexRoute,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { createFileRoute } from '@tanstack/react-router'
2+
import { ConfigDrawer } from '@/components/config-drawer'
3+
import { Header } from '@/components/layout/header'
4+
import { ProfileDropdown } from '@/components/profile-dropdown'
5+
import { Search } from '@/components/search'
6+
import { ThemeSwitch } from '@/components/theme-switch'
7+
import ForbiddenError from '@/features/errors/forbidden'
8+
import GeneralError from '@/features/errors/general-error'
9+
import MaintenanceError from '@/features/errors/maintenance-error'
10+
import NotFoundError from '@/features/errors/not-found-error'
11+
import UnauthorisedError from '@/features/errors/unauthorized-error'
12+
13+
export const Route = createFileRoute('/_authenticated/errors/$error')({
14+
component: RouteComponent,
15+
})
16+
17+
function RouteComponent() {
18+
const { error } = Route.useParams()
19+
20+
const errorMap: Record<string, React.ComponentType> = {
21+
unauthorized: UnauthorisedError,
22+
forbidden: ForbiddenError,
23+
'not-found': NotFoundError,
24+
'internal-server-error': GeneralError,
25+
'maintenance-error': MaintenanceError,
26+
}
27+
const ErrorComponent = errorMap[error] || NotFoundError
28+
29+
return (
30+
<>
31+
<Header fixed className='border-b'>
32+
<Search />
33+
<div className='ms-auto flex items-center space-x-4'>
34+
<ThemeSwitch />
35+
<ConfigDrawer />
36+
<ProfileDropdown />
37+
</div>
38+
</Header>
39+
<div className='flex-1 [&>div]:h-full'>
40+
<ErrorComponent />
41+
</div>
42+
</>
43+
)
44+
}

0 commit comments

Comments
 (0)