Once a buyer confirms their cart, SansiStore creates an order record in Firestore and begins tracking it through a multi-stage lifecycle. The order history dashboard atDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ProcesosAgilesUMSS/sansistore/llms.txt
Use this file to discover all available pages before exploring further.
/mis-pedidos gives buyers a live view of all their purchases, lets them confirm delivery reception, and provides access to return requests — all protected by the comprador role guard.
Order History Dashboard (/mis-pedidos)
The /mis-pedidos page renders <MyOrdersDashboard> (src/features/orders/components/MyOrdersDashboard.tsx), which is wrapped in a <RouteGuard> requiring the comprador role. The component subscribes to the buyer’s orders in real time via subscribeToMyOrders() and fetches return requests with getMyReturns().
| Counter | Value |
|---|---|
| Pedidos | Total order count |
| Activos | Orders in CREADO, ASIGNADO, RESERVADO, PENDIENTE, EMPAQUETADO, LISTO, or EN CAMINO |
| Devoluciones | Total return request count |
<OrderList>) and the Devoluciones list (rendered by <ReturnCard> items).
Real-Time Delivery Notification
When an order’s status transitions toENTREGADO (or deliveryStatus becomes DELIVERED) while the buyer has the page open, a toast notification slides in from the top-right corner:
subscribeToMyOrders() snapshots using a Map<orderId, wasDelivered> ref.
Order Detail Page (/mis-pedidos/[id])
Clicking any order card navigates to /mis-pedidos/[id], which renders <MyOrderDetailView>. The detail view shows:
- Order ID (friendly label from
parseOrderId()) - Delivery address and location
- All
orderItems(product name, unit price, quantity, subtotal) - Order total
- Status badges for order status, payment status, and delivery status
- Buyer reception confirmation button (when status is
ENTREGADO) - Return request initiation (via
createReturnRequest())
Order Lifecycle
Orders progress through a set of statuses defined inOrderStatus (src/features/orders/types.ts). The primary buyer-visible flow is:
CREADO
stockReserved += quantity) in the inventory collection. A payments document is created with status: 'PENDIENTE'.RESERVADO
stockAvailable is decremented for each item.ENTREGADO
COMPLETADO and sets buyerReceptionConfirmed: true.Status Reference
CREADO — Order placed
CREADO — Order placed
createOrder(). The order exists in Firestore and stock has been reserved, but no seller has claimed it yet.RESERVADO — Claimed by seller
RESERVADO — Claimed by seller
reserveOrder(). The seller has accepted the order; stockAvailable is reduced transactionally. The buyer’s order card updates in real time.PENDIENTE — Pending seller action
PENDIENTE — Pending seller action
EMPAQUETADO — Packed
EMPAQUETADO — Packed
LISTO — Ready for pickup
LISTO — Ready for pickup
readyOrder(). The courier can now pick up the order from the seller.PENDIENTE-ASIGNACION — Awaiting courier
PENDIENTE-ASIGNACION — Awaiting courier
LISTO and ASIGNADO.ASIGNADO / ACEPTADO — Courier assigned
ASIGNADO / ACEPTADO — Courier assigned
EN CAMINO — In transit
EN CAMINO — In transit
ENTREGADO — Delivered
ENTREGADO — Delivered
CANCELADO — Cancelled
CANCELADO — Cancelled
cancelOrder(). Requires an incidentReason string. Stock is restored transactionally: stockAvailable += quantity, stockReserved -= quantity.NO ENTREGADO — Failed delivery
NO ENTREGADO — Failed delivery
incidentReason and optional incidentNotes are recorded.DEVUELTO — Returned
DEVUELTO — Returned
returnOrder().RECHAZADO — Rejected
RECHAZADO — Rejected
rejectOrder(). Requires an incidentReason.PAGADO — Payment validated
PAGADO — Payment validated
paidOrder() after the seller confirms receipt of payment. stockTotal and stockReserved are decremented in a transaction. Only delivered orders can be moved to this status.CERRADO — Closed
CERRADO — Closed
paymentStatus — Payment tracking
paymentStatus — Payment tracking
PENDIENTE (awaiting payment), PAGADO (payment confirmed by seller). Stored both on the orders document and the linked payments document.deliveryStatus — Delivery tracking
deliveryStatus — Delivery tracking
DELIVERED, delivered, and custom courier-set states. Checked alongside status === 'ENTREGADO' to determine buyer reception eligibility.Real-Time Subscription
subscribeToMyOrders() opens a Firestore onSnapshot listener scoped to the authenticated buyer:
processQuerySnapshot() performs parallel fetches of related locations, users, and deliveries documents, then fetches each order’s orderItems subcollection, resulting in fully hydrated Order objects.
Firestore Data Model
orders collection
| Field | Type | Description |
|---|---|---|
orderId | string | UUID v7 + z-base-32 label (document ID) |
secret | string | 4-digit PIN for anonymous order lookup |
buyerId | string | Firebase Auth UID of the buyer |
sellerId | string | null | UID of the seller who claimed the order |
customerName | string | Buyer’s display name at time of order |
customerPhone | string | Buyer’s phone number |
address | string | label from the selected Location document |
status | OrderStatus | Current order status (see status reference above) |
total | number | Total order amount in Bolivianos |
locationId | string | Reference to locations collection |
paymentStatus | string | PENDIENTE or PAGADO |
deliveryStatus | string | null | Set by the delivery/courier service |
paymentId | string | Same as orderId; used as payments document ID |
incidentReason | string | null | Required for CANCELADO / RECHAZADO / NO ENTREGADO |
incidentNotes | string | null | Optional extra detail for incidents |
buyerReceptionConfirmed | boolean | Set true when buyer confirms delivery |
createdAt | Timestamp | Order creation time |
updatedAt | Timestamp | Last modification time |
orders/{orderId}/orderItems subcollection
| Field | Type | Description |
|---|---|---|
itemId | string | UUID v7 (document ID) |
productId | string | Reference to products collection |
productName | string | Product name captured at order time |
unitPrice | number | Price per unit at time of order |
quantity | number | Number of units ordered |
subtotal | number | unitPrice × quantity, rounded to 2 decimal places |
returns collection
| Key | Label |
|---|---|
damaged | Producto dañado |
wrong_product | Producto incorrecto |
unwanted | No deseado |
other | Otro |
Returns Page (/my-returns)
The <MyReturnsView> component displays return requests fetched from getMyReturns():
<ReturnCard> showing the order ID, reason, description, and current review status (pending_review, approved, or rejected).
status === 'ENTREGADO' or deliveryStatus === 'DELIVERED'. The Confirmar recepción action must be completed before initiating a return.End-to-End Tests
Order pages are covered by Playwright tests intests/orders/my-orders.spec.ts: