updates
This commit is contained in:
@@ -15,22 +15,21 @@ import OfflineIndicator from './components/common/OfflineIndicator';
|
||||
import CookieConsentBanner from './components/common/CookieConsentBanner';
|
||||
import AnalyticsLoader from './components/common/AnalyticsLoader';
|
||||
import Loading from './components/common/Loading';
|
||||
import ScrollToTop from './components/common/ScrollToTop';
|
||||
|
||||
// Store
|
||||
import useAuthStore from './store/useAuthStore';
|
||||
import useFavoritesStore from './store/useFavoritesStore';
|
||||
|
||||
// Layout Components
|
||||
import { LayoutMain } from './components/layout';
|
||||
import AdminLayout from './pages/AdminLayout';
|
||||
|
||||
// Auth Components
|
||||
import {
|
||||
ProtectedRoute,
|
||||
AdminRoute
|
||||
AdminRoute,
|
||||
StaffRoute,
|
||||
CustomerRoute
|
||||
} from './components/auth';
|
||||
|
||||
// Lazy load pages for code splitting
|
||||
const HomePage = lazy(() => import('./pages/HomePage'));
|
||||
const DashboardPage = lazy(() => import('./pages/customer/DashboardPage'));
|
||||
const RoomListPage = lazy(() => import('./pages/customer/RoomListPage'));
|
||||
@@ -56,18 +55,21 @@ const RegisterPage = lazy(() => import('./pages/auth/RegisterPage'));
|
||||
const ForgotPasswordPage = lazy(() => import('./pages/auth/ForgotPasswordPage'));
|
||||
const ResetPasswordPage = lazy(() => import('./pages/auth/ResetPasswordPage'));
|
||||
|
||||
// Lazy load admin pages
|
||||
const AdminDashboardPage = lazy(() => import('./pages/admin/DashboardPage'));
|
||||
const InvoiceManagementPage = lazy(() => import('./pages/admin/InvoiceManagementPage'));
|
||||
const PaymentManagementPage = lazy(() => import('./pages/admin/PaymentManagementPage'));
|
||||
const UserManagementPage = lazy(() => import('./pages/admin/UserManagementPage'));
|
||||
const BookingManagementPage = lazy(() => import('./pages/admin/BookingManagementPage'));
|
||||
const PageContentDashboardPage = lazy(() => import('./pages/admin/PageContentDashboard'));
|
||||
const AnalyticsDashboardPage = lazy(() => import('./pages/admin/AnalyticsDashboardPage'));
|
||||
const BusinessDashboardPage = lazy(() => import('./pages/admin/BusinessDashboardPage'));
|
||||
const SettingsPage = lazy(() => import('./pages/admin/SettingsPage'));
|
||||
const ReceptionDashboardPage = lazy(() => import('./pages/admin/ReceptionDashboardPage'));
|
||||
|
||||
// Demo component for pages not yet created
|
||||
const StaffDashboardPage = lazy(() => import('./pages/staff/DashboardPage'));
|
||||
const ChatManagementPage = lazy(() => import('./pages/staff/ChatManagementPage'));
|
||||
const StaffLayout = lazy(() => import('./pages/StaffLayout'));
|
||||
|
||||
const DemoPage: React.FC<{ title: string }> = ({ title }) => (
|
||||
<div className="container mx-auto px-4 py-8">
|
||||
<h1 className="text-3xl font-bold text-gray-800">
|
||||
@@ -80,7 +82,7 @@ const DemoPage: React.FC<{ title: string }> = ({ title }) => (
|
||||
);
|
||||
|
||||
function App() {
|
||||
// Use Zustand store
|
||||
|
||||
const {
|
||||
isAuthenticated,
|
||||
userInfo,
|
||||
@@ -94,20 +96,20 @@ function App() {
|
||||
loadGuestFavorites,
|
||||
} = useFavoritesStore();
|
||||
|
||||
// Initialize auth state when app loads
|
||||
|
||||
useEffect(() => {
|
||||
initializeAuth();
|
||||
}, [initializeAuth]);
|
||||
|
||||
// Load favorites when authenticated or load guest favorites
|
||||
|
||||
useEffect(() => {
|
||||
if (isAuthenticated) {
|
||||
// Sync guest favorites first, then fetch
|
||||
|
||||
syncGuestFavorites().then(() => {
|
||||
fetchFavorites();
|
||||
});
|
||||
} else {
|
||||
// Load guest favorites from localStorage
|
||||
|
||||
loadGuestFavorites();
|
||||
}
|
||||
}, [
|
||||
@@ -117,7 +119,7 @@ function App() {
|
||||
loadGuestFavorites,
|
||||
]);
|
||||
|
||||
// Handle logout
|
||||
|
||||
const handleLogout = async () => {
|
||||
await logout();
|
||||
};
|
||||
@@ -133,9 +135,10 @@ function App() {
|
||||
v7_relativeSplatPath: true,
|
||||
}}
|
||||
>
|
||||
<ScrollToTop />
|
||||
<Suspense fallback={<Loading fullScreen text="Loading page..." />}>
|
||||
<Routes>
|
||||
{/* Public Routes with Main Layout */}
|
||||
{}
|
||||
<Route
|
||||
path="/"
|
||||
element={
|
||||
@@ -161,7 +164,11 @@ function App() {
|
||||
/>
|
||||
<Route
|
||||
path="favorites"
|
||||
element={<FavoritesPage />}
|
||||
element={
|
||||
<CustomerRoute>
|
||||
<FavoritesPage />
|
||||
</CustomerRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="payment-result"
|
||||
@@ -192,7 +199,7 @@ function App() {
|
||||
element={<ContactPage />}
|
||||
/>
|
||||
|
||||
{/* Protected Routes - Requires login */}
|
||||
{}
|
||||
<Route
|
||||
path="dashboard"
|
||||
element={
|
||||
@@ -204,57 +211,57 @@ function App() {
|
||||
<Route
|
||||
path="booking/:id"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<CustomerRoute>
|
||||
<BookingPage />
|
||||
</ProtectedRoute>
|
||||
</CustomerRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="booking-success/:id"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<CustomerRoute>
|
||||
<BookingSuccessPage />
|
||||
</ProtectedRoute>
|
||||
</CustomerRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="payment/deposit/:bookingId"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<CustomerRoute>
|
||||
<DepositPaymentPage />
|
||||
</ProtectedRoute>
|
||||
</CustomerRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="bookings"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<CustomerRoute>
|
||||
<MyBookingsPage />
|
||||
</ProtectedRoute>
|
||||
</CustomerRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="bookings/:id"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<CustomerRoute>
|
||||
<BookingDetailPage />
|
||||
</ProtectedRoute>
|
||||
</CustomerRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="payment/:bookingId"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<CustomerRoute>
|
||||
<FullPaymentPage />
|
||||
</ProtectedRoute>
|
||||
</CustomerRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="payment-confirmation/:id"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<CustomerRoute>
|
||||
<PaymentConfirmationPage />
|
||||
</ProtectedRoute>
|
||||
</CustomerRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
@@ -267,7 +274,7 @@ function App() {
|
||||
/>
|
||||
</Route>
|
||||
|
||||
{/* Auth Routes (no layout) */}
|
||||
{}
|
||||
<Route
|
||||
path="/login"
|
||||
element={<LoginPage />}
|
||||
@@ -285,7 +292,7 @@ function App() {
|
||||
element={<ResetPasswordPage />}
|
||||
/>
|
||||
|
||||
{/* Admin Routes - Only admin can access */}
|
||||
{}
|
||||
<Route
|
||||
path="/admin"
|
||||
element={
|
||||
@@ -337,7 +344,43 @@ function App() {
|
||||
/>
|
||||
</Route>
|
||||
|
||||
{/* 404 Route */}
|
||||
{}
|
||||
<Route
|
||||
path="/staff"
|
||||
element={
|
||||
<StaffRoute>
|
||||
<StaffLayout />
|
||||
</StaffRoute>
|
||||
}
|
||||
>
|
||||
<Route
|
||||
index
|
||||
element={<Navigate to="dashboard" replace />}
|
||||
/>
|
||||
<Route path="dashboard" element={<StaffDashboardPage />} />
|
||||
<Route
|
||||
path="bookings"
|
||||
element={<BookingManagementPage />}
|
||||
/>
|
||||
<Route
|
||||
path="reception"
|
||||
element={<ReceptionDashboardPage />}
|
||||
/>
|
||||
<Route
|
||||
path="payments"
|
||||
element={<PaymentManagementPage />}
|
||||
/>
|
||||
<Route
|
||||
path="reports"
|
||||
element={<AnalyticsDashboardPage />}
|
||||
/>
|
||||
<Route
|
||||
path="chats"
|
||||
element={<ChatManagementPage />}
|
||||
/>
|
||||
</Route>
|
||||
|
||||
{}
|
||||
<Route
|
||||
path="*"
|
||||
element={<DemoPage title="404 - Page not found" />}
|
||||
|
||||
Reference in New Issue
Block a user