1- import { createBrowserRouter } from "react-router-dom" ;
1+ import { Paper , Typography } from "@mui/material" ;
2+ import { createBrowserRouter , useRouteError } from "react-router-dom" ;
23import { App } from "./App" ;
34import { Dashboard } from "./components/dashboard/Dashboard" ;
4- import { UserProvider } from "./contexts/UserContext" ;
5+ import { LoginButton } from "./components/dashboard/LoginButton" ;
6+ import { UserProvider , UserTokenMissingError } from "./contexts/UserContext" ;
57import { AdapterDashboard } from "./tools/adapter/AdapterDashboard" ;
68import { AdapterDetails } from "./tools/adapter/AdapterDetails" ;
79import { AdapterRatings } from "./tools/adapter/AdapterRatings" ;
8- import { AdapterStatistics } from "./tools/adapter/AdapterStatistics" ;
910import { CreateReleaseDialog } from "./tools/adapter/releases/CreateReleaseDialog" ;
1011import { Releases } from "./tools/adapter/releases/Releases" ;
1112import { UpdateRepositoriesDialog } from "./tools/adapter/releases/UpdateRepositoriesDialog" ;
13+ import { Statistics } from "./tools/adapter/statistics/Statistics" ;
1214import { AdapterCheck } from "./tools/AdapterCheck" ;
1315import { StartCreateAdapter } from "./tools/create-adapter/StartCreateAdapter" ;
1416import { Wizard } from "./tools/create-adapter/Wizard" ;
@@ -24,66 +26,89 @@ export const router = createBrowserRouter([
2426
2527 children : [
2628 {
27- path : "/create-adapter" ,
29+ path : "/" ,
30+ errorElement : < ErrorBoundary /> ,
2831 children : [
2932 {
30- index : true ,
31- element : < StartCreateAdapter /> ,
33+ path : "/create-adapter" ,
34+ children : [
35+ {
36+ index : true ,
37+ element : < StartCreateAdapter /> ,
38+ } ,
39+ {
40+ path : "wizard" ,
41+ element : < Wizard /> ,
42+ } ,
43+ ] ,
3244 } ,
3345 {
34- path : "wizard " ,
35- element : < Wizard /> ,
46+ path : "/adapter-check " ,
47+ element : < AdapterCheck /> ,
3648 } ,
37- ] ,
38- } ,
39- {
40- path : "/adapter-check" ,
41- element : < AdapterCheck /> ,
42- } ,
43- {
44- path : "/adapter/:name" ,
45- element : < AdapterDetails /> ,
46- children : [
4749 {
48- index : true ,
49- element : < AdapterDashboard /> ,
50- } ,
51- {
52- path : "releases" ,
53- element : < Releases /> ,
50+ path : "/adapter/:name" ,
51+ element : < AdapterDetails /> ,
5452 children : [
5553 {
56- path : "~release" ,
57- element : < CreateReleaseDialog /> ,
54+ index : true ,
55+ element : < AdapterDashboard /> ,
5856 } ,
5957 {
60- path : "~to-latest" ,
61- element : (
62- < UpdateRepositoriesDialog action = "to-latest" />
63- ) ,
58+ path : "releases" ,
59+ element : < Releases /> ,
60+ children : [
61+ {
62+ path : "~release" ,
63+ element : < CreateReleaseDialog /> ,
64+ } ,
65+ {
66+ path : "~to-latest" ,
67+ element : (
68+ < UpdateRepositoriesDialog action = "to-latest" />
69+ ) ,
70+ } ,
71+ {
72+ path : "~to-stable/:version" ,
73+ element : (
74+ < UpdateRepositoriesDialog action = "to-stable" />
75+ ) ,
76+ } ,
77+ ] ,
6478 } ,
6579 {
66- path : "~to-stable/:version" ,
67- element : (
68- < UpdateRepositoriesDialog action = "to-stable" />
69- ) ,
80+ path : "statistics" ,
81+ element : < Statistics /> ,
82+ } ,
83+ {
84+ path : "ratings" ,
85+ element : < AdapterRatings /> ,
7086 } ,
7187 ] ,
7288 } ,
7389 {
74- path : "statistics" ,
75- element : < AdapterStatistics /> ,
76- } ,
77- {
78- path : "ratings" ,
79- element : < AdapterRatings /> ,
90+ index : true ,
91+ element : < Dashboard /> ,
8092 } ,
8193 ] ,
8294 } ,
83- {
84- index : true ,
85- element : < Dashboard /> ,
86- } ,
8795 ] ,
8896 } ,
8997] ) ;
98+
99+ function ErrorBoundary ( ) {
100+ let error = useRouteError ( ) ;
101+ if ( error instanceof UserTokenMissingError ) {
102+ return (
103+ < Paper sx = { { padding : 2 } } >
104+ < Typography variant = "h4" > Not logged in</ Typography >
105+ < p > You need to be logged in to access this page.</ p >
106+ < p >
107+ < LoginButton variant = "contained" />
108+ </ p >
109+ </ Paper >
110+ ) ;
111+ }
112+
113+ throw error ;
114+ }
0 commit comments