# React Native dispatch and fleet tracking template (Pro)

> A React Native dispatch board for iOS, Android and the web: a live fleet on a map with each van's health and heading, KPIs, van and order lists with filters and search, a stop timeline with ETAs, assigning orders to the best van and reassigning a broken-down van's stops, each with undo. Built on Patine Pro's MapView and charts, no native modules.

# Dispatch Pro

A live dispatch board, Onfleet-style. The fleet moves on the map, each van ringed in its health's colour and pointing where it's heading, with KPIs across the top. A fleet panel shows today's stops as a donut and what needs attention, worst first. The van and order lists have filters and search. Pick a van to see its driver, vehicle and stop timeline with ETAs, and late stops flagged. Assign a waiting order to the best van suggested, or hand a broken-down van's stops to another; each change has an undo. On desktops the panels float over the map. On phones you switch between Map (with a sheet), Vans and Orders.

Built from [MapView](../blocks/map), the [Donut chart](../components/pie-chart) and free components.

```tsx
import { DispatchScreen } from '@patine-ui/pro';

<DispatchScreen />;
```

```tsx live full
import { View } from 'react-native';
import { DispatchScreen } from '@patine-ui/pro';

export default function Example() {
  return (
    <View style={{ width: '100%', height: 680 }}>
      <DispatchScreen />
    </View>
  );
}
```

## Make it yours

| Prop | Type | Default |
| --- | --- | --- |
| `initialFleet` | `Fleet`: `vans`, `orders`, `clock` | The Seattle demo, 8 vans in 4 zones |
| `onCall` | `(van) => void` | A notice, for the demo |
| `onMessage` | `(van) => void` | |
| `title` | `string` | `'Dispatch'` |
| `subtitle` | `string` | `'Seattle · 8 vans · 4 zones'` |

The demo moves its fleet with `useFleetSimulation`. For live data, copy the screen and swap that hook for your feed: a websocket or subscription that replaces the fleet. The logic is pure and exported, so a server can share it: `tickFleet`, `fleetStats`, `attention`, `stopStatuses`, `suggestVans`, `assignOrder` and `reassignStops`.

The map opens on OpenStreetMap's tiles, which suit development. For production, pass a provider's URL with your key to `MapView` (see [Tiles](../blocks/map#tiles)).

## Built with

The free components, from `patine-ui`:

[Avatar](/docs/components/avatar) · [Badge](/docs/components/badge) · [Button](/docs/components/button) · [ChipGroup](/docs/components/chip-group) · [Heading, Text](/docs/components/text) · [Progress](/docs/components/progress) · [SearchField](/docs/components/search-field) · [SegmentedControl](/docs/components/segmented-control) · [Separator](/docs/components/separator)

And from Patine Pro:

- [App shell and layout](/docs/pro/layout) PRO
- [Map](/docs/blocks/map) PRO
- [Patine Icons, the Pro set](/docs/components/icons) PRO
- [Pie chart](/docs/components/pie-chart) PRO

## Files

```text
dispatch/
├── components/
│   ├── AlertBanner.tsx
│   ├── DispatchTopBar.tsx
│   ├── FleetMap.tsx
│   ├── FleetPanel.tsx
│   ├── KpiStrip.tsx
│   ├── LiveIndicator.tsx
│   ├── Notice.tsx
│   ├── OrderQueue.tsx
│   ├── StopTimeline.tsx
│   ├── VanDetail.tsx
│   ├── VanList.tsx
│   ├── VanPin.tsx
│   └── VanRow.tsx
├── hooks/
│   ├── useDispatch.ts
│   └── useFleetSimulation.ts
├── dispatch.constants.ts
├── dispatch.data.ts
├── dispatch.types.ts
├── dispatch.utils.ts
├── DispatchScreen.tsx
└── index.ts
```

It also uses `shared/`, the theme, money formatting and screen transitions every Pro app shares.

## A look at the code

Each van’s health, from `dispatch.utils.ts`:

```tsx
/** A van's health from its numbers: stuck with stops or cargo too warm, stopped, a low battery, misses or late stops, or fine. */
export const healthOf = (van: Van, clock: number): VanHealth => {
  if ((van.speed <= 0 && pending(van).length > 0) || (van.vehicle.refrigerated && (van.temp ?? 0) > SIM.maxTemp)) return 'alert';
  if (van.speed <= 0) return 'watch';
  if (van.battery < SIM.lowBattery || van.failed.length || stopStatuses(van, clock).some((s) => s.late && s.state !== 'done'))
    return 'watch';
  return 'ok';
};
```

Get the source with Pro

## Accessibility

- Every van, stop, waiting order and the depot is named on the map: "V-18, Maya Lindgren, on track".
- Van rows include health, the current stop and stops done; KPIs and the donut are read as words.
- The live indicator says when the fleet last updated, and pauses or resumes the updates.
- Health is in words as well as colour.

## Related

- [Map](../blocks/map) · [Store locator](./store-locator) · [Delivery tracking](./courier-tracking)
