The current implementation of order creation in POS involves handling the creation process outside the WooPosTotalsViewModel. There is a proposal by @samiuelson to move the order creation logic into the WooPosTotalsViewModel, which could streamline state management, especially handling loading, success, and errors more effectively within the same ViewModel.
Proposal
Move the order creation logic to WooPosTotalsViewModel and update the workflow:
Event Modification:
Change the CheckoutClicked event to include a list of product IDs: CheckoutClicked(val productIds: List<Long>).
Centralize Order Creation:
Perform the actual order creation in the WooPosTotalsViewModel.
Handle State Internally:
Manage loading state, success, and errors within WooPosTotalsViewModel.
Return Result to Cart:
Ensure the result of the order creation (success or failure) is communicated back to the cart to enable/disable the checkout button appropriately.
Benefits
Centralized State Management: Simplifies the process by handling the loading, errors, and success states within a single ViewModel.
Cleaner Architecture: Decouples the order creation process from the cart, making the workflow more modular.
Improves Maintenance: Easier to maintain and test the order creation logic.
The current implementation of order creation in POS involves handling the creation process outside the
WooPosTotalsViewModel
. There is a proposal by @samiuelson to move the order creation logic into theWooPosTotalsViewModel
, which could streamline state management, especially handling loading, success, and errors more effectively within the same ViewModel.Proposal
Move the order creation logic to
WooPosTotalsViewModel
and update the workflow:Event Modification:
CheckoutClicked
event to include a list of product IDs:CheckoutClicked(val productIds: List<Long>)
.Centralize Order Creation:
WooPosTotalsViewModel
.Handle State Internally:
WooPosTotalsViewModel
.Return Result to Cart:
Benefits
References