@@ -69,6 +69,8 @@ final class DashboardViewModel: ObservableObject {
69
69
70
70
@Published private( set) var isEligibleForInbox = false
71
71
72
+ @Published private( set) var isEligibleForStock = false
73
+
72
74
@Published var showingCustomization = false
73
75
74
76
@Published private( set) var showNewCardsNotice = false
@@ -83,6 +85,7 @@ final class DashboardViewModel: ObservableObject {
83
85
private let userDefaults : UserDefaults
84
86
private let storageManager : StorageManagerType
85
87
private let inboxEligibilityChecker : InboxEligibilityChecker
88
+ private let siteIsCIABEligibilityChecker : CIABEligibilityCheckerProtocol
86
89
private let usageTracksEventEmitter : StoreStatsUsageTracksEventEmitter
87
90
private let blazeLocalNotificationScheduler : BlazeLocalNotificationScheduler
88
91
private let tapToPayAwarenessMomentDeterminer : TapToPayAwarenessMomentDetermining
@@ -118,6 +121,7 @@ final class DashboardViewModel: ObservableObject {
118
121
blazeEligibilityChecker: BlazeEligibilityCheckerProtocol = BlazeEligibilityChecker ( ) ,
119
122
inboxEligibilityChecker: InboxEligibilityChecker = InboxEligibilityUseCase ( ) ,
120
123
googleAdsEligibilityChecker: GoogleAdsEligibilityChecker = DefaultGoogleAdsEligibilityChecker ( ) ,
124
+ siteIsCIABEligibilityChecker: CIABEligibilityCheckerProtocol = CIABEligibilityChecker ( ) ,
121
125
localNotificationScheduler: BlazeLocalNotificationScheduler ? = nil ,
122
126
tapToPayAwarenessMomentDeterminer: TapToPayAwarenessMomentDetermining = TapToPayAwarenessMomentDeterminer ( ) ) {
123
127
self . siteID = siteID
@@ -147,6 +151,7 @@ final class DashboardViewModel: ObservableObject {
147
151
)
148
152
149
153
self . inboxEligibilityChecker = inboxEligibilityChecker
154
+ self . siteIsCIABEligibilityChecker = siteIsCIABEligibilityChecker
150
155
self . usageTracksEventEmitter = usageTracksEventEmitter
151
156
152
157
self . blazeLocalNotificationScheduler = localNotificationScheduler ?? DefaultBlazeLocalNotificationScheduler ( siteID: siteID,
@@ -164,6 +169,7 @@ final class DashboardViewModel: ObservableObject {
164
169
self ? . onInAppFeedbackCardAction ( )
165
170
}
166
171
172
+ observeStockEligibility ( )
167
173
configureOrdersResultController ( )
168
174
setupDashboardCards ( )
169
175
observeWPCOMSiteSuspendedState ( )
@@ -187,6 +193,7 @@ final class DashboardViewModel: ObservableObject {
187
193
canShowBlaze: blazeCampaignDashboardViewModel. canShowInDashboard,
188
194
canShowGoogle: googleAdsDashboardCardViewModel. canShowOnDashboard,
189
195
canShowInbox: isEligibleForInbox,
196
+ canShowStock: isEligibleForStock,
190
197
hasOrders: hasOrders)
191
198
192
199
await reloadCardsWithBackgroundUpdateSupportIfNeeded ( )
@@ -487,18 +494,20 @@ private extension DashboardViewModel {
487
494
private extension DashboardViewModel {
488
495
func observeValuesForDashboardCards( ) {
489
496
storeOnboardingViewModel. $canShowInDashboard
490
- . combineLatest ( blazeCampaignDashboardViewModel. $canShowInDashboard)
497
+ . combineLatest ( blazeCampaignDashboardViewModel. $canShowInDashboard,
498
+ $isEligibleForStock)
491
499
. combineLatest ( googleAdsDashboardCardViewModel. $canShowOnDashboard,
492
500
$hasOrders,
493
501
$isEligibleForInbox)
494
502
. receive ( on: DispatchQueue . main)
495
503
. sink { [ weak self] combinedResult in
496
504
guard let self else { return }
497
- let ( ( canShowOnboarding, canShowBlaze) , canShowGoogle, hasOrders, isEligibleForInbox) = combinedResult
505
+ let ( ( canShowOnboarding, canShowBlaze, canShowStock ) , canShowGoogle, hasOrders, isEligibleForInbox) = combinedResult
498
506
updateDashboardCards ( canShowOnboarding: canShowOnboarding,
499
507
canShowBlaze: canShowBlaze,
500
508
canShowGoogle: canShowGoogle,
501
509
canShowInbox: isEligibleForInbox,
510
+ canShowStock: canShowStock,
502
511
hasOrders: hasOrders)
503
512
}
504
513
. store ( in: & subscriptions)
@@ -531,6 +540,26 @@ private extension DashboardViewModel {
531
540
isEligibleForInbox = inboxEligibilityChecker. isEligibleForInbox ( siteID: siteID)
532
541
}
533
542
543
+ func observeStockEligibility( ) {
544
+ stores. site
545
+ . removeDuplicates ( )
546
+ . map { [ weak self] in
547
+ guard
548
+ let self,
549
+ let site = $0
550
+ else {
551
+ return false
552
+ }
553
+
554
+ return siteIsCIABEligibilityChecker
555
+ . isFeatureSupported (
556
+ . productsStockDashboardCard,
557
+ for: site
558
+ )
559
+ }
560
+ . assign ( to: & $isEligibleForStock)
561
+ }
562
+
534
563
func configureOrdersResultController( ) {
535
564
func refreshHasOrders( ) {
536
565
/// Upon logging out, `CoreDataManager` clears the storage triggering data change.
@@ -586,6 +615,7 @@ private extension DashboardViewModel {
586
615
canShowGoogle: Bool ,
587
616
canShowAnalytics: Bool ,
588
617
canShowLastOrders: Bool ,
618
+ canShowStock: Bool ,
589
619
canShowInbox: Bool ) -> [ DashboardCard ] {
590
620
var cards = [ DashboardCard] ( )
591
621
@@ -616,7 +646,14 @@ private extension DashboardViewModel {
616
646
enabled: false ) )
617
647
cards. append ( DashboardCard ( type: . reviews, availability: . show, enabled: false ) )
618
648
cards. append ( DashboardCard ( type: . coupons, availability: . show, enabled: false ) )
619
- cards. append ( DashboardCard ( type: . stock, availability: . show, enabled: false ) )
649
+
650
+ cards. append (
651
+ DashboardCard (
652
+ type: . stock,
653
+ availability: canShowStock ? . show : . hide,
654
+ enabled: false
655
+ )
656
+ )
620
657
621
658
// When not available, Last orders cards need to be hidden from Dashboard, but appear on Customize as "Unavailable"
622
659
cards. append ( DashboardCard ( type: . lastOrders,
@@ -634,6 +671,7 @@ private extension DashboardViewModel {
634
671
canShowBlaze: Bool ,
635
672
canShowGoogle: Bool ,
636
673
canShowInbox: Bool ,
674
+ canShowStock: Bool ,
637
675
hasOrders: Bool ) {
638
676
639
677
let canShowAnalytics = hasOrders
@@ -645,6 +683,7 @@ private extension DashboardViewModel {
645
683
canShowGoogle: canShowGoogle,
646
684
canShowAnalytics: canShowAnalytics,
647
685
canShowLastOrders: canShowLastOrders,
686
+ canShowStock: canShowStock,
648
687
canShowInbox: canShowInbox)
649
688
650
689
// Next, get saved cards and preserve existing enabled state for all available cards.
0 commit comments