refactor of usecases

This commit is contained in:
2026-02-23 17:18:50 +05:30
parent 56666ece30
commit 13f8003bda
37 changed files with 1563 additions and 105 deletions

View File

@@ -601,6 +601,54 @@ class OrderEditSheetState extends State<OrderEditSheet> {
});
}
Future<void> _cancelOrder() async {
final bool? confirm = await showDialog<bool>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('Cancel Order'),
content: const Text(
'Are you sure you want to cancel this order? This action cannot be undone.',
),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('No, Keep It'),
),
TextButton(
onPressed: () => Navigator.pop(context, true),
style: TextButton.styleFrom(foregroundColor: UiColors.destructive),
child: const Text('Yes, Cancel Order'),
),
],
),
);
if (confirm != true) return;
setState(() => _isLoading = true);
try {
await _dataConnect.deleteOrder(id: widget.order.orderId).execute();
if (mounted) {
widget.onUpdated?.call();
Navigator.pop(context);
UiSnackbar.show(
context,
message: 'Order cancelled successfully',
type: UiSnackbarType.success,
);
}
} catch (e) {
if (mounted) {
setState(() => _isLoading = false);
UiSnackbar.show(
context,
message: 'Failed to cancel order',
type: UiSnackbarType.error,
);
}
}
}
void _removePosition(int index) {
if (_positions.length > 1) {
setState(() => _positions.removeAt(index));
@@ -788,6 +836,23 @@ class OrderEditSheetState extends State<OrderEditSheet> {
label: 'Review ${_positions.length} Positions',
onPressed: () => setState(() => _showReview = true),
),
Padding(
padding: EdgeInsets.fromLTRB(
UiConstants.space5,
0,
UiConstants.space5,
MediaQuery.of(context).padding.bottom + UiConstants.space2,
),
child: UiButton.secondary(
text: 'Cancel Entire Order',
style: OutlinedButton.styleFrom(
foregroundColor: UiColors.destructive,
side: const BorderSide(color: UiColors.destructive),
),
fullWidth: true,
onPressed: _cancelOrder,
),
),
],
),
);

View File

@@ -35,7 +35,7 @@ class _ViewOrderCardState extends State<ViewOrderCard> {
builder: (BuildContext context) => OrderEditSheet(
order: order,
onUpdated: () =>
this.context.read<ViewOrdersCubit>().updateWeekOffset(0),
ReadContext(context).read<ViewOrdersCubit>().updateWeekOffset(0),
),
);
}