app.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import { Route, Routes, Navigate } from 'react-router-dom';
  2. import { useAtomValue } from 'jotai';
  3. import { Layout } from '../components/layout';
  4. import { ThemeProvider } from '../components/theme-provider';
  5. import { ProtectedRoute } from '../components/protected-route';
  6. import { AdminRoute } from '../components/admin-route';
  7. import { LoginForm } from '../components/login-form';
  8. import { RegisterForm } from '../components/register-form';
  9. import { OAuthCallback } from '../components/oauth-callback';
  10. import { isAuthenticatedAtom } from '../atoms/auth-atoms';
  11. import {
  12. HomeView,
  13. NotFoundView,
  14. ProjectsView,
  15. ProjectEditView,
  16. ProjectConfigView,
  17. TasksView,
  18. AnnotationsView,
  19. AnnotationView,
  20. UserManagementView,
  21. MyTasksView,
  22. ExternalProjectsView,
  23. } from '../views';
  24. import { ProjectAnnotationView } from '../views/project-annotation-view';
  25. import { EditorTest } from '../views/editor-test';
  26. import { ToastContainer } from '../components/toast-container';
  27. import { ErrorBoundary } from '../components/error-boundary';
  28. /**
  29. * Annotation Platform Application
  30. *
  31. * This is the main application component for the annotation platform.
  32. * It provides routing and integrates with Layout component for
  33. * backend management UI style.
  34. *
  35. * Includes JWT authentication with protected routes.
  36. *
  37. * Requirements: 4.1, 4.2, 4.8, 7.3, 7.6, 10.1, 10.3, 10.5, 10.7, 1.1, 2.1, 4.1
  38. */
  39. export function App() {
  40. const isAuthenticated = useAtomValue(isAuthenticatedAtom);
  41. return (
  42. <ThemeProvider>
  43. <ErrorBoundary>
  44. <Routes>
  45. {/* Public Routes - Login and Register */}
  46. <Route
  47. path="/login"
  48. element={
  49. isAuthenticated ? <Navigate to="/" replace /> : <LoginForm />
  50. }
  51. />
  52. <Route
  53. path="/register"
  54. element={
  55. isAuthenticated ? <Navigate to="/" replace /> : <RegisterForm />
  56. }
  57. />
  58. <Route path="/auth/callback" element={<OAuthCallback />} />
  59. {/* Protected Routes - Require Authentication */}
  60. <Route
  61. path="/*"
  62. element={
  63. <ProtectedRoute>
  64. <Layout>
  65. <Routes>
  66. {/* Home Route */}
  67. <Route path="/" element={<HomeView />} />
  68. {/* Editor Test Route */}
  69. <Route path="/editor-test" element={<EditorTest />} />
  70. {/* Projects Routes */}
  71. <Route path="/projects" element={<ProjectsView />} />
  72. <Route
  73. path="/projects/:id/edit"
  74. element={<ProjectEditView />}
  75. />
  76. <Route
  77. path="/projects/:projectId/config"
  78. element={<ProjectConfigView />}
  79. />
  80. <Route
  81. path="/projects/:projectId/annotate"
  82. element={<ProjectAnnotationView />}
  83. />
  84. {/* External Projects Routes (Admin Only) */}
  85. <Route
  86. path="/external-projects"
  87. element={
  88. <AdminRoute>
  89. <ExternalProjectsView />
  90. </AdminRoute>
  91. }
  92. />
  93. {/* Tasks Routes (Admin Only for /tasks) */}
  94. <Route
  95. path="/tasks"
  96. element={
  97. <AdminRoute>
  98. <TasksView />
  99. </AdminRoute>
  100. }
  101. />
  102. <Route path="/my-tasks" element={<MyTasksView />} />
  103. <Route
  104. path="/tasks/:id/annotate"
  105. element={<AnnotationView />}
  106. />
  107. {/* Annotations Routes */}
  108. <Route path="/annotations" element={<AnnotationsView />} />
  109. {/* User Management Routes (Admin Only) */}
  110. <Route
  111. path="/users"
  112. element={
  113. <AdminRoute>
  114. <UserManagementView />
  115. </AdminRoute>
  116. }
  117. />
  118. {/* 404 Not Found */}
  119. <Route path="*" element={<NotFoundView />} />
  120. </Routes>
  121. </Layout>
  122. </ProtectedRoute>
  123. }
  124. />
  125. </Routes>
  126. {/* Global Toast Container */}
  127. <ToastContainer />
  128. </ErrorBoundary>
  129. </ThemeProvider>
  130. );
  131. }
  132. export default App;