Pricing & Fleet Data Models
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The Pricing & Fleet Data Models system serves as the core data layer for the Wasalny landing page, managing the relationships between geographic locations, transportation routes, and vehicle specifications. It provides a structured framework for calculating trip costs based on vehicle categories (Sedan, SUV, Family Cruiser, Minibus) and route types (Travel or Internal Damietta).
This system enables the dynamic pricing engine to resolve complex routing logic, such as bidirectional travel and multi-location grouping, while ensuring that passenger capacity constraints are strictly enforced. The data models defined here are consumed by React hooks and utility functions to provide users with instant, accurate quotes and an interactive fleet showcase.
Sources: src/data/pricing.ts:1-5, src/utils/pricingCalculator.ts:31-40
Data Models & Core Structures
The architecture relies on several TypeScript interfaces that define the shape of the transportation network and the fleet attributes.
1. Location and Route Groups
Locations are classified by RouteType, distinguishing between long-distance travel (e.g., Cairo Airport) and local movement within Damietta. The RouteGroup interface is the pivot point for pricing, linking sets of "From" and "To" locations to specific price points.
Sources: src/data/pricing.ts:4-29
2. Vehicle Specifications
The fleet is categorized into four primary tiers. Each tier defines its physical capacity and localization strings used across the UI.
| Field | Type | Description |
|---|---|---|
category | VehicleCategory | Unique identifier (sedan, suv, family_cruiser, minibus) |
categoryAr | string | Arabic localized name for the vehicle tier |
maxPassengers | number | Maximum occupancy limit |
minPassengers | number | Minimum required passengers (usually 1) |
Sources: src/data/pricing.ts:31-36, src/components/sections/FleetSection.tsx:18-47
Pricing Engine Logic
The calculation logic is encapsulated within calculatePrice, which utilizes a set of utility functions to find the appropriate pricing bracket based on the user's trip details.
Calculation Flow
The engine follows a strict sequence to resolve the final cost:
- Route Resolution: Checks if the selected "From" and "To" IDs exist within a
RouteGroup. - Vehicle Validation: Verifies the selected category against
vehiclePricingdata. - Capacity Check: Compares
passengerCountagainst the vehicle'smaxPassengers. - Price Retrieval: Accesses the nested pricing object using the
tripType(oneWay/roundTrip) as a key.
State Management via Hooks
The usePricingCalculator hook manages the interactive state of the pricing form. It handles derived state, such as filtering valid "To" locations based on the selected "From" location.
Hook Derived State Logic
| Derived Value | Source Logic |
|---|---|
availableToLocations | Filters locations based on routeGroups where the current fromLocation is a valid starting point. |
whatsappLink | Formats a PriceCalculationResult into an encoded string for the WhatsApp API. |
isValid | Boolean check ensuring both locations are selected and no validation errors exist. |
Sources: src/hooks/usePricingCalculator.ts:38-48, src/hooks/usePricingCalculator.ts:117-121
Persistence and Sync
The hook implements useEffect to persist user selections (Route Type, Category, Passenger Count) to localStorage, ensuring a seamless experience across page reloads. It also includes a "Smart Vehicle Switch" that automatically updates the vehicleCategory if the passenger count exceeds the current vehicle's capacity.
Sources: src/hooks/usePricingCalculator.ts:98-115, src/hooks/usePricingCalculator.ts:126-135
Fleet Presentation Data
The FleetSection component utilizes the carImages and carCategories datasets to render a 3D-perspective carousel.
Data Relationships
- Images: Indexed by
VehicleCategory, containing arrays of high-quality assets. - Categorization: Links technical IDs to UI-friendly Arabic labels and icons (e.g.,
Car,Bus,UsersRound). - Feature Sets: Hardcoded metadata in the component (e.g., "Air Conditioning", "USB Charger") mapped to each category.
Sources: src/components/sections/FleetSection.tsx:18-47, src/data/cars.ts (referenced)
Conclusion
The Pricing & Fleet Data Models provide a robust, type-safe foundation for the Wasalny platform. By decoupling geographic routing from vehicle-specific pricing, the system allows for easy scaling of the transportation network while maintaining strict validation of passenger capacity and trip logistics. This architecture ensures that the data flow—from raw static definitions to complex UI state—remains predictable and technically accurate.