Overview
MisReservasCubit manages the state for customers to view their reservations filtered by verified phone number and cancel reservations. It ensures customers only see reservations associated with their verified phone number.
Location: lib/presentacion/mis_reservas/mis_reservas_cubit.dart:8
Purpose
This Cubit handles:- Loading reservations filtered by phone number and restaurant
- Canceling reservations
- Automatic reloading after operations
- Maintaining verification context (phone number)
State Classes
The Cubit uses states defined inmis_reservas_estados_de_cubit.dart:
MisReservasInicial
Initial state before verification and loading.MisReservasCargando
Emitted when loading or processing reservations.MisReservasExitoso
Emitted when reservations are successfully loaded.reservas: List of customer’s reservations
MisReservasConError
Emitted when loading fails.ReservaCancelada
Emitted when a reservation is successfully canceled.ReservaCancelacionError
Emitted when cancellation fails.Constructor
MisReservasInicial.
Key Methods
cargarReservasFiltradas
Loads reservations for a verified phone number at a specific restaurant.telefono: Verified phone number (format: “+54 9 261 123-4567”)negocioId: Restaurant ID to filter by
MisReservasCargando→ Loading reservationsMisReservasExitoso→ Success with reservation list (may be empty)MisReservasConError→ If loading fails
mis_reservas_cubit.dart:26
Implementation Details:
- Stores phone and business ID for future reloads
- Uses
obtenerReservasPorTelefonoYNegociofor filtered query - Filters on server side for better performance
recargarReservas
Reloads reservations using previously stored filters.- Only reloads if phone and business ID were previously set
- Uses same filters as last
cargarReservasFiltradascall - Called automatically after successful cancellation
mis_reservas_cubit.dart:46
cancelarReserva
Cancels a reservation and reloads the list.reservaId: ID of reservation to cancel
MisReservasCargando→ Processing cancellationReservaCancelada→ Success with messageMisReservasExitoso→ Automatically reloaded listReservaCancelacionError→ If cancellation fails (still attempts reload)
mis_reservas_cubit.dart:55
Important: Cancellation delegates to CancelarReserva use case which:
- Validates business rules (cancellation window)
- Updates reservation status
- Sends cancellation email notifications
- Records cancellation in history
Properties
telefonoVerificado
Returns the currently verified phone number.negocioId
Returns the current restaurant ID.State Transition Diagram
Usage Example
Frommis_reservas_screen.dart:22:
Complete User Flow Example
Frommis_reservas_screen.dart:427:
Integration Points
With Repositories
ReservaRepositorio: Filtered reservation queries
With Use Cases
CancelarReserva: Handles cancellation business logic and notifications
With Services
ServicioVerificacionCliente: SMS verification before loading reservations
With UI Components
MisReservasScreen: Customer reservation list interface- SMS verification dialog verifies phone before calling
cargarReservasFiltradas - Reservation cards display data from
MisReservasExitoso.reservas - Cancel button triggers confirmation dialog then
cancelarReserva
Security Considerations
- Phone Verification: Reservations only loaded after SMS verification
- Filtered Queries: Server-side filtering ensures customers only see their reservations
- No Direct Access: Cubit requires verification flow; can’t be bypassed
- Immutable Phone Context: Once loaded, phone number is cached for session
Error Handling
The Cubit handles errors gracefully:- Errors are logged for debugging
- User-friendly messages in states
- Attempts to reload even after errors for data consistency
- Exception messages cleaned up for display
State Management Pattern
This Cubit follows these patterns:- Verification First: Requires phone verification before operations
- Auto-Reload: Automatically reloads after mutations
- Consistent State: Always attempts to show current data
- Listener Pattern: Uses
BlocConsumerfor one-time events (snackbars) - Builder Pattern: Uses
BlocBuilderfor UI rendering - Filter Caching: Stores filters for easy reload without re-verification
Related Documentation
- DisponibilidadCubit - Creating reservations
- PantallaDuenoCubit - Owner reservation management
- Reserva Entity - Reservation entity
- CancelarReserva Use Case - Cancellation logic
- ServicioVerificacionCliente - SMS verification