Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Eleazarguitar18/kantuta_pos_front/llms.txt
Use this file to discover all available pages before exploring further.
CajaContext manages the active cash-drawer (caja) session for the currently signed-in user. It is the central gating mechanism for POS, Recargas, and Agentes operations — any feature that involves recording a transaction reads sesionActiva from this context before proceeding. The session is persisted to localStorage under the key sesion_caja so that a hard browser refresh does not clear the working state while a session is genuinely open.
CajaContextType Interface
| Field | Type | Description |
|---|---|---|
sesionActiva | SesionCaja | null | The active session object returned by the API, or null if no session is open |
loading | boolean | true while checkSesion is in flight on mount; modules should gate rendering until this is false |
checkSesion | () => Promise<void> | Re-queries the backend for the user’s active session; called automatically on mount and when user changes |
abrirCaja | (idCaja, montoInicial) => Promise<any> | Opens a new cash session via POST /cajas/abrir |
cerrarCaja | (montoFinalReal, idSesion?) => Promise<any> | Closes the session via PATCH /cajas/sesion/:id/cerrar |
Consuming the Context
Session Lifecycle
checkSesion — querying the active session on mount
CajaProvider calls checkSesion() inside a useEffect that runs whenever user changes (including the initial mount). It calls GET /cajas/sesion-activa/:userId:sesionActiva is set to null and sesion_caja is removed from storage. Any other network failure leaves the existing localStorage value untouched as an offline fallback.abrirCaja — opening a cash session
Sends After
POST /cajas/abrir with the physical caja ID, the opening cash amount, and the user’s ID. On success, the response data is written to both React state and localStorage:abrirCaja resolves, sesionActiva becomes non-null and all dependent modules unlock their operations.cerrarCaja — closing the cash session
Sends After a successful close,
PATCH /cajas/sesion/:id/cerrar with the physical closing amount. The session ID defaults to sesionActiva.id but can be overridden via the optional idSesion parameter — useful when an administrator closes a different user’s session:sesionActiva is set to null and sesion_caja is removed from localStorage.localStorage Persistence
The initial state forsesionActiva is hydrated from localStorage synchronously, before any API call completes:
checkSesion() call reconciles the local value with the server state and updates localStorage accordingly.
Each user has at most one active session at a time.
checkSesion queries by user.id, so two different users logged into the same browser will each see only their own sesionActiva. Switching users (via logoutStorage and re-login) triggers a new checkSesion call because CajaProvider re-runs its effect whenever the user object from useAuth() changes.API Endpoints Used by CajasService
All calls go throughCajasService in src/modules/Cajas/services/cajasService.ts, which attaches the Bearer token from localStorage via getHeaders():
SocketContext and Real-Time Events
AlongsideCajaContext, the SocketContext provides a single socket.io-client instance to the entire app. The socket connects to the API base URL (with the /api suffix stripped) as soon as the module loads:
useSocket() hook and listen for dataChanged events to invalidate and re-fetch their data without a manual page refresh. This keeps multiple operator tabs consistent when another user updates the inventory or completes a transaction.