125 lines
6.7 KiB
TypeScript
125 lines
6.7 KiB
TypeScript
import type { ComponentType } from 'react';
|
|
import { createBrowserRouter, Navigate } from 'react-router-dom';
|
|
import Layout from '../components/Layout';
|
|
import ProtectedRoute from '../components/ProtectedRoute';
|
|
import { RouteErrorBoundary } from '../components/RouteErrorBoundary';
|
|
import Login from '../pages/Login';
|
|
import { lazyWithRetry } from '../utils/lazyWithRetry';
|
|
|
|
// Lazy loading admin pages with automatic retry and cache recovery
|
|
const Dashboard = lazyWithRetry(() => import('../pages/Dashboard'));
|
|
const Users = lazyWithRetry(() => import('../pages/Users'));
|
|
const Products = lazyWithRetry(() => import('../pages/Products'));
|
|
const Orders = lazyWithRetry(() => import('../pages/Orders'));
|
|
const Coupons = lazyWithRetry(() => import('../pages/Coupons'));
|
|
const Settings = lazyWithRetry(() => import('../pages/Settings'));
|
|
const Reports = lazyWithRetry(() => import('../pages/Reports'));
|
|
const Categories = lazyWithRetry(() => import('../pages/Categories'));
|
|
const Blogs = lazyWithRetry(() => import('../pages/Blogs'));
|
|
const Wiki = lazyWithRetry(() => import('../pages/Wiki'));
|
|
const Pets = lazyWithRetry(() => import('../pages/Pets'));
|
|
const UITexts = lazyWithRetry(() => import('../pages/UITexts'));
|
|
const Media = lazyWithRetry(() => import('../pages/Media'));
|
|
const CMS = lazyWithRetry(() => import('../pages/CMS'));
|
|
const WholesaleApplications = lazyWithRetry(() => import('../pages/WholesaleApplications'));
|
|
const Videos = lazyWithRetry(() => import('../pages/Videos'));
|
|
const ContactSubmissions = lazyWithRetry(() => import('../pages/ContactSubmissions'));
|
|
const BannersManager = lazyWithRetry(() => import('../pages/BannersManager'));
|
|
const SmartAdvisorManager = lazyWithRetry(() => import('../pages/SmartAdvisorManager'));
|
|
const TestimonialsManager = lazyWithRetry(() => import('../pages/TestimonialsManager'));
|
|
const IngredientsManager = lazyWithRetry(() => import('../pages/IngredientsManager'));
|
|
const PrescriptionsManager = lazyWithRetry(() => import('../pages/PrescriptionsManager'));
|
|
const B2BManager = lazyWithRetry(() => import('../pages/B2BManager'));
|
|
const SeoSettingsPage = lazyWithRetry(() => import('../pages/SeoSettingsPage'));
|
|
const FinancialSettingsPage = lazyWithRetry(() => import('../pages/FinancialSettingsPage'));
|
|
const PaymentGatewaysPage = lazyWithRetry(() => import('../pages/PaymentGatewaysPage'));
|
|
const ZibalPortalPage = lazyWithRetry(() => import('../pages/ZibalPortalPage'));
|
|
const ShippingSettingsPage = lazyWithRetry(() => import('../pages/ShippingSettingsPage'));
|
|
const SystemSettingsPage = lazyWithRetry(() => import('../pages/SystemSettingsPage'));
|
|
const SmsSettingsPage = lazyWithRetry(() => import('../pages/SmsSettingsPage'));
|
|
const SslSettingsPage = lazyWithRetry(() => import('../pages/SslSettingsPage'));
|
|
const ApiKeysPage = lazyWithRetry(() => import('../pages/ApiKeysPage'));
|
|
const Transactions = lazyWithRetry(() => import('../pages/Transactions'));
|
|
const Tickets = lazyWithRetry(() => import('../pages/Tickets'));
|
|
const Reviews = lazyWithRetry(() => import('../pages/Reviews'));
|
|
const DoctorsManager = lazyWithRetry(() => import('../pages/DoctorsManager'));
|
|
const FAQManager = lazyWithRetry(() => import('../pages/FAQManager'));
|
|
const MenuManager = lazyWithRetry(() => import('../pages/MenuManager'));
|
|
const MonitoringPage = lazyWithRetry(() => import('../pages/MonitoringPage'));
|
|
const ApprovalsPage = lazyWithRetry(() => import('../pages/ApprovalsPage'));
|
|
const AuditHistoryPage = lazyWithRetry(() => import('../pages/AuditHistoryPage'));
|
|
const TasksManagementPage = lazyWithRetry(() => import('../pages/TasksManagementPage'));
|
|
|
|
export interface AdminRouteConfig {
|
|
path: string;
|
|
component: ComponentType;
|
|
index?: boolean;
|
|
}
|
|
|
|
export const router = createBrowserRouter([
|
|
{
|
|
path: '/login',
|
|
element: <Login />,
|
|
errorElement: <RouteErrorBoundary><Login /></RouteErrorBoundary>,
|
|
},
|
|
{
|
|
element: <ProtectedRoute />,
|
|
errorElement: <RouteErrorBoundary><Layout /></RouteErrorBoundary>,
|
|
children: [
|
|
{
|
|
path: '/',
|
|
element: <Layout />,
|
|
errorElement: <RouteErrorBoundary><Layout /></RouteErrorBoundary>,
|
|
children: [
|
|
{ index: true, element: <Dashboard /> },
|
|
{ path: 'users/*', element: <Users /> },
|
|
{ path: 'products/*', element: <Products /> },
|
|
{ path: 'orders/*', element: <Orders /> },
|
|
{ path: 'transactions/*', element: <Transactions /> },
|
|
{ path: 'zibal-portal/*', element: <ZibalPortalPage /> },
|
|
{ path: 'coupons/*', element: <Coupons /> },
|
|
{ path: 'settings', element: <Settings /> },
|
|
{ path: 'settings/payment-methods', element: <PaymentGatewaysPage /> },
|
|
{ path: 'settings/shipping', element: <ShippingSettingsPage /> },
|
|
{ path: 'settings/ssl', element: <SslSettingsPage /> },
|
|
{ path: 'settings/api-keys', element: <ApiKeysPage /> },
|
|
{ path: 'settings/sms', element: <SmsSettingsPage /> },
|
|
{ path: 'settings/seo', element: <SeoSettingsPage /> },
|
|
{ path: 'settings/financial', element: <FinancialSettingsPage /> },
|
|
{ path: 'settings/system', element: <SystemSettingsPage /> },
|
|
{ path: 'reports/*', element: <Reports /> },
|
|
{ path: 'categories/*', element: <Categories /> },
|
|
{ path: 'blogs/*', element: <Blogs /> },
|
|
{ path: 'wiki/*', element: <Wiki /> },
|
|
{ path: 'videos/*', element: <Videos /> },
|
|
{ path: 'doctors/*', element: <DoctorsManager /> },
|
|
{ path: 'pets/*', element: <Pets /> },
|
|
{ path: 'ui-texts/*', element: <UITexts /> },
|
|
{ path: 'media/*', element: <Media /> },
|
|
{ path: 'cms/*', element: <CMS /> },
|
|
{ path: 'banners/*', element: <BannersManager /> },
|
|
{ path: 'smart-advisor/*', element: <SmartAdvisorManager /> },
|
|
{ path: 'testimonials/*', element: <TestimonialsManager /> },
|
|
{ path: 'ingredients/*', element: <IngredientsManager /> },
|
|
{ path: 'prescriptions/*', element: <PrescriptionsManager /> },
|
|
{ path: 'b2b/*', element: <B2BManager /> },
|
|
{ path: 'wholesale/*', element: <WholesaleApplications /> },
|
|
{ path: 'contact/*', element: <ContactSubmissions /> },
|
|
{ path: 'tickets/*', element: <Tickets /> },
|
|
{ path: 'reviews/*', element: <Reviews /> },
|
|
{ path: 'faq/*', element: <FAQManager /> },
|
|
{ path: 'menu/*', element: <MenuManager /> },
|
|
{ path: 'monitoring/*', element: <MonitoringPage /> },
|
|
{ path: 'approvals/*', element: <ApprovalsPage /> },
|
|
{ path: 'history/*', element: <AuditHistoryPage /> },
|
|
{ path: 'tasks/*', element: <TasksManagementPage /> },
|
|
],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
path: '*',
|
|
element: <Navigate to="/" replace />,
|
|
},
|
|
]);
|