diff --git a/lib/application/checkout/checkout_form/checkout_form_bloc.dart b/lib/application/checkout/checkout_form/checkout_form_bloc.dart index 8dfbeb7..eb4e82f 100644 --- a/lib/application/checkout/checkout_form/checkout_form_bloc.dart +++ b/lib/application/checkout/checkout_form/checkout_form_bloc.dart @@ -2,10 +2,11 @@ import 'dart:developer'; import 'package:bloc/bloc.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; -import 'package:injectable/injectable.dart'; +import 'package:injectable/injectable.dart' hide Order; import '../../../common/types/order_type.dart'; import '../../../domain/delivery/delivery.dart'; +import '../../../domain/order/order.dart'; import '../../../domain/product/product.dart'; import '../../../domain/table/table.dart'; @@ -176,6 +177,9 @@ class CheckoutFormBloc extends Bloc { updateTable: (e) async { emit(state.copyWith(table: e.table)); }, + orderAddedItems: (e) async { + emit(state.copyWith(orderAdded: e.order)); + }, ); } } diff --git a/lib/application/checkout/checkout_form/checkout_form_bloc.freezed.dart b/lib/application/checkout/checkout_form/checkout_form_bloc.freezed.dart index 0f6b1c3..c5949bb 100644 --- a/lib/application/checkout/checkout_form/checkout_form_bloc.freezed.dart +++ b/lib/application/checkout/checkout_form/checkout_form_bloc.freezed.dart @@ -27,6 +27,7 @@ mixin _$CheckoutFormEvent { required TResult Function(OrderType orderType) updateOrderType, required TResult Function(Delivery delivery) updateDelivery, required TResult Function(Table? table) updateTable, + required TResult Function(Order? order) orderAddedItems, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult? whenOrNull({ @@ -37,6 +38,7 @@ mixin _$CheckoutFormEvent { TResult? Function(OrderType orderType)? updateOrderType, TResult? Function(Delivery delivery)? updateDelivery, TResult? Function(Table? table)? updateTable, + TResult? Function(Order? order)? orderAddedItems, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeWhen({ @@ -47,6 +49,7 @@ mixin _$CheckoutFormEvent { TResult Function(OrderType orderType)? updateOrderType, TResult Function(Delivery delivery)? updateDelivery, TResult Function(Table? table)? updateTable, + TResult Function(Order? order)? orderAddedItems, required TResult orElse(), }) => throw _privateConstructorUsedError; @optionalTypeArgs @@ -58,6 +61,7 @@ mixin _$CheckoutFormEvent { required TResult Function(_UpdateOrderType value) updateOrderType, required TResult Function(_UpdateDelivery value) updateDelivery, required TResult Function(_UpdateTable value) updateTable, + required TResult Function(_OrderAddedItems value) orderAddedItems, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult? mapOrNull({ @@ -68,6 +72,7 @@ mixin _$CheckoutFormEvent { TResult? Function(_UpdateOrderType value)? updateOrderType, TResult? Function(_UpdateDelivery value)? updateDelivery, TResult? Function(_UpdateTable value)? updateTable, + TResult? Function(_OrderAddedItems value)? orderAddedItems, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeMap({ @@ -78,6 +83,7 @@ mixin _$CheckoutFormEvent { TResult Function(_UpdateOrderType value)? updateOrderType, TResult Function(_UpdateDelivery value)? updateDelivery, TResult Function(_UpdateTable value)? updateTable, + TResult Function(_OrderAddedItems value)? orderAddedItems, required TResult orElse(), }) => throw _privateConstructorUsedError; } @@ -188,6 +194,7 @@ class _$StartedImpl implements _Started { required TResult Function(OrderType orderType) updateOrderType, required TResult Function(Delivery delivery) updateDelivery, required TResult Function(Table? table) updateTable, + required TResult Function(Order? order) orderAddedItems, }) { return started(items); } @@ -202,6 +209,7 @@ class _$StartedImpl implements _Started { TResult? Function(OrderType orderType)? updateOrderType, TResult? Function(Delivery delivery)? updateDelivery, TResult? Function(Table? table)? updateTable, + TResult? Function(Order? order)? orderAddedItems, }) { return started?.call(items); } @@ -216,6 +224,7 @@ class _$StartedImpl implements _Started { TResult Function(OrderType orderType)? updateOrderType, TResult Function(Delivery delivery)? updateDelivery, TResult Function(Table? table)? updateTable, + TResult Function(Order? order)? orderAddedItems, required TResult orElse(), }) { if (started != null) { @@ -234,6 +243,7 @@ class _$StartedImpl implements _Started { required TResult Function(_UpdateOrderType value) updateOrderType, required TResult Function(_UpdateDelivery value) updateDelivery, required TResult Function(_UpdateTable value) updateTable, + required TResult Function(_OrderAddedItems value) orderAddedItems, }) { return started(this); } @@ -248,6 +258,7 @@ class _$StartedImpl implements _Started { TResult? Function(_UpdateOrderType value)? updateOrderType, TResult? Function(_UpdateDelivery value)? updateDelivery, TResult? Function(_UpdateTable value)? updateTable, + TResult? Function(_OrderAddedItems value)? orderAddedItems, }) { return started?.call(this); } @@ -262,6 +273,7 @@ class _$StartedImpl implements _Started { TResult Function(_UpdateOrderType value)? updateOrderType, TResult Function(_UpdateDelivery value)? updateDelivery, TResult Function(_UpdateTable value)? updateTable, + TResult Function(_OrderAddedItems value)? orderAddedItems, required TResult orElse(), }) { if (started != null) { @@ -395,6 +407,7 @@ class _$AddItemImpl implements _AddItem { required TResult Function(OrderType orderType) updateOrderType, required TResult Function(Delivery delivery) updateDelivery, required TResult Function(Table? table) updateTable, + required TResult Function(Order? order) orderAddedItems, }) { return addItem(product, variant); } @@ -409,6 +422,7 @@ class _$AddItemImpl implements _AddItem { TResult? Function(OrderType orderType)? updateOrderType, TResult? Function(Delivery delivery)? updateDelivery, TResult? Function(Table? table)? updateTable, + TResult? Function(Order? order)? orderAddedItems, }) { return addItem?.call(product, variant); } @@ -423,6 +437,7 @@ class _$AddItemImpl implements _AddItem { TResult Function(OrderType orderType)? updateOrderType, TResult Function(Delivery delivery)? updateDelivery, TResult Function(Table? table)? updateTable, + TResult Function(Order? order)? orderAddedItems, required TResult orElse(), }) { if (addItem != null) { @@ -441,6 +456,7 @@ class _$AddItemImpl implements _AddItem { required TResult Function(_UpdateOrderType value) updateOrderType, required TResult Function(_UpdateDelivery value) updateDelivery, required TResult Function(_UpdateTable value) updateTable, + required TResult Function(_OrderAddedItems value) orderAddedItems, }) { return addItem(this); } @@ -455,6 +471,7 @@ class _$AddItemImpl implements _AddItem { TResult? Function(_UpdateOrderType value)? updateOrderType, TResult? Function(_UpdateDelivery value)? updateDelivery, TResult? Function(_UpdateTable value)? updateTable, + TResult? Function(_OrderAddedItems value)? orderAddedItems, }) { return addItem?.call(this); } @@ -469,6 +486,7 @@ class _$AddItemImpl implements _AddItem { TResult Function(_UpdateOrderType value)? updateOrderType, TResult Function(_UpdateDelivery value)? updateDelivery, TResult Function(_UpdateTable value)? updateTable, + TResult Function(_OrderAddedItems value)? orderAddedItems, required TResult orElse(), }) { if (addItem != null) { @@ -604,6 +622,7 @@ class _$RemoveItemImpl implements _RemoveItem { required TResult Function(OrderType orderType) updateOrderType, required TResult Function(Delivery delivery) updateDelivery, required TResult Function(Table? table) updateTable, + required TResult Function(Order? order) orderAddedItems, }) { return removeItem(product, variant); } @@ -618,6 +637,7 @@ class _$RemoveItemImpl implements _RemoveItem { TResult? Function(OrderType orderType)? updateOrderType, TResult? Function(Delivery delivery)? updateDelivery, TResult? Function(Table? table)? updateTable, + TResult? Function(Order? order)? orderAddedItems, }) { return removeItem?.call(product, variant); } @@ -632,6 +652,7 @@ class _$RemoveItemImpl implements _RemoveItem { TResult Function(OrderType orderType)? updateOrderType, TResult Function(Delivery delivery)? updateDelivery, TResult Function(Table? table)? updateTable, + TResult Function(Order? order)? orderAddedItems, required TResult orElse(), }) { if (removeItem != null) { @@ -650,6 +671,7 @@ class _$RemoveItemImpl implements _RemoveItem { required TResult Function(_UpdateOrderType value) updateOrderType, required TResult Function(_UpdateDelivery value) updateDelivery, required TResult Function(_UpdateTable value) updateTable, + required TResult Function(_OrderAddedItems value) orderAddedItems, }) { return removeItem(this); } @@ -664,6 +686,7 @@ class _$RemoveItemImpl implements _RemoveItem { TResult? Function(_UpdateOrderType value)? updateOrderType, TResult? Function(_UpdateDelivery value)? updateDelivery, TResult? Function(_UpdateTable value)? updateTable, + TResult? Function(_OrderAddedItems value)? orderAddedItems, }) { return removeItem?.call(this); } @@ -678,6 +701,7 @@ class _$RemoveItemImpl implements _RemoveItem { TResult Function(_UpdateOrderType value)? updateOrderType, TResult Function(_UpdateDelivery value)? updateDelivery, TResult Function(_UpdateTable value)? updateTable, + TResult Function(_OrderAddedItems value)? orderAddedItems, required TResult orElse(), }) { if (removeItem != null) { @@ -803,6 +827,7 @@ class _$UpdateItemNotesImpl implements _UpdateItemNotes { required TResult Function(OrderType orderType) updateOrderType, required TResult Function(Delivery delivery) updateDelivery, required TResult Function(Table? table) updateTable, + required TResult Function(Order? order) orderAddedItems, }) { return updateItemNotes(product, notes); } @@ -817,6 +842,7 @@ class _$UpdateItemNotesImpl implements _UpdateItemNotes { TResult? Function(OrderType orderType)? updateOrderType, TResult? Function(Delivery delivery)? updateDelivery, TResult? Function(Table? table)? updateTable, + TResult? Function(Order? order)? orderAddedItems, }) { return updateItemNotes?.call(product, notes); } @@ -831,6 +857,7 @@ class _$UpdateItemNotesImpl implements _UpdateItemNotes { TResult Function(OrderType orderType)? updateOrderType, TResult Function(Delivery delivery)? updateDelivery, TResult Function(Table? table)? updateTable, + TResult Function(Order? order)? orderAddedItems, required TResult orElse(), }) { if (updateItemNotes != null) { @@ -849,6 +876,7 @@ class _$UpdateItemNotesImpl implements _UpdateItemNotes { required TResult Function(_UpdateOrderType value) updateOrderType, required TResult Function(_UpdateDelivery value) updateDelivery, required TResult Function(_UpdateTable value) updateTable, + required TResult Function(_OrderAddedItems value) orderAddedItems, }) { return updateItemNotes(this); } @@ -863,6 +891,7 @@ class _$UpdateItemNotesImpl implements _UpdateItemNotes { TResult? Function(_UpdateOrderType value)? updateOrderType, TResult? Function(_UpdateDelivery value)? updateDelivery, TResult? Function(_UpdateTable value)? updateTable, + TResult? Function(_OrderAddedItems value)? orderAddedItems, }) { return updateItemNotes?.call(this); } @@ -877,6 +906,7 @@ class _$UpdateItemNotesImpl implements _UpdateItemNotes { TResult Function(_UpdateOrderType value)? updateOrderType, TResult Function(_UpdateDelivery value)? updateDelivery, TResult Function(_UpdateTable value)? updateTable, + TResult Function(_OrderAddedItems value)? orderAddedItems, required TResult orElse(), }) { if (updateItemNotes != null) { @@ -982,6 +1012,7 @@ class _$UpdateOrderTypeImpl implements _UpdateOrderType { required TResult Function(OrderType orderType) updateOrderType, required TResult Function(Delivery delivery) updateDelivery, required TResult Function(Table? table) updateTable, + required TResult Function(Order? order) orderAddedItems, }) { return updateOrderType(orderType); } @@ -996,6 +1027,7 @@ class _$UpdateOrderTypeImpl implements _UpdateOrderType { TResult? Function(OrderType orderType)? updateOrderType, TResult? Function(Delivery delivery)? updateDelivery, TResult? Function(Table? table)? updateTable, + TResult? Function(Order? order)? orderAddedItems, }) { return updateOrderType?.call(orderType); } @@ -1010,6 +1042,7 @@ class _$UpdateOrderTypeImpl implements _UpdateOrderType { TResult Function(OrderType orderType)? updateOrderType, TResult Function(Delivery delivery)? updateDelivery, TResult Function(Table? table)? updateTable, + TResult Function(Order? order)? orderAddedItems, required TResult orElse(), }) { if (updateOrderType != null) { @@ -1028,6 +1061,7 @@ class _$UpdateOrderTypeImpl implements _UpdateOrderType { required TResult Function(_UpdateOrderType value) updateOrderType, required TResult Function(_UpdateDelivery value) updateDelivery, required TResult Function(_UpdateTable value) updateTable, + required TResult Function(_OrderAddedItems value) orderAddedItems, }) { return updateOrderType(this); } @@ -1042,6 +1076,7 @@ class _$UpdateOrderTypeImpl implements _UpdateOrderType { TResult? Function(_UpdateOrderType value)? updateOrderType, TResult? Function(_UpdateDelivery value)? updateDelivery, TResult? Function(_UpdateTable value)? updateTable, + TResult? Function(_OrderAddedItems value)? orderAddedItems, }) { return updateOrderType?.call(this); } @@ -1056,6 +1091,7 @@ class _$UpdateOrderTypeImpl implements _UpdateOrderType { TResult Function(_UpdateOrderType value)? updateOrderType, TResult Function(_UpdateDelivery value)? updateDelivery, TResult Function(_UpdateTable value)? updateTable, + TResult Function(_OrderAddedItems value)? orderAddedItems, required TResult orElse(), }) { if (updateOrderType != null) { @@ -1160,6 +1196,7 @@ class _$UpdateDeliveryImpl implements _UpdateDelivery { required TResult Function(OrderType orderType) updateOrderType, required TResult Function(Delivery delivery) updateDelivery, required TResult Function(Table? table) updateTable, + required TResult Function(Order? order) orderAddedItems, }) { return updateDelivery(delivery); } @@ -1174,6 +1211,7 @@ class _$UpdateDeliveryImpl implements _UpdateDelivery { TResult? Function(OrderType orderType)? updateOrderType, TResult? Function(Delivery delivery)? updateDelivery, TResult? Function(Table? table)? updateTable, + TResult? Function(Order? order)? orderAddedItems, }) { return updateDelivery?.call(delivery); } @@ -1188,6 +1226,7 @@ class _$UpdateDeliveryImpl implements _UpdateDelivery { TResult Function(OrderType orderType)? updateOrderType, TResult Function(Delivery delivery)? updateDelivery, TResult Function(Table? table)? updateTable, + TResult Function(Order? order)? orderAddedItems, required TResult orElse(), }) { if (updateDelivery != null) { @@ -1206,6 +1245,7 @@ class _$UpdateDeliveryImpl implements _UpdateDelivery { required TResult Function(_UpdateOrderType value) updateOrderType, required TResult Function(_UpdateDelivery value) updateDelivery, required TResult Function(_UpdateTable value) updateTable, + required TResult Function(_OrderAddedItems value) orderAddedItems, }) { return updateDelivery(this); } @@ -1220,6 +1260,7 @@ class _$UpdateDeliveryImpl implements _UpdateDelivery { TResult? Function(_UpdateOrderType value)? updateOrderType, TResult? Function(_UpdateDelivery value)? updateDelivery, TResult? Function(_UpdateTable value)? updateTable, + TResult? Function(_OrderAddedItems value)? orderAddedItems, }) { return updateDelivery?.call(this); } @@ -1234,6 +1275,7 @@ class _$UpdateDeliveryImpl implements _UpdateDelivery { TResult Function(_UpdateOrderType value)? updateOrderType, TResult Function(_UpdateDelivery value)? updateDelivery, TResult Function(_UpdateTable value)? updateTable, + TResult Function(_OrderAddedItems value)? orderAddedItems, required TResult orElse(), }) { if (updateDelivery != null) { @@ -1349,6 +1391,7 @@ class _$UpdateTableImpl implements _UpdateTable { required TResult Function(OrderType orderType) updateOrderType, required TResult Function(Delivery delivery) updateDelivery, required TResult Function(Table? table) updateTable, + required TResult Function(Order? order) orderAddedItems, }) { return updateTable(table); } @@ -1363,6 +1406,7 @@ class _$UpdateTableImpl implements _UpdateTable { TResult? Function(OrderType orderType)? updateOrderType, TResult? Function(Delivery delivery)? updateDelivery, TResult? Function(Table? table)? updateTable, + TResult? Function(Order? order)? orderAddedItems, }) { return updateTable?.call(table); } @@ -1377,6 +1421,7 @@ class _$UpdateTableImpl implements _UpdateTable { TResult Function(OrderType orderType)? updateOrderType, TResult Function(Delivery delivery)? updateDelivery, TResult Function(Table? table)? updateTable, + TResult Function(Order? order)? orderAddedItems, required TResult orElse(), }) { if (updateTable != null) { @@ -1395,6 +1440,7 @@ class _$UpdateTableImpl implements _UpdateTable { required TResult Function(_UpdateOrderType value) updateOrderType, required TResult Function(_UpdateDelivery value) updateDelivery, required TResult Function(_UpdateTable value) updateTable, + required TResult Function(_OrderAddedItems value) orderAddedItems, }) { return updateTable(this); } @@ -1409,6 +1455,7 @@ class _$UpdateTableImpl implements _UpdateTable { TResult? Function(_UpdateOrderType value)? updateOrderType, TResult? Function(_UpdateDelivery value)? updateDelivery, TResult? Function(_UpdateTable value)? updateTable, + TResult? Function(_OrderAddedItems value)? orderAddedItems, }) { return updateTable?.call(this); } @@ -1423,6 +1470,7 @@ class _$UpdateTableImpl implements _UpdateTable { TResult Function(_UpdateOrderType value)? updateOrderType, TResult Function(_UpdateDelivery value)? updateDelivery, TResult Function(_UpdateTable value)? updateTable, + TResult Function(_OrderAddedItems value)? orderAddedItems, required TResult orElse(), }) { if (updateTable != null) { @@ -1444,8 +1492,191 @@ abstract class _UpdateTable implements CheckoutFormEvent { throw _privateConstructorUsedError; } +/// @nodoc +abstract class _$$OrderAddedItemsImplCopyWith<$Res> { + factory _$$OrderAddedItemsImplCopyWith( + _$OrderAddedItemsImpl value, + $Res Function(_$OrderAddedItemsImpl) then, + ) = __$$OrderAddedItemsImplCopyWithImpl<$Res>; + @useResult + $Res call({Order? order}); +} + +/// @nodoc +class __$$OrderAddedItemsImplCopyWithImpl<$Res> + extends _$CheckoutFormEventCopyWithImpl<$Res, _$OrderAddedItemsImpl> + implements _$$OrderAddedItemsImplCopyWith<$Res> { + __$$OrderAddedItemsImplCopyWithImpl( + _$OrderAddedItemsImpl _value, + $Res Function(_$OrderAddedItemsImpl) _then, + ) : super(_value, _then); + + /// Create a copy of CheckoutFormEvent + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({Object? order = freezed}) { + return _then( + _$OrderAddedItemsImpl( + freezed == order + ? _value.order + : order // ignore: cast_nullable_to_non_nullable + as Order?, + ), + ); + } +} + +/// @nodoc + +class _$OrderAddedItemsImpl implements _OrderAddedItems { + const _$OrderAddedItemsImpl(this.order); + + @override + final Order? order; + + @override + String toString() { + return 'CheckoutFormEvent.orderAddedItems(order: $order)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$OrderAddedItemsImpl && + (identical(other.order, order) || other.order == order)); + } + + @override + int get hashCode => Object.hash(runtimeType, order); + + /// Create a copy of CheckoutFormEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$OrderAddedItemsImplCopyWith<_$OrderAddedItemsImpl> get copyWith => + __$$OrderAddedItemsImplCopyWithImpl<_$OrderAddedItemsImpl>( + this, + _$identity, + ); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(List items) started, + required TResult Function(Product product, ProductVariant? variant) addItem, + required TResult Function(Product product, ProductVariant? variant) + removeItem, + required TResult Function(Product product, String notes) updateItemNotes, + required TResult Function(OrderType orderType) updateOrderType, + required TResult Function(Delivery delivery) updateDelivery, + required TResult Function(Table? table) updateTable, + required TResult Function(Order? order) orderAddedItems, + }) { + return orderAddedItems(order); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(List items)? started, + TResult? Function(Product product, ProductVariant? variant)? addItem, + TResult? Function(Product product, ProductVariant? variant)? removeItem, + TResult? Function(Product product, String notes)? updateItemNotes, + TResult? Function(OrderType orderType)? updateOrderType, + TResult? Function(Delivery delivery)? updateDelivery, + TResult? Function(Table? table)? updateTable, + TResult? Function(Order? order)? orderAddedItems, + }) { + return orderAddedItems?.call(order); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(List items)? started, + TResult Function(Product product, ProductVariant? variant)? addItem, + TResult Function(Product product, ProductVariant? variant)? removeItem, + TResult Function(Product product, String notes)? updateItemNotes, + TResult Function(OrderType orderType)? updateOrderType, + TResult Function(Delivery delivery)? updateDelivery, + TResult Function(Table? table)? updateTable, + TResult Function(Order? order)? orderAddedItems, + required TResult orElse(), + }) { + if (orderAddedItems != null) { + return orderAddedItems(order); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_Started value) started, + required TResult Function(_AddItem value) addItem, + required TResult Function(_RemoveItem value) removeItem, + required TResult Function(_UpdateItemNotes value) updateItemNotes, + required TResult Function(_UpdateOrderType value) updateOrderType, + required TResult Function(_UpdateDelivery value) updateDelivery, + required TResult Function(_UpdateTable value) updateTable, + required TResult Function(_OrderAddedItems value) orderAddedItems, + }) { + return orderAddedItems(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_Started value)? started, + TResult? Function(_AddItem value)? addItem, + TResult? Function(_RemoveItem value)? removeItem, + TResult? Function(_UpdateItemNotes value)? updateItemNotes, + TResult? Function(_UpdateOrderType value)? updateOrderType, + TResult? Function(_UpdateDelivery value)? updateDelivery, + TResult? Function(_UpdateTable value)? updateTable, + TResult? Function(_OrderAddedItems value)? orderAddedItems, + }) { + return orderAddedItems?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_Started value)? started, + TResult Function(_AddItem value)? addItem, + TResult Function(_RemoveItem value)? removeItem, + TResult Function(_UpdateItemNotes value)? updateItemNotes, + TResult Function(_UpdateOrderType value)? updateOrderType, + TResult Function(_UpdateDelivery value)? updateDelivery, + TResult Function(_UpdateTable value)? updateTable, + TResult Function(_OrderAddedItems value)? orderAddedItems, + required TResult orElse(), + }) { + if (orderAddedItems != null) { + return orderAddedItems(this); + } + return orElse(); + } +} + +abstract class _OrderAddedItems implements CheckoutFormEvent { + const factory _OrderAddedItems(final Order? order) = _$OrderAddedItemsImpl; + + Order? get order; + + /// Create a copy of CheckoutFormEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$OrderAddedItemsImplCopyWith<_$OrderAddedItemsImpl> get copyWith => + throw _privateConstructorUsedError; +} + /// @nodoc mixin _$CheckoutFormState { + Order? get orderAdded => throw _privateConstructorUsedError; List get items => throw _privateConstructorUsedError; int get discount => throw _privateConstructorUsedError; int get discountAmount => throw _privateConstructorUsedError; @@ -1474,6 +1705,7 @@ abstract class $CheckoutFormStateCopyWith<$Res> { ) = _$CheckoutFormStateCopyWithImpl<$Res, CheckoutFormState>; @useResult $Res call({ + Order? orderAdded, List items, int discount, int discountAmount, @@ -1506,6 +1738,7 @@ class _$CheckoutFormStateCopyWithImpl<$Res, $Val extends CheckoutFormState> @pragma('vm:prefer-inline') @override $Res call({ + Object? orderAdded = freezed, Object? items = null, Object? discount = null, Object? discountAmount = null, @@ -1521,6 +1754,10 @@ class _$CheckoutFormStateCopyWithImpl<$Res, $Val extends CheckoutFormState> }) { return _then( _value.copyWith( + orderAdded: freezed == orderAdded + ? _value.orderAdded + : orderAdded // ignore: cast_nullable_to_non_nullable + as Order?, items: null == items ? _value.items : items // ignore: cast_nullable_to_non_nullable @@ -1599,6 +1836,7 @@ abstract class _$$CheckoutFormStateImplCopyWith<$Res> @override @useResult $Res call({ + Order? orderAdded, List items, int discount, int discountAmount, @@ -1631,6 +1869,7 @@ class __$$CheckoutFormStateImplCopyWithImpl<$Res> @pragma('vm:prefer-inline') @override $Res call({ + Object? orderAdded = freezed, Object? items = null, Object? discount = null, Object? discountAmount = null, @@ -1646,6 +1885,10 @@ class __$$CheckoutFormStateImplCopyWithImpl<$Res> }) { return _then( _$CheckoutFormStateImpl( + orderAdded: freezed == orderAdded + ? _value.orderAdded + : orderAdded // ignore: cast_nullable_to_non_nullable + as Order?, items: null == items ? _value._items : items // ignore: cast_nullable_to_non_nullable @@ -1703,6 +1946,7 @@ class __$$CheckoutFormStateImplCopyWithImpl<$Res> class _$CheckoutFormStateImpl implements _CheckoutFormState { _$CheckoutFormStateImpl({ + this.orderAdded, required final List items, required this.discount, required this.discountAmount, @@ -1717,6 +1961,8 @@ class _$CheckoutFormStateImpl implements _CheckoutFormState { this.isLoading = false, }) : _items = items; + @override + final Order? orderAdded; final List _items; @override List get items { @@ -1751,7 +1997,7 @@ class _$CheckoutFormStateImpl implements _CheckoutFormState { @override String toString() { - return 'CheckoutFormState(items: $items, discount: $discount, discountAmount: $discountAmount, tax: $tax, serviceCharge: $serviceCharge, totalQuantity: $totalQuantity, totalPrice: $totalPrice, draftName: $draftName, orderType: $orderType, delivery: $delivery, table: $table, isLoading: $isLoading)'; + return 'CheckoutFormState(orderAdded: $orderAdded, items: $items, discount: $discount, discountAmount: $discountAmount, tax: $tax, serviceCharge: $serviceCharge, totalQuantity: $totalQuantity, totalPrice: $totalPrice, draftName: $draftName, orderType: $orderType, delivery: $delivery, table: $table, isLoading: $isLoading)'; } @override @@ -1759,6 +2005,8 @@ class _$CheckoutFormStateImpl implements _CheckoutFormState { return identical(this, other) || (other.runtimeType == runtimeType && other is _$CheckoutFormStateImpl && + (identical(other.orderAdded, orderAdded) || + other.orderAdded == orderAdded) && const DeepCollectionEquality().equals(other._items, _items) && (identical(other.discount, discount) || other.discount == discount) && @@ -1785,6 +2033,7 @@ class _$CheckoutFormStateImpl implements _CheckoutFormState { @override int get hashCode => Object.hash( runtimeType, + orderAdded, const DeepCollectionEquality().hash(_items), discount, discountAmount, @@ -1813,6 +2062,7 @@ class _$CheckoutFormStateImpl implements _CheckoutFormState { abstract class _CheckoutFormState implements CheckoutFormState { factory _CheckoutFormState({ + final Order? orderAdded, required final List items, required final int discount, required final int discountAmount, @@ -1827,6 +2077,8 @@ abstract class _CheckoutFormState implements CheckoutFormState { final bool isLoading, }) = _$CheckoutFormStateImpl; + @override + Order? get orderAdded; @override List get items; @override diff --git a/lib/application/checkout/checkout_form/checkout_form_event.dart b/lib/application/checkout/checkout_form/checkout_form_event.dart index 78e20c0..f45e4b7 100644 --- a/lib/application/checkout/checkout_form/checkout_form_event.dart +++ b/lib/application/checkout/checkout_form/checkout_form_event.dart @@ -27,4 +27,7 @@ class CheckoutFormEvent with _$CheckoutFormEvent { _UpdateDelivery; const factory CheckoutFormEvent.updateTable(Table? table) = _UpdateTable; + + const factory CheckoutFormEvent.orderAddedItems(Order? order) = + _OrderAddedItems; } diff --git a/lib/application/checkout/checkout_form/checkout_form_state.dart b/lib/application/checkout/checkout_form/checkout_form_state.dart index a756979..3ef1582 100644 --- a/lib/application/checkout/checkout_form/checkout_form_state.dart +++ b/lib/application/checkout/checkout_form/checkout_form_state.dart @@ -3,6 +3,7 @@ part of 'checkout_form_bloc.dart'; @freezed class CheckoutFormState with _$CheckoutFormState { factory CheckoutFormState({ + Order? orderAdded, required List items, required int discount, required int discountAmount, diff --git a/lib/application/order/order_form/order_form_bloc.dart b/lib/application/order/order_form/order_form_bloc.dart index 0cb8f4b..cff91b6 100644 --- a/lib/application/order/order_form/order_form_bloc.dart +++ b/lib/application/order/order_form/order_form_bloc.dart @@ -120,6 +120,40 @@ class OrderFormBloc extends Bloc { ), ); }, + addItemOrder: (e) async { + Either failureOrAddItemOrder; + + emit( + state.copyWith( + isAddingItemOrder: true, + failureOrAddItemOrder: none(), + ), + ); + + final request = e.items + .map( + (item) => AddItemOrderRequest( + productId: item.product.id, + productVariantId: item.variant?.id ?? '', + quantity: item.quantity, + unitPrice: item.product.price.toInt(), + notes: item.notes, + ), + ) + .toList(); + + failureOrAddItemOrder = await _repository.addItemOrder( + id: e.orderId, + request: request, + ); + + emit( + state.copyWith( + isAddingItemOrder: false, + failureOrAddItemOrder: optionOf(failureOrAddItemOrder), + ), + ); + }, ); } } diff --git a/lib/application/order/order_form/order_form_bloc.freezed.dart b/lib/application/order/order_form/order_form_bloc.freezed.dart index bb36fa6..2cd8cfc 100644 --- a/lib/application/order/order_form/order_form_bloc.freezed.dart +++ b/lib/application/order/order_form/order_form_bloc.freezed.dart @@ -34,6 +34,8 @@ mixin _$OrderFormEvent { Table? table, ) createOrder, + required TResult Function(String orderId, List items) + addItemOrder, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult? whenOrNull({ @@ -52,6 +54,8 @@ mixin _$OrderFormEvent { Table? table, )? createOrder, + TResult? Function(String orderId, List items)? + addItemOrder, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeWhen({ @@ -70,6 +74,7 @@ mixin _$OrderFormEvent { Table? table, )? createOrder, + TResult Function(String orderId, List items)? addItemOrder, required TResult orElse(), }) => throw _privateConstructorUsedError; @optionalTypeArgs @@ -80,6 +85,7 @@ mixin _$OrderFormEvent { required TResult Function(_CreateOrderWithPayment value) createOrderWithPayment, required TResult Function(_CreateOrder value) createOrder, + required TResult Function(_AddItemOrder value) addItemOrder, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult? mapOrNull({ @@ -88,6 +94,7 @@ mixin _$OrderFormEvent { TResult? Function(_CustomerChanged value)? customerChanged, TResult? Function(_CreateOrderWithPayment value)? createOrderWithPayment, TResult? Function(_CreateOrder value)? createOrder, + TResult? Function(_AddItemOrder value)? addItemOrder, }) => throw _privateConstructorUsedError; @optionalTypeArgs TResult maybeMap({ @@ -96,6 +103,7 @@ mixin _$OrderFormEvent { TResult Function(_CustomerChanged value)? customerChanged, TResult Function(_CreateOrderWithPayment value)? createOrderWithPayment, TResult Function(_CreateOrder value)? createOrder, + TResult Function(_AddItemOrder value)? addItemOrder, required TResult orElse(), }) => throw _privateConstructorUsedError; } @@ -221,6 +229,8 @@ class _$CustomerNameChangedImpl Table? table, ) createOrder, + required TResult Function(String orderId, List items) + addItemOrder, }) { return customerNameChanged(customerName); } @@ -243,6 +253,8 @@ class _$CustomerNameChangedImpl Table? table, )? createOrder, + TResult? Function(String orderId, List items)? + addItemOrder, }) { return customerNameChanged?.call(customerName); } @@ -265,6 +277,7 @@ class _$CustomerNameChangedImpl Table? table, )? createOrder, + TResult Function(String orderId, List items)? addItemOrder, required TResult orElse(), }) { if (customerNameChanged != null) { @@ -282,6 +295,7 @@ class _$CustomerNameChangedImpl required TResult Function(_CreateOrderWithPayment value) createOrderWithPayment, required TResult Function(_CreateOrder value) createOrder, + required TResult Function(_AddItemOrder value) addItemOrder, }) { return customerNameChanged(this); } @@ -294,6 +308,7 @@ class _$CustomerNameChangedImpl TResult? Function(_CustomerChanged value)? customerChanged, TResult? Function(_CreateOrderWithPayment value)? createOrderWithPayment, TResult? Function(_CreateOrder value)? createOrder, + TResult? Function(_AddItemOrder value)? addItemOrder, }) { return customerNameChanged?.call(this); } @@ -306,6 +321,7 @@ class _$CustomerNameChangedImpl TResult Function(_CustomerChanged value)? customerChanged, TResult Function(_CreateOrderWithPayment value)? createOrderWithPayment, TResult Function(_CreateOrder value)? createOrder, + TResult Function(_AddItemOrder value)? addItemOrder, required TResult orElse(), }) { if (customerNameChanged != null) { @@ -439,6 +455,8 @@ class _$PaymentMethodChangedImpl Table? table, ) createOrder, + required TResult Function(String orderId, List items) + addItemOrder, }) { return paymentMethodChanged(payment); } @@ -461,6 +479,8 @@ class _$PaymentMethodChangedImpl Table? table, )? createOrder, + TResult? Function(String orderId, List items)? + addItemOrder, }) { return paymentMethodChanged?.call(payment); } @@ -483,6 +503,7 @@ class _$PaymentMethodChangedImpl Table? table, )? createOrder, + TResult Function(String orderId, List items)? addItemOrder, required TResult orElse(), }) { if (paymentMethodChanged != null) { @@ -500,6 +521,7 @@ class _$PaymentMethodChangedImpl required TResult Function(_CreateOrderWithPayment value) createOrderWithPayment, required TResult Function(_CreateOrder value) createOrder, + required TResult Function(_AddItemOrder value) addItemOrder, }) { return paymentMethodChanged(this); } @@ -512,6 +534,7 @@ class _$PaymentMethodChangedImpl TResult? Function(_CustomerChanged value)? customerChanged, TResult? Function(_CreateOrderWithPayment value)? createOrderWithPayment, TResult? Function(_CreateOrder value)? createOrder, + TResult? Function(_AddItemOrder value)? addItemOrder, }) { return paymentMethodChanged?.call(this); } @@ -524,6 +547,7 @@ class _$PaymentMethodChangedImpl TResult Function(_CustomerChanged value)? customerChanged, TResult Function(_CreateOrderWithPayment value)? createOrderWithPayment, TResult Function(_CreateOrder value)? createOrder, + TResult Function(_AddItemOrder value)? addItemOrder, required TResult orElse(), }) { if (paymentMethodChanged != null) { @@ -661,6 +685,8 @@ class _$CustomerChangedImpl Table? table, ) createOrder, + required TResult Function(String orderId, List items) + addItemOrder, }) { return customerChanged(customer); } @@ -683,6 +709,8 @@ class _$CustomerChangedImpl Table? table, )? createOrder, + TResult? Function(String orderId, List items)? + addItemOrder, }) { return customerChanged?.call(customer); } @@ -705,6 +733,7 @@ class _$CustomerChangedImpl Table? table, )? createOrder, + TResult Function(String orderId, List items)? addItemOrder, required TResult orElse(), }) { if (customerChanged != null) { @@ -722,6 +751,7 @@ class _$CustomerChangedImpl required TResult Function(_CreateOrderWithPayment value) createOrderWithPayment, required TResult Function(_CreateOrder value) createOrder, + required TResult Function(_AddItemOrder value) addItemOrder, }) { return customerChanged(this); } @@ -734,6 +764,7 @@ class _$CustomerChangedImpl TResult? Function(_CustomerChanged value)? customerChanged, TResult? Function(_CreateOrderWithPayment value)? createOrderWithPayment, TResult? Function(_CreateOrder value)? createOrder, + TResult? Function(_AddItemOrder value)? addItemOrder, }) { return customerChanged?.call(this); } @@ -746,6 +777,7 @@ class _$CustomerChangedImpl TResult Function(_CustomerChanged value)? customerChanged, TResult Function(_CreateOrderWithPayment value)? createOrderWithPayment, TResult Function(_CreateOrder value)? createOrder, + TResult Function(_AddItemOrder value)? addItemOrder, required TResult orElse(), }) { if (customerChanged != null) { @@ -921,6 +953,8 @@ class _$CreateOrderWithPaymentImpl Table? table, ) createOrder, + required TResult Function(String orderId, List items) + addItemOrder, }) { return createOrderWithPayment(items, orderType, table); } @@ -943,6 +977,8 @@ class _$CreateOrderWithPaymentImpl Table? table, )? createOrder, + TResult? Function(String orderId, List items)? + addItemOrder, }) { return createOrderWithPayment?.call(items, orderType, table); } @@ -965,6 +1001,7 @@ class _$CreateOrderWithPaymentImpl Table? table, )? createOrder, + TResult Function(String orderId, List items)? addItemOrder, required TResult orElse(), }) { if (createOrderWithPayment != null) { @@ -982,6 +1019,7 @@ class _$CreateOrderWithPaymentImpl required TResult Function(_CreateOrderWithPayment value) createOrderWithPayment, required TResult Function(_CreateOrder value) createOrder, + required TResult Function(_AddItemOrder value) addItemOrder, }) { return createOrderWithPayment(this); } @@ -994,6 +1032,7 @@ class _$CreateOrderWithPaymentImpl TResult? Function(_CustomerChanged value)? customerChanged, TResult? Function(_CreateOrderWithPayment value)? createOrderWithPayment, TResult? Function(_CreateOrder value)? createOrder, + TResult? Function(_AddItemOrder value)? addItemOrder, }) { return createOrderWithPayment?.call(this); } @@ -1006,6 +1045,7 @@ class _$CreateOrderWithPaymentImpl TResult Function(_CustomerChanged value)? customerChanged, TResult Function(_CreateOrderWithPayment value)? createOrderWithPayment, TResult Function(_CreateOrder value)? createOrder, + TResult Function(_AddItemOrder value)? addItemOrder, required TResult orElse(), }) { if (createOrderWithPayment != null) { @@ -1178,6 +1218,8 @@ class _$CreateOrderImpl with DiagnosticableTreeMixin implements _CreateOrder { Table? table, ) createOrder, + required TResult Function(String orderId, List items) + addItemOrder, }) { return createOrder(items, orderType, table); } @@ -1200,6 +1242,8 @@ class _$CreateOrderImpl with DiagnosticableTreeMixin implements _CreateOrder { Table? table, )? createOrder, + TResult? Function(String orderId, List items)? + addItemOrder, }) { return createOrder?.call(items, orderType, table); } @@ -1222,6 +1266,7 @@ class _$CreateOrderImpl with DiagnosticableTreeMixin implements _CreateOrder { Table? table, )? createOrder, + TResult Function(String orderId, List items)? addItemOrder, required TResult orElse(), }) { if (createOrder != null) { @@ -1239,6 +1284,7 @@ class _$CreateOrderImpl with DiagnosticableTreeMixin implements _CreateOrder { required TResult Function(_CreateOrderWithPayment value) createOrderWithPayment, required TResult Function(_CreateOrder value) createOrder, + required TResult Function(_AddItemOrder value) addItemOrder, }) { return createOrder(this); } @@ -1251,6 +1297,7 @@ class _$CreateOrderImpl with DiagnosticableTreeMixin implements _CreateOrder { TResult? Function(_CustomerChanged value)? customerChanged, TResult? Function(_CreateOrderWithPayment value)? createOrderWithPayment, TResult? Function(_CreateOrder value)? createOrder, + TResult? Function(_AddItemOrder value)? addItemOrder, }) { return createOrder?.call(this); } @@ -1263,6 +1310,7 @@ class _$CreateOrderImpl with DiagnosticableTreeMixin implements _CreateOrder { TResult Function(_CustomerChanged value)? customerChanged, TResult Function(_CreateOrderWithPayment value)? createOrderWithPayment, TResult Function(_CreateOrder value)? createOrder, + TResult Function(_AddItemOrder value)? addItemOrder, required TResult orElse(), }) { if (createOrder != null) { @@ -1290,6 +1338,237 @@ abstract class _CreateOrder implements OrderFormEvent { throw _privateConstructorUsedError; } +/// @nodoc +abstract class _$$AddItemOrderImplCopyWith<$Res> { + factory _$$AddItemOrderImplCopyWith( + _$AddItemOrderImpl value, + $Res Function(_$AddItemOrderImpl) then, + ) = __$$AddItemOrderImplCopyWithImpl<$Res>; + @useResult + $Res call({String orderId, List items}); +} + +/// @nodoc +class __$$AddItemOrderImplCopyWithImpl<$Res> + extends _$OrderFormEventCopyWithImpl<$Res, _$AddItemOrderImpl> + implements _$$AddItemOrderImplCopyWith<$Res> { + __$$AddItemOrderImplCopyWithImpl( + _$AddItemOrderImpl _value, + $Res Function(_$AddItemOrderImpl) _then, + ) : super(_value, _then); + + /// Create a copy of OrderFormEvent + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({Object? orderId = null, Object? items = null}) { + return _then( + _$AddItemOrderImpl( + orderId: null == orderId + ? _value.orderId + : orderId // ignore: cast_nullable_to_non_nullable + as String, + items: null == items + ? _value._items + : items // ignore: cast_nullable_to_non_nullable + as List, + ), + ); + } +} + +/// @nodoc + +class _$AddItemOrderImpl with DiagnosticableTreeMixin implements _AddItemOrder { + const _$AddItemOrderImpl({ + required this.orderId, + required final List items, + }) : _items = items; + + @override + final String orderId; + final List _items; + @override + List get items { + if (_items is EqualUnmodifiableListView) return _items; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_items); + } + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'OrderFormEvent.addItemOrder(orderId: $orderId, items: $items)'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'OrderFormEvent.addItemOrder')) + ..add(DiagnosticsProperty('orderId', orderId)) + ..add(DiagnosticsProperty('items', items)); + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$AddItemOrderImpl && + (identical(other.orderId, orderId) || other.orderId == orderId) && + const DeepCollectionEquality().equals(other._items, _items)); + } + + @override + int get hashCode => Object.hash( + runtimeType, + orderId, + const DeepCollectionEquality().hash(_items), + ); + + /// Create a copy of OrderFormEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$AddItemOrderImplCopyWith<_$AddItemOrderImpl> get copyWith => + __$$AddItemOrderImplCopyWithImpl<_$AddItemOrderImpl>(this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(String customerName) customerNameChanged, + required TResult Function(PaymentMethod payment) paymentMethodChanged, + required TResult Function(Customer? customer) customerChanged, + required TResult Function( + List items, + OrderType orderType, + Table? table, + ) + createOrderWithPayment, + required TResult Function( + List items, + OrderType orderType, + Table? table, + ) + createOrder, + required TResult Function(String orderId, List items) + addItemOrder, + }) { + return addItemOrder(orderId, items); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(String customerName)? customerNameChanged, + TResult? Function(PaymentMethod payment)? paymentMethodChanged, + TResult? Function(Customer? customer)? customerChanged, + TResult? Function( + List items, + OrderType orderType, + Table? table, + )? + createOrderWithPayment, + TResult? Function( + List items, + OrderType orderType, + Table? table, + )? + createOrder, + TResult? Function(String orderId, List items)? + addItemOrder, + }) { + return addItemOrder?.call(orderId, items); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(String customerName)? customerNameChanged, + TResult Function(PaymentMethod payment)? paymentMethodChanged, + TResult Function(Customer? customer)? customerChanged, + TResult Function( + List items, + OrderType orderType, + Table? table, + )? + createOrderWithPayment, + TResult Function( + List items, + OrderType orderType, + Table? table, + )? + createOrder, + TResult Function(String orderId, List items)? addItemOrder, + required TResult orElse(), + }) { + if (addItemOrder != null) { + return addItemOrder(orderId, items); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function(_CustomerNameChanged value) customerNameChanged, + required TResult Function(_PaymentMethodChanged value) paymentMethodChanged, + required TResult Function(_CustomerChanged value) customerChanged, + required TResult Function(_CreateOrderWithPayment value) + createOrderWithPayment, + required TResult Function(_CreateOrder value) createOrder, + required TResult Function(_AddItemOrder value) addItemOrder, + }) { + return addItemOrder(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function(_CustomerNameChanged value)? customerNameChanged, + TResult? Function(_PaymentMethodChanged value)? paymentMethodChanged, + TResult? Function(_CustomerChanged value)? customerChanged, + TResult? Function(_CreateOrderWithPayment value)? createOrderWithPayment, + TResult? Function(_CreateOrder value)? createOrder, + TResult? Function(_AddItemOrder value)? addItemOrder, + }) { + return addItemOrder?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function(_CustomerNameChanged value)? customerNameChanged, + TResult Function(_PaymentMethodChanged value)? paymentMethodChanged, + TResult Function(_CustomerChanged value)? customerChanged, + TResult Function(_CreateOrderWithPayment value)? createOrderWithPayment, + TResult Function(_CreateOrder value)? createOrder, + TResult Function(_AddItemOrder value)? addItemOrder, + required TResult orElse(), + }) { + if (addItemOrder != null) { + return addItemOrder(this); + } + return orElse(); + } +} + +abstract class _AddItemOrder implements OrderFormEvent { + const factory _AddItemOrder({ + required final String orderId, + required final List items, + }) = _$AddItemOrderImpl; + + String get orderId; + List get items; + + /// Create a copy of OrderFormEvent + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + _$$AddItemOrderImplCopyWith<_$AddItemOrderImpl> get copyWith => + throw _privateConstructorUsedError; +} + /// @nodoc mixin _$OrderFormState { PaymentMethod? get paymentMethod => throw _privateConstructorUsedError; @@ -1299,8 +1578,11 @@ mixin _$OrderFormState { throw _privateConstructorUsedError; Option> get failureOrCreateOrderWithPayment => throw _privateConstructorUsedError; + Option> get failureOrAddItemOrder => + throw _privateConstructorUsedError; bool get isCreating => throw _privateConstructorUsedError; bool get isCreatingWithPayment => throw _privateConstructorUsedError; + bool get isAddingItemOrder => throw _privateConstructorUsedError; /// Create a copy of OrderFormState /// with the given fields replaced by the non-null parameter values. @@ -1322,8 +1604,10 @@ abstract class $OrderFormStateCopyWith<$Res> { Customer? customer, Option> failureOrCreateOrder, Option> failureOrCreateOrderWithPayment, + Option> failureOrAddItemOrder, bool isCreating, bool isCreatingWithPayment, + bool isAddingItemOrder, }); $PaymentMethodCopyWith<$Res>? get paymentMethod; @@ -1350,8 +1634,10 @@ class _$OrderFormStateCopyWithImpl<$Res, $Val extends OrderFormState> Object? customer = freezed, Object? failureOrCreateOrder = null, Object? failureOrCreateOrderWithPayment = null, + Object? failureOrAddItemOrder = null, Object? isCreating = null, Object? isCreatingWithPayment = null, + Object? isAddingItemOrder = null, }) { return _then( _value.copyWith( @@ -1376,6 +1662,10 @@ class _$OrderFormStateCopyWithImpl<$Res, $Val extends OrderFormState> ? _value.failureOrCreateOrderWithPayment : failureOrCreateOrderWithPayment // ignore: cast_nullable_to_non_nullable as Option>, + failureOrAddItemOrder: null == failureOrAddItemOrder + ? _value.failureOrAddItemOrder + : failureOrAddItemOrder // ignore: cast_nullable_to_non_nullable + as Option>, isCreating: null == isCreating ? _value.isCreating : isCreating // ignore: cast_nullable_to_non_nullable @@ -1384,6 +1674,10 @@ class _$OrderFormStateCopyWithImpl<$Res, $Val extends OrderFormState> ? _value.isCreatingWithPayment : isCreatingWithPayment // ignore: cast_nullable_to_non_nullable as bool, + isAddingItemOrder: null == isAddingItemOrder + ? _value.isAddingItemOrder + : isAddingItemOrder // ignore: cast_nullable_to_non_nullable + as bool, ) as $Val, ); @@ -1433,8 +1727,10 @@ abstract class _$$OrderFormStateImplCopyWith<$Res> Customer? customer, Option> failureOrCreateOrder, Option> failureOrCreateOrderWithPayment, + Option> failureOrAddItemOrder, bool isCreating, bool isCreatingWithPayment, + bool isAddingItemOrder, }); @override @@ -1462,8 +1758,10 @@ class __$$OrderFormStateImplCopyWithImpl<$Res> Object? customer = freezed, Object? failureOrCreateOrder = null, Object? failureOrCreateOrderWithPayment = null, + Object? failureOrAddItemOrder = null, Object? isCreating = null, Object? isCreatingWithPayment = null, + Object? isAddingItemOrder = null, }) { return _then( _$OrderFormStateImpl( @@ -1487,6 +1785,10 @@ class __$$OrderFormStateImplCopyWithImpl<$Res> ? _value.failureOrCreateOrderWithPayment : failureOrCreateOrderWithPayment // ignore: cast_nullable_to_non_nullable as Option>, + failureOrAddItemOrder: null == failureOrAddItemOrder + ? _value.failureOrAddItemOrder + : failureOrAddItemOrder // ignore: cast_nullable_to_non_nullable + as Option>, isCreating: null == isCreating ? _value.isCreating : isCreating // ignore: cast_nullable_to_non_nullable @@ -1495,6 +1797,10 @@ class __$$OrderFormStateImplCopyWithImpl<$Res> ? _value.isCreatingWithPayment : isCreatingWithPayment // ignore: cast_nullable_to_non_nullable as bool, + isAddingItemOrder: null == isAddingItemOrder + ? _value.isAddingItemOrder + : isAddingItemOrder // ignore: cast_nullable_to_non_nullable + as bool, ), ); } @@ -1511,8 +1817,10 @@ class _$OrderFormStateImpl this.customer, required this.failureOrCreateOrder, required this.failureOrCreateOrderWithPayment, + required this.failureOrAddItemOrder, this.isCreating = false, this.isCreatingWithPayment = false, + this.isAddingItemOrder = false, }); @override @@ -1526,15 +1834,20 @@ class _$OrderFormStateImpl @override final Option> failureOrCreateOrderWithPayment; @override + final Option> failureOrAddItemOrder; + @override @JsonKey() final bool isCreating; @override @JsonKey() final bool isCreatingWithPayment; + @override + @JsonKey() + final bool isAddingItemOrder; @override String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { - return 'OrderFormState(paymentMethod: $paymentMethod, customerName: $customerName, customer: $customer, failureOrCreateOrder: $failureOrCreateOrder, failureOrCreateOrderWithPayment: $failureOrCreateOrderWithPayment, isCreating: $isCreating, isCreatingWithPayment: $isCreatingWithPayment)'; + return 'OrderFormState(paymentMethod: $paymentMethod, customerName: $customerName, customer: $customer, failureOrCreateOrder: $failureOrCreateOrder, failureOrCreateOrderWithPayment: $failureOrCreateOrderWithPayment, failureOrAddItemOrder: $failureOrAddItemOrder, isCreating: $isCreating, isCreatingWithPayment: $isCreatingWithPayment, isAddingItemOrder: $isAddingItemOrder)'; } @override @@ -1552,10 +1865,10 @@ class _$OrderFormStateImpl failureOrCreateOrderWithPayment, ), ) + ..add(DiagnosticsProperty('failureOrAddItemOrder', failureOrAddItemOrder)) ..add(DiagnosticsProperty('isCreating', isCreating)) - ..add( - DiagnosticsProperty('isCreatingWithPayment', isCreatingWithPayment), - ); + ..add(DiagnosticsProperty('isCreatingWithPayment', isCreatingWithPayment)) + ..add(DiagnosticsProperty('isAddingItemOrder', isAddingItemOrder)); } @override @@ -1577,10 +1890,14 @@ class _$OrderFormStateImpl ) || other.failureOrCreateOrderWithPayment == failureOrCreateOrderWithPayment) && + (identical(other.failureOrAddItemOrder, failureOrAddItemOrder) || + other.failureOrAddItemOrder == failureOrAddItemOrder) && (identical(other.isCreating, isCreating) || other.isCreating == isCreating) && (identical(other.isCreatingWithPayment, isCreatingWithPayment) || - other.isCreatingWithPayment == isCreatingWithPayment)); + other.isCreatingWithPayment == isCreatingWithPayment) && + (identical(other.isAddingItemOrder, isAddingItemOrder) || + other.isAddingItemOrder == isAddingItemOrder)); } @override @@ -1591,8 +1908,10 @@ class _$OrderFormStateImpl customer, failureOrCreateOrder, failureOrCreateOrderWithPayment, + failureOrAddItemOrder, isCreating, isCreatingWithPayment, + isAddingItemOrder, ); /// Create a copy of OrderFormState @@ -1615,8 +1934,10 @@ abstract class _OrderFormState implements OrderFormState { required final Option> failureOrCreateOrder, required final Option> failureOrCreateOrderWithPayment, + required final Option> failureOrAddItemOrder, final bool isCreating, final bool isCreatingWithPayment, + final bool isAddingItemOrder, }) = _$OrderFormStateImpl; @override @@ -1630,9 +1951,13 @@ abstract class _OrderFormState implements OrderFormState { @override Option> get failureOrCreateOrderWithPayment; @override + Option> get failureOrAddItemOrder; + @override bool get isCreating; @override bool get isCreatingWithPayment; + @override + bool get isAddingItemOrder; /// Create a copy of OrderFormState /// with the given fields replaced by the non-null parameter values. diff --git a/lib/application/order/order_form/order_form_event.dart b/lib/application/order/order_form/order_form_event.dart index d500c76..550a1b4 100644 --- a/lib/application/order/order_form/order_form_event.dart +++ b/lib/application/order/order_form/order_form_event.dart @@ -19,4 +19,9 @@ class OrderFormEvent with _$OrderFormEvent { required OrderType orderType, Table? table, }) = _CreateOrder; + + const factory OrderFormEvent.addItemOrder({ + required String orderId, + required List items, + }) = _AddItemOrder; } diff --git a/lib/application/order/order_form/order_form_state.dart b/lib/application/order/order_form/order_form_state.dart index a3fb4e4..ed8b946 100644 --- a/lib/application/order/order_form/order_form_state.dart +++ b/lib/application/order/order_form/order_form_state.dart @@ -9,12 +9,15 @@ class OrderFormState with _$OrderFormState { required Option> failureOrCreateOrder, required Option> failureOrCreateOrderWithPayment, + required Option> failureOrAddItemOrder, @Default(false) bool isCreating, @Default(false) bool isCreatingWithPayment, + @Default(false) bool isAddingItemOrder, }) = _OrderFormState; factory OrderFormState.initial() => OrderFormState( failureOrCreateOrder: none(), failureOrCreateOrderWithPayment: none(), + failureOrAddItemOrder: none(), ); } diff --git a/lib/domain/order/entities/add_item_order_request_entity.dart b/lib/domain/order/entities/add_item_order_request_entity.dart new file mode 100644 index 0000000..4dd4635 --- /dev/null +++ b/lib/domain/order/entities/add_item_order_request_entity.dart @@ -0,0 +1,20 @@ +part of '../order.dart'; + +@freezed +class AddItemOrderRequest with _$AddItemOrderRequest { + const factory AddItemOrderRequest({ + required String productId, + required String productVariantId, + required int quantity, + required int unitPrice, + required String notes, + }) = _AddItemOrderRequest; + + factory AddItemOrderRequest.empty() => AddItemOrderRequest( + productId: '', + productVariantId: '', + quantity: 0, + unitPrice: 0, + notes: '', + ); +} diff --git a/lib/domain/order/order.dart b/lib/domain/order/order.dart index 92464db..e3069a7 100644 --- a/lib/domain/order/order.dart +++ b/lib/domain/order/order.dart @@ -9,5 +9,6 @@ part 'entities/order_entity.dart'; part 'entities/order_request_entity.dart'; part 'entities/payment_request_entity.dart'; part 'entities/payment_entity.dart'; +part 'entities/add_item_order_request_entity.dart'; part 'failures/order_failure.dart'; part 'repositories/i_order_repository.dart'; diff --git a/lib/domain/order/order.freezed.dart b/lib/domain/order/order.freezed.dart index 37fefe8..ab95aaf 100644 --- a/lib/domain/order/order.freezed.dart +++ b/lib/domain/order/order.freezed.dart @@ -2886,6 +2886,244 @@ abstract class _Payment implements Payment { throw _privateConstructorUsedError; } +/// @nodoc +mixin _$AddItemOrderRequest { + String get productId => throw _privateConstructorUsedError; + String get productVariantId => throw _privateConstructorUsedError; + int get quantity => throw _privateConstructorUsedError; + int get unitPrice => throw _privateConstructorUsedError; + String get notes => throw _privateConstructorUsedError; + + /// Create a copy of AddItemOrderRequest + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $AddItemOrderRequestCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $AddItemOrderRequestCopyWith<$Res> { + factory $AddItemOrderRequestCopyWith( + AddItemOrderRequest value, + $Res Function(AddItemOrderRequest) then, + ) = _$AddItemOrderRequestCopyWithImpl<$Res, AddItemOrderRequest>; + @useResult + $Res call({ + String productId, + String productVariantId, + int quantity, + int unitPrice, + String notes, + }); +} + +/// @nodoc +class _$AddItemOrderRequestCopyWithImpl<$Res, $Val extends AddItemOrderRequest> + implements $AddItemOrderRequestCopyWith<$Res> { + _$AddItemOrderRequestCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of AddItemOrderRequest + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? productId = null, + Object? productVariantId = null, + Object? quantity = null, + Object? unitPrice = null, + Object? notes = null, + }) { + return _then( + _value.copyWith( + productId: null == productId + ? _value.productId + : productId // ignore: cast_nullable_to_non_nullable + as String, + productVariantId: null == productVariantId + ? _value.productVariantId + : productVariantId // ignore: cast_nullable_to_non_nullable + as String, + quantity: null == quantity + ? _value.quantity + : quantity // ignore: cast_nullable_to_non_nullable + as int, + unitPrice: null == unitPrice + ? _value.unitPrice + : unitPrice // ignore: cast_nullable_to_non_nullable + as int, + notes: null == notes + ? _value.notes + : notes // ignore: cast_nullable_to_non_nullable + as String, + ) + as $Val, + ); + } +} + +/// @nodoc +abstract class _$$AddItemOrderRequestImplCopyWith<$Res> + implements $AddItemOrderRequestCopyWith<$Res> { + factory _$$AddItemOrderRequestImplCopyWith( + _$AddItemOrderRequestImpl value, + $Res Function(_$AddItemOrderRequestImpl) then, + ) = __$$AddItemOrderRequestImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({ + String productId, + String productVariantId, + int quantity, + int unitPrice, + String notes, + }); +} + +/// @nodoc +class __$$AddItemOrderRequestImplCopyWithImpl<$Res> + extends _$AddItemOrderRequestCopyWithImpl<$Res, _$AddItemOrderRequestImpl> + implements _$$AddItemOrderRequestImplCopyWith<$Res> { + __$$AddItemOrderRequestImplCopyWithImpl( + _$AddItemOrderRequestImpl _value, + $Res Function(_$AddItemOrderRequestImpl) _then, + ) : super(_value, _then); + + /// Create a copy of AddItemOrderRequest + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? productId = null, + Object? productVariantId = null, + Object? quantity = null, + Object? unitPrice = null, + Object? notes = null, + }) { + return _then( + _$AddItemOrderRequestImpl( + productId: null == productId + ? _value.productId + : productId // ignore: cast_nullable_to_non_nullable + as String, + productVariantId: null == productVariantId + ? _value.productVariantId + : productVariantId // ignore: cast_nullable_to_non_nullable + as String, + quantity: null == quantity + ? _value.quantity + : quantity // ignore: cast_nullable_to_non_nullable + as int, + unitPrice: null == unitPrice + ? _value.unitPrice + : unitPrice // ignore: cast_nullable_to_non_nullable + as int, + notes: null == notes + ? _value.notes + : notes // ignore: cast_nullable_to_non_nullable + as String, + ), + ); + } +} + +/// @nodoc + +class _$AddItemOrderRequestImpl implements _AddItemOrderRequest { + const _$AddItemOrderRequestImpl({ + required this.productId, + required this.productVariantId, + required this.quantity, + required this.unitPrice, + required this.notes, + }); + + @override + final String productId; + @override + final String productVariantId; + @override + final int quantity; + @override + final int unitPrice; + @override + final String notes; + + @override + String toString() { + return 'AddItemOrderRequest(productId: $productId, productVariantId: $productVariantId, quantity: $quantity, unitPrice: $unitPrice, notes: $notes)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$AddItemOrderRequestImpl && + (identical(other.productId, productId) || + other.productId == productId) && + (identical(other.productVariantId, productVariantId) || + other.productVariantId == productVariantId) && + (identical(other.quantity, quantity) || + other.quantity == quantity) && + (identical(other.unitPrice, unitPrice) || + other.unitPrice == unitPrice) && + (identical(other.notes, notes) || other.notes == notes)); + } + + @override + int get hashCode => Object.hash( + runtimeType, + productId, + productVariantId, + quantity, + unitPrice, + notes, + ); + + /// Create a copy of AddItemOrderRequest + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$AddItemOrderRequestImplCopyWith<_$AddItemOrderRequestImpl> get copyWith => + __$$AddItemOrderRequestImplCopyWithImpl<_$AddItemOrderRequestImpl>( + this, + _$identity, + ); +} + +abstract class _AddItemOrderRequest implements AddItemOrderRequest { + const factory _AddItemOrderRequest({ + required final String productId, + required final String productVariantId, + required final int quantity, + required final int unitPrice, + required final String notes, + }) = _$AddItemOrderRequestImpl; + + @override + String get productId; + @override + String get productVariantId; + @override + int get quantity; + @override + int get unitPrice; + @override + String get notes; + + /// Create a copy of AddItemOrderRequest + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$AddItemOrderRequestImplCopyWith<_$AddItemOrderRequestImpl> get copyWith => + throw _privateConstructorUsedError; +} + /// @nodoc mixin _$OrderFailure { @optionalTypeArgs diff --git a/lib/domain/order/repositories/i_order_repository.dart b/lib/domain/order/repositories/i_order_repository.dart index 558b96e..06da956 100644 --- a/lib/domain/order/repositories/i_order_repository.dart +++ b/lib/domain/order/repositories/i_order_repository.dart @@ -20,4 +20,9 @@ abstract class IOrderRepository { required OrderRequest request, required String paymentMethodId, }); + + Future> addItemOrder({ + required String id, + required List request, + }); } diff --git a/lib/infrastructure/order/datasources/remote_data_provider.dart b/lib/infrastructure/order/datasources/remote_data_provider.dart index bb202fd..b641942 100644 --- a/lib/infrastructure/order/datasources/remote_data_provider.dart +++ b/lib/infrastructure/order/datasources/remote_data_provider.dart @@ -173,4 +173,33 @@ class OrderRemoteDataProvider { return DC.error(OrderFailure.serverError(e)); } } + + Future> addItemOrder({ + required String id, + required List request, + }) async { + try { + final response = await _apiClient.post( + '${ApiPath.orders}/$id/add-items', + data: { + 'notes': '', + 'order_items': request.map((e) => e.toRequest()).toList(), + }, + headers: getAuthorizationHeader(), + ); + + if (response.data['success'] == false) { + return DC.error(OrderFailure.unexpectedError()); + } + + final order = OrderDto.fromJson( + response.data['data'] as Map, + ); + + return DC.data(order); + } on ApiFailure catch (e, s) { + log('addItemOrderError', name: _logName, error: e, stackTrace: s); + return DC.error(OrderFailure.serverError(e)); + } + } } diff --git a/lib/infrastructure/order/dtos/add_item_order_request_dto.dart b/lib/infrastructure/order/dtos/add_item_order_request_dto.dart new file mode 100644 index 0000000..f26f1b4 --- /dev/null +++ b/lib/infrastructure/order/dtos/add_item_order_request_dto.dart @@ -0,0 +1,50 @@ +part of '../order_dtos.dart'; + +@freezed +class AddItemOrderRequestDto with _$AddItemOrderRequestDto { + const AddItemOrderRequestDto._(); + + const factory AddItemOrderRequestDto({ + @JsonKey(name: 'product_id') String? productId, + @JsonKey(name: 'product_variant_id') String? productvariantId, + @JsonKey(name: 'quantity') int? quantity, + @JsonKey(name: 'unit_price') int? unitPrice, + @JsonKey(name: 'notes') String? notes, + }) = _AddItemOrderRequestDto; + + factory AddItemOrderRequestDto.fromJson(Map json) => + _$AddItemOrderRequestDtoFromJson(json); + + AddItemOrderRequest toDomain() => AddItemOrderRequest( + productId: productId ?? '', + productVariantId: productvariantId ?? '', + quantity: quantity ?? 0, + unitPrice: unitPrice ?? 0, + notes: notes ?? '', + ); + + factory AddItemOrderRequestDto.fromDomain( + AddItemOrderRequest addItemOrderRequest, + ) => AddItemOrderRequestDto( + productId: addItemOrderRequest.productId, + productvariantId: addItemOrderRequest.productVariantId, + quantity: addItemOrderRequest.quantity, + unitPrice: addItemOrderRequest.unitPrice, + notes: addItemOrderRequest.notes, + ); + + Map toRequest() { + Map data = { + 'product_id': productId, + 'quantity': quantity, + 'unit_price': unitPrice, + 'notes': notes, + }; + + if (productvariantId != null && productvariantId != '') { + data['product_variant_id'] = productvariantId; + } + + return data; + } +} diff --git a/lib/infrastructure/order/order_dtos.dart b/lib/infrastructure/order/order_dtos.dart index a1ca0b0..ac4840d 100644 --- a/lib/infrastructure/order/order_dtos.dart +++ b/lib/infrastructure/order/order_dtos.dart @@ -9,3 +9,4 @@ part 'dtos/order_dto.dart'; part 'dtos/order_request_dto.dart'; part 'dtos/payment_request_dto.dart'; part 'dtos/payment_dto.dart'; +part 'dtos/add_item_order_request_dto.dart'; diff --git a/lib/infrastructure/order/order_dtos.freezed.dart b/lib/infrastructure/order/order_dtos.freezed.dart index c09ce69..61ba067 100644 --- a/lib/infrastructure/order/order_dtos.freezed.dart +++ b/lib/infrastructure/order/order_dtos.freezed.dart @@ -3353,3 +3353,283 @@ abstract class _PaymentOrderDto extends PaymentDto { _$$PaymentOrderDtoImplCopyWith<_$PaymentOrderDtoImpl> get copyWith => throw _privateConstructorUsedError; } + +AddItemOrderRequestDto _$AddItemOrderRequestDtoFromJson( + Map json, +) { + return _AddItemOrderRequestDto.fromJson(json); +} + +/// @nodoc +mixin _$AddItemOrderRequestDto { + @JsonKey(name: 'product_id') + String? get productId => throw _privateConstructorUsedError; + @JsonKey(name: 'product_variant_id') + String? get productvariantId => throw _privateConstructorUsedError; + @JsonKey(name: 'quantity') + int? get quantity => throw _privateConstructorUsedError; + @JsonKey(name: 'unit_price') + int? get unitPrice => throw _privateConstructorUsedError; + @JsonKey(name: 'notes') + String? get notes => throw _privateConstructorUsedError; + + /// Serializes this AddItemOrderRequestDto to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of AddItemOrderRequestDto + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $AddItemOrderRequestDtoCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $AddItemOrderRequestDtoCopyWith<$Res> { + factory $AddItemOrderRequestDtoCopyWith( + AddItemOrderRequestDto value, + $Res Function(AddItemOrderRequestDto) then, + ) = _$AddItemOrderRequestDtoCopyWithImpl<$Res, AddItemOrderRequestDto>; + @useResult + $Res call({ + @JsonKey(name: 'product_id') String? productId, + @JsonKey(name: 'product_variant_id') String? productvariantId, + @JsonKey(name: 'quantity') int? quantity, + @JsonKey(name: 'unit_price') int? unitPrice, + @JsonKey(name: 'notes') String? notes, + }); +} + +/// @nodoc +class _$AddItemOrderRequestDtoCopyWithImpl< + $Res, + $Val extends AddItemOrderRequestDto +> + implements $AddItemOrderRequestDtoCopyWith<$Res> { + _$AddItemOrderRequestDtoCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of AddItemOrderRequestDto + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? productId = freezed, + Object? productvariantId = freezed, + Object? quantity = freezed, + Object? unitPrice = freezed, + Object? notes = freezed, + }) { + return _then( + _value.copyWith( + productId: freezed == productId + ? _value.productId + : productId // ignore: cast_nullable_to_non_nullable + as String?, + productvariantId: freezed == productvariantId + ? _value.productvariantId + : productvariantId // ignore: cast_nullable_to_non_nullable + as String?, + quantity: freezed == quantity + ? _value.quantity + : quantity // ignore: cast_nullable_to_non_nullable + as int?, + unitPrice: freezed == unitPrice + ? _value.unitPrice + : unitPrice // ignore: cast_nullable_to_non_nullable + as int?, + notes: freezed == notes + ? _value.notes + : notes // ignore: cast_nullable_to_non_nullable + as String?, + ) + as $Val, + ); + } +} + +/// @nodoc +abstract class _$$AddItemOrderRequestDtoImplCopyWith<$Res> + implements $AddItemOrderRequestDtoCopyWith<$Res> { + factory _$$AddItemOrderRequestDtoImplCopyWith( + _$AddItemOrderRequestDtoImpl value, + $Res Function(_$AddItemOrderRequestDtoImpl) then, + ) = __$$AddItemOrderRequestDtoImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({ + @JsonKey(name: 'product_id') String? productId, + @JsonKey(name: 'product_variant_id') String? productvariantId, + @JsonKey(name: 'quantity') int? quantity, + @JsonKey(name: 'unit_price') int? unitPrice, + @JsonKey(name: 'notes') String? notes, + }); +} + +/// @nodoc +class __$$AddItemOrderRequestDtoImplCopyWithImpl<$Res> + extends + _$AddItemOrderRequestDtoCopyWithImpl<$Res, _$AddItemOrderRequestDtoImpl> + implements _$$AddItemOrderRequestDtoImplCopyWith<$Res> { + __$$AddItemOrderRequestDtoImplCopyWithImpl( + _$AddItemOrderRequestDtoImpl _value, + $Res Function(_$AddItemOrderRequestDtoImpl) _then, + ) : super(_value, _then); + + /// Create a copy of AddItemOrderRequestDto + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? productId = freezed, + Object? productvariantId = freezed, + Object? quantity = freezed, + Object? unitPrice = freezed, + Object? notes = freezed, + }) { + return _then( + _$AddItemOrderRequestDtoImpl( + productId: freezed == productId + ? _value.productId + : productId // ignore: cast_nullable_to_non_nullable + as String?, + productvariantId: freezed == productvariantId + ? _value.productvariantId + : productvariantId // ignore: cast_nullable_to_non_nullable + as String?, + quantity: freezed == quantity + ? _value.quantity + : quantity // ignore: cast_nullable_to_non_nullable + as int?, + unitPrice: freezed == unitPrice + ? _value.unitPrice + : unitPrice // ignore: cast_nullable_to_non_nullable + as int?, + notes: freezed == notes + ? _value.notes + : notes // ignore: cast_nullable_to_non_nullable + as String?, + ), + ); + } +} + +/// @nodoc +@JsonSerializable() +class _$AddItemOrderRequestDtoImpl extends _AddItemOrderRequestDto { + const _$AddItemOrderRequestDtoImpl({ + @JsonKey(name: 'product_id') this.productId, + @JsonKey(name: 'product_variant_id') this.productvariantId, + @JsonKey(name: 'quantity') this.quantity, + @JsonKey(name: 'unit_price') this.unitPrice, + @JsonKey(name: 'notes') this.notes, + }) : super._(); + + factory _$AddItemOrderRequestDtoImpl.fromJson(Map json) => + _$$AddItemOrderRequestDtoImplFromJson(json); + + @override + @JsonKey(name: 'product_id') + final String? productId; + @override + @JsonKey(name: 'product_variant_id') + final String? productvariantId; + @override + @JsonKey(name: 'quantity') + final int? quantity; + @override + @JsonKey(name: 'unit_price') + final int? unitPrice; + @override + @JsonKey(name: 'notes') + final String? notes; + + @override + String toString() { + return 'AddItemOrderRequestDto(productId: $productId, productvariantId: $productvariantId, quantity: $quantity, unitPrice: $unitPrice, notes: $notes)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$AddItemOrderRequestDtoImpl && + (identical(other.productId, productId) || + other.productId == productId) && + (identical(other.productvariantId, productvariantId) || + other.productvariantId == productvariantId) && + (identical(other.quantity, quantity) || + other.quantity == quantity) && + (identical(other.unitPrice, unitPrice) || + other.unitPrice == unitPrice) && + (identical(other.notes, notes) || other.notes == notes)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash( + runtimeType, + productId, + productvariantId, + quantity, + unitPrice, + notes, + ); + + /// Create a copy of AddItemOrderRequestDto + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$AddItemOrderRequestDtoImplCopyWith<_$AddItemOrderRequestDtoImpl> + get copyWith => + __$$AddItemOrderRequestDtoImplCopyWithImpl<_$AddItemOrderRequestDtoImpl>( + this, + _$identity, + ); + + @override + Map toJson() { + return _$$AddItemOrderRequestDtoImplToJson(this); + } +} + +abstract class _AddItemOrderRequestDto extends AddItemOrderRequestDto { + const factory _AddItemOrderRequestDto({ + @JsonKey(name: 'product_id') final String? productId, + @JsonKey(name: 'product_variant_id') final String? productvariantId, + @JsonKey(name: 'quantity') final int? quantity, + @JsonKey(name: 'unit_price') final int? unitPrice, + @JsonKey(name: 'notes') final String? notes, + }) = _$AddItemOrderRequestDtoImpl; + const _AddItemOrderRequestDto._() : super._(); + + factory _AddItemOrderRequestDto.fromJson(Map json) = + _$AddItemOrderRequestDtoImpl.fromJson; + + @override + @JsonKey(name: 'product_id') + String? get productId; + @override + @JsonKey(name: 'product_variant_id') + String? get productvariantId; + @override + @JsonKey(name: 'quantity') + int? get quantity; + @override + @JsonKey(name: 'unit_price') + int? get unitPrice; + @override + @JsonKey(name: 'notes') + String? get notes; + + /// Create a copy of AddItemOrderRequestDto + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$AddItemOrderRequestDtoImplCopyWith<_$AddItemOrderRequestDtoImpl> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/infrastructure/order/order_dtos.g.dart b/lib/infrastructure/order/order_dtos.g.dart index c0099ff..e26b2fd 100644 --- a/lib/infrastructure/order/order_dtos.g.dart +++ b/lib/infrastructure/order/order_dtos.g.dart @@ -257,3 +257,23 @@ Map _$$PaymentOrderDtoImplToJson( 'created_at': instance.createdAt, 'updated_at': instance.updatedAt, }; + +_$AddItemOrderRequestDtoImpl _$$AddItemOrderRequestDtoImplFromJson( + Map json, +) => _$AddItemOrderRequestDtoImpl( + productId: json['product_id'] as String?, + productvariantId: json['product_variant_id'] as String?, + quantity: (json['quantity'] as num?)?.toInt(), + unitPrice: (json['unit_price'] as num?)?.toInt(), + notes: json['notes'] as String?, +); + +Map _$$AddItemOrderRequestDtoImplToJson( + _$AddItemOrderRequestDtoImpl instance, +) => { + 'product_id': instance.productId, + 'product_variant_id': instance.productvariantId, + 'quantity': instance.quantity, + 'unit_price': instance.unitPrice, + 'notes': instance.notes, +}; diff --git a/lib/infrastructure/order/repositories/order_repository.dart b/lib/infrastructure/order/repositories/order_repository.dart index 1f112f9..f9b2ab1 100644 --- a/lib/infrastructure/order/repositories/order_repository.dart +++ b/lib/infrastructure/order/repositories/order_repository.dart @@ -105,4 +105,29 @@ class OrderRepository implements IOrderRepository { return left(const OrderFailure.unexpectedError()); } } + + @override + Future> addItemOrder({ + required String id, + required List request, + }) async { + try { + final result = await _dataProvider.addItemOrder( + id: id, + request: request + .map((e) => AddItemOrderRequestDto.fromDomain(e)) + .toList(), + ); + + if (result.hasError) { + return left(result.error!); + } + + final order = result.data!.toDomain(); + return right(order); + } catch (e) { + log('addItemOrderError', name: _logName, error: e); + return left(const OrderFailure.unexpectedError()); + } + } } diff --git a/lib/presentation/components/dialog/order/order_add_item_dialog.dart b/lib/presentation/components/dialog/order/order_add_item_dialog.dart new file mode 100644 index 0000000..7a6028f --- /dev/null +++ b/lib/presentation/components/dialog/order/order_add_item_dialog.dart @@ -0,0 +1,284 @@ +import 'package:dropdown_search/dropdown_search.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +import '../../../../application/checkout/checkout_form/checkout_form_bloc.dart'; +import '../../../../application/order/order_form/order_form_bloc.dart'; +import '../../../../application/order/order_loader/order_loader_bloc.dart'; +import '../../../../common/theme/theme.dart'; +import '../../../../domain/order/order.dart'; +import '../../button/button.dart'; +import '../../loader/loader_with_text.dart'; +import '../../spaces/space.dart'; +import '../dialog.dart'; + +class OrderAddItemDialog extends StatefulWidget { + final CheckoutFormState checkoutState; + const OrderAddItemDialog({super.key, required this.checkoutState}); + + @override + State createState() => _OrderAddItemDialogState(); +} + +class _OrderAddItemDialogState extends State { + Order? selectedOrder; + + @override + void initState() { + super.initState(); + context.read().add( + OrderLoaderEvent.fetched(status: 'pending', isRefresh: true), + ); + } + + @override + Widget build(BuildContext context) { + return CustomModalDialog( + title: 'Tambah Pesanan', + subtitle: 'Silahkan tambahkan pesanan ke pesanan yang sudah ada', + contentPadding: const EdgeInsets.symmetric( + horizontal: 16.0, + vertical: 24.0, + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Pilih Meja yang sudah dipesan', + style: AppStyle.lg.copyWith(fontWeight: FontWeight.w600), + ), + const SpaceHeight(8.0), + BlocBuilder( + builder: (context, state) { + if (state.isFetching) { + return Center(child: LoaderWithText()); + } + + final availableOrders = state.orders; + + if (selectedOrder == null && availableOrders.isNotEmpty) { + selectedOrder = availableOrders.first; + } + + if (availableOrders.isEmpty) { + return Container( + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + color: AppColor.warning.withOpacity(0.1), + borderRadius: BorderRadius.circular(16), + border: Border.all(color: AppColor.warning, width: 1), + ), + child: Text( + 'Tidak ada meja yang tersedia. Silakan pilih opsi lain.', + style: AppStyle.md.copyWith(color: AppColor.warning), + ), + ); + } + + return DropdownSearch( + items: state.orders, + selectedItem: selectedOrder, + + // Dropdown properties + dropdownDecoratorProps: DropDownDecoratorProps( + dropdownSearchDecoration: InputDecoration( + hintText: "Pilih Meja", + hintStyle: TextStyle( + color: Colors.grey.shade600, + fontSize: 14, + ), + prefixIcon: Icon( + Icons.category_outlined, + color: Colors.grey.shade500, + size: 20, + ), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(12), + borderSide: BorderSide( + color: Colors.grey.shade300, + width: 1.5, + ), + ), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(12), + borderSide: BorderSide( + color: Colors.grey.shade300, + width: 1.5, + ), + ), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(12), + borderSide: BorderSide( + color: Colors.blue.shade400, + width: 2, + ), + ), + filled: true, + fillColor: Colors.white, + contentPadding: const EdgeInsets.symmetric( + horizontal: 16, + vertical: 16, + ), + ), + ), + + // Popup properties + popupProps: PopupProps.menu( + showSearchBox: true, + searchFieldProps: TextFieldProps( + decoration: InputDecoration( + hintText: "Cari meja...", + prefixIcon: const Icon(Icons.search), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(8), + ), + contentPadding: const EdgeInsets.symmetric( + horizontal: 16, + vertical: 12, + ), + ), + ), + menuProps: MenuProps( + backgroundColor: Colors.white, + elevation: 8, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + ), + itemBuilder: (context, order, isSelected) { + return Container( + padding: const EdgeInsets.symmetric( + horizontal: 16, + vertical: 12, + ), + decoration: BoxDecoration( + color: isSelected + ? Colors.blue.shade50 + : Colors.transparent, + border: Border( + bottom: BorderSide( + color: Colors.grey.shade100, + width: 0.5, + ), + ), + ), + child: Row( + children: [ + Container( + width: 8, + height: 8, + decoration: BoxDecoration( + color: isSelected + ? Colors.blue.shade600 + : Colors.grey.shade400, + shape: BoxShape.circle, + ), + ), + const SizedBox(width: 12), + Expanded( + child: Text( + "${order.tableNumber} - ${order.metadata['customer_name']}", + style: TextStyle( + fontSize: 14, + fontWeight: isSelected + ? FontWeight.w600 + : FontWeight.w500, + color: isSelected + ? Colors.blue.shade700 + : Colors.black87, + ), + ), + ), + if (isSelected) + Icon( + Icons.check, + color: Colors.blue.shade600, + size: 18, + ), + ], + ), + ); + }, + emptyBuilder: (context, searchEntry) { + return Container( + padding: const EdgeInsets.all(20), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Icon( + Icons.search_off, + color: Colors.grey.shade400, + size: 48, + ), + const SizedBox(height: 12), + Text( + searchEntry.isEmpty + ? "Tidak ada meja tersedia" + : "Tidak ditemukan meja dengan '$searchEntry'", + style: TextStyle( + color: Colors.grey.shade600, + fontSize: 14, + ), + textAlign: TextAlign.center, + ), + ], + ), + ); + }, + ), + + // Item as string (for search functionality) + itemAsString: (Order order) => + "${order.tableNumber} - ${order.metadata['customer_name']}", + + // Comparison function + compareFn: (Order? item1, Order? item2) { + return item1?.id == item2?.id; + }, + + // On changed callback + onChanged: (Order? selectedOrder) { + if (selectedOrder != null) { + context.read().add( + CheckoutFormEvent.orderAddedItems(selectedOrder), + ); + setState(() { + this.selectedOrder = selectedOrder; + }); + } + }, + + // Validator (optional) + validator: (Order? value) { + if (value == null) { + return "Meja harus dipilih"; + } + return null; + }, + ); + }, + ), + SpaceHeight(16), + BlocBuilder( + builder: (context, state) { + return AppElevatedButton.filled( + isLoading: state.isAddingItemOrder, + onPressed: state.isAddingItemOrder + ? null + : () { + context.read().add( + OrderFormEvent.addItemOrder( + orderId: selectedOrder?.id ?? '', + items: widget.checkoutState.items, + ), + ); + }, + label: 'Simpan', + ); + }, + ), + ], + ), + ); + } +} diff --git a/lib/presentation/components/dialog/order/order_save_dialog.dart b/lib/presentation/components/dialog/order/order_save_dialog.dart index 6bb4694..80ca5ca 100644 --- a/lib/presentation/components/dialog/order/order_save_dialog.dart +++ b/lib/presentation/components/dialog/order/order_save_dialog.dart @@ -7,6 +7,7 @@ import '../../../../common/types/order_type.dart'; import '../../../../domain/table/table.dart'; import '../../spaces/space.dart'; import '../dialog.dart'; +import 'order_add_item_dialog.dart'; import 'order_pay_later_dialog.dart'; import 'order_save_confirm_dialog.dart'; @@ -60,7 +61,13 @@ class OrderSaveDialog extends StatelessWidget { icon: Icons.shopping_cart_checkout_outlined, title: 'Tambahkan Pesanan', subtitle: 'Tambah item ke daftar pesanan', - onTap: () {}, + onTap: () { + showDialog( + context: context, + builder: (context) => + OrderAddItemDialog(checkoutState: checkoutState), + ); + }, ), ], ), diff --git a/lib/presentation/pages/checkout/checkout_page.dart b/lib/presentation/pages/checkout/checkout_page.dart index 7cae704..a3e7522 100644 --- a/lib/presentation/pages/checkout/checkout_page.dart +++ b/lib/presentation/pages/checkout/checkout_page.dart @@ -61,6 +61,22 @@ class CheckoutPage extends StatelessWidget implements AutoRouteWrapper { }); }, ), + BlocListener( + listenWhen: (previous, current) => + previous.failureOrAddItemOrder != current.failureOrAddItemOrder, + listener: (context, state) { + state.failureOrAddItemOrder.fold(() {}, (either) { + either.fold( + (f) => AppFlushbar.showOrderFailureToast(context, f), + (order) { + if (context.mounted) { + context.router.replace(SuccessAddItemOrderRoute()); + } + }, + ); + }); + }, + ), ], child: SafeArea( child: Hero( diff --git a/lib/presentation/pages/order/pages/success_add_item_order/success_add_item_order_page.dart b/lib/presentation/pages/order/pages/success_add_item_order/success_add_item_order_page.dart new file mode 100644 index 0000000..ef44ace --- /dev/null +++ b/lib/presentation/pages/order/pages/success_add_item_order/success_add_item_order_page.dart @@ -0,0 +1,47 @@ +import 'package:auto_route/auto_route.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +import '../../../../../application/checkout/checkout_form/checkout_form_bloc.dart'; +import '../../../../../common/theme/theme.dart'; +import '../../../../components/spaces/space.dart'; +import 'widgets/success_add_item_order_left_panel.dart'; +import 'widgets/success_add_item_order_right_panel.dart'; + +@RoutePage() +class SuccessAddItemOrderPage extends StatelessWidget { + const SuccessAddItemOrderPage({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: AppColor.background, + body: SafeArea( + child: BlocBuilder( + builder: (context, checkoutState) { + return Padding( + padding: const EdgeInsets.all(24.0), + child: Row( + children: [ + Expanded( + flex: 35, + child: SuccessAddItemOrderLeftPanel( + checkoutState: checkoutState, + ), + ), + SpaceWidth(16), + Expanded( + flex: 65, + child: SuccessAddItemOrderRightPanel( + checkoutState: checkoutState, + ), + ), + ], + ), + ); + }, + ), + ), + ); + } +} diff --git a/lib/presentation/pages/order/pages/success_add_item_order/widgets/success_add_item_order_left_panel.dart b/lib/presentation/pages/order/pages/success_add_item_order/widgets/success_add_item_order_left_panel.dart new file mode 100644 index 0000000..06811c7 --- /dev/null +++ b/lib/presentation/pages/order/pages/success_add_item_order/widgets/success_add_item_order_left_panel.dart @@ -0,0 +1,267 @@ +import 'package:auto_route/auto_route.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +import '../../../../../../application/checkout/checkout_form/checkout_form_bloc.dart'; +import '../../../../../../common/extension/extension.dart'; +import '../../../../../../common/theme/theme.dart'; +import '../../../../../components/button/button.dart'; +import '../../../../../components/spaces/space.dart'; +import '../../../../../router/app_router.gr.dart'; + +class SuccessAddItemOrderLeftPanel extends StatelessWidget { + final CheckoutFormState checkoutState; + const SuccessAddItemOrderLeftPanel({super.key, required this.checkoutState}); + + @override + Widget build(BuildContext context) { + return Container( + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(24), + ), + child: Column( + children: [ + Expanded( + child: SingleChildScrollView( + child: Column( + children: [ + Container( + width: double.infinity, + padding: const EdgeInsets.all(32.0), + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topLeft, + end: Alignment.bottomRight, + colors: [ + AppColor.primary.withOpacity(0.1), + AppColor.primary.withOpacity(0.05), + ], + ), + borderRadius: const BorderRadius.vertical( + top: Radius.circular(24), + ), + ), + child: Column( + children: [ + Container( + padding: const EdgeInsets.all(20.0), + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topLeft, + end: Alignment.bottomRight, + colors: [ + AppColor.primary, + AppColor.primary.withOpacity(0.8), + ], + ), + shape: BoxShape.circle, + boxShadow: [ + BoxShadow( + color: AppColor.primary.withOpacity(0.3), + blurRadius: 20, + offset: const Offset(0, 10), + ), + ], + ), + child: const Icon( + Icons.check_rounded, + size: 48, + color: Colors.white, + ), + ), + SpaceHeight(16), + Text( + 'Pesanan Berhasil!', + style: AppStyle.h4.copyWith( + fontWeight: FontWeight.bold, + color: AppColor.primary, + ), + ), + SpaceHeight(12), + Text( + 'Pesanan telah diterima dan\nsedang diproses', + style: AppStyle.md.copyWith( + color: AppColor.primary, + fontWeight: FontWeight.w500, + ), + textAlign: TextAlign.center, + ), + ], + ), + ), + Padding( + padding: const EdgeInsets.all(24.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Informasi Pesanan', + style: AppStyle.lg.copyWith( + fontWeight: FontWeight.bold, + ), + ), + SpaceHeight(24), + _buildInfoRow( + icon: Icons.person, + label: 'Pemesan', + value: + checkoutState + .orderAdded + ?.metadata['customer_name'] ?? + "-", + ), + if (checkoutState.orderAdded?.payments.isNotEmpty ?? + false) ...[ + const SpaceHeight(12), + _buildInfoRow( + icon: Icons.wallet_outlined, + label: 'Metode Pembayaran', + value: + checkoutState + .orderAdded + ?.payments + .first + .paymentMethodName ?? + '-', + ), + ], + if (checkoutState.orderAdded != null && + checkoutState.orderAdded?.tableNumber != "") ...[ + const SpaceHeight(12), + _buildInfoRow( + icon: Icons.table_restaurant_outlined, + label: 'No. Meja', + value: checkoutState.orderAdded?.tableNumber ?? '-', + ), + ], + const SpaceHeight(12), + _buildInfoRow( + icon: Icons.access_time_rounded, + label: 'Waktu', + value: (DateTime.now()).toFormattedDateTime(), + ), + ], + ), + ), + ], + ), + ), + ), + _buildBottomSection(context), + ], + ), + ); + } + + Widget _buildBottomSection(BuildContext context) { + return Container( + width: double.infinity, + padding: const EdgeInsets.all(24.0), + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + colors: [Colors.grey.shade50, Colors.white], + ), + borderRadius: const BorderRadius.vertical(bottom: Radius.circular(24)), + ), + child: Column( + children: [ + // Action Buttons with Modern Design + Row( + children: [ + Expanded( + child: AppElevatedButton.outlined( + onPressed: () { + context.read().add( + CheckoutFormEvent.started([]), + ); + context.router.replaceAll([const MainRoute()]); + }, + label: "Kembali", + ), + ), + const SpaceWidth(16), + Expanded( + child: AppElevatedButton.filled( + onPressed: () { + // onPrintRecipt( + // context, + // order: widget.order, + // paymentMethod: widget.paymentMethod, + // nominalBayar: widget.paymentMethod == "Cash" + // ? widget.nominalBayar + // : widget.order.totalAmount ?? 0, + // kembalian: widget.nominalBayar - + // (widget.order.totalAmount ?? 0), + // productQuantity: widget.productQuantity, + // ); + // onPrint( + // context, + // productQuantity: widget.productQuantity, + // order: widget.order, + // ); + }, + label: 'Cetak Struk', + icon: Icon(Icons.print_rounded, color: AppColor.white), + ), + ), + ], + ), + ], + ), + ); + } + + Widget _buildInfoRow({ + required IconData icon, + required String label, + required String value, + Color? valueColor, + bool showBadge = false, + }) { + return Row( + children: [ + Icon(icon, size: 18, color: AppColor.primary), + const SizedBox(width: 12), + Expanded( + child: Text( + label, + style: AppStyle.md.copyWith(color: AppColor.textSecondary), + ), + ), + if (showBadge && valueColor != null) + Container( + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + decoration: BoxDecoration( + color: valueColor.withOpacity(0.1), + borderRadius: BorderRadius.circular(12), + ), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Icon(Icons.check_circle, size: 14, color: valueColor), + const SizedBox(width: 4), + Text( + value, + style: AppStyle.sm.copyWith( + fontWeight: FontWeight.bold, + color: valueColor, + ), + ), + ], + ), + ) + else + Text( + value, + style: AppStyle.md.copyWith( + fontWeight: FontWeight.bold, + color: valueColor ?? AppColor.primary, + ), + ), + ], + ); + } +} diff --git a/lib/presentation/pages/order/pages/success_add_item_order/widgets/success_add_item_order_right_panel.dart b/lib/presentation/pages/order/pages/success_add_item_order/widgets/success_add_item_order_right_panel.dart new file mode 100644 index 0000000..452c7fa --- /dev/null +++ b/lib/presentation/pages/order/pages/success_add_item_order/widgets/success_add_item_order_right_panel.dart @@ -0,0 +1,371 @@ +import 'package:flutter/material.dart'; + +import '../../../../../../application/checkout/checkout_form/checkout_form_bloc.dart'; +import '../../../../../../common/extension/extension.dart'; +import '../../../../../../common/theme/theme.dart'; +import '../../../../../components/spaces/space.dart'; + +class SuccessAddItemOrderRightPanel extends StatelessWidget { + final CheckoutFormState checkoutState; + const SuccessAddItemOrderRightPanel({super.key, required this.checkoutState}); + + @override + Widget build(BuildContext context) { + return Container( + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(24), + ), + child: Column( + children: [ + _header(), + Expanded( + child: ListView.separated( + padding: const EdgeInsets.all(24.0), + itemCount: checkoutState.items.length, + separatorBuilder: (context, index) => const SizedBox(height: 12), + itemBuilder: (context, index) { + return _buildProductCard(index); + }, + ), + ), + _buildSummaryFooter(), + ], + ), + ); + } + + Widget _buildSummaryFooter() { + return Container( + width: double.infinity, + padding: const EdgeInsets.all(24.0), + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + colors: [Colors.grey.shade50, Colors.white], + ), + borderRadius: const BorderRadius.vertical(bottom: Radius.circular(24)), + ), + child: Column( + children: [ + // Decorative Divider + Container( + height: 1, + margin: const EdgeInsets.only(bottom: 20), + decoration: BoxDecoration( + gradient: LinearGradient( + colors: [ + Colors.transparent, + AppColor.primary.withOpacity(0.3), + Colors.transparent, + ], + ), + ), + ), + + // Subtotal Row + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Row( + children: [ + Icon( + Icons.shopping_cart_outlined, + size: 16, + color: AppColor.textSecondary, + ), + const SizedBox(width: 8), + Text( + 'Subtotal (${checkoutState.items.length} items)', + style: AppStyle.md.copyWith( + color: AppColor.textSecondary, + fontWeight: FontWeight.w500, + ), + ), + ], + ), + Text( + (checkoutState.items.fold( + 0, + (previousValue, element) => + previousValue + + (element.product.price.toInt() + + (element.variant?.priceModifier.toInt() ?? 0)) * + element.quantity, + )).toString().currencyFormatRpV2, + style: AppStyle.md.copyWith(fontWeight: FontWeight.w600), + ), + ], + ), + + const SpaceHeight(16), + + // Total Payment Row with Enhanced Styling + Container( + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topLeft, + end: Alignment.bottomRight, + colors: [ + AppColor.primary.withOpacity(0.1), + AppColor.primary.withOpacity(0.05), + ], + ), + borderRadius: BorderRadius.circular(12), + border: Border.all( + color: AppColor.primary.withOpacity(0.2), + width: 1, + ), + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Row( + children: [ + Container( + padding: const EdgeInsets.all(6), + decoration: BoxDecoration( + color: AppColor.primary.withOpacity(0.2), + borderRadius: BorderRadius.circular(8), + ), + child: Icon( + Icons.payments_rounded, + size: 16, + color: AppColor.primary, + ), + ), + SpaceWidth(12), + Text( + 'Total Pembayaran', + style: AppStyle.lg.copyWith(fontWeight: FontWeight.bold), + ), + ], + ), + Container( + padding: const EdgeInsets.symmetric( + horizontal: 12, + vertical: 6, + ), + decoration: BoxDecoration( + gradient: LinearGradient( + colors: [ + AppColor.primary, + AppColor.primary.withOpacity(0.8), + ], + ), + borderRadius: BorderRadius.circular(8), + boxShadow: [ + BoxShadow( + color: AppColor.primary.withOpacity(0.3), + blurRadius: 4, + offset: const Offset(0, 2), + ), + ], + ), + child: Text( + (checkoutState.items.fold( + 0, + (previousValue, element) => + previousValue + + (element.product.price.toInt() + + (element.variant?.priceModifier.toInt() ?? + 0)) * + element.quantity, + )).toString().currencyFormatRpV2, + style: AppStyle.xl.copyWith( + fontWeight: FontWeight.bold, + color: Colors.white, + ), + ), + ), + ], + ), + ), + ], + ), + ); + } + + Widget _buildProductCard(int index) { + final item = checkoutState.items[index]; + + return Container( + padding: const EdgeInsets.all(16.0), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(16.0), + border: Border.all(color: AppColor.border, width: 1), + ), + child: Row( + children: [ + // Enhanced Product Image + Container( + width: 70, + height: 70, + decoration: BoxDecoration( + color: AppColor.primaryWithOpacity(0.1), + borderRadius: BorderRadius.circular(16.0), + ), + child: Icon( + Icons.restaurant_rounded, + color: AppColor.primary, + size: 28, + ), + ), + + const SpaceWidth(16), + + // Product Details + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + item.product.name, + style: AppStyle.lg.copyWith(fontWeight: FontWeight.bold), + maxLines: 2, + overflow: TextOverflow.ellipsis, + ), + const SpaceHeight(6), + Container( + padding: const EdgeInsets.symmetric( + horizontal: 8, + vertical: 4, + ), + decoration: BoxDecoration( + color: Colors.grey.shade100, + borderRadius: BorderRadius.circular(8), + ), + child: Text( + item.product.price.currencyFormatRpV2, + style: AppStyle.md.copyWith( + color: AppColor.textSecondary, + fontWeight: FontWeight.w500, + ), + ), + ), + ], + ), + ), + + const SpaceWidth(16), + + // Quantity and Total + Column( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Container( + padding: const EdgeInsets.symmetric( + horizontal: 12, + vertical: 8, + ), + decoration: BoxDecoration( + gradient: LinearGradient( + colors: [ + AppColor.primary, + AppColor.primary.withOpacity(0.8), + ], + ), + borderRadius: BorderRadius.circular(12), + ), + child: Text( + '${item.quantity}x', + style: AppStyle.md.copyWith( + fontWeight: FontWeight.bold, + color: Colors.white, + ), + ), + ), + const SpaceHeight(8), + Text( + ((item.product.price.toInt() + + (item.variant?.priceModifier.toInt() ?? 0)) * + item.quantity) + .toString() + .currencyFormatRpV2, + style: AppStyle.lg.copyWith( + fontWeight: FontWeight.bold, + color: AppColor.primary, + ), + ), + ], + ), + ], + ), + ); + } + + Container _header() { + return Container( + width: double.infinity, + padding: const EdgeInsets.all(24.0), + decoration: BoxDecoration( + border: Border(bottom: BorderSide(color: AppColor.border)), + borderRadius: const BorderRadius.vertical(top: Radius.circular(24)), + ), + child: Row( + children: [ + Container( + padding: const EdgeInsets.all(12.0), + decoration: BoxDecoration( + gradient: LinearGradient( + colors: [ + AppColor.primary.withOpacity(0.2), + AppColor.primary.withOpacity(0.1), + ], + ), + borderRadius: BorderRadius.circular(16.0), + ), + child: Icon( + Icons.receipt_long_rounded, + color: AppColor.primary, + size: 28, + ), + ), + SpaceWidth(16), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Detail Pesanan', + style: AppStyle.xxl.copyWith(fontWeight: FontWeight.bold), + ), + SpaceHeight(4), + Text( + 'Ringkasan item yang dipesan', + style: AppStyle.md.copyWith(color: Colors.grey.shade600), + ), + ], + ), + ), + Container( + padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10), + decoration: BoxDecoration( + gradient: LinearGradient( + colors: [AppColor.primary, AppColor.primary.withOpacity(0.8)], + ), + borderRadius: BorderRadius.circular(20), + boxShadow: [ + BoxShadow( + color: AppColor.primary.withOpacity(0.3), + blurRadius: 8, + offset: const Offset(0, 4), + ), + ], + ), + child: Text( + '${checkoutState.items.length} Items', + style: const TextStyle( + fontSize: 13, + color: Colors.white, + fontWeight: FontWeight.bold, + ), + ), + ), + ], + ), + ); + } +} diff --git a/lib/presentation/pages/order/pages/success_order/widgets/success_order_left_panel.dart b/lib/presentation/pages/order/pages/success_order/widgets/success_order_left_panel.dart index a3f01ba..7084501 100644 --- a/lib/presentation/pages/order/pages/success_order/widgets/success_order_left_panel.dart +++ b/lib/presentation/pages/order/pages/success_order/widgets/success_order_left_panel.dart @@ -69,7 +69,7 @@ class SuccessOrderLeftPanel extends StatelessWidget { color: Colors.white, ), ), - SpaceWidth(24), + SpaceHeight(16), Text( 'Pesanan Berhasil!', style: AppStyle.h4.copyWith( @@ -77,7 +77,7 @@ class SuccessOrderLeftPanel extends StatelessWidget { color: AppColor.primary, ), ), - SpaceWidth(12), + SpaceHeight(12), Text( 'Pesanan telah diterima dan\nsedang diproses', style: AppStyle.md.copyWith( diff --git a/lib/presentation/router/app_router.dart b/lib/presentation/router/app_router.dart index ea153ac..1450a2e 100644 --- a/lib/presentation/router/app_router.dart +++ b/lib/presentation/router/app_router.dart @@ -32,5 +32,6 @@ class AppRouter extends RootStackRouter { // Order AutoRoute(page: OrderRoute.page), AutoRoute(page: SuccessOrderRoute.page), + AutoRoute(page: SuccessAddItemOrderRoute.page), ]; } diff --git a/lib/presentation/router/app_router.gr.dart b/lib/presentation/router/app_router.gr.dart index 93a191c..4136ede 100644 --- a/lib/presentation/router/app_router.gr.dart +++ b/lib/presentation/router/app_router.gr.dart @@ -9,7 +9,7 @@ // coverage:ignore-file // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'package:apskel_pos_flutter_v2/domain/order/order.dart' as _i15; +import 'package:apskel_pos_flutter_v2/domain/order/order.dart' as _i16; import 'package:apskel_pos_flutter_v2/presentation/pages/auth/login/login_page.dart' as _i4; import 'package:apskel_pos_flutter_v2/presentation/pages/checkout/checkout_page.dart' @@ -25,91 +25,93 @@ import 'package:apskel_pos_flutter_v2/presentation/pages/main/pages/report/repor import 'package:apskel_pos_flutter_v2/presentation/pages/main/pages/setting/setting_page.dart' as _i8; import 'package:apskel_pos_flutter_v2/presentation/pages/main/pages/table/table_page.dart' - as _i12; + as _i13; import 'package:apskel_pos_flutter_v2/presentation/pages/order/order_page.dart' as _i6; -import 'package:apskel_pos_flutter_v2/presentation/pages/order/pages/success_order/success_order_page.dart' +import 'package:apskel_pos_flutter_v2/presentation/pages/order/pages/success_add_item_order/success_add_item_order_page.dart' as _i10; +import 'package:apskel_pos_flutter_v2/presentation/pages/order/pages/success_order/success_order_page.dart' + as _i11; import 'package:apskel_pos_flutter_v2/presentation/pages/splash/splash_page.dart' as _i9; import 'package:apskel_pos_flutter_v2/presentation/pages/sync/sync_page.dart' - as _i11; -import 'package:auto_route/auto_route.dart' as _i13; -import 'package:flutter/material.dart' as _i14; + as _i12; +import 'package:auto_route/auto_route.dart' as _i14; +import 'package:flutter/material.dart' as _i15; /// generated route for /// [_i1.CheckoutPage] -class CheckoutRoute extends _i13.PageRouteInfo { - const CheckoutRoute({List<_i13.PageRouteInfo>? children}) +class CheckoutRoute extends _i14.PageRouteInfo { + const CheckoutRoute({List<_i14.PageRouteInfo>? children}) : super(CheckoutRoute.name, initialChildren: children); static const String name = 'CheckoutRoute'; - static _i13.PageInfo page = _i13.PageInfo( + static _i14.PageInfo page = _i14.PageInfo( name, builder: (data) { - return _i13.WrappedRoute(child: const _i1.CheckoutPage()); + return _i14.WrappedRoute(child: const _i1.CheckoutPage()); }, ); } /// generated route for /// [_i2.CustomerPage] -class CustomerRoute extends _i13.PageRouteInfo { - const CustomerRoute({List<_i13.PageRouteInfo>? children}) +class CustomerRoute extends _i14.PageRouteInfo { + const CustomerRoute({List<_i14.PageRouteInfo>? children}) : super(CustomerRoute.name, initialChildren: children); static const String name = 'CustomerRoute'; - static _i13.PageInfo page = _i13.PageInfo( + static _i14.PageInfo page = _i14.PageInfo( name, builder: (data) { - return _i13.WrappedRoute(child: const _i2.CustomerPage()); + return _i14.WrappedRoute(child: const _i2.CustomerPage()); }, ); } /// generated route for /// [_i3.HomePage] -class HomeRoute extends _i13.PageRouteInfo { - const HomeRoute({List<_i13.PageRouteInfo>? children}) +class HomeRoute extends _i14.PageRouteInfo { + const HomeRoute({List<_i14.PageRouteInfo>? children}) : super(HomeRoute.name, initialChildren: children); static const String name = 'HomeRoute'; - static _i13.PageInfo page = _i13.PageInfo( + static _i14.PageInfo page = _i14.PageInfo( name, builder: (data) { - return _i13.WrappedRoute(child: const _i3.HomePage()); + return _i14.WrappedRoute(child: const _i3.HomePage()); }, ); } /// generated route for /// [_i4.LoginPage] -class LoginRoute extends _i13.PageRouteInfo { - const LoginRoute({List<_i13.PageRouteInfo>? children}) +class LoginRoute extends _i14.PageRouteInfo { + const LoginRoute({List<_i14.PageRouteInfo>? children}) : super(LoginRoute.name, initialChildren: children); static const String name = 'LoginRoute'; - static _i13.PageInfo page = _i13.PageInfo( + static _i14.PageInfo page = _i14.PageInfo( name, builder: (data) { - return _i13.WrappedRoute(child: const _i4.LoginPage()); + return _i14.WrappedRoute(child: const _i4.LoginPage()); }, ); } /// generated route for /// [_i5.MainPage] -class MainRoute extends _i13.PageRouteInfo { - const MainRoute({List<_i13.PageRouteInfo>? children}) +class MainRoute extends _i14.PageRouteInfo { + const MainRoute({List<_i14.PageRouteInfo>? children}) : super(MainRoute.name, initialChildren: children); static const String name = 'MainRoute'; - static _i13.PageInfo page = _i13.PageInfo( + static _i14.PageInfo page = _i14.PageInfo( name, builder: (data) { return const _i5.MainPage(); @@ -119,11 +121,11 @@ class MainRoute extends _i13.PageRouteInfo { /// generated route for /// [_i6.OrderPage] -class OrderRoute extends _i13.PageRouteInfo { +class OrderRoute extends _i14.PageRouteInfo { OrderRoute({ - _i14.Key? key, + _i15.Key? key, required String status, - List<_i13.PageRouteInfo>? children, + List<_i14.PageRouteInfo>? children, }) : super( OrderRoute.name, args: OrderRouteArgs(key: key, status: status), @@ -132,11 +134,11 @@ class OrderRoute extends _i13.PageRouteInfo { static const String name = 'OrderRoute'; - static _i13.PageInfo page = _i13.PageInfo( + static _i14.PageInfo page = _i14.PageInfo( name, builder: (data) { final args = data.argsAs(); - return _i13.WrappedRoute( + return _i14.WrappedRoute( child: _i6.OrderPage(key: args.key, status: args.status), ); }, @@ -146,7 +148,7 @@ class OrderRoute extends _i13.PageRouteInfo { class OrderRouteArgs { const OrderRouteArgs({this.key, required this.status}); - final _i14.Key? key; + final _i15.Key? key; final String status; @@ -158,13 +160,13 @@ class OrderRouteArgs { /// generated route for /// [_i7.ReportPage] -class ReportRoute extends _i13.PageRouteInfo { - const ReportRoute({List<_i13.PageRouteInfo>? children}) +class ReportRoute extends _i14.PageRouteInfo { + const ReportRoute({List<_i14.PageRouteInfo>? children}) : super(ReportRoute.name, initialChildren: children); static const String name = 'ReportRoute'; - static _i13.PageInfo page = _i13.PageInfo( + static _i14.PageInfo page = _i14.PageInfo( name, builder: (data) { return const _i7.ReportPage(); @@ -174,13 +176,13 @@ class ReportRoute extends _i13.PageRouteInfo { /// generated route for /// [_i8.SettingPage] -class SettingRoute extends _i13.PageRouteInfo { - const SettingRoute({List<_i13.PageRouteInfo>? children}) +class SettingRoute extends _i14.PageRouteInfo { + const SettingRoute({List<_i14.PageRouteInfo>? children}) : super(SettingRoute.name, initialChildren: children); static const String name = 'SettingRoute'; - static _i13.PageInfo page = _i13.PageInfo( + static _i14.PageInfo page = _i14.PageInfo( name, builder: (data) { return const _i8.SettingPage(); @@ -190,13 +192,13 @@ class SettingRoute extends _i13.PageRouteInfo { /// generated route for /// [_i9.SplashPage] -class SplashRoute extends _i13.PageRouteInfo { - const SplashRoute({List<_i13.PageRouteInfo>? children}) +class SplashRoute extends _i14.PageRouteInfo { + const SplashRoute({List<_i14.PageRouteInfo>? children}) : super(SplashRoute.name, initialChildren: children); static const String name = 'SplashRoute'; - static _i13.PageInfo page = _i13.PageInfo( + static _i14.PageInfo page = _i14.PageInfo( name, builder: (data) { return const _i9.SplashPage(); @@ -205,12 +207,28 @@ class SplashRoute extends _i13.PageRouteInfo { } /// generated route for -/// [_i10.SuccessOrderPage] -class SuccessOrderRoute extends _i13.PageRouteInfo { +/// [_i10.SuccessAddItemOrderPage] +class SuccessAddItemOrderRoute extends _i14.PageRouteInfo { + const SuccessAddItemOrderRoute({List<_i14.PageRouteInfo>? children}) + : super(SuccessAddItemOrderRoute.name, initialChildren: children); + + static const String name = 'SuccessAddItemOrderRoute'; + + static _i14.PageInfo page = _i14.PageInfo( + name, + builder: (data) { + return const _i10.SuccessAddItemOrderPage(); + }, + ); +} + +/// generated route for +/// [_i11.SuccessOrderPage] +class SuccessOrderRoute extends _i14.PageRouteInfo { SuccessOrderRoute({ - _i14.Key? key, - required _i15.Order order, - List<_i13.PageRouteInfo>? children, + _i15.Key? key, + required _i16.Order order, + List<_i14.PageRouteInfo>? children, }) : super( SuccessOrderRoute.name, args: SuccessOrderRouteArgs(key: key, order: order), @@ -219,12 +237,12 @@ class SuccessOrderRoute extends _i13.PageRouteInfo { static const String name = 'SuccessOrderRoute'; - static _i13.PageInfo page = _i13.PageInfo( + static _i14.PageInfo page = _i14.PageInfo( name, builder: (data) { final args = data.argsAs(); - return _i13.WrappedRoute( - child: _i10.SuccessOrderPage(key: args.key, order: args.order), + return _i14.WrappedRoute( + child: _i11.SuccessOrderPage(key: args.key, order: args.order), ); }, ); @@ -233,9 +251,9 @@ class SuccessOrderRoute extends _i13.PageRouteInfo { class SuccessOrderRouteArgs { const SuccessOrderRouteArgs({this.key, required this.order}); - final _i14.Key? key; + final _i15.Key? key; - final _i15.Order order; + final _i16.Order order; @override String toString() { @@ -244,33 +262,33 @@ class SuccessOrderRouteArgs { } /// generated route for -/// [_i11.SyncPage] -class SyncRoute extends _i13.PageRouteInfo { - const SyncRoute({List<_i13.PageRouteInfo>? children}) +/// [_i12.SyncPage] +class SyncRoute extends _i14.PageRouteInfo { + const SyncRoute({List<_i14.PageRouteInfo>? children}) : super(SyncRoute.name, initialChildren: children); static const String name = 'SyncRoute'; - static _i13.PageInfo page = _i13.PageInfo( + static _i14.PageInfo page = _i14.PageInfo( name, builder: (data) { - return _i13.WrappedRoute(child: const _i11.SyncPage()); + return _i14.WrappedRoute(child: const _i12.SyncPage()); }, ); } /// generated route for -/// [_i12.TablePage] -class TableRoute extends _i13.PageRouteInfo { - const TableRoute({List<_i13.PageRouteInfo>? children}) +/// [_i13.TablePage] +class TableRoute extends _i14.PageRouteInfo { + const TableRoute({List<_i14.PageRouteInfo>? children}) : super(TableRoute.name, initialChildren: children); static const String name = 'TableRoute'; - static _i13.PageInfo page = _i13.PageInfo( + static _i14.PageInfo page = _i14.PageInfo( name, builder: (data) { - return _i13.WrappedRoute(child: const _i12.TablePage()); + return _i14.WrappedRoute(child: const _i13.TablePage()); }, ); }