update to python fastpi
This commit is contained in:
338
Frontend/src/App.tsx
Normal file
338
Frontend/src/App.tsx
Normal file
@@ -0,0 +1,338 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import {
|
||||
BrowserRouter,
|
||||
Routes,
|
||||
Route,
|
||||
Navigate
|
||||
} from 'react-router-dom';
|
||||
import { ToastContainer } from 'react-toastify';
|
||||
import 'react-toastify/dist/ReactToastify.css';
|
||||
|
||||
// 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
|
||||
} from './components/auth';
|
||||
|
||||
// Pages
|
||||
import HomePage from './pages/HomePage';
|
||||
import DashboardPage from
|
||||
'./pages/customer/DashboardPage';
|
||||
import RoomListPage from
|
||||
'./pages/customer/RoomListPage';
|
||||
import RoomDetailPage from
|
||||
'./pages/customer/RoomDetailPage';
|
||||
import SearchResultsPage from
|
||||
'./pages/customer/SearchResultsPage';
|
||||
import FavoritesPage from
|
||||
'./pages/customer/FavoritesPage';
|
||||
import MyBookingsPage from
|
||||
'./pages/customer/MyBookingsPage';
|
||||
import BookingPage from
|
||||
'./pages/customer/BookingPage';
|
||||
import BookingSuccessPage from
|
||||
'./pages/customer/BookingSuccessPage';
|
||||
import BookingDetailPage from
|
||||
'./pages/customer/BookingDetailPage';
|
||||
import DepositPaymentPage from
|
||||
'./pages/customer/DepositPaymentPage';
|
||||
import PaymentConfirmationPage from
|
||||
'./pages/customer/PaymentConfirmationPage';
|
||||
import PaymentResultPage from
|
||||
'./pages/customer/PaymentResultPage';
|
||||
import {
|
||||
LoginPage,
|
||||
RegisterPage,
|
||||
ForgotPasswordPage,
|
||||
ResetPasswordPage
|
||||
} from './pages/auth';
|
||||
|
||||
// Admin Pages
|
||||
import {
|
||||
DashboardPage as AdminDashboardPage,
|
||||
RoomManagementPage,
|
||||
UserManagementPage,
|
||||
BookingManagementPage,
|
||||
PaymentManagementPage,
|
||||
ServiceManagementPage,
|
||||
ReviewManagementPage,
|
||||
PromotionManagementPage,
|
||||
CheckInPage,
|
||||
CheckOutPage,
|
||||
} from './pages/admin';
|
||||
|
||||
// Demo component for pages not yet created
|
||||
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">
|
||||
{title}
|
||||
</h1>
|
||||
<p className="text-gray-600 mt-4">
|
||||
This page is under development...
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
function App() {
|
||||
// Use Zustand store
|
||||
const {
|
||||
isAuthenticated,
|
||||
userInfo,
|
||||
logout,
|
||||
initializeAuth
|
||||
} = useAuthStore();
|
||||
|
||||
const {
|
||||
fetchFavorites,
|
||||
syncGuestFavorites,
|
||||
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();
|
||||
}
|
||||
}, [
|
||||
isAuthenticated,
|
||||
fetchFavorites,
|
||||
syncGuestFavorites,
|
||||
loadGuestFavorites,
|
||||
]);
|
||||
|
||||
// Handle logout
|
||||
const handleLogout = async () => {
|
||||
await logout();
|
||||
};
|
||||
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<Routes>
|
||||
{/* Public Routes with Main Layout */}
|
||||
<Route
|
||||
path="/"
|
||||
element={
|
||||
<LayoutMain
|
||||
isAuthenticated={isAuthenticated}
|
||||
userInfo={userInfo}
|
||||
onLogout={handleLogout}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<Route index element={<HomePage />} />
|
||||
<Route
|
||||
path="rooms"
|
||||
element={<RoomListPage />}
|
||||
/>
|
||||
<Route
|
||||
path="rooms/search"
|
||||
element={<SearchResultsPage />}
|
||||
/>
|
||||
<Route
|
||||
path="rooms/:id"
|
||||
element={<RoomDetailPage />}
|
||||
/>
|
||||
<Route
|
||||
path="favorites"
|
||||
element={<FavoritesPage />}
|
||||
/>
|
||||
<Route
|
||||
path="payment-result"
|
||||
element={<PaymentResultPage />}
|
||||
/>
|
||||
<Route
|
||||
path="about"
|
||||
element={<DemoPage title="About" />}
|
||||
/>
|
||||
|
||||
{/* Protected Routes - Requires login */}
|
||||
<Route
|
||||
path="dashboard"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<DashboardPage />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="booking/:id"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<BookingPage />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="booking-success/:id"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<BookingSuccessPage />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="deposit-payment/:bookingId"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<DepositPaymentPage />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="bookings"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<MyBookingsPage />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="bookings/:id"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<BookingDetailPage />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="payment/:id"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<PaymentConfirmationPage />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="profile"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<DemoPage title="Profile" />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
</Route>
|
||||
|
||||
{/* Auth Routes (no layout) */}
|
||||
<Route
|
||||
path="/login"
|
||||
element={<LoginPage />}
|
||||
/>
|
||||
<Route
|
||||
path="/register"
|
||||
element={<RegisterPage />}
|
||||
/>
|
||||
<Route
|
||||
path="/forgot-password"
|
||||
element={<ForgotPasswordPage />}
|
||||
/>
|
||||
<Route
|
||||
path="/reset-password/:token"
|
||||
element={<ResetPasswordPage />}
|
||||
/>
|
||||
|
||||
{/* Admin Routes - Only admin can access */}
|
||||
<Route
|
||||
path="/admin"
|
||||
element={
|
||||
<AdminRoute>
|
||||
<AdminLayout />
|
||||
</AdminRoute>
|
||||
}
|
||||
>
|
||||
<Route
|
||||
index
|
||||
element={<Navigate to="dashboard" replace />}
|
||||
/>
|
||||
<Route path="dashboard" element={<AdminDashboardPage />} />
|
||||
<Route
|
||||
path="users"
|
||||
element={<UserManagementPage />}
|
||||
/>
|
||||
<Route
|
||||
path="rooms"
|
||||
element={<RoomManagementPage />}
|
||||
/>
|
||||
<Route
|
||||
path="bookings"
|
||||
element={<BookingManagementPage />}
|
||||
/>
|
||||
<Route
|
||||
path="payments"
|
||||
element={<PaymentManagementPage />}
|
||||
/>
|
||||
<Route
|
||||
path="services"
|
||||
element={<ServiceManagementPage />}
|
||||
/>
|
||||
<Route
|
||||
path="reviews"
|
||||
element={<ReviewManagementPage />}
|
||||
/>
|
||||
<Route
|
||||
path="promotions"
|
||||
element={<PromotionManagementPage />}
|
||||
/>
|
||||
<Route
|
||||
path="check-in"
|
||||
element={<CheckInPage />}
|
||||
/>
|
||||
<Route
|
||||
path="check-out"
|
||||
element={<CheckOutPage />}
|
||||
/>
|
||||
<Route
|
||||
path="banners"
|
||||
element={<DemoPage title="Banner Management" />}
|
||||
/>
|
||||
<Route
|
||||
path="reports"
|
||||
element={<DemoPage title="Reports" />}
|
||||
/>
|
||||
<Route
|
||||
path="settings"
|
||||
element={<DemoPage title="Settings" />}
|
||||
/>
|
||||
</Route>
|
||||
|
||||
{/* 404 Route */}
|
||||
<Route
|
||||
path="*"
|
||||
element={<DemoPage title="404 - Page not found" />}
|
||||
/>
|
||||
</Routes>
|
||||
|
||||
<ToastContainer
|
||||
position="top-right"
|
||||
autoClose={3000}
|
||||
hideProgressBar={false}
|
||||
newestOnTop
|
||||
closeOnClick
|
||||
rtl={false}
|
||||
pauseOnFocusLoss
|
||||
draggable
|
||||
pauseOnHover
|
||||
/>
|
||||
</BrowserRouter>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
Reference in New Issue
Block a user