From 6eb26efa0c7a615e7714c5541dc18c1a98e9a422 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Fri, 20 Dec 2024 10:53:34 +0700 Subject: [PATCH] Make cash view modal presentation from totals --- .../POS/Presentation/PointOfSaleCollectCashView.swift | 6 ++++-- .../POS/Presentation/PointOfSaleDashboardView.swift | 11 +++-------- WooCommerce/Classes/POS/Presentation/TotalsView.swift | 7 ++++++- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/WooCommerce/Classes/POS/Presentation/PointOfSaleCollectCashView.swift b/WooCommerce/Classes/POS/Presentation/PointOfSaleCollectCashView.swift index 53b5e63b09a..b37f066b7fe 100644 --- a/WooCommerce/Classes/POS/Presentation/PointOfSaleCollectCashView.swift +++ b/WooCommerce/Classes/POS/Presentation/PointOfSaleCollectCashView.swift @@ -7,6 +7,8 @@ struct PointOfSaleCollectCashView: View { @State private var isLoading: Bool = false @State private var errorMessage: String? + @Binding var isVisible: Bool + private var orderTotal: String? { if case .loaded(let totals) = posModel.orderState { return totals.orderTotal @@ -18,7 +20,7 @@ struct PointOfSaleCollectCashView: View { VStack(alignment: .center, spacing: 20) { HStack { Button(action: { - posModel.cancelCashPayment() + isVisible = false }, label: { VStack { HStack { @@ -124,6 +126,6 @@ private extension PointOfSaleCollectCashView { itemsController: PointOfSalePreviewItemsController(), cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController()) - PointOfSaleCollectCashView() + PointOfSaleCollectCashView(isVisible: .constant(true)) .environmentObject(posModel) } diff --git a/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift b/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift index 65aa6bcc2c1..607806f46e0 100644 --- a/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift +++ b/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift @@ -87,14 +87,9 @@ struct PointOfSaleDashboardView: View { } if posModel.orderStage == .finalizing { - switch posModel.paymentState { - case .acceptingCash: - PointOfSaleCollectCashView() - default: - TotalsView() - .accessibilitySortPriority(2) - .transition(.move(edge: .trailing)) - } + TotalsView() + .accessibilitySortPriority(2) + .transition(.move(edge: .trailing)) } } .animation(.default, value: posModel.orderStage) diff --git a/WooCommerce/Classes/POS/Presentation/TotalsView.swift b/WooCommerce/Classes/POS/Presentation/TotalsView.swift index 9c55ecda203..499312be44b 100644 --- a/WooCommerce/Classes/POS/Presentation/TotalsView.swift +++ b/WooCommerce/Classes/POS/Presentation/TotalsView.swift @@ -24,6 +24,8 @@ struct TotalsView: View { @Environment(\.dynamicTypeSize) var dynamicTypeSize @Environment(\.colorScheme) var colorScheme + @State private var shouldShowCollectCashPayment: Bool = false + var body: some View { HStack { switch posModel.orderState { @@ -57,7 +59,7 @@ struct TotalsView: View { .layoutPriority(2) } Button(action: { - posModel.collectCashPayment() + shouldShowCollectCashPayment = true }, label: { Text(Localization.cashPaymentButtonTitle) .font(POSFontStyle.posBodyEmphasized) @@ -86,6 +88,9 @@ struct TotalsView: View { } .onChange(of: shouldShowTotalsFields, perform: hideTotalsFieldsWithDelay) .geometryGroupIfSupported() + .fullScreenCover(isPresented: $shouldShowCollectCashPayment) { + PointOfSaleCollectCashView(isVisible: $shouldShowCollectCashPayment) + } } private var backgroundColor: Color {