Skip to content
 
 

Repository files navigation

Vanlife

Vanlife is a camper van rental marketplace that makes discovering and booking the perfect road trip van effortless. Travelers can browse, filter, and explore van details, while hosts get a clean dashboard to manage listings, track income, and monitor reviews. Everything runs in the browser with a mock API that feels just like the real thing.

Overview

The site puts a fleet of camper vans right at your fingertips. Search through options by type, dive into van details, and if you're a host, log in to see your earnings, review scores, and vans at a glance. It's built to be fast, responsive, and dead simple to use, no matter what device you're on.

System Architecture

The application is a single‑page React app powered by Vite. All API calls go to an in‑browser MirageJS mock server that stores data in memory and responds exactly like a real backend. This setup keeps everything self‑contained, so you can develop and demo it without any external services.

flowchart LR
    Browser["Web Browser"]
    ReactApp["React SPA (Vite)"]
    ApiModule["API Module (api.js)"]
    Mirage["MirageJS Mock Server"]
    Models[("In-Memory Models")]

    Browser --> ReactApp
    ReactApp --> ApiModule
    ApiModule --> Mirage
    Mirage --> Models

    style Browser fill:#1e1b4b,stroke:#6366f1,stroke-width:2px,color:#fff
    style ReactApp fill:#2e1065,stroke:#8b5cf6,stroke-width:2px,color:#fff
    style ApiModule fill:#2e1065,stroke:#8b5cf6,stroke-width:2px,color:#fff
    style Mirage fill:#2e1065,stroke:#8b5cf6,stroke-width:2px,color:#fff
    style Models fill:#0f172a,stroke:#3b82f6,stroke-width:2px,color:#fff
Loading

Features

User Authentication

The login system verifies credentials against the mock user store, stores a login flag in localStorage, and protects host routes. If a user isn't logged in, they're redirected to the login page with a friendly message. The auth state is checked on every host route to keep things secure.

sequenceDiagram
    actor User
    participant LoginPage
    participant ApiModule as API Module
    participant Mirage as MirageJS Server
    participant LocalStorage

    User->>LoginPage: Enter email & password
    LoginPage->>ApiModule: loginUser({email, password})
    ApiModule->>Mirage: POST /api/login
    Mirage->>Mirage: Find user by email and password
    alt User found
        Mirage->>ApiModule: { user, token }
        ApiModule->>LoginPage: Success
        LoginPage->>LocalStorage: Set "loggedin" = true
        LoginPage->>User: Navigate to host dashboard
    else User not found
        Mirage->>ApiModule: 401 { message: "No user with those credentials found!" }
        ApiModule->>LoginPage: Error thrown
        LoginPage->>User: Show error message
    end
Loading

Van Browsing with Smart Filters

The van listing page lets users filter vans by type (simple, rugged, luxury) using URL search parameters. The filter state stays in the URL, so you can share or bookmark filtered views. Clicking a van navigates to its detail page and preserves the filter context, making the back navigation feel seamless.

sequenceDiagram
    actor User
    participant VansPage
    participant ApiModule as API Module
    participant Mirage as MirageJS Server

    User->>VansPage: Visits /vans
    VansPage->>ApiModule: getVans()
    ApiModule->>Mirage: GET /api/vans
    Mirage->>ApiModule: all vans
    ApiModule->>VansPage: vans array
    VansPage->>User: Render all vans
    User->>VansPage: Click filter (e.g. "Simple")
    VansPage->>VansPage: Update searchParams, filter vans by type
    VansPage->>User: Show only simple vans
    User->>VansPage: Click van tile
    VansPage->>User: Navigate to /vans/:id, passing search string
Loading

Host Dashboard

After logging in, hosts land on a dashboard that shows a 30‑day earnings summary, current review score, and all listed vans. The dashboard fetches host‑specific van data from the mock API and renders each van with a quick link to its detail page.

Host Van Management

Hosts can drill into each van to see details, pricing, and photos. The host detail layout uses React Router outlet context to share van data between tabs, keeping the interface snappy and consistent.

API Documentation

All endpoints are simulated by a MirageJS server running inside the browser. No external server is needed. Authentication works through a simple login endpoint that returns a mock token; host‑specific endpoints are hard‑coded to return vans for hostId 123.

GET /api/vans

Description: Returns all available vans.

Response:

[
  {
    "id": "1",
    "name": "Modest Explorer",
    "price": 60,
    "description": "The Modest Explorer is a van designed...",
    "imageUrl": "https://assets.scrimba.com/advanced-react/react-router/modest-explorer.png",
    "type": "simple",
    "hostId": "123"
  },
  ...
]

Errors:

  • 400: Generic error (returned if you uncomment the error simulation in server.js)

GET /api/vans/:id

Description: Returns a single van by its ID.

Response:

{
  "id": "1",
  "name": "Modest Explorer",
  "price": 60,
  "description": "...",
  "imageUrl": "...",
  "type": "simple",
  "hostId": "123"
}

Errors:

  • 404: Van not found

GET /api/host/vans

Description: Returns vans belonging to the hard‑coded host (hostId: "123"). This is a quick demo endpoint for the host dashboard.

Response: Same structure as /api/vans, filtered to host vans.


GET /api/host/vans/:id

Description: Returns a single host van by ID (only if hostId matches 123).

Response: Same as /api/vans/:id.


POST /api/login

Description: Authenticates a user against the mock user store.

Request:

{
  "email": "b@b.com",
  "password": "p123"
}

Response (on success):

{
  "user": {
    "id": "123",
    "email": "b@b.com",
    "name": "Bob"
  },
  "token": "Enjoy your pizza, here's your tokens."
}

Errors:

  • 401: { "message": "No user with those credentials found!" }

Test credentials for the frontend:

  • Email: b@b.com
  • Password: p123

Installation

  1. Clone the repository:

    git clone https://github.com/Spectra010s/vanlife.git
  2. Navigate into the project directory:

    cd vanlife
  3. Install dependencies:

    npm install
  4. Start the development server:

    npm run dev
  5. Open your browser and visit the URL shown in the terminal (usually http://localhost:5173).

Usage

Once the app is running, you can:

  • Browse vans on the homepage or the /vans page.
  • Filter vans by type using the buttons at the top of the van list.
  • Click any van to see its details and a "Rent this van" button (currently non‑functional for demo purposes).
  • Navigate to /login to sign in with the demo credentials above.
  • After login, access the host dashboard at /host to see earnings, reviews, and listed vans.
  • Use the host navigation to explore income, reviews, and manage individual vans (details, pricing, photos).

All data is stored in memory and will reset on page refresh.

Technologies Used

Technology Purpose
React 18.2 UI library
React Router 6.4 Client‑side routing
Vite latest Build tool & dev server
MirageJS 0.1.48 In‑browser mock API server
react-icons 4.7.1 Icon library (used for stars)
CSS3 Styling without any frameworks

Contributing

Contributions are welcome. If you'd like to improve Vanlife, please open an issue to discuss your ideas before submitting a pull request. Make sure your code follows the existing style and that all features still work with the mock server.

Badges

React React Router Vite MirageJS

Readme was generated by Dokugen

About

a simple e commerce site for vans

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages