Site resource conservation added, for faster loading time. Only for Admin Frontend
This commit is contained in:
@@ -1,34 +1,46 @@
|
||||
import React from 'react';
|
||||
import React, { lazy, Suspense } from 'react';
|
||||
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
|
||||
import Login from './pages/Login';
|
||||
import POS from './pages/POS';
|
||||
import Orders from './pages/Orders';
|
||||
import Categories from './pages/Categories';
|
||||
import Products from './pages/Products';
|
||||
import Layout from './components/Layout';
|
||||
|
||||
// Lazy load pages to decrease initial bundle size
|
||||
const Login = lazy(() => import('./pages/Login'));
|
||||
const POS = lazy(() => import('./pages/POS'));
|
||||
const Orders = lazy(() => import('./pages/Orders'));
|
||||
const Categories = lazy(() => import('./pages/Categories'));
|
||||
const Products = lazy(() => import('./pages/Products'));
|
||||
|
||||
const ProtectedRoute = ({ children }: { children: React.ReactNode }) => {
|
||||
const isLoggedIn = sessionStorage.getItem('isCounterLoggedIn') === 'true';
|
||||
return isLoggedIn ? <>{children}</> : <Navigate to="/login" replace />;
|
||||
};
|
||||
|
||||
const LoadingFallback = () => (
|
||||
<div className="min-h-screen flex items-center justify-center bg-[#f4fbf7]">
|
||||
<div className="text-primary font-black uppercase tracking-widest text-sm animate-pulse">
|
||||
Loading...
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<Router>
|
||||
<Routes>
|
||||
<Route path="/login" element={<Login />} />
|
||||
<Route path="/" element={
|
||||
<ProtectedRoute>
|
||||
<Layout />
|
||||
</ProtectedRoute>
|
||||
}>
|
||||
<Route index element={<Navigate to="/pos" replace />} />
|
||||
<Route path="pos" element={<POS />} />
|
||||
<Route path="orders" element={<Orders />} />
|
||||
<Route path="categories" element={<Categories />} />
|
||||
<Route path="products" element={<Products />} />
|
||||
</Route>
|
||||
</Routes>
|
||||
<Suspense fallback={<LoadingFallback />}>
|
||||
<Routes>
|
||||
<Route path="/login" element={<Login />} />
|
||||
<Route path="/" element={
|
||||
<ProtectedRoute>
|
||||
<Layout />
|
||||
</ProtectedRoute>
|
||||
}>
|
||||
<Route index element={<Navigate to="/pos" replace />} />
|
||||
<Route path="pos" element={<POS />} />
|
||||
<Route path="orders" element={<Orders />} />
|
||||
<Route path="categories" element={<Categories />} />
|
||||
<Route path="products" element={<Products />} />
|
||||
</Route>
|
||||
</Routes>
|
||||
</Suspense>
|
||||
</Router>
|
||||
);
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 MiB After Width: | Height: | Size: 204 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 4.8 MiB After Width: | Height: | Size: 41 KiB |
@@ -26,7 +26,7 @@ const Login = () => {
|
||||
e.preventDefault();
|
||||
|
||||
try {
|
||||
const host = window.location.hostname;
|
||||
|
||||
const response = await fetch(`https://cmsapi.rit-services.in/api/system/login`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
|
||||
Reference in New Issue
Block a user