App.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { Routes, Route, Navigate } from 'react-router-dom'
  2. import { useAuth } from '@/contexts/AuthContext'
  3. import Login from '@/pages/Login'
  4. import Dashboard from '@/pages/Dashboard'
  5. import Collections from '@/pages/Collections'
  6. import Documents from '@/pages/Documents'
  7. import Views from '@/pages/Views'
  8. import Pages from '@/pages/Pages'
  9. import PageDisplay from '@/pages/PageDisplay'
  10. import PageBuilder from '@/components/PageBuilder'
  11. import DocumentForm from '@/pages/DocumentForm'
  12. import Users from '@/pages/Users'
  13. import Groups from '@/pages/Groups'
  14. import ApiKeys from '@/pages/ApiKeys'
  15. import Workspaces from '@/pages/Workspaces'
  16. import WorkspaceEdit from '@/pages/WorkspaceEdit'
  17. import LlmProviders from '@/pages/LlmProviders'
  18. import ChatPage from '@/pages/ChatPage'
  19. import Archives from '@/pages/Archives'
  20. import ProtectedRoute from '@/components/ProtectedRoute'
  21. import { DashboardLayout } from '@/components/layout'
  22. function App() {
  23. const { isAuthenticated, isLoading } = useAuth()
  24. // Show loading spinner while checking auth state
  25. if (isLoading) {
  26. return (
  27. <div className="flex min-h-screen items-center justify-center bg-gray-50">
  28. <div className="flex flex-col items-center gap-4">
  29. <svg
  30. className="h-8 w-8 animate-spin text-primary-600"
  31. xmlns="http://www.w3.org/2000/svg"
  32. fill="none"
  33. viewBox="0 0 24 24"
  34. >
  35. <circle
  36. className="opacity-25"
  37. cx="12"
  38. cy="12"
  39. r="10"
  40. stroke="currentColor"
  41. strokeWidth="4"
  42. />
  43. <path
  44. className="opacity-75"
  45. fill="currentColor"
  46. d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
  47. />
  48. </svg>
  49. <p className="text-gray-600">Loading...</p>
  50. </div>
  51. </div>
  52. )
  53. }
  54. return (
  55. <Routes>
  56. {/* Public routes */}
  57. <Route
  58. path="/"
  59. element={
  60. isAuthenticated ? (
  61. <Navigate to="/dashboard" replace />
  62. ) : (
  63. <div className="flex min-h-screen items-center justify-center bg-gray-50">
  64. <div className="text-center">
  65. <div className="mx-auto mb-6 flex h-16 w-16 items-center justify-center rounded-xl bg-primary-600">
  66. <span className="text-3xl font-bold text-white">S</span>
  67. </div>
  68. <h1 className="text-4xl font-bold text-gray-900">SmartBotic CRM</h1>
  69. <p className="mt-4 text-lg text-gray-600">Manage your business smarter</p>
  70. <div className="mt-8 flex justify-center gap-4">
  71. <a
  72. href="/login"
  73. className="rounded-lg bg-primary-600 px-6 py-3 text-white transition hover:bg-primary-700"
  74. >
  75. Sign in
  76. </a>
  77. </div>
  78. </div>
  79. </div>
  80. )
  81. }
  82. />
  83. <Route path="/login" element={<Login />} />
  84. {/* Protected routes with dashboard layout */}
  85. <Route
  86. element={
  87. <ProtectedRoute>
  88. <DashboardLayout />
  89. </ProtectedRoute>
  90. }
  91. >
  92. <Route path="/dashboard" element={<Dashboard />} />
  93. <Route path="/collections" element={<Collections />} />
  94. <Route path="/collections/:collectionName" element={<Documents />} />
  95. <Route path="/views" element={<Views />} />
  96. <Route path="/views/:collectionName" element={<Views />} />
  97. <Route path="/views/:viewId/create" element={<DocumentForm />} />
  98. <Route path="/views/:viewId/edit/:docId" element={<DocumentForm />} />
  99. <Route path="/pages" element={<Pages />} />
  100. <Route path="/pages/:pageId/edit" element={<PageBuilder />} />
  101. <Route path="/p/:slug" element={<PageDisplay />} />
  102. <Route path="/users" element={<Users />} />
  103. <Route path="/groups" element={<Groups />} />
  104. <Route path="/api-keys" element={<ApiKeys />} />
  105. <Route path="/workspaces" element={<Workspaces />} />
  106. <Route path="/workspaces/:workspaceId/edit" element={<WorkspaceEdit />} />
  107. <Route path="/llm-providers" element={<LlmProviders />} />
  108. <Route path="/chat" element={<ChatPage />} />
  109. <Route path="/archives" element={<Archives />} />
  110. </Route>
  111. {/* Catch-all redirect */}
  112. <Route path="*" element={<Navigate to="/" replace />} />
  113. </Routes>
  114. )
  115. }
  116. export default App