feat: save order
This commit is contained in:
@@ -67,8 +67,8 @@ class _TableWidgetState extends State<TableWidget> {
|
||||
} else {
|
||||
// Handle occupied table click - load draft order and navigate to payment
|
||||
context.read<CheckoutBloc>().add(
|
||||
CheckoutEvent.loadDraftOrder(data!),
|
||||
);
|
||||
CheckoutEvent.loadDraftOrder(data!),
|
||||
);
|
||||
log("Data Draft Order: ${data!.toMap()}");
|
||||
context.push(PaymentTablePage(
|
||||
table: widget.table,
|
||||
@@ -220,7 +220,8 @@ class _TableWidgetState extends State<TableWidget> {
|
||||
builder: (context) => AlertDialog(
|
||||
title: Row(
|
||||
children: [
|
||||
Icon(Icons.warning, color: AppColors.red),
|
||||
Icon(Icons.warning,
|
||||
color: AppColors.red),
|
||||
SizedBox(width: 8),
|
||||
Text('Void Order?'),
|
||||
],
|
||||
@@ -229,24 +230,33 @@ class _TableWidgetState extends State<TableWidget> {
|
||||
'Apakah anda yakin ingin membatalkan pesanan untuk meja ${widget.table.tableName}?\n\nPesanan akan dihapus secara permanen.'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text('Tidak',
|
||||
style: TextStyle(color: AppColors.primary)),
|
||||
onPressed: () =>
|
||||
Navigator.pop(context),
|
||||
child: Text('Tidak',
|
||||
style: TextStyle(
|
||||
color: AppColors.primary)),
|
||||
),
|
||||
BlocListener<StatusTableBloc, StatusTableState>(
|
||||
BlocListener<StatusTableBloc,
|
||||
StatusTableState>(
|
||||
listener: (context, state) {
|
||||
state.maybeWhen(
|
||||
orElse: () {},
|
||||
success: () {
|
||||
context
|
||||
.read<GetTableBloc>()
|
||||
.add(const GetTableEvent.getTables());
|
||||
Navigator.pop(context); // Close void dialog
|
||||
Navigator.pop(context); // Close table info dialog
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
.add(const GetTableEvent
|
||||
.getTables());
|
||||
Navigator.pop(
|
||||
context); // Close void dialog
|
||||
Navigator.pop(
|
||||
context); // Close table info dialog
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Pesanan berhasil dibatalkan'),
|
||||
backgroundColor: AppColors.primary,
|
||||
content: Text(
|
||||
'Pesanan berhasil dibatalkan'),
|
||||
backgroundColor:
|
||||
AppColors.primary,
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -260,24 +270,31 @@ class _TableWidgetState extends State<TableWidget> {
|
||||
// Void the order
|
||||
final newTable = TableModel(
|
||||
id: widget.table.id,
|
||||
tableName: widget.table.tableName,
|
||||
tableName:
|
||||
widget.table.tableName,
|
||||
status: 'available',
|
||||
orderId: 0,
|
||||
paymentAmount: 0,
|
||||
startTime: DateTime.now().toIso8601String(),
|
||||
startTime: DateTime.now()
|
||||
.toIso8601String(),
|
||||
position: widget.table.position,
|
||||
);
|
||||
context.read<StatusTableBloc>().add(
|
||||
StatusTableEvent.statusTabel(newTable),
|
||||
context
|
||||
.read<StatusTableBloc>()
|
||||
.add(
|
||||
StatusTableEvent
|
||||
.statusTabel(newTable),
|
||||
);
|
||||
// Remove draft order from local storage
|
||||
ProductLocalDatasource.instance
|
||||
.removeDraftOrderById(widget.table.orderId);
|
||||
.removeDraftOrderById(
|
||||
widget.table.orderId);
|
||||
log("Voided order for table: ${widget.table.tableName}");
|
||||
},
|
||||
child: const Text(
|
||||
"Ya, Batalkan",
|
||||
style: TextStyle(color: Colors.white),
|
||||
style: TextStyle(
|
||||
color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -292,14 +309,14 @@ class _TableWidgetState extends State<TableWidget> {
|
||||
),
|
||||
SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: BlocConsumer<StatusTableBloc, StatusTableState>(
|
||||
child: BlocConsumer<StatusTableBloc,
|
||||
StatusTableState>(
|
||||
listener: (context, state) {
|
||||
state.maybeWhen(
|
||||
orElse: () {},
|
||||
success: () {
|
||||
context
|
||||
.read<GetTableBloc>()
|
||||
.add(const GetTableEvent.getTables());
|
||||
context.read<GetTableBloc>().add(
|
||||
const GetTableEvent.getTables());
|
||||
context.pop();
|
||||
});
|
||||
},
|
||||
@@ -308,7 +325,8 @@ class _TableWidgetState extends State<TableWidget> {
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
context.read<CheckoutBloc>().add(
|
||||
CheckoutEvent.loadDraftOrder(data!),
|
||||
CheckoutEvent.loadDraftOrder(
|
||||
data!),
|
||||
);
|
||||
context.push(PaymentTablePage(
|
||||
table: widget.table,
|
||||
|
||||
Reference in New Issue
Block a user