This commit is contained in:
Iliyan Angelov
2025-11-16 15:12:43 +02:00
parent 824eec6190
commit 93d4c1df80
54 changed files with 1606 additions and 1612 deletions

View File

@@ -1,48 +1,48 @@
# Layout Components - Chức năng 1
# Layout Components - Function 1
## Tổng quan
Đã triển khai thành công **Chức năng 1: Layout cơ bản** bao gồm:
## Overview
Successfully implemented **Function 1: Basic Layout** including:
### Components đã tạo
### Components Created
#### 1. **Header** (`src/components/layout/Header.tsx`)
- Logo và tên ứng dụng
- Sticky header với shadow
- Logo and application name
- Sticky header with shadow
- Responsive design
- Links cơ bản (Trang chủ, Phòng, Đặt phòng)
- Basic links (Home, Rooms, Bookings)
#### 2. **Footer** (`src/components/layout/Footer.tsx`)
- Thông tin công ty
- Quick links (Liên kết nhanh)
- Support links (Hỗ trợ)
- Contact info (Thông tin liên hệ)
- Company information
- Quick links
- Support links
- Contact information
- Social media icons
- Copyright info
- Copyright information
- Fully responsive (4 columns → 2 → 1)
#### 3. **Navbar** (`src/components/layout/Navbar.tsx`)
- **Trạng thái chưa đăng nhập**:
- Hiển thị nút "Đăng nhập" và "Đăng ký"
- **Trạng thái đã đăng nhập**:
- Hiển thị avatar/tên user
- Dropdown menu với "Hồ sơ", "Quản trị" (admin), "Đăng xuất"
- Mobile menu với hamburger icon
- Responsive cho desktop mobile
- **Not logged in state**:
- Display "Login" and "Register" buttons
- **Logged in state**:
- Display avatar/user name
- Dropdown menu with "Profile", "Admin" (admin), "Logout"
- Mobile menu with hamburger icon
- Responsive for desktop and mobile
#### 4. **SidebarAdmin** (`src/components/layout/SidebarAdmin.tsx`)
- Chỉ hiển thị cho role = "admin"
- Collapsible sidebar (mở/đóng)
- Only displays for role = "admin"
- Collapsible sidebar (open/close)
- Menu items: Dashboard, Users, Rooms, Bookings, Payments, Services, Promotions, Banners, Reports, Settings
- Active state highlighting
- Responsive design
#### 5. **LayoutMain** (`src/components/layout/LayoutMain.tsx`)
- Tích hợp Header, Navbar, Footer
- Sử dụng `<Outlet />` để render nội dung động
- Integrates Header, Navbar, Footer
- Uses `<Outlet />` to render dynamic content
- Props: `isAuthenticated`, `userInfo`, `onLogout`
- Min-height 100vh với flex layout
- Min-height 100vh with flex layout
### Cấu trúc thư mục
### Directory Structure
```
src/
├── components/
@@ -62,13 +62,13 @@ src/
└── main.tsx
```
### Cách sử dụng
### Usage
#### 1. Import Layout o App
#### 1. Import Layout into App
```tsx
import LayoutMain from './components/layout/LayoutMain';
// Trong Routes
// In Routes
<Route
path="/"
element={
@@ -80,11 +80,11 @@ import LayoutMain from './components/layout/LayoutMain';
}
>
<Route index element={<HomePage />} />
{/* Các route con khác */}
{/* Other child routes */}
</Route>
```
#### 2. Sử dụng SidebarAdmin cho trang Admin
#### 2. Use SidebarAdmin for Admin Pages
```tsx
import SidebarAdmin from '../components/layout/SidebarAdmin';
@@ -98,78 +98,78 @@ const AdminLayout = () => (
);
```
### Tính năng đã hoàn thành
### Completed Features
- [x] Tạo thư mục `src/components/layout/`
- [x] Header.tsx với logo navigation
- [x] Footer.tsx với thông tin đầy đủ
- [x] Navbar.tsx với logic đăng nhập/đăng xuất động
- [x] SidebarAdmin.tsx chỉ hiển thị với role admin
- [x] LayoutMain.tsx sử dụng `<Outlet />`
- [x] Navbar thay đổi theo trạng thái đăng nhập
- [x] Giao diện responsive, tương thích desktop/mobile
- [x] Tích hợp TailwindCSS cho styling
- [x] Export tất cả components qua index.ts
- [x] Create `src/components/layout/` directory
- [x] Header.tsx with logo and navigation
- [x] Footer.tsx with complete information
- [x] Navbar.tsx with dynamic login/logout logic
- [x] SidebarAdmin.tsx only displays with admin role
- [x] LayoutMain.tsx uses `<Outlet />`
- [x] Navbar changes based on login state
- [x] Responsive interface, compatible with desktop/mobile
- [x] TailwindCSS integration for styling
- [x] Export all components via index.ts
### Demo Routes đã tạo
### Demo Routes Created
**Public Routes** (với LayoutMain):
- `/` - Trang chủ
- `/rooms` - Danh sách phòng
- `/bookings` - Đặt phòng
- `/about` - Giới thiệu
**Public Routes** (with LayoutMain):
- `/` - Home
- `/rooms` - Room list
- `/bookings` - Bookings
- `/about` - About
**Auth Routes** (không có layout):
- `/login` - Đăng nhập
- `/register` - Đăng ký
- `/forgot-password` - Quên mật khẩu
**Auth Routes** (no layout):
- `/login` - Login
- `/register` - Register
- `/forgot-password` - Forgot password
**Admin Routes** (với SidebarAdmin):
**Admin Routes** (with SidebarAdmin):
- `/admin/dashboard` - Dashboard
- `/admin/users` - Quản lý người dùng
- `/admin/rooms` - Quản lý phòng
- `/admin/bookings` - Quản lý đặt phòng
- `/admin/payments` - Quản lý thanh toán
- `/admin/services` - Quản lý dịch vụ
- `/admin/promotions` - Quản lý khuyến mãi
- `/admin/banners` - Quản lý banner
- `/admin/users` - User Management
- `/admin/rooms` - Room Management
- `/admin/bookings` - Booking Management
- `/admin/payments` - Payment Management
- `/admin/services` - Service Management
- `/admin/promotions` - Promotion Management
- `/admin/banners` - Banner Management
### Chạy ứng dụng
### Run Application
```bash
# Di chuyển vào thư mục client
# Navigate to client directory
cd client
# Cài đặt dependencies (nếu chưa cài)
# Install dependencies (if not installed)
npm install
# Chạy development server
# Run development server
npm run dev
# Mở trình duyệt tại: http://localhost:5173
# Open browser at: http://localhost:5173
```
### Các bước tiếp theo
### Next Steps
**Chức năng 2**: Cấu hình Routing (react-router-dom)
**Function 2**: Routing Configuration (react-router-dom)
- ProtectedRoute component
- AdminRoute component
- Redirect logic
**Chức năng 3**: useAuthStore (Zustand Store)
- Quản lý authentication state
**Function 3**: useAuthStore (Zustand Store)
- Manage authentication state
- Login/Logout functions
- Persist state trong localStorage
- Persist state in localStorage
**Chức năng 4-8**: Auth Forms
**Function 4-8**: Auth Forms
- LoginPage
- RegisterPage
- ForgotPasswordPage
- ResetPasswordPage
### Notes
- Layout components được thiết kế để tái sử dụng
- Props-based design cho flexibility
- Sẵn sàng tích hợp với Zustand store
- Tailwind classes tuân thủ 80 ký tự/dòng
- Icons sử dụng lucide-react (đã có trong dependencies)
- Layout components designed for reusability
- Props-based design for flexibility
- Ready to integrate with Zustand store
- Tailwind classes follow 80 characters/line
- Icons use lucide-react (already in dependencies)