Files
bakery-ia/frontend/src/router/AppRouter.tsx

296 lines
8.7 KiB
TypeScript
Raw Normal View History

2025-08-28 10:41:04 +02:00
import React, { Suspense } from 'react';
import { Routes, Route, Navigate } from 'react-router-dom';
import { ProtectedRoute } from './ProtectedRoute';
import { LoadingSpinner } from '../components/shared/LoadingSpinner';
import { AppShell } from '../components/layout';
// Lazy load the pages we actually have
const LandingPage = React.lazy(() => import('../pages/public/LandingPage'));
const LoginPage = React.lazy(() => import('../pages/public/LoginPage'));
const RegisterPage = React.lazy(() => import('../pages/public/RegisterPage'));
const DashboardPage = React.lazy(() => import('../pages/app/DashboardPage'));
// Operations pages
const InventoryPage = React.lazy(() => import('../pages/app/operations/inventory/InventoryPage'));
const ProductionPage = React.lazy(() => import('../pages/app/operations/production/ProductionPage'));
const RecipesPage = React.lazy(() => import('../pages/app/operations/recipes/RecipesPage'));
const ProcurementPage = React.lazy(() => import('../pages/app/operations/procurement/ProcurementPage'));
2025-09-09 21:39:12 +02:00
const SuppliersPage = React.lazy(() => import('../pages/app/operations/suppliers/SuppliersPage'));
2025-08-28 10:41:04 +02:00
const OrdersPage = React.lazy(() => import('../pages/app/operations/orders/OrdersPage'));
const POSPage = React.lazy(() => import('../pages/app/operations/pos/POSPage'));
// Analytics pages
const ForecastingPage = React.lazy(() => import('../pages/app/analytics/forecasting/ForecastingPage'));
const SalesAnalyticsPage = React.lazy(() => import('../pages/app/analytics/sales-analytics/SalesAnalyticsPage'));
const AIInsightsPage = React.lazy(() => import('../pages/app/analytics/ai-insights/AIInsightsPage'));
const PerformanceAnalyticsPage = React.lazy(() => import('../pages/app/analytics/performance/PerformanceAnalyticsPage'));
// Settings pages
2025-08-28 23:40:44 +02:00
const ProfilePage = React.lazy(() => import('../pages/app/settings/profile/ProfilePage'));
2025-08-28 10:41:04 +02:00
const BakeryConfigPage = React.lazy(() => import('../pages/app/settings/bakery-config/BakeryConfigPage'));
const TeamPage = React.lazy(() => import('../pages/app/settings/team/TeamPage'));
2025-09-19 12:06:26 +02:00
// Database pages
const DatabasePage = React.lazy(() => import('../pages/app/database/DatabasePage'));
2025-09-20 22:11:05 +02:00
const ModelsConfigPage = React.lazy(() => import('../pages/app/database/models/ModelsConfigPage'));
2025-09-19 12:06:26 +02:00
2025-08-28 10:41:04 +02:00
// Data pages
const WeatherPage = React.lazy(() => import('../pages/app/data/weather/WeatherPage'));
const TrafficPage = React.lazy(() => import('../pages/app/data/traffic/TrafficPage'));
const EventsPage = React.lazy(() => import('../pages/app/data/events/EventsPage'));
// Onboarding pages
const OnboardingPage = React.lazy(() => import('../pages/onboarding/OnboardingPage'));
2025-08-28 10:41:04 +02:00
export const AppRouter: React.FC = () => {
return (
<Suspense fallback={<LoadingSpinner overlay text="Cargando aplicación..." />}>
<Routes>
{/* Public Routes */}
<Route path="/" element={<LandingPage />} />
<Route path="/login" element={<LoginPage />} />
<Route path="/register" element={<RegisterPage />} />
{/* Protected Routes with AppShell Layout */}
<Route
path="/app"
element={
<ProtectedRoute>
<AppShell>
<DashboardPage />
</AppShell>
</ProtectedRoute>
}
/>
<Route
path="/app/dashboard"
element={
<ProtectedRoute>
<AppShell>
<DashboardPage />
</AppShell>
</ProtectedRoute>
}
/>
2025-09-19 12:06:26 +02:00
{/* Operations Routes - Business Operations Only */}
<Route
path="/app/operations/procurement"
2025-08-28 10:41:04 +02:00
element={
<ProtectedRoute>
<AppShell>
2025-09-19 12:06:26 +02:00
<ProcurementPage />
2025-08-28 10:41:04 +02:00
</AppShell>
</ProtectedRoute>
2025-09-19 12:06:26 +02:00
}
2025-08-28 10:41:04 +02:00
/>
2025-09-19 12:06:26 +02:00
<Route
path="/app/operations/production"
2025-08-28 10:41:04 +02:00
element={
<ProtectedRoute>
<AppShell>
<ProductionPage />
</AppShell>
</ProtectedRoute>
2025-09-19 12:06:26 +02:00
}
2025-08-28 10:41:04 +02:00
/>
2025-09-19 12:06:26 +02:00
<Route
path="/app/operations/pos"
2025-08-28 10:41:04 +02:00
element={
<ProtectedRoute>
<AppShell>
2025-09-19 12:06:26 +02:00
<POSPage />
2025-08-28 10:41:04 +02:00
</AppShell>
</ProtectedRoute>
2025-09-19 12:06:26 +02:00
}
2025-08-28 10:41:04 +02:00
/>
2025-09-19 12:06:26 +02:00
{/* Database Routes - Current Bakery Status */}
<Route
path="/app/database"
2025-08-28 10:41:04 +02:00
element={
<ProtectedRoute>
<AppShell>
2025-09-19 12:06:26 +02:00
<DatabasePage />
2025-08-28 10:41:04 +02:00
</AppShell>
</ProtectedRoute>
2025-09-19 12:06:26 +02:00
}
2025-09-09 21:39:12 +02:00
/>
2025-09-19 12:06:26 +02:00
<Route
path="/app/database/recipes"
2025-09-09 21:39:12 +02:00
element={
<ProtectedRoute>
<AppShell>
2025-09-19 12:06:26 +02:00
<RecipesPage />
2025-09-09 21:39:12 +02:00
</AppShell>
</ProtectedRoute>
2025-09-19 12:06:26 +02:00
}
2025-08-28 10:41:04 +02:00
/>
2025-09-19 12:06:26 +02:00
<Route
path="/app/database/orders"
2025-08-28 10:41:04 +02:00
element={
<ProtectedRoute>
<AppShell>
<OrdersPage />
</AppShell>
</ProtectedRoute>
2025-09-19 12:06:26 +02:00
}
2025-08-28 10:41:04 +02:00
/>
2025-09-19 12:06:26 +02:00
<Route
path="/app/database/suppliers"
2025-08-28 10:41:04 +02:00
element={
<ProtectedRoute>
<AppShell>
2025-09-19 12:06:26 +02:00
<SuppliersPage />
2025-08-28 10:41:04 +02:00
</AppShell>
</ProtectedRoute>
2025-09-19 12:06:26 +02:00
}
2025-08-28 10:41:04 +02:00
/>
2025-09-19 12:06:26 +02:00
<Route
path="/app/database/inventory"
2025-08-28 10:41:04 +02:00
element={
<ProtectedRoute>
<AppShell>
2025-09-19 12:06:26 +02:00
<InventoryPage />
2025-08-28 10:41:04 +02:00
</AppShell>
</ProtectedRoute>
2025-09-19 12:06:26 +02:00
}
2025-08-28 10:41:04 +02:00
/>
2025-09-19 12:06:26 +02:00
<Route
path="/app/database/bakery-config"
2025-08-28 10:41:04 +02:00
element={
<ProtectedRoute>
<AppShell>
2025-09-19 12:06:26 +02:00
<BakeryConfigPage />
2025-08-28 10:41:04 +02:00
</AppShell>
</ProtectedRoute>
2025-09-19 12:06:26 +02:00
}
2025-08-28 10:41:04 +02:00
/>
2025-09-19 12:06:26 +02:00
<Route
path="/app/database/team"
2025-08-28 10:41:04 +02:00
element={
<ProtectedRoute>
<AppShell>
2025-09-19 12:06:26 +02:00
<TeamPage />
2025-08-28 10:41:04 +02:00
</AppShell>
</ProtectedRoute>
2025-09-19 12:06:26 +02:00
}
2025-08-28 10:41:04 +02:00
/>
2025-09-20 22:11:05 +02:00
<Route
path="/app/database/models"
element={
<ProtectedRoute>
<AppShell>
<ModelsConfigPage />
</AppShell>
</ProtectedRoute>
}
/>
2025-09-19 12:06:26 +02:00
{/* Analytics Routes */}
2025-08-28 10:41:04 +02:00
<Route
2025-09-19 12:06:26 +02:00
path="/app/analytics/forecasting"
2025-08-28 10:41:04 +02:00
element={
<ProtectedRoute>
<AppShell>
2025-09-19 12:06:26 +02:00
<ForecastingPage />
2025-08-28 10:41:04 +02:00
</AppShell>
</ProtectedRoute>
}
/>
<Route
2025-09-19 12:06:26 +02:00
path="/app/analytics/sales"
2025-08-28 10:41:04 +02:00
element={
<ProtectedRoute>
<AppShell>
2025-09-19 12:06:26 +02:00
<SalesAnalyticsPage />
2025-08-28 10:41:04 +02:00
</AppShell>
</ProtectedRoute>
}
/>
2025-08-28 23:40:44 +02:00
<Route
2025-09-19 12:06:26 +02:00
path="/app/analytics/ai-insights"
2025-08-28 23:40:44 +02:00
element={
<ProtectedRoute>
<AppShell>
2025-09-19 12:06:26 +02:00
<AIInsightsPage />
2025-08-28 23:40:44 +02:00
</AppShell>
</ProtectedRoute>
}
/>
2025-08-28 10:41:04 +02:00
<Route
2025-09-19 12:06:26 +02:00
path="/app/analytics/performance"
2025-08-28 10:41:04 +02:00
element={
<ProtectedRoute>
<AppShell>
2025-09-19 12:06:26 +02:00
<PerformanceAnalyticsPage />
2025-08-28 10:41:04 +02:00
</AppShell>
</ProtectedRoute>
}
/>
2025-09-19 12:06:26 +02:00
{/* Settings Routes */}
2025-08-28 10:41:04 +02:00
<Route
2025-09-19 12:06:26 +02:00
path="/app/settings/profile"
2025-08-28 10:41:04 +02:00
element={
<ProtectedRoute>
<AppShell>
2025-09-19 12:06:26 +02:00
<ProfilePage />
2025-08-28 10:41:04 +02:00
</AppShell>
</ProtectedRoute>
}
/>
{/* Data Routes */}
<Route
path="/app/data/weather"
element={
<ProtectedRoute>
<AppShell>
<WeatherPage />
</AppShell>
</ProtectedRoute>
}
/>
<Route
path="/app/data/traffic"
element={
<ProtectedRoute>
<AppShell>
<TrafficPage />
</AppShell>
</ProtectedRoute>
}
/>
<Route
path="/app/data/events"
element={
<ProtectedRoute>
<AppShell>
<EventsPage />
</AppShell>
</ProtectedRoute>
}
/>
{/* Onboarding Route - Protected but without AppShell */}
2025-08-28 10:41:04 +02:00
<Route
2025-09-03 14:06:38 +02:00
path="/app/onboarding"
2025-08-28 10:41:04 +02:00
element={
<ProtectedRoute>
2025-09-03 14:06:38 +02:00
<OnboardingPage />
2025-08-28 10:41:04 +02:00
</ProtectedRoute>
}
/>
{/* Default redirects */}
<Route path="/app/*" element={<Navigate to="/app/dashboard" replace />} />
<Route path="*" element={<Navigate to="/" replace />} />
</Routes>
</Suspense>
);
};
export default AppRouter;