cpe241-booking-website-client

Public
OVERVIEW.md

A cinema booking interface had to connect the staff schedule to the customer's seat map.

I used a database-course final project to build a cinema workflow from both sides under a fixed deadline. Staff create movies, halls, and showings; customers choose a showing and seats. Each new screen raised a data question for the other side: a changed schedule or seat state had to appear there too. The React app grew around those linked workflows and the companion API, rather than around isolated mock pages.

Following a showing through both sides

The admin portal includes movie and venue management, an hourly schedule view, bookings, a dashboard, and reports. The customer path moves through movie and showtime selection, an interactive seat map, checkout, and confirmation. Admin and customer routes keep separate session state and API helpers, while server responses supply the movies, schedules, seat states, and records shown in the interface. Charts turn booking and revenue queries into a view staff can scan.

The seat map is where the two journeys meet. A hall's configured seats become availability for a particular showing; a customer's checkout changes what the next customer sees and what staff can review. That made state and error handling more important than simply drawing a grid of seats.

This repository owns the pages, visual flow, and browser-side state. The server owns SQL transactions and the rules that prevent conflicting schedule and seat changes. The result is a connected course application and booking demonstration. Its checkout does not integrate a real payment processor, and the repository does not establish use by an actual cinema.

README.md

Cinema Admin — Client

The React 19 + TypeScript frontend for the Cinema Admin System. Covers two distinct portals running in the same SPA:

  • Admin portal (/admin) — authenticated cinema staff manage movies, screen schedules, venues, bookings, and view revenue reports.
  • Customer booking flow (/booking) — authenticated customers browse movies, pick showtimes, select seats, and complete bookings.

The client communicates with the Express API at http://localhost:5000. See ../server/README.md for backend setup.


Table of Contents

  1. Tech Stack
  2. Prerequisites
  3. Setup and Scripts
  4. Environment and API Base URL
  5. Route Map
  6. Admin Portal
  7. Customer Booking Flow
  8. Architecture
  9. Zustand Stores
  10. Authentication
  11. Theming System
  12. Project Structure
  13. Production Build
  14. Troubleshooting

Tech Stack

LayerChoiceVersion
UI frameworkReact19
LanguageTypeScript~6.x, strict mode
BundlerVite8
RoutingReact Router7
StylingTailwind CSS4 (@tailwindcss/vite)
ChartsRecharts3
StateZustand5 (persist middleware)

Import alias: @/* → src/* (configured in vite.config.ts and tsconfig.app.json).


Prerequisites

  • Node.js 20 or newer
  • npm (bundled with Node)
  • The Express API server running at http://localhost:5000 — see ../server/README.md

Setup and Scripts

cd client
npm install
ScriptWhat it does
npm run devVite dev server at http://localhost:5173 (HMR enabled)
npm run buildTypeScript check then production output to dist/
npm run previewServe the production build locally
npm run lintESLint with flat config (eslint.config.js)

Environment and API Base URL

The API base URL defaults to http://localhost:5000 and is hardcoded in two API helper files:

FileUsed by
src/lib/api.tsAdmin portal stores
src/lib/customerApi.tsCustomer booking flow

To point at a different API host, update the base URL constants in those two files (or replace them with import.meta.env.VITE_API_URL).


Route Map

/                               LandingPage
/login                          UserLoginPage      (→ /booking/movies if already authed)
/admin/login                    LoginPage          (→ /admin/ if already authed)
/admin/                         DashboardPage      ─┐
/admin/movies                   MovieManagementPage  │ AdminProtectedRoute
/admin/screens                  ScreenManagementPage │ (→ /admin/login if not authed)
/admin/venues                   VenueManagementPage  │
/admin/booking                  BookingPage          │
/admin/reports                  ReportsPage        ─┘
/booking                        CustomerBookingLayout ─┐
/booking/movies                 CustomerMoviePick      │ CustomerProtectedRoute
/booking/movies/:showId/…       CustomerShowtimePick   │ (→ /login if not authed)
/booking/showings/:id/seats     CustomerSeatSelection  │
/booking/checkout               CustomerCheckoutPage   │
/booking/checkout/:bookingId    CustomerCheckoutPage ──┘
*                               NotFound (404)

Admin Portal

All admin routes live under /admin and require a valid admin JWT. AdminPageLayout provides the persistent sidebar (NavSidebar) and top bar (Topbar) via React Router's <Outlet>.

Pages

RouteStoreDescription
/admin/useDashboardStore4 live stat cards, 7-day booking trend chart, today's upcoming showings table
/admin/moviesuseMovieStoreCard grid — add, edit, delete movies. Delete is blocked server-side if showings exist.
/admin/screensuseShowingStore + useMovieStoreHourly timeline grid per venue + showtime table. Create showing triggers auto-seat population.
/admin/venuesuseVenueStoreVenue list with seat counts. Click a venue to manage its seat assignments.
/admin/bookinguseBookingStorePaginated booking list with search, status/date filters, and a Cancel action.
/admin/reportslocal useStatePeriod selector (week/month/year) + revenue charts (area + bar) + stat cards. No global store — read-only aggregates.

Customer Booking Flow

Public-facing booking lives under /booking and requires a customer JWT. The layout component is CustomerBookingLayout.

Flow

Landing (/)
  └─→ Customer Login (/login)
        └─→ Movie Picker (/booking/movies)
              └─→ Showtime Picker (/booking/movies/:showId/showtimes)
                    └─→ Seat Selection (/booking/showings/:showingId/seats)
                          └─→ Checkout (/booking/checkout)
                                └─→ Confirmation (/booking/checkout/:bookingId)
PageAPI callsDescription
CustomerMoviePickGET /api/moviesBrowse movies sorted by availability
CustomerShowtimePickGET /api/showings?show_id=Available showtimes for a movie
CustomerSeatSelectionGET /api/customer/showings/:id/seatsInteractive seat map; Free / Reserved / Confirmed
CustomerCheckoutPagePOST /api/customer/bookings, POST .../checkout, POST .../completeCreate booking → checkout → complete

All customer API requests use customerApi (src/lib/customerApi.ts) which attaches the customer JWT from the useCustomerAuth store.


Architecture

State flow

Page component
  → Zustand store action (e.g. fetchMovies())
    → api.ts / customerApi.ts (typed fetch wrapper, attaches JWT)
      → Express API (:5000)
        → MySQL

API helpers

FilePurpose
src/lib/api.tsAdmin API calls — reads token from useAuthStore; on 401 redirects to /admin/login
src/lib/customerApi.tsCustomer API calls — reads token from useCustomerAuthStore; on 401 redirects to /login

Zustand Stores

StorePersistedState
useAuthYes (cinema-admin-auth){ authed, token }
useCustomerAuthYes (cinema-customer-auth){ authed, token, user }
useMovieStoreNo{ movies, loading, error }
useShowingStoreNo{ showings, venues, loading, error }
useBookingStoreNo{ bookings, loading, error }
useDashboardStoreNo{ stats, trend, upcoming, loading }
useVenueStoreNo{ venues, seats, selectedVenueId, loading, error }

All persisted stores use Zustand's persist middleware with localStorage.


Authentication

Admin

  • Login: POST /api/auth/login — server validates email + password, checks role = 'Admin', returns a signed JWT (8-hour expiry).
  • Token stored in localStorage via useAuthStore.
  • Every admin API request sends Authorization: Bearer <token>.
  • 401 response → store is cleared and the user is redirected to /admin/login.

Customer

  • Login: POST /api/auth/customer/login — same JWT mechanism, role = 'Customer'.
  • Token stored in localStorage via useCustomerAuthStore.
  • Customer-scoped API calls go through customerApi.ts.
  • 401 response → redirect to /login.

Demo credentials:

RoleEmailPassword
Adminadmin@cinema.comAdmin@1234
Customerjohn@example.comUser@1234

Theming System

AdminPageLayout sets data-admin-theme="light" or "dark" on the content wrapper based on the current route:

ThemeRoutes
lightDashboard, Reports
darkMovies, Screens, Venues, Booking

All component colors are CSS custom property tokens (e.g. var(--color-surface)). No hardcoded hex values in components. The single source of truth for all tokens is src/index.css.

UrlPathConfig.ts holds ADMIN_PATH_CONFIG — the single source of truth for route paths, nav labels, icon assets, and per-route color sets. Both NavSidebar and Topbar read from this config.


Project Structure

client/
├── index.html
├── vite.config.ts
├── tsconfig.json / tsconfig.app.json / tsconfig.node.json
├── eslint.config.js
├── vercel.json                   # SPA fallback rewrite for Vercel
└── src/
    ├── main.tsx                  # Entry: StrictMode + BrowserRouter + App
    ├── App.tsx                   # All routes + auth guard components
    ├── index.css                 # ALL color tokens (var(--color-*))
    ├── lib/
    │   ├── api.ts                # Admin typed fetch wrapper
    │   ├── customerApi.ts        # Customer typed fetch wrapper
    │   ├── customerBookingUi.ts  # Movie availability helpers
    │   └── seatRowGrouping.ts    # Seat layout helpers
    ├── assets/
    │   ├── hero.png
    │   ├── login_bg.png
    │   ├── tempMoviePoster.jpg   # Fallback poster image
    │   └── navbar/               # dashboard.png, movie.png, …
    ├── components/
    │   ├── AdminPageLayout.tsx   # Shell: NavSidebar + Topbar + <Outlet>
    │   ├── NavSidebar.tsx
    │   ├── Topbar.tsx
    │   ├── LoginShell.tsx        # Shared login form used by both portals
    │   ├── UrlPathConfig.ts      # ADMIN_PATH_CONFIG, route/color/icon config
    │   └── editModal/
    │       ├── MovieFormModal.tsx
    │       └── ScreenFormModal.tsx
    ├── pages/
    │   ├── LandingPage.tsx
    │   ├── Login.tsx             # Admin login
    │   ├── UserLogin.tsx         # Customer login
    │   ├── Dashboard.tsx
    │   ├── MovieManagement.tsx
    │   ├── ScreenManagement.tsx
    │   ├── VenueManagement.tsx
    │   ├── Booking.tsx
    │   ├── Report.tsx
    │   ├── NotFound.tsx
    │   └── customer/
    │       ├── CustomerBookingLayout.tsx
    │       ├── CustomerMoviePick.tsx
    │       ├── CustomerShowtimePick.tsx
    │       ├── CustomerSeatSelection.tsx
    │       └── CustomerCheckoutPage.tsx
    └── store/
        ├── useAuth.ts
        ├── useCustomerAuth.ts
        ├── useMovieStore.ts
        ├── useShowingStore.ts
        ├── useBookingStore.ts
        ├── useDashboardStore.ts
        └── useVenueStore.ts

Production Build

npm run build

Output: dist/ — static HTML/JS/CSS.

The app uses BrowserRouter, so the host must serve index.html for all unknown paths (SPA fallback). vercel.json includes a catch-all rewrite suitable for Vercel.

For other hosts, configure the equivalent:

  • Nginx: try_files $uri /index.html
  • Apache: FallbackResource /index.html

Troubleshooting

IssueFix
Blank page / 404 on refresh at /admin/moviesEnable SPA history fallback on your host (see Production Build)
"Failed to fetch" on loginEnsure the API server is running on :5000 and CORS allows :5173
Missing poster imagesThe server serves uploaded posters via Cloudinary; check CLOUDINARY_* env vars in server/.env
TypeScript errors after editingRun npm run build to surface tsc -b type errors
Wrong or missing sidebar iconEnsure src/assets/navbar/<name>.png exists and matches iconPath("<name>") in UrlPathConfig.ts

License

Original code and documentation authored by Jakkarin Promsee are licensed under the MIT License. Third-party code, assets, datasets, and other materials are not covered by this license; their original terms apply.