feat: Optimize loading perf. by spliting big chunks and lazy loading them

This commit is contained in:
Ahmed Bouhuolia
2024-08-26 22:51:40 +02:00
parent 161d60393a
commit c9fe6d9b37
3 changed files with 53 additions and 38 deletions

View File

@@ -12,7 +12,6 @@ import AppIntlLoader from './AppIntlLoader';
import { EnsureAuthenticated } from '@/components/Guards/EnsureAuthenticated';
import GlobalErrors from '@/containers/GlobalErrors/GlobalErrors';
import DashboardPrivatePages from '@/components/Dashboard/PrivatePages';
import { Authentication } from '@/containers/Authentication/Authentication';
import LazyLoader from '@/components/LazyLoader';
import { SplashScreen, DashboardThemeProvider } from '../components';
@@ -21,6 +20,9 @@ import { EnsureUserEmailVerified } from './Guards/EnsureUserEmailVerified';
import { EnsureAuthNotAuthenticated } from './Guards/EnsureAuthNotAuthenticated';
import { EnsureUserEmailNotVerified } from './Guards/EnsureUserEmailNotVerified';
const AuthenticationPage = LazyLoader({
loader: () => import('@/containers/Authentication/AuthenticationPage'),
});
const EmailConfirmation = LazyLoader({
loader: () => import('@/containers/Authentication/EmailConfirmation'),
});
@@ -53,12 +55,7 @@ function AppInsider({ history }) {
<EmailConfirmation />
</Route>
<Route path={'/auth'}>
<EnsureAuthNotAuthenticated>
<Authentication />
</EnsureAuthNotAuthenticated>
</Route>
<Route path={'/auth'} children={<AuthenticationPage />} />
<Route path={'/'}>
<EnsureAuthenticated>
<EnsureUserEmailVerified>

View File

@@ -0,0 +1,10 @@
import { EnsureAuthNotAuthenticated } from "@/components/Guards/EnsureAuthNotAuthenticated";
import { Authentication } from "./Authentication";
export default function AuthenticationPage() {
return (
<EnsureAuthNotAuthenticated>
<Authentication />
</EnsureAuthNotAuthenticated>
);
}

View File

@@ -1,88 +1,96 @@
// @ts-nocheck
import { lazy } from 'react';
import General from '@/containers/Preferences/General/General';
import Users from '../containers/Preferences/Users/Users';
import Roles from '../containers/Preferences/Users/Roles/RolesForm/RolesFormPage';
import Accountant from '@/containers/Preferences/Accountant/Accountant';
import Currencies from '@/containers/Preferences/Currencies/Currencies';
import Item from '@/containers/Preferences/Item';
// import SMSIntegration from '../containers/Preferences/SMSIntegration';
import DefaultRoute from '../containers/Preferences/DefaultRoute';
import Warehouses from '../containers/Preferences/Warehouses';
import Branches from '../containers/Preferences/Branches';
import Invoices from '../containers/Preferences/Invoices/PreferencesInvoices';
import { PreferencesCreditNotes } from '../containers/Preferences/CreditNotes/PreferencesCreditNotes';
import { PreferencesEstimates } from '@/containers/Preferences/Estimates/PreferencesEstimates';
import { PreferencesReceipts } from '@/containers/Preferences/Receipts/PreferencesReceipts';
import BillingPage from '@/containers/Subscriptions/BillingPage';
const BASE_URL = '/preferences';
export default [
{
path: `${BASE_URL}/general`,
component: General,
component: lazy(() => import('@/containers/Preferences/General/General')),
exact: true,
},
{
path: `${BASE_URL}/users`,
component: Users,
component: lazy(() => import('../containers/Preferences/Users/Users')),
exact: true,
},
{
path: `${BASE_URL}/invoices`,
component: Invoices,
component: lazy(
() => import('../containers/Preferences/Invoices/PreferencesInvoices'),
),
exact: true,
},
{
path: `${BASE_URL}/credit-notes`,
component: PreferencesCreditNotes,
component: lazy(() =>
import(
'../containers/Preferences/CreditNotes/PreferencesCreditNotes'
).then((module) => ({ default: module.PreferencesCreditNotes })),
),
exact: true,
},
{
path: `${BASE_URL}/estimates`,
component: PreferencesEstimates,
component: lazy(() =>
import('@/containers/Preferences/Estimates/PreferencesEstimates').then(
(module) => ({ default: module.PreferencesEstimates }),
),
),
exact: true,
},
{
path: `${BASE_URL}/receipts`,
component: PreferencesReceipts,
component: lazy(() =>
import('@/containers/Preferences/Receipts/PreferencesReceipts').then(
(module) => ({ default: module.PreferencesReceipts }),
),
),
exact: true,
},
{
path: `${BASE_URL}/roles`,
component: Roles,
component: lazy(
() =>
import('../containers/Preferences/Users/Roles/RolesForm/RolesFormPage'),
),
exact: true,
},
{
path: `${BASE_URL}/roles/:id`,
component: Roles,
component: lazy(
() =>
import('../containers/Preferences/Users/Roles/RolesForm/RolesFormPage'),
),
exact: true,
},
{
path: `${BASE_URL}/currencies`,
component: Currencies,
component: lazy(
() => import('@/containers/Preferences/Currencies/Currencies'),
),
exact: true,
},
{
path: `${BASE_URL}/warehouses`,
component: Warehouses,
component: lazy(() => import('../containers/Preferences/Warehouses')),
exact: true,
},
{
path: `${BASE_URL}/branches`,
component: Branches,
component: lazy(() => import('../containers/Preferences/Branches')),
exact: true,
},
{
path: `${BASE_URL}/accountant`,
component: Accountant,
component: lazy(
() => import('@/containers/Preferences/Accountant/Accountant'),
),
exact: true,
},
{
path: `${BASE_URL}/items`,
component: Item,
component: lazy(() => import('@/containers/Preferences/Item')),
exact: true,
},
// {
@@ -92,12 +100,12 @@ export default [
// },
{
path: `${BASE_URL}/billing`,
component: BillingPage,
component: lazy(() => import('@/containers/Subscriptions/BillingPage')),
exact: true,
},
{
path: `${BASE_URL}/`,
component: DefaultRoute,
component: lazy(() => import('../containers/Preferences/DefaultRoute')),
exact: true,
},
];