4.0 KiB
4.0 KiB
Booking & Payment
Function 1: BookingPage – Booking Form
Objective
Build a complete booking form with information, data validation, calculate total by number of days, and send booking request.
Detailed Tasks
-
Route:
/booking/:roomId -
When user clicks "Book Now" on RoomDetailPage → navigate to BookingPage.
-
Display:
- Room image, room name, price/night
- User information (auto-fill if logged in)
- Form:
- Check-in / check-out date (DateRangePicker)
- Number of guests
- Notes
- Payment method:
- Pay at hotel
- Bank transfer (display QR + instructions)
-
Validate using Yup + React Hook Form:
- Check-in < Check-out
- Dates not empty
- Payment method selected
-
Calculate total:
total = room.price * (number of nights) -
"Book" button:
- Loading spinner
- Disable when submitting
-
If not logged in → redirect to /login.
Function 2: Booking API (Backend communication)
Objective
Connect and handle APIs related to booking.
Detailed Tasks
🔧 Endpoints:
POST /api/bookings → Create booking GET /api/bookings/me → Get user's booking list PATCH /api/bookings/:id/cancel → Cancel booking GET /api/bookings/:id → Booking details GET /api/bookings/check/:bookingNumber → Look up booking
🔄 Processing flow:
- Frontend calls POST /api/bookings
- Backend checks room availability:
GET /api/rooms/available?roomId=...&from=...&to=... - If available → create booking
- If schedule conflict → return 409 "Room already booked during this time"
- Send booking confirmation email (if needed)
- Return booking data to display /booking-success/:id.
Function 3: BookingSuccess – Page after booking
Objective
Display successful booking result and next actions.
Detailed Tasks
- Route: /booking-success/:id
- Call GET /api/bookings/:id → display details
- Buttons:
- "View my bookings" → /my-bookings
- "Go to home" → /
- If payment method is Bank transfer:
- Display bank QR code
- Allow upload confirmation image
- Call POST /api/notify/payment when user confirms transfer.
Function 4: MyBookingsPage – User's booking list
Objective
Display all user's bookings + allow canceling bookings.
Detailed Tasks
- Route: /my-bookings
- API: GET /api/bookings/me
- Display booking list:
- Room, check-in/check-out dates, total amount
- Status: 🟡 pending 🟢 confirmed 🔴 cancelled
- "Cancel booking" button:
- window.confirm("Are you sure you want to cancel?")
- Call PATCH /api/bookings/:id/cancel (or DELETE /api/bookings/:id depending on implementation)
- Cancel logic:
- Keep 20% of order value
- Refund remaining 80% to user
- Update room status to available
- Display toast "Booking cancelled successfully"
- Allow viewing booking details:
- Route: /bookings/:id
- Call GET /api/bookings/:id
- Display room details, user information, total amount, status.
Function 5: Payment (Simulated Payment)
Objective
Allow users to select payment method and confirm payment.
Detailed Tasks
- Payment methods:
- Pay at hotel
- Booking created with status = "pending"
- Bank transfer
- Display bank QR code (static or from API)
- Upload receipt image (image upload)
- After upload → call POST /api/notify/payment send confirmation email
- Update status = "confirmed"
- Pay at hotel
Function 6: UX & Performance
Objective
Improve user experience and intuitiveness.
Detailed Tasks
- Toasts (react-hot-toast or sonner)
- Clear loading spinner
- DateRangePicker for date selection
- Form fully validated (and detailed error messages)
- Focus first input
- Auto redirect when booking succeeds / canceling booking