Documentation Index
Fetch the complete documentation index at: https://mintlify.com/DavidCevallos15/Crucidrive---APP/llms.txt
Use this file to discover all available pages before exploring further.
useRideStore manages all frontend state for an active ride. It mirrors the server-side ride states stored in the viajes table and additionally tracks driver info, the associated chat thread ID, and the isRequesting UI loading flag that disables the request button during the API call. When a ride reaches finalizado or cancelado, call clearRide() to return the store to its idle baseline.
Types
RideStatus
The union type for every valid state in the ride lifecycle:
DriverInfo
Populated once a conductor accepts the ride request:
ActiveRide
The full data shape for a ride in progress:
State shape
Actions
| Action | Signature | Description |
|---|---|---|
setActiveRide | (ride: ActiveRide | null) => void | Replaces the entire activeRide object. Use this immediately after a successful /api/viajes/solicitar response. |
updateRide | (updates: Partial<ActiveRide>) => void | Merges partial updates into the existing activeRide. No-ops if activeRide is null. |
setRideStatus | (status: RideStatus) => void | Updates only the status field of the active ride. No-ops if activeRide is null. |
setDriver | (driver: DriverInfo) => void | Sets the driver field and simultaneously transitions status to 'aceptado'. |
setRequesting | (requesting: boolean) => void | Toggles the isRequesting loading flag. Set to true before the API call, false in the finally block. |
clearRide | () => void | Resets to { activeRide: null, isRequesting: false }. Call after finalizado or cancelado. |
Ride status flow
idle state exists only in the store — there is no corresponding row in viajes. A ride enters solicitado the moment the API creates it. cancelado can be reached from solicitado, aceptado, or en_curso (either party may cancel, subject to server rules). Once finalizado or cancelado, call clearRide() to return the store to idle.
Usage example
After a successful call to the ride request endpoint, hydrate the store with the full ride object returned by the API:setDriver automatically transitions the ride status to 'aceptado' in the same atomic set call — do not call setRideStatus('aceptado') separately after setDriver, or you may trigger two renders with inconsistent state where driver is set but the status hasn’t updated yet.