aboutsummaryrefslogtreecommitdiff
path: root/web/src/router.tsx
blob: 5105fec0fa202de4d2c5d984d829ab5ac0a33c14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
 * router.tsx
 * Rotas da aplicação com proteção por autenticação.
 */

import { createBrowserRouter, Navigate } from 'react-router-dom';
import { lazy, Suspense } from 'react';
import AppLayout from '@/components/layout/AppLayout';
import PageLoader from '@/components/ui/PageLoader';
import { ProtectedRoute } from '@/components/auth/ProtectedRoute';

// ─── Lazy pages ───────────────────────────────────────────────────────────────
const LoginPage        = lazy(() => import('@/pages/LoginPage'));
const DashboardPage    = lazy(() => import('@/pages/DashboardPage'));
const NewTicketPage    = lazy(() => import('@/pages/NewTicketPage'));
const TicketDetailPage = lazy(() => import('@/pages/TicketDetailPage'));
const UsersPage        = lazy(() => import('@/pages/UsersPage'));
const SettingsPage     = lazy(() => import('@/pages/SettingsPage'));

function Lazy({ children }: { children: React.ReactNode }) {
  return <Suspense fallback={<PageLoader />}>{children}</Suspense>;
}

// ─── Router ───────────────────────────────────────────────────────────────────
export const router = createBrowserRouter([
  // ── Rota pública: login (sem AppLayout) ───────────────────────────────────
  {
    path: '/login',
    element: <Lazy><LoginPage /></Lazy>,
  },

  // ── Rotas protegidas (requerem autenticação) ──────────────────────────────
  {
    path: '/',
    element: (
      <ProtectedRoute>
        <AppLayout />
      </ProtectedRoute>
    ),
    children: [
      {
        index: true,
        element: <Navigate to="/dashboard" replace />,
      },
      {
        path: 'dashboard',
        element: <Lazy><DashboardPage /></Lazy>,
      },
      {
        path: 'tickets/new',
        element: <Lazy><NewTicketPage /></Lazy>,
      },
      {
        path: 'tickets/:id',
        element: <Lazy><TicketDetailPage /></Lazy>,
      },
      {
        path: 'users',
        element: <Lazy><UsersPage /></Lazy>,
      },
      {
        path: 'settings',
        element: <Lazy><SettingsPage /></Lazy>,
      },
    ],
  },

  // Fallback
  { path: '*', element: <Navigate to="/dashboard" replace /> },
]);