Skip to content

[Woo POS] Update conditions for showing POS entry point #12783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 21, 2024
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
3 changes: 1 addition & 2 deletions WooCommerce/Classes/Model/BetaFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ extension BetaFeature {
case .inAppPurchases:
return ServiceLocator.featureFlagService.isFeatureFlagEnabled(.inAppPurchasesDebugMenu)
case .pointOfSale:
return ServiceLocator.featureFlagService.isFeatureFlagEnabled(.displayPointOfSaleToggle) &&
UIDevice.current.userInterfaceIdiom == .pad
return POSEligibilityChecker().isEligible()
default:
return true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Foundation
import UIKit
import class WooFoundation.CurrencySettings
import enum WooFoundation.CountryCode
import protocol Experiments.FeatureFlagService
import struct Yosemite.SiteSetting
Comment on lines +3 to +6
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know if there are any performance effects when importing specific structs, enums, classes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think there's performance gain from this, but this makes it clear what the exact dependencies are if we ever want to move it to a framework.


/// Determines whether the POS entry point can be shown based on the selected store and feature gates.
final class POSEligibilityChecker {
private let cardPresentPaymentsOnboarding: CardPresentPaymentsOnboardingUseCaseProtocol
private let siteSettings: [SiteSetting]
private let currencySettings: CurrencySettings
private let featureFlagService: FeatureFlagService

init(cardPresentPaymentsOnboarding: CardPresentPaymentsOnboardingUseCaseProtocol = CardPresentPaymentsOnboardingUseCase(),
siteSettings: [SiteSetting] = ServiceLocator.selectedSiteSettings.siteSettings,
currencySettings: CurrencySettings = ServiceLocator.currencySettings,
featureFlagService: FeatureFlagService = ServiceLocator.featureFlagService) {
self.siteSettings = siteSettings
self.currencySettings = currencySettings
self.cardPresentPaymentsOnboarding = cardPresentPaymentsOnboarding
self.featureFlagService = featureFlagService
}

/// Returns whether the selected store is eligible for POS.
func isEligible() -> Bool {
// Always checks the main POS feature flag before any other checks.
guard featureFlagService.isFeatureFlagEnabled(.displayPointOfSaleToggle) else {
return false
}

let isCountryCodeUS = SiteAddress(siteSettings: siteSettings).countryCode == CountryCode.US
let isCurrencyUSD = currencySettings.currencyCode == .USD

// Tablet device
return UIDevice.current.userInterfaceIdiom == .pad
// Woo Payments plugin enabled and user setup complete
&& (cardPresentPaymentsOnboarding.state == .completed(plugin: .wcPayOnly) || cardPresentPaymentsOnboarding.state == .completed(plugin: .wcPayPreferred))
// USD currency
&& isCurrencyUSD
// US store location
&& isCountryCodeUS
}
}
67 changes: 31 additions & 36 deletions WooCommerce/Classes/ViewRelated/Hub Menu/HubMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,51 +82,24 @@ private extension HubMenu {
.disabled(!viewModel.switchStoreEnabled)
}

// Point of Sale
if let menu = viewModel.posElement {
Section {
menuItemView(menu: menu)
}
}

// Settings Section
Section(Localization.settings) {
ForEach(viewModel.settingsElements, id: \.id) { menu in
Button {
handleTap(menu: menu)
} label: {
Row(title: menu.title,
titleBadge: nil,
iconBadge: menu.iconBadge,
description: menu.description,
icon: .local(menu.icon),
chevron: .leading)
.foregroundColor(Color(menu.iconColor))
}
.accessibilityIdentifier(menu.accessibilityIdentifier)
.overlay {
NavigationLink(value: menu.id) {
EmptyView()
}
.opacity(0)
}
menuItemView(menu: menu)
}
}

// General Section
Section(Localization.general) {
ForEach(viewModel.generalElements, id: \.id) { menu in
Button {
handleTap(menu: menu)
} label: {
Row(title: menu.title,
titleBadge: nil,
iconBadge: menu.iconBadge,
description: menu.description,
icon: .local(menu.icon),
chevron: .leading)
.foregroundColor(Color(menu.iconColor))
}
.accessibilityIdentifier(menu.accessibilityIdentifier)
.overlay {
NavigationLink(value: menu.id) {
EmptyView()
}
.opacity(0)
}
menuItemView(menu: menu)
}
}
}
Expand All @@ -135,6 +108,28 @@ private extension HubMenu {
.accentColor(Color(.listSelectedBackground))
}

@ViewBuilder
func menuItemView(menu: HubMenuItem) -> some View {
Button {
handleTap(menu: menu)
} label: {
Row(title: menu.title,
titleBadge: nil,
iconBadge: menu.iconBadge,
description: menu.description,
icon: .local(menu.icon),
chevron: .leading)
.foregroundColor(Color(menu.iconColor))
}
.accessibilityIdentifier(menu.accessibilityIdentifier)
.overlay {
NavigationLink(value: menu.id) {
EmptyView()
}
.opacity(0)
}
}

@ViewBuilder
func detailView(menuID: String) -> some View {
Group {
Expand Down
21 changes: 18 additions & 3 deletions WooCommerce/Classes/ViewRelated/Hub Menu/HubMenuViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ final class HubMenuViewModel: ObservableObject {

@Published private(set) var woocommerceAdminURL = WooConstants.URLs.blog.asURL()

/// POS Section Element
///
@Published private(set) var posElement: HubMenuItem?

/// Settings Elements
///
@Published private(set) var settingsElements: [HubMenuItem] = []
Expand Down Expand Up @@ -122,6 +126,7 @@ final class HubMenuViewModel: ObservableObject {
/// Resets the menu elements displayed on the menu.
///
func setupMenuElements() {
setupPOSElement()
setupSettingsElements()
setupGeneralElements()
}
Expand All @@ -132,6 +137,19 @@ final class HubMenuViewModel: ObservableObject {
navigationPath.append(HubMenuNavigationDestination.payments)
}

private func setupPOSElement() {
let isBetaFeatureEnabled = generalAppSettings.betaFeatureEnabled(.pointOfSale)
let eligibilityChecker = POSEligibilityChecker(cardPresentPaymentsOnboarding: CardPresentPaymentsOnboardingUseCase(),
siteSettings: ServiceLocator.selectedSiteSettings.siteSettings,
currencySettings: ServiceLocator.currencySettings,
featureFlagService: featureFlagService)
if isBetaFeatureEnabled && eligibilityChecker.isEligible() {
posElement = PointOfSaleEntryPoint()
} else {
posElement = nil
}
}

private func setupSettingsElements() {
settingsElements = [Settings()]

Expand All @@ -153,9 +171,6 @@ final class HubMenuViewModel: ObservableObject {
if generalAppSettings.betaFeatureEnabled(.inAppPurchases) {
generalElements.append(InAppPurchases())
}
if generalAppSettings.betaFeatureEnabled(.pointOfSale) {
generalElements.append(PointOfSaleEntryPoint())
}

let inboxUseCase = InboxEligibilityUseCase(stores: stores, featureFlagService: featureFlagService)
inboxUseCase.isEligibleForInbox(siteID: siteID) { [weak self] isInboxMenuShown in
Expand Down
12 changes: 12 additions & 0 deletions WooCommerce/WooCommerce.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@
02E4908929AE49B9005942AE /* TopPerformersEmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02E4908829AE49B9005942AE /* TopPerformersEmptyView.swift */; };
02E4908D29AF216E005942AE /* TopPerformersPeriodView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02E4908C29AF216E005942AE /* TopPerformersPeriodView.swift */; };
02E493EF245C1087000AEA9E /* ProductFormBottomSheetListSelectorCommandTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02E493EE245C1087000AEA9E /* ProductFormBottomSheetListSelectorCommandTests.swift */; };
02E4A0832BFB1C4F006D4F87 /* POSEligibilityChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02E4A0822BFB1C4F006D4F87 /* POSEligibilityChecker.swift */; };
02E4AF7126FC4F16002AD9F4 /* ProductReviewFromNoteParcelFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02E4AF7026FC4F16002AD9F4 /* ProductReviewFromNoteParcelFactory.swift */; };
02E4FD7E2306A8180049610C /* StatsTimeRangeBarViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02E4FD7D2306A8180049610C /* StatsTimeRangeBarViewModel.swift */; };
02E4FD812306AA890049610C /* StatsTimeRangeBarViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02E4FD802306AA890049610C /* StatsTimeRangeBarViewModelTests.swift */; };
Expand Down Expand Up @@ -3333,6 +3334,7 @@
02E4908829AE49B9005942AE /* TopPerformersEmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopPerformersEmptyView.swift; sourceTree = "<group>"; };
02E4908C29AF216E005942AE /* TopPerformersPeriodView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopPerformersPeriodView.swift; sourceTree = "<group>"; };
02E493EE245C1087000AEA9E /* ProductFormBottomSheetListSelectorCommandTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductFormBottomSheetListSelectorCommandTests.swift; sourceTree = "<group>"; };
02E4A0822BFB1C4F006D4F87 /* POSEligibilityChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSEligibilityChecker.swift; sourceTree = "<group>"; };
02E4AF7026FC4F16002AD9F4 /* ProductReviewFromNoteParcelFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductReviewFromNoteParcelFactory.swift; sourceTree = "<group>"; };
02E4FD7D2306A8180049610C /* StatsTimeRangeBarViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsTimeRangeBarViewModel.swift; sourceTree = "<group>"; };
02E4FD802306AA890049610C /* StatsTimeRangeBarViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsTimeRangeBarViewModelTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6898,6 +6900,14 @@
path = Authentication;
sourceTree = "<group>";
};
02E4A0842BFB1D1F006D4F87 /* POS */ = {
isa = PBXGroup;
children = (
02E4A0822BFB1C4F006D4F87 /* POSEligibilityChecker.swift */,
);
path = POS;
sourceTree = "<group>";
};
02E4FD7F2306AA770049610C /* Dashboard */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -10974,6 +10984,7 @@
E138D4F2269ED99A006EA5C6 /* In-Person Payments */,
CE27257A219249B5002B22EB /* Help */,
CE22E3F821714639005A6BEF /* Privacy */,
02E4A0842BFB1D1F006D4F87 /* POS */,
03191AE828E20C9200670723 /* PluginDetailsRowView.swift */,
);
path = Settings;
Expand Down Expand Up @@ -14683,6 +14694,7 @@
B57C744E20F56E3800EEFC87 /* UITableViewCell+Helpers.swift in Sources */,
0295355B245ADF8100BDC42B /* FilterType+Products.swift in Sources */,
02CA63DA23D1ADD100BBF148 /* CameraCaptureCoordinator.swift in Sources */,
02E4A0832BFB1C4F006D4F87 /* POSEligibilityChecker.swift in Sources */,
DE8BEB962ABC19B100F5E56C /* ProductDetailPreviewView.swift in Sources */,
260C31602524ECA900157BC2 /* IssueRefundViewController.swift in Sources */,
4521397027FF53E400964ED3 /* CouponExpiryDateView.swift in Sources */,
Expand Down