Skip to content

Commit 23b5b39

Browse files
committed
Check for app settings to show or hide the coupon element on the hub menu
1 parent 7d28021 commit 23b5b39

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

WooCommerce/Classes/ViewRelated/Hub Menu/HubMenu.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ struct HubMenu: View {
8080
}
8181
.navigationBarHidden(true)
8282
.background(Color(.listBackground).edgesIgnoringSafeArea(.all))
83+
.onAppear {
84+
viewModel.setupMenuElements()
85+
}
8386
}
8487

8588
func pushReviewDetailsView(using parcel: ProductReviewFromNoteParcel) {

WooCommerce/Classes/ViewRelated/Hub Menu/HubMenuViewModel.swift

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ final class HubMenuViewModel: ObservableObject {
4747
@Published var showingReviewDetail = false
4848

4949
private let stores: StoresManager
50+
private let featureFlagService: FeatureFlagService
5051

5152
private var productReviewFromNoteParcel: ProductReviewFromNoteParcel?
5253

@@ -61,15 +62,31 @@ final class HubMenuViewModel: ObservableObject {
6162
self.siteID = siteID
6263
self.navigationController = navigationController
6364
self.stores = stores
65+
self.featureFlagService = featureFlagService
66+
observeSiteForUIUpdates()
67+
}
68+
69+
/// Resets the menu elements displayed on the menu.
70+
///
71+
func setupMenuElements() {
6472
menuElements = [.woocommerceAdmin, .viewStore]
6573
if featureFlagService.isFeatureFlagEnabled(.inbox) {
6674
menuElements.append(.inbox)
6775
}
68-
if featureFlagService.isFeatureFlagEnabled(.couponManagement) {
69-
menuElements.append(.coupons)
70-
}
7176
menuElements.append(.reviews)
72-
observeSiteForUIUpdates()
77+
78+
let action = AppSettingsAction.loadCouponManagementFeatureSwitchState { [weak self] result in
79+
guard let self = self else { return }
80+
guard case let .success(enabled) = result, enabled else {
81+
return
82+
}
83+
if let index = self.menuElements.firstIndex(of: .reviews) {
84+
self.menuElements.insert(.coupons, at: index)
85+
} else {
86+
self.menuElements.append(.coupons)
87+
}
88+
}
89+
ServiceLocator.stores.dispatch(action)
7390
}
7491

7592
/// Present the `StorePickerViewController` using the `StorePickerCoordinator`, passing the navigation controller from the entry point.

0 commit comments

Comments
 (0)