Android_Retail/src/App.jsx

120 lines
3.5 KiB
React
Raw Normal View History

2026-02-10 16:35:19 +05:30
import { useEffect, lazy, Suspense } from 'react';
2026-01-27 18:27:29 +05:30
import { Routes, Route } from 'react-router-dom';
2026-02-10 16:35:19 +05:30
import { useSelector } from 'react-redux';
2026-01-27 18:27:29 +05:30
import ProtectedRoutes from './ProtectedRoutes';
2026-02-10 16:35:19 +05:30
import { isMobile, isIOS } from 'react-device-detect';
2026-01-27 18:27:29 +05:30
import { routesConfig } from './routesConfig';
2026-02-10 16:35:19 +05:30
import { GlobalItemCard } from './Features/BookingScreen/BookingData/BookingData.js';
import { clearSession, getSession } from './Services/Others.js';
2026-01-27 18:27:29 +05:30
import devtools from 'devtools-detect';
2026-02-10 16:35:19 +05:30
const KisokSelBooking = lazy(
() => import('./Pages/SelfBooking/KisokSelBooking')
);
const IndividualBooking = lazy(
() => import('./Pages/SelfBooking/IndividualBooking')
);
2026-02-23 12:18:31 +05:30
const CustomerMenuPage = lazy(
() => import('./Pages/Reports/MenuQRCode/CustomerMenuPage.jsx')
);
const WeightScaleApp = lazy(
() => import('./Pages/BookingScreen/WeightscaleApp.jsx')
);
const SelfBooking = lazy(() => import('./Pages/SelfBooking/SelfBooking.jsx'));
import useSessionManager from './useSessionManager.js';
import useSubscriptionManager from './useSubscriptionManager.js';
const ExtendSubscriptionModal = lazy(
() => import('./Pages/ExtentedModal/ExtendSubscriptionModal.jsx')
);
2026-01-27 18:27:29 +05:30
const commonSubDir = import.meta.env.ENV_COMMON_BASE_URL;
const subDirectory = import.meta.env.ENV_BASE_URL;
2026-02-10 16:35:19 +05:30
import '../ownLib/my-ui-lib.css';
2026-02-11 12:45:21 +05:30
2026-01-27 18:27:29 +05:30
const AppRoutes = () => {
const ItemCard = useSelector(GlobalItemCard);
2026-02-11 15:27:50 +05:30
const { sessionData, logout } = useSessionManager(ItemCard);
2026-02-23 12:18:31 +05:30
const { remainingDays, handleCancel, handlePay, freeExtend, extendModel } =
useSubscriptionManager(sessionData, logout);
2026-02-10 16:35:19 +05:30
2026-01-27 18:27:29 +05:30
useEffect(() => {
2026-02-10 16:35:19 +05:30
const handlePopState = () => {
2026-01-27 18:27:29 +05:30
const SessionId = getSession('SessionId');
if (!SessionId) {
alert(
'Session invalid and Unauthorized action detected. Redirecting to login...'
);
clearSession();
window.location.replace(`${commonSubDir}`);
} else {
window.history.go(1);
}
};
// Add event listener on mount
window.addEventListener('popstate', handlePopState);
// Clean up the event listener on unmount
return () => {
window.removeEventListener('popstate', handlePopState);
};
}, []);
2026-02-12 18:15:06 +05:30
// useEffect(() => {
// if (isMobile || isIOS) return;
// const timer = setInterval(() => {
// if (devtools.isOpen) {
// document.body.innerHTML =
// "<h1 style='color:red;text-align:center'>Close Inspect to continue</h1>";
// }
// }, 1000);
2026-01-27 18:27:29 +05:30
2026-02-12 18:15:06 +05:30
// return () => clearInterval(timer);
// }, []);
2026-01-27 18:27:29 +05:30
2026-02-11 12:09:36 +05:30
if (extendModel) {
return (
<ExtendSubscriptionModal
onClose={handleCancel}
2026-02-23 12:18:31 +05:30
onPayNow={handlePay}
onContinueWithCredits={freeExtend}
2026-01-27 18:27:29 +05:30
/>
2026-02-11 12:09:36 +05:30
);
}
return (
2026-02-10 16:35:19 +05:30
<Suspense fallback={<div>Loading</div>}>
2026-02-11 12:09:36 +05:30
<Routes>
<Route
path={`${subDirectory}selfBooking/:SelfBookingId`}
element={<SelfBooking />}
/>
<Route
path={`${subDirectory}MenuQRCode`}
element={<CustomerMenuPage />}
/>
<Route
path={`${subDirectory}weightscaleapp`}
element={<WeightScaleApp />}
/>
2026-02-10 16:35:19 +05:30
<Route
path={`${subDirectory}kioskSelfBooking`}
element={<KisokSelBooking />}
/>
2026-01-27 18:27:29 +05:30
2026-02-11 12:09:36 +05:30
<Route
path={`${subDirectory}kiosk-individual-self-booking`}
element={<IndividualBooking />}
/>
<Route
path="/*"
element={<ProtectedRoutes routesConfig={routesConfig} />}
/>
</Routes>
2026-02-10 16:35:19 +05:30
</Suspense>
2026-01-27 18:27:29 +05:30
);
};
export default AppRoutes;