unified-fleet.ts
Type definitions for the unified fleet management dashboard that combines drivers, vehicles, and trailers.Import
Driver Types
Driver
Driver
Core driver entity from
/api/drivers/current endpoint.| Field | Type | Notes |
|---|---|---|
driver_id | string | Primary identifier (may have drv_ prefix) |
source_id | string | ID in the provider’s system |
provider | string | Data source: "motive", "geotab", etc. |
status | string | "active" or "inactive" |
ID formats: Both
driver_id and source_id can be used to match drivers. The useUnifiedFleetData hook creates mappings for both formats (with and without drv_ prefix).DriverLicense
DriverLicense
Driver’s license information.
DriverMetadata
DriverMetadata
System metadata for driver records.
DriverBatchResponse
DriverBatchResponse
API response from
/api/drivers/current.DriverSummary
DriverSummary
Compact driver representation for dashboard tables.
Fleet Data Types
UnifiedFleetData
UnifiedFleetData
Combined data from all three sources.
| Field | Type | Notes |
|---|---|---|
*Count | number | Count from API response |
*PolledAt | string | null | ISO timestamp of last fetch/update |
Timestamps: The
*PolledAt fields are useful for displaying “Last updated X seconds ago” and detecting stale data.FleetStatistics
FleetStatistics
Aggregated statistics for KPI display.
DriverStatistics
DriverStatistics
Driver-related statistics.
VehicleStatistics
VehicleStatistics
Vehicle/tractor statistics.
| Stat | Calculation |
|---|---|
available | !driver_id (falsy) |
lowFuel | fuel.primary_percentage < 25 |
avgSpeed | Average where engine_state === "on" AND speed != null |
withDrivers | driver_id is truthy |
TrailerStatistics
TrailerStatistics
Trailer statistics.
Speed threshold: The 5 mph threshold prevents GPS drift from being counted as movement.Speed conversion: Motive speeds are in km/h and converted to mph before comparison.
Connection State Types
FleetConnectionState
FleetConnectionState
Connection status for all three data sources.
Drivers don’t have SSE: Only vehicles and trailers have SSE connections. Drivers use polling-only REST API.
Summary Types
TractorSummary
TractorSummary
Compact vehicle representation for dashboard tables.
TrailerSummary
TrailerSummary
Compact trailer representation for dashboard tables.
UseUnifiedFleetDataResult
UseUnifiedFleetDataResult
Return type of the
useUnifiedFleetData hook.vehicle-locations.ts
Type definitions for real-time vehicle location data from backend SSE/REST APIs.Import
Note: This file defines its own
Coordinates and Address interfaces, identical to those in trailer-locations.ts. They are not shared/imported to keep each domain self-contained.Core Types
VehicleLocation
VehicleLocation
Primary vehicle location entity.
Two tractor ID fields:
tractor_number: Legacy field from database mappingmcleod_tractor_id: Current field from/locations/currentendpoint
Coordinates
Coordinates
Geographic coordinates.
Address
Address
Geocoded address information.
Fallback display: If
formatted is missing, components typically show coordinates in "lat, lng" format.FuelData
FuelData
Fuel level information.
EngineState
EngineState
Engine state type.
The API may also return
"running" which should be treated as "on".Response Types
VehicleLocationsResponse
VehicleLocationsResponse
API response from
/locations/current and SSE events.cache_status: Indicates whether the response came from backend cache (
"hit") or fresh fetch ("miss"). Useful for debugging latency issues.SSEConnectionState
SSEConnectionState
SSE connection status.
| Status | Meaning |
|---|---|
connecting | Initial state, establishing connection |
connected | Receiving real-time updates |
disconnected | Connection lost (auto-reconnecting) |
error | REST fetch failed (requires manual action) |
UseVehicleLocationsResult
UseVehicleLocationsResult
Return type of the
useVehicleLocations hook.Filter & Sort Types
Filter Types
Filter Types
Types for filtering vehicle lists.
Fuel level thresholds (implied):
low: < 25%medium: 25-75%high: > 75%
Sort Types
Sort Types
Types for sorting vehicle lists.
trailer-locations.ts
Type definitions for real-time trailer location data with SSE integration.Import
Note: This file defines its own
Coordinates and Address interfaces (same as vehicle-locations.ts). This keeps each domain self-contained but may cause issues if you try to mix types directly.Core Types
TrailerLocation
TrailerLocation
Real-time trailer location from
location_update SSE events.address can be null: Unlike vehicles, trailers may not have geocoded addresses. Always check for null before accessing address fields.TrailerInfo
TrailerInfo
Static trailer information from
trailer_info SSE events.Metadata is inline: Unlike
DriverMetadata, the trailer metadata type is defined inline (not a separate interface). It includes deleted_at for soft-delete tracking.LicensePlate
LicensePlate
License plate information.
CombinedTrailerData
CombinedTrailerData
Merged location + static info for complete trailer view.
This type extends
TrailerLocation with optional static fields from TrailerInfo. Used when you need complete trailer data in one object.Response Types
TrailerLocationBatch
TrailerLocationBatch
API response from
/api/trailers/current and SSE location_update events.TrailerInfoBatch
TrailerInfoBatch
Response for static trailer information.
SSEConnectedEvent
SSEConnectedEvent
Payload of the SSE
connected event.SSEConnectionState (Trailer)
SSEConnectionState (Trailer)
Trailer SSE connection status (extends base with
clientId).clientId: Unique identifier assigned by the server. Useful for debugging multiple connections.
Hook Result Types
UseTrailerLocationsResult
UseTrailerLocationsResult
Return type for a basic trailer locations hook.
UseTrailerSSEResult
UseTrailerSSEResult
Return type for full SSE integration with both location and info events.
Three data arrays:
locations: Real-time location datastaticInfo: Equipment details (VIN, make, model)combined: Merged view of both
Filter & Sort Types
Filter Types
Filter Types
Types for filtering trailer lists.Typical implementation thresholds:
| Filter | Typical Condition |
|---|---|
moving | Speed ≥ 5 mph |
stationary | Speed < 5 mph |
recent | Updated < 5 min ago |
stale | Updated > 10 min ago |
north | Heading 315-45° (implementation-specific) |
east | Heading 45-135° (implementation-specific) |
south | Heading 135-225° (implementation-specific) |
west | Heading 225-315° (implementation-specific) |
Sort Types
Sort Types
Types for sorting trailer lists.
MotionState
MotionState
Type alias for trailer motion state.
Type Relationships
Visual overview of how types relate across files:Common Gotchas
Speed unit inconsistency
Speed unit inconsistency
Problem: Different providers return speed in different units.Solution: Always check the provider and convert if necessary:
Nullable vs undefined fields
Nullable vs undefined fields
Problem: Some fields use
null, others use undefined, some use both.Solution: Use nullish coalescing for safe access:ID format variations
ID format variations
Problem: IDs may have prefixes (
drv_, trl_) or not.Solution: The hooks create mappings for both formats. When matching manually:Timestamp formats
Timestamp formats
Problem: All timestamps are ISO 8601 strings, not Date objects.Solution: Parse before using:
Coordinate validation
Coordinate validation
Problem: Coordinates may be null, NaN, or out of valid range.Solution: Always validate before use:

