Skip to content

Commit 93a5b18

Browse files
committed
Make products onboarding banner dismissible
1 parent 984c17b commit 93a5b18

File tree

3 files changed

+42
-16
lines changed

3 files changed

+42
-16
lines changed

Storage/Storage/Model/Feature Announcements/FeatureAnnouncementCampaign.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public enum FeatureAnnouncementCampaign: String, Codable, Equatable {
55
case linkedProductsPromo = "linked_products_promo"
66
case paymentsInMenuTabBarButton = "payments_menu_tabbar_button"
77
case paymentsInHubMenuButton = "payments_hub_menu_button"
8+
case productsOnboarding = "products_onboarding_first_product"
89

910
/// Added for use in `test_setFeatureAnnouncementDismissed_with_another_campaign_previously_dismissed_keeps_values_for_both`
1011
/// This can be removed when we have a second campaign, which can be used in the above test instead.

WooCommerce/Classes/ViewModels/Feature Announcement Cards/ProductsOnboardingAnnouncementCardViewModel.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22
import UIKit
3+
import enum Yosemite.AppSettingsAction
34

45
struct ProductsOnboardingAnnouncementCardViewModel: AnnouncementCardViewModelProtocol {
56
var showDividers: Bool = true
@@ -27,6 +28,17 @@ struct ProductsOnboardingAnnouncementCardViewModel: AnnouncementCardViewModelPro
2728
onCTATapped?()
2829
}
2930

31+
// MARK: Dismiss button
32+
33+
/// Ensures the banner isn't shown again after the user manually dismisses it.
34+
///
35+
func dontShowAgainTapped() {
36+
let action = AppSettingsAction.setFeatureAnnouncementDismissed(campaign: .productsOnboarding,
37+
remindLater: false,
38+
onCompletion: nil)
39+
ServiceLocator.stores.dispatch(action)
40+
}
41+
3042
// MARK: Dismiss confirmation alert (disabled)
3143

3244
var showDismissConfirmation: Bool = false
@@ -35,10 +47,6 @@ struct ProductsOnboardingAnnouncementCardViewModel: AnnouncementCardViewModelPro
3547

3648
var dismissAlertMessage: String = ""
3749

38-
func dontShowAgainTapped() {
39-
// No-op
40-
}
41-
4250
func remindLaterTapped() {
4351
// No-op
4452
}

WooCommerce/Classes/ViewRelated/Dashboard/DashboardViewModel.swift

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,14 @@ final class DashboardViewModel {
124124
if isEligible {
125125
ServiceLocator.analytics.track(event: .ProductsOnboarding.storeIsEligible())
126126

127-
if ABTest.productsOnboardingBanner.variation == .treatment(nil) {
128-
let viewModel = ProductsOnboardingAnnouncementCardViewModel(onCTATapped: { [weak self] in
129-
self?.announcementViewModel = nil // Dismiss announcement
130-
MainTabBarController.presentAddProductFlow()
131-
})
132-
self?.announcementViewModel = viewModel
133-
// For now, products onboarding takes precedence over Just In Time Messages,
134-
// so we can stop if there is an onboarding announcement to display.
135-
// This should be revisited when either onboarding or JITMs are expanded. See:
136-
// pe5pgL-11B-p2
137-
return
138-
}
127+
self?.setProductsOnboardingBannerIfNeeded()
128+
}
129+
130+
// For now, products onboarding takes precedence over Just In Time Messages,
131+
// so we can stop if there is an onboarding announcement to display.
132+
// This should be revisited when either onboarding or JITMs are expanded. See: pe5pgL-11B-p2
133+
if self?.announcementViewModel is ProductsOnboardingAnnouncementCardViewModel {
134+
return
139135
}
140136
onCompletion()
141137
case .failure(let error):
@@ -146,6 +142,27 @@ final class DashboardViewModel {
146142
stores.dispatch(action)
147143
}
148144

145+
/// Sets the view model for the products onboarding banner if the user hasn't dismissed it before,
146+
/// and if the user is part of the treatment group for the products onboarding A/B test.
147+
///
148+
private func setProductsOnboardingBannerIfNeeded() {
149+
guard ABTest.productsOnboardingBanner.variation == .treatment(nil) else {
150+
return
151+
}
152+
153+
let getVisibility = AppSettingsAction.getFeatureAnnouncementVisibility(campaign: .productsOnboarding) { [weak self] result in
154+
guard let self else { return }
155+
if case let .success(isVisible) = result, isVisible {
156+
let viewModel = ProductsOnboardingAnnouncementCardViewModel(onCTATapped: { [weak self] in
157+
self?.announcementViewModel = nil // Dismiss announcement
158+
MainTabBarController.presentAddProductFlow()
159+
})
160+
self.announcementViewModel = viewModel
161+
}
162+
}
163+
stores.dispatch(getVisibility)
164+
}
165+
149166
/// Checks for Just In Time Messages and prepares the announcement if needed.
150167
///
151168
private func syncJustInTimeMessages(for siteID: Int64) {

0 commit comments

Comments
 (0)