diff --git a/Modules/Sources/PointOfSale/Models/PointOfSaleAggregateModel.swift b/Modules/Sources/PointOfSale/Models/PointOfSaleAggregateModel.swift index 85f96bd19fc..05f9b19f753 100644 --- a/Modules/Sources/PointOfSale/Models/PointOfSaleAggregateModel.swift +++ b/Modules/Sources/PointOfSale/Models/PointOfSaleAggregateModel.swift @@ -43,7 +43,7 @@ protocol PointOfSaleAggregateModelProtocol { let popularPurchasableItemsController: PointOfSaleItemsControllerProtocol let couponsController: PointOfSaleCouponsControllerProtocol let couponsSearchController: PointOfSaleSearchingItemsControllerProtocol - let settingsController: PointOfSaleSettingsControllerProtocol + let settingsController: POSSettingsControllerProtocol private let cardPresentPaymentService: CardPresentPaymentFacade private let orderController: PointOfSaleOrderControllerProtocol @@ -79,7 +79,7 @@ protocol PointOfSaleAggregateModelProtocol { couponsSearchController: PointOfSaleSearchingItemsControllerProtocol, cardPresentPaymentService: CardPresentPaymentFacade, orderController: PointOfSaleOrderControllerProtocol, - settingsController: PointOfSaleSettingsControllerProtocol, + settingsController: POSSettingsControllerProtocol, analytics: POSAnalyticsProviding, collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalyticsTracking, searchHistoryService: POSSearchHistoryProviding, diff --git a/Modules/Sources/PointOfSale/Models/PointOfSaleSettingsController.swift b/Modules/Sources/PointOfSale/Models/PointOfSaleSettingsController.swift index 05e6bc2ed2b..808bbfb1ed6 100644 --- a/Modules/Sources/PointOfSale/Models/PointOfSaleSettingsController.swift +++ b/Modules/Sources/PointOfSale/Models/PointOfSaleSettingsController.swift @@ -11,14 +11,14 @@ import protocol Storage.GRDBManagerProtocol import protocol Yosemite.POSCatalogSyncCoordinatorProtocol import class Yosemite.POSCatalogSettingsService -protocol PointOfSaleSettingsControllerProtocol { +protocol POSSettingsControllerProtocol { var connectedCardReader: CardPresentPaymentCardReader? { get } var storeViewModel: POSSettingsStoreViewModel { get } var localCatalogViewModel: POSSettingsLocalCatalogViewModel? { get } var isLocalCatalogEligible: Bool { get } } -@Observable final class PointOfSaleSettingsController: PointOfSaleSettingsControllerProtocol { +@Observable final class PointOfSaleSettingsController: POSSettingsControllerProtocol { private(set) var connectedCardReader: CardPresentPaymentCardReader? private var cancellables: AnyCancellable? @@ -72,7 +72,7 @@ protocol PointOfSaleSettingsControllerProtocol { } #if DEBUG -final class PointOfSaleSettingsPreviewController: PointOfSaleSettingsControllerProtocol { +final class POSSettingsPreviewController: POSSettingsControllerProtocol { var connectedCardReader: CardPresentPaymentCardReader? = CardPresentPaymentCardReader( name: "WisePad 3", batteryLevel: 0.75 diff --git a/Modules/Sources/PointOfSale/Presentation/Barcode Scanner Setup/PointOfSaleBarcodeScannerSetup.swift b/Modules/Sources/PointOfSale/Presentation/Barcode Scanner Setup/POSBarcodeScannerSetup.swift similarity index 97% rename from Modules/Sources/PointOfSale/Presentation/Barcode Scanner Setup/PointOfSaleBarcodeScannerSetup.swift rename to Modules/Sources/PointOfSale/Presentation/Barcode Scanner Setup/POSBarcodeScannerSetup.swift index ea4f942998c..6b80b6db257 100644 --- a/Modules/Sources/PointOfSale/Presentation/Barcode Scanner Setup/PointOfSaleBarcodeScannerSetup.swift +++ b/Modules/Sources/PointOfSale/Presentation/Barcode Scanner Setup/POSBarcodeScannerSetup.swift @@ -1,6 +1,6 @@ import SwiftUI -struct PointOfSaleBarcodeScannerSetup: View { +struct POSBarcodeScannerSetup: View { @Binding var isPresented: Bool @State private var flowManager: PointOfSaleBarcodeScannerSetupFlowManager @Environment(\.posModalParentSize) var parentSize @@ -91,7 +91,7 @@ private enum Constants { } // MARK: - Private Localization Extension -private extension PointOfSaleBarcodeScannerSetup { +private extension POSBarcodeScannerSetup { enum Localization { static let starBSH20BTitle = NSLocalizedString( "pos.barcodeScannerSetup.starBSH20B.title", @@ -120,7 +120,7 @@ private extension PointOfSaleBarcodeScannerSetup { #if DEBUG #Preview { - PointOfSaleBarcodeScannerSetup(isPresented: .constant(true), analytics: EmptyPOSAnalytics()) + POSBarcodeScannerSetup(isPresented: .constant(true), analytics: EmptyPOSAnalytics()) } #endif diff --git a/Modules/Sources/PointOfSale/Presentation/CartView.swift b/Modules/Sources/PointOfSale/Presentation/CartView.swift index 60fe0e30e7c..1c594cad998 100644 --- a/Modules/Sources/PointOfSale/Presentation/CartView.swift +++ b/Modules/Sources/PointOfSale/Presentation/CartView.swift @@ -69,7 +69,7 @@ struct CartView: View { } } .posModal(isPresented: $showBarcodeScanningModal) { - PointOfSaleBarcodeScannerSetup(isPresented: $showBarcodeScanningModal, analytics: analytics) + POSBarcodeScannerSetup(isPresented: $showBarcodeScanningModal, analytics: analytics) } .animation(Constants.cartAnimation, value: posModel.cart.isEmpty) .frame(maxWidth: .infinity) diff --git a/Modules/Sources/PointOfSale/Presentation/POSFloatingControlView.swift b/Modules/Sources/PointOfSale/Presentation/POSFloatingControlView.swift index e7c9686304e..7d78b023608 100644 --- a/Modules/Sources/PointOfSale/Presentation/POSFloatingControlView.swift +++ b/Modules/Sources/PointOfSale/Presentation/POSFloatingControlView.swift @@ -55,7 +55,7 @@ struct POSFloatingControlView: View { SimpleProductsOnlyInformation(isPresented: $showProductRestrictionsModal) } .posModal(isPresented: $showBarcodeScanningModal) { - PointOfSaleBarcodeScannerSetup(isPresented: $showBarcodeScanningModal, analytics: analytics) + POSBarcodeScannerSetup(isPresented: $showBarcodeScanningModal, analytics: analytics) } .posFullScreenCover(isPresented: $showOrders) { POSOrdersView(isPresented: $showOrders) diff --git a/Modules/Sources/PointOfSale/Presentation/PointOfSaleEntryPointView.swift b/Modules/Sources/PointOfSale/Presentation/PointOfSaleEntryPointView.swift index f7d96f7894f..1bfb6354870 100644 --- a/Modules/Sources/PointOfSale/Presentation/PointOfSaleEntryPointView.swift +++ b/Modules/Sources/PointOfSale/Presentation/PointOfSaleEntryPointView.swift @@ -33,7 +33,7 @@ public struct PointOfSaleEntryPointView: View { private let couponsSearchController: PointOfSaleSearchingItemsControllerProtocol private let cardPresentPaymentService: CardPresentPaymentFacade private let orderController: PointOfSaleOrderControllerProtocol - private let settingsController: PointOfSaleSettingsControllerProtocol + private let settingsController: POSSettingsControllerProtocol private let collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalyticsTracking private let searchHistoryService: POSSearchHistoryProviding private let popularPurchasableItemsController: PointOfSaleItemsControllerProtocol diff --git a/Modules/Sources/PointOfSale/Presentation/Reusable Views/POSModalViewModifier.swift b/Modules/Sources/PointOfSale/Presentation/Reusable Views/POSModalViewModifier.swift index efb55522e28..fdf6ed51d82 100644 --- a/Modules/Sources/PointOfSale/Presentation/Reusable Views/POSModalViewModifier.swift +++ b/Modules/Sources/PointOfSale/Presentation/Reusable Views/POSModalViewModifier.swift @@ -251,7 +251,7 @@ extension EnvironmentValues { } } .posModal(isPresented: $showModal) { - PointOfSaleBarcodeScannerSetup(isPresented: $showModal, analytics: EmptyPOSAnalytics()) + POSBarcodeScannerSetup(isPresented: $showModal, analytics: EmptyPOSAnalytics()) } .posRootModal() .environmentObject(modalManager) diff --git a/Modules/Sources/PointOfSale/Presentation/Settings/PointOfSaleSettingsHardwareDetailView.swift b/Modules/Sources/PointOfSale/Presentation/Settings/POSSettingsHardwareDetailView.swift similarity index 94% rename from Modules/Sources/PointOfSale/Presentation/Settings/PointOfSaleSettingsHardwareDetailView.swift rename to Modules/Sources/PointOfSale/Presentation/Settings/POSSettingsHardwareDetailView.swift index 21ce9657cc6..0ae42ddcff4 100644 --- a/Modules/Sources/PointOfSale/Presentation/Settings/PointOfSaleSettingsHardwareDetailView.swift +++ b/Modules/Sources/PointOfSale/Presentation/Settings/POSSettingsHardwareDetailView.swift @@ -1,13 +1,13 @@ import SwiftUI import struct WooFoundation.SafariView -struct PointOfSaleSettingsHardwareDetailView: View { +struct POSSettingsHardwareDetailView: View { @Environment(PointOfSaleAggregateModel.self) private var posModel @Environment(\.posFeatureFlags) private var featureFlags @Environment(\.dynamicTypeSize) private var dynamicTypeSize @Environment(\.posAnalytics) private var analytics - let settingsController: PointOfSaleSettingsControllerProtocol + let settingsController: POSSettingsControllerProtocol @State private var navigationPath: [NavigationDestination] = [] @State private var showBarcodeScanningSetupModal: Bool = false @@ -36,6 +36,7 @@ struct PointOfSaleSettingsHardwareDetailView: View { } var body: some View { + @Bindable var posModel = posModel NavigationStack(path: $navigationPath) { POSPageHeaderView(title: Localization.hardwareTitle) .foregroundColor(.posSurface) @@ -81,25 +82,25 @@ struct PointOfSaleSettingsHardwareDetailView: View { scannersView } } + .posModal(item: $posModel.cardPresentPaymentAlertViewModel, onDismiss: { + posModel.cardPresentPaymentAlertViewModel?.onDismiss?() + }, content: { alertType in + PointOfSaleCardPresentPaymentAlert(alertType: alertType) + .posInteractiveDismissDisabled(alertType.isDismissDisabled) + }) .posModal(isPresented: $showBarcodeScanningSetupModal) { - PointOfSaleBarcodeScannerSetup(isPresented: $showBarcodeScanningSetupModal, analytics: analytics) + POSBarcodeScannerSetup(isPresented: $showBarcodeScanningSetupModal, analytics: analytics) } .posFullScreenCover(isPresented: $showBarcodeScanningDocumentationModal) { SafariView(url: POSConstants.URLs.pointOfSaleBarcodeScannerDocumentation.asURL()) } } } +} - private func handleScannerDestination(_ destination: ScannerDestination) { - switch destination { - case .setup: - showBarcodeScanningSetupModal = true - case .documentation: - showBarcodeScanningDocumentationModal = true - } - } - - private var legacyCardReadersView: some View { +// MARK: - Views +private extension POSSettingsHardwareDetailView { + var legacyCardReadersView: some View { VStack(spacing: POSSpacing.none) { POSPageHeaderView( title: Localization.cardReadersTitle, @@ -168,7 +169,7 @@ struct PointOfSaleSettingsHardwareDetailView: View { } } - private var cardReadersView: some View { + var cardReadersView: some View { VStack(spacing: POSSpacing.none) { POSPageHeaderView( title: Localization.cardReadersTitle, @@ -224,7 +225,7 @@ struct PointOfSaleSettingsHardwareDetailView: View { } } - private var scannersView: some View { + var scannersView: some View { VStack(spacing: POSSpacing.none) { POSPageHeaderView( title: Localization.scannersTitle, @@ -268,7 +269,7 @@ struct PointOfSaleSettingsHardwareDetailView: View { } // MARK: - Navigation -private extension PointOfSaleSettingsHardwareDetailView { +private extension POSSettingsHardwareDetailView { enum HardwareDestination: Identifiable, CaseIterable { case cardReaders case scanners @@ -340,9 +341,19 @@ private extension PointOfSaleSettingsHardwareDetailView { } } } + + func handleScannerDestination(_ destination: ScannerDestination) { + switch destination { + case .setup: + showBarcodeScanningSetupModal = true + case .documentation: + showBarcodeScanningDocumentationModal = true + } + } } -private extension PointOfSaleSettingsHardwareDetailView { +// MARK: - Constants +private extension POSSettingsHardwareDetailView { enum Localization { static let readerModelTitle = NSLocalizedString( "pointOfSaleSettingsHardwareDetailView.readerModelTitle", @@ -460,6 +471,6 @@ private extension PointOfSaleSettingsHardwareDetailView { #if DEBUG #Preview { - PointOfSaleSettingsHardwareDetailView(settingsController: PointOfSaleSettingsPreviewController()) + POSSettingsHardwareDetailView(settingsController: POSSettingsPreviewController()) } #endif diff --git a/Modules/Sources/PointOfSale/Presentation/Settings/PointOfSaleSettingsStoreDetailView.swift b/Modules/Sources/PointOfSale/Presentation/Settings/PointOfSaleSettingsStoreDetailView.swift index 2917b596fe5..1cfd1b0860e 100644 --- a/Modules/Sources/PointOfSale/Presentation/Settings/PointOfSaleSettingsStoreDetailView.swift +++ b/Modules/Sources/PointOfSale/Presentation/Settings/PointOfSaleSettingsStoreDetailView.swift @@ -198,7 +198,7 @@ private extension PointOfSaleSettingsStoreDetailView { #if DEBUG #Preview { - let controller = PointOfSaleSettingsPreviewController() + let controller = POSSettingsPreviewController() PointOfSaleSettingsStoreDetailView(viewModel: controller.storeViewModel) } #endif diff --git a/Modules/Sources/PointOfSale/Presentation/Settings/PointOfSaleSettingsView.swift b/Modules/Sources/PointOfSale/Presentation/Settings/PointOfSaleSettingsView.swift index 1458dcd0791..1ed53e3a9e3 100644 --- a/Modules/Sources/PointOfSale/Presentation/Settings/PointOfSaleSettingsView.swift +++ b/Modules/Sources/PointOfSale/Presentation/Settings/PointOfSaleSettingsView.swift @@ -5,7 +5,7 @@ struct PointOfSaleSettingsView: View { @Environment(\.posAnalytics) private var analytics @State private var selection: SidebarNavigation? = .store - let settingsController: PointOfSaleSettingsControllerProtocol + let settingsController: POSSettingsControllerProtocol var body: some View { GeometryReader { geometry in @@ -86,7 +86,7 @@ extension PointOfSaleSettingsView { case .store: PointOfSaleSettingsStoreDetailView(viewModel: settingsController.storeViewModel) case .hardware: - PointOfSaleSettingsHardwareDetailView(settingsController: settingsController) + POSSettingsHardwareDetailView(settingsController: settingsController) case .localCatalog: if let viewModel = settingsController.localCatalogViewModel { POSSettingsLocalCatalogDetailView(viewModel: viewModel) @@ -250,6 +250,6 @@ extension PointOfSaleSettingsView { #if DEBUG #Preview { - PointOfSaleSettingsView(settingsController: PointOfSaleSettingsPreviewController()) + PointOfSaleSettingsView(settingsController: POSSettingsPreviewController()) } #endif diff --git a/Modules/Sources/PointOfSale/Utils/PreviewHelpers.swift b/Modules/Sources/PointOfSale/Utils/PreviewHelpers.swift index 88fbe1c4ff2..2fbf4b9e3b8 100644 --- a/Modules/Sources/PointOfSale/Utils/PreviewHelpers.swift +++ b/Modules/Sources/PointOfSale/Utils/PreviewHelpers.swift @@ -208,7 +208,7 @@ struct POSPreviewHelpers { couponsSearchController: PointOfSaleCouponsControllerProtocol = PointOfSalePreviewCouponsController(), cardPresentPaymentService: CardPresentPaymentFacade = CardPresentPaymentPreviewService(), orderController: PointOfSaleOrderControllerProtocol = PointOfSalePreviewOrderController(), - settingsController: PointOfSaleSettingsControllerProtocol = PointOfSaleSettingsPreviewController(), + settingsController: POSSettingsControllerProtocol = POSSettingsPreviewController(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalyticsTracking = POSCollectOrderPaymentPreviewAnalytics(), searchHistoryService: POSSearchHistoryProviding = PointOfSalePreviewHistoryService(), popularItemsController: PointOfSaleItemsControllerProtocol = PointOfSalePreviewItemsController(), diff --git a/Modules/Tests/PointOfSaleTests/Controllers/PointOfSaleSettingsControllerTests.swift b/Modules/Tests/PointOfSaleTests/Controllers/POSSettingsControllerTests.swift similarity index 96% rename from Modules/Tests/PointOfSaleTests/Controllers/PointOfSaleSettingsControllerTests.swift rename to Modules/Tests/PointOfSaleTests/Controllers/POSSettingsControllerTests.swift index 152cfbc24e9..1de2f9187c6 100644 --- a/Modules/Tests/PointOfSaleTests/Controllers/PointOfSaleSettingsControllerTests.swift +++ b/Modules/Tests/PointOfSaleTests/Controllers/POSSettingsControllerTests.swift @@ -5,7 +5,7 @@ import Foundation import Storage @MainActor -struct PointOfSaleSettingsControllerTests { +struct POSSettingsControllerTests { private let mockSettingsService = MockPointOfSaleSettingsService() private let mockCardPresentPaymentService = MockCardPresentPaymentService() private let mockPluginService = MockPluginsService() @@ -75,7 +75,7 @@ private final class MockPointOfSaleSettingsService: PointOfSaleSettingsServicePr } } -final class MockPointOfSaleSettingsController: PointOfSaleSettingsControllerProtocol { +final class MockPOSSettingsController: POSSettingsControllerProtocol { var connectedCardReader: CardPresentPaymentCardReader? = nil var storeViewModel: POSSettingsStoreViewModel = POSSettingsStoreViewModel(siteID: 123, settingsService: MockPointOfSaleSettingsService(), diff --git a/Modules/Tests/PointOfSaleTests/Models/PointOfSaleAggregateModelTests.swift b/Modules/Tests/PointOfSaleTests/Models/PointOfSaleAggregateModelTests.swift index ed179e65638..e22038b4106 100644 --- a/Modules/Tests/PointOfSaleTests/Models/PointOfSaleAggregateModelTests.swift +++ b/Modules/Tests/PointOfSaleTests/Models/PointOfSaleAggregateModelTests.swift @@ -974,7 +974,7 @@ private func makePointOfSaleAggregateModel( couponsSearchController: PointOfSaleSearchingItemsControllerProtocol = MockPointOfSaleCouponsController(), cardPresentPaymentService: CardPresentPaymentFacade = MockCardPresentPaymentService(), orderController: PointOfSaleOrderControllerProtocol = MockPointOfSaleOrderController(), - settingsController: PointOfSaleSettingsControllerProtocol = MockPointOfSaleSettingsController(), + settingsController: POSSettingsControllerProtocol = MockPOSSettingsController(), analytics: POSAnalyticsProviding = MockPOSAnalytics(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalyticsTracking = MockPOSCollectOrderPaymentAnalyticsTracker(), searchHistoryService: POSSearchHistoryProviding = MockPOSSearchHistoryService(), diff --git a/Modules/Tests/PointOfSaleTests/Presentation/POSItemActionHandlerTests.swift b/Modules/Tests/PointOfSaleTests/Presentation/POSItemActionHandlerTests.swift index c1c1e4433cf..16929a3eac0 100644 --- a/Modules/Tests/PointOfSaleTests/Presentation/POSItemActionHandlerTests.swift +++ b/Modules/Tests/PointOfSaleTests/Presentation/POSItemActionHandlerTests.swift @@ -105,7 +105,7 @@ private func makePointOfSaleAggregateModel( couponsSearchController: PointOfSaleSearchingItemsControllerProtocol = MockPointOfSaleCouponsController(), cardPresentPaymentService: CardPresentPaymentFacade = MockCardPresentPaymentService(), orderController: PointOfSaleOrderControllerProtocol = MockPointOfSaleOrderController(), - settingsController: PointOfSaleSettingsControllerProtocol = MockPointOfSaleSettingsController(), + settingsController: POSSettingsControllerProtocol = MockPOSSettingsController(), analytics: POSAnalyticsProviding = MockPOSAnalytics(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalyticsTracking = MockPOSCollectOrderPaymentAnalyticsTracker(), searchHistoryService: POSSearchHistoryProviding = MockPOSSearchHistoryService(),