Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,7 +79,7 @@ protocol PointOfSaleAggregateModelProtocol {
couponsSearchController: PointOfSaleSearchingItemsControllerProtocol,
cardPresentPaymentService: CardPresentPaymentFacade,
orderController: PointOfSaleOrderControllerProtocol,
settingsController: PointOfSaleSettingsControllerProtocol,
settingsController: POSSettingsControllerProtocol,
analytics: POSAnalyticsProviding,
collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalyticsTracking,
searchHistoryService: POSSearchHistoryProviding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -120,7 +120,7 @@ private extension PointOfSaleBarcodeScannerSetup {

#if DEBUG
#Preview {
PointOfSaleBarcodeScannerSetup(isPresented: .constant(true), analytics: EmptyPOSAnalytics())
POSBarcodeScannerSetup(isPresented: .constant(true), analytics: EmptyPOSAnalytics())
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion Modules/Sources/PointOfSale/Presentation/CartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ extension EnvironmentValues {
}
}
.posModal(isPresented: $showModal) {
PointOfSaleBarcodeScannerSetup(isPresented: $showModal, analytics: EmptyPOSAnalytics())
POSBarcodeScannerSetup(isPresented: $showModal, analytics: EmptyPOSAnalytics())
}
.posRootModal()
.environmentObject(modalManager)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -36,6 +36,7 @@ struct PointOfSaleSettingsHardwareDetailView: View {
}

var body: some View {
@Bindable var posModel = posModel
NavigationStack(path: $navigationPath) {
POSPageHeaderView(title: Localization.hardwareTitle)
.foregroundColor(.posSurface)
Expand Down Expand Up @@ -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)
})
Comment on lines +85 to +90
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps there could be a shared definition of this somehow? Not if it's difficult; we're not going to use it in that many places, but it's essentially identical to PointOfSaleDashboardView's use.

I think it would have to be a view modifier, something like this:

struct CardReaderConnectingModifier: ViewModifier {
    @Environment(PointOfSaleAggregateModel.self) private var posModel

    func body(content: Content) -> some View {
        @Bindable var posModel = self.posModel
        content
            .posModal(item: $posModel.cardPresentPaymentAlertViewModel,
                      onDismiss: {
                posModel.cardPresentPaymentAlertViewModel?.onDismiss?()
            }) { alertType in
                PointOfSaleCardPresentPaymentAlert(alertType: alertType)
                    .posInteractiveDismissDisabled(alertType.isDismissDisabled)
            }
    }
}

extension View {
    func cardReaderConnecting() -> some View {
        modifier(CardReaderConnectingModifier())
    }
}

Though perhaps it would be better named as POS specific, and have the posModal requirement more obvious than using the environment var directly. It might be interesting to try some options for a few minutes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That definitely looks cleaner, thanks! I'll play with this separately and merge this PR for now.

.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,
Expand Down Expand Up @@ -168,7 +169,7 @@ struct PointOfSaleSettingsHardwareDetailView: View {
}
}

private var cardReadersView: some View {
var cardReadersView: some View {
VStack(spacing: POSSpacing.none) {
POSPageHeaderView(
title: Localization.cardReadersTitle,
Expand Down Expand Up @@ -224,7 +225,7 @@ struct PointOfSaleSettingsHardwareDetailView: View {
}
}

private var scannersView: some View {
var scannersView: some View {
VStack(spacing: POSSpacing.none) {
POSPageHeaderView(
title: Localization.scannersTitle,
Expand Down Expand Up @@ -268,7 +269,7 @@ struct PointOfSaleSettingsHardwareDetailView: View {
}

// MARK: - Navigation
private extension PointOfSaleSettingsHardwareDetailView {
private extension POSSettingsHardwareDetailView {
enum HardwareDestination: Identifiable, CaseIterable {
case cardReaders
case scanners
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -460,6 +471,6 @@ private extension PointOfSaleSettingsHardwareDetailView {

#if DEBUG
#Preview {
PointOfSaleSettingsHardwareDetailView(settingsController: PointOfSaleSettingsPreviewController())
POSSettingsHardwareDetailView(settingsController: POSSettingsPreviewController())
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private extension PointOfSaleSettingsStoreDetailView {

#if DEBUG
#Preview {
let controller = PointOfSaleSettingsPreviewController()
let controller = POSSettingsPreviewController()
PointOfSaleSettingsStoreDetailView(viewModel: controller.storeViewModel)
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -250,6 +250,6 @@ extension PointOfSaleSettingsView {

#if DEBUG
#Preview {
PointOfSaleSettingsView(settingsController: PointOfSaleSettingsPreviewController())
PointOfSaleSettingsView(settingsController: POSSettingsPreviewController())
}
#endif
2 changes: 1 addition & 1 deletion Modules/Sources/PointOfSale/Utils/PreviewHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down