Skip to content

Commit 8eefce5

Browse files
authored
[Woo POS][Surveys] Hook survey notification scheduler with order creation and POS (#16241)
2 parents 061882d + bfdc744 commit 8eefce5

File tree

11 files changed

+493
-61
lines changed

11 files changed

+493
-61
lines changed

Modules/Sources/Storage/Model/Copiable/Models+Copiable.generated.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ extension Storage.GeneralAppSettings {
6565
sitesWithAtLeastOneIPPTransactionFinished: CopiableProp<Set<Int64>> = .copy,
6666
isEUShippingNoticeDismissed: CopiableProp<Bool> = .copy,
6767
isCustomFieldsTopBannerDismissed: CopiableProp<Bool> = .copy,
68-
isPOSSurveyNotificationScheduled: CopiableProp<Bool> = .copy
68+
isPOSSurveyPotentialMerchantNotificationScheduled: CopiableProp<Bool> = .copy,
69+
isPOSSurveyCurrentMerchantNotificationScheduled: CopiableProp<Bool> = .copy,
70+
hasPOSBeenOpenedAtLeastOnce: CopiableProp<Bool> = .copy
6971
) -> Storage.GeneralAppSettings {
7072
let installationDate = installationDate ?? self.installationDate
7173
let feedbacks = feedbacks ?? self.feedbacks
@@ -78,7 +80,11 @@ extension Storage.GeneralAppSettings {
7880
let sitesWithAtLeastOneIPPTransactionFinished = sitesWithAtLeastOneIPPTransactionFinished ?? self.sitesWithAtLeastOneIPPTransactionFinished
7981
let isEUShippingNoticeDismissed = isEUShippingNoticeDismissed ?? self.isEUShippingNoticeDismissed
8082
let isCustomFieldsTopBannerDismissed = isCustomFieldsTopBannerDismissed ?? self.isCustomFieldsTopBannerDismissed
81-
let isPOSSurveyNotificationScheduled = isPOSSurveyNotificationScheduled ?? self.isPOSSurveyNotificationScheduled
83+
let isPOSSurveyPotentialMerchantNotificationScheduled = isPOSSurveyPotentialMerchantNotificationScheduled ??
84+
self.isPOSSurveyPotentialMerchantNotificationScheduled
85+
let isPOSSurveyCurrentMerchantNotificationScheduled = isPOSSurveyCurrentMerchantNotificationScheduled ??
86+
self.isPOSSurveyCurrentMerchantNotificationScheduled
87+
let hasPOSBeenOpenedAtLeastOnce = hasPOSBeenOpenedAtLeastOnce ?? self.hasPOSBeenOpenedAtLeastOnce
8288

8389
return Storage.GeneralAppSettings(
8490
installationDate: installationDate,
@@ -92,7 +98,9 @@ extension Storage.GeneralAppSettings {
9298
sitesWithAtLeastOneIPPTransactionFinished: sitesWithAtLeastOneIPPTransactionFinished,
9399
isEUShippingNoticeDismissed: isEUShippingNoticeDismissed,
94100
isCustomFieldsTopBannerDismissed: isCustomFieldsTopBannerDismissed,
95-
isPOSSurveyNotificationScheduled: isPOSSurveyNotificationScheduled
101+
isPOSSurveyPotentialMerchantNotificationScheduled: isPOSSurveyPotentialMerchantNotificationScheduled,
102+
isPOSSurveyCurrentMerchantNotificationScheduled: isPOSSurveyCurrentMerchantNotificationScheduled,
103+
hasPOSBeenOpenedAtLeastOnce: hasPOSBeenOpenedAtLeastOnce
96104
)
97105
}
98106
}

Modules/Sources/Storage/Model/GeneralAppSettings.swift

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,17 @@ public struct GeneralAppSettings: Codable, Equatable, GeneratedCopiable {
5656
///
5757
public var isCustomFieldsTopBannerDismissed: Bool
5858

59-
/// Whether the Point of Sale survey notification has been scheduled
59+
/// Whether the Point of Sale survey notification has been scheduled for potential merchants
6060
///
61-
public var isPOSSurveyNotificationScheduled: Bool
61+
public var isPOSSurveyPotentialMerchantNotificationScheduled: Bool
62+
63+
/// Whether the Point of Sale survey notification has been scheduled for current merchants
64+
///
65+
public var isPOSSurveyCurrentMerchantNotificationScheduled: Bool
66+
67+
/// Whether POS mode has been opened at least once
68+
///
69+
public var hasPOSBeenOpenedAtLeastOnce: Bool
6270

6371
public init(installationDate: Date?,
6472
feedbacks: [FeedbackType: FeedbackSettings],
@@ -71,7 +79,9 @@ public struct GeneralAppSettings: Codable, Equatable, GeneratedCopiable {
7179
sitesWithAtLeastOneIPPTransactionFinished: Set<Int64>,
7280
isEUShippingNoticeDismissed: Bool,
7381
isCustomFieldsTopBannerDismissed: Bool,
74-
isPOSSurveyNotificationScheduled: Bool) {
82+
isPOSSurveyPotentialMerchantNotificationScheduled: Bool,
83+
isPOSSurveyCurrentMerchantNotificationScheduled: Bool,
84+
hasPOSBeenOpenedAtLeastOnce: Bool) {
7585
self.installationDate = installationDate
7686
self.feedbacks = feedbacks
7787
self.isViewAddOnsSwitchEnabled = isViewAddOnsSwitchEnabled
@@ -83,7 +93,9 @@ public struct GeneralAppSettings: Codable, Equatable, GeneratedCopiable {
8393
self.sitesWithAtLeastOneIPPTransactionFinished = sitesWithAtLeastOneIPPTransactionFinished
8494
self.isEUShippingNoticeDismissed = isEUShippingNoticeDismissed
8595
self.isCustomFieldsTopBannerDismissed = isCustomFieldsTopBannerDismissed
86-
self.isPOSSurveyNotificationScheduled = isPOSSurveyNotificationScheduled
96+
self.isPOSSurveyPotentialMerchantNotificationScheduled = isPOSSurveyPotentialMerchantNotificationScheduled
97+
self.isPOSSurveyCurrentMerchantNotificationScheduled = isPOSSurveyCurrentMerchantNotificationScheduled
98+
self.hasPOSBeenOpenedAtLeastOnce = hasPOSBeenOpenedAtLeastOnce
8799
}
88100

89101
public static var `default`: Self {
@@ -97,7 +109,9 @@ public struct GeneralAppSettings: Codable, Equatable, GeneratedCopiable {
97109
sitesWithAtLeastOneIPPTransactionFinished: [],
98110
isEUShippingNoticeDismissed: false,
99111
isCustomFieldsTopBannerDismissed: false,
100-
isPOSSurveyNotificationScheduled: false)
112+
isPOSSurveyPotentialMerchantNotificationScheduled: false,
113+
isPOSSurveyCurrentMerchantNotificationScheduled: false,
114+
hasPOSBeenOpenedAtLeastOnce: false)
101115
}
102116

103117
/// Returns the status of a given feedback type. If the feedback is not stored in the feedback array. it is assumed that it has a pending status.
@@ -128,7 +142,9 @@ public struct GeneralAppSettings: Codable, Equatable, GeneratedCopiable {
128142
sitesWithAtLeastOneIPPTransactionFinished: sitesWithAtLeastOneIPPTransactionFinished,
129143
isEUShippingNoticeDismissed: isEUShippingNoticeDismissed,
130144
isCustomFieldsTopBannerDismissed: isCustomFieldsTopBannerDismissed,
131-
isPOSSurveyNotificationScheduled: isPOSSurveyNotificationScheduled
145+
isPOSSurveyPotentialMerchantNotificationScheduled: isPOSSurveyPotentialMerchantNotificationScheduled,
146+
isPOSSurveyCurrentMerchantNotificationScheduled: isPOSSurveyCurrentMerchantNotificationScheduled,
147+
hasPOSBeenOpenedAtLeastOnce: hasPOSBeenOpenedAtLeastOnce
132148
)
133149
}
134150

@@ -150,7 +166,9 @@ public struct GeneralAppSettings: Codable, Equatable, GeneratedCopiable {
150166
sitesWithAtLeastOneIPPTransactionFinished: sitesWithAtLeastOneIPPTransactionFinished,
151167
isEUShippingNoticeDismissed: isEUShippingNoticeDismissed,
152168
isCustomFieldsTopBannerDismissed: isCustomFieldsTopBannerDismissed,
153-
isPOSSurveyNotificationScheduled: isPOSSurveyNotificationScheduled
169+
isPOSSurveyPotentialMerchantNotificationScheduled: isPOSSurveyPotentialMerchantNotificationScheduled,
170+
isPOSSurveyCurrentMerchantNotificationScheduled: isPOSSurveyCurrentMerchantNotificationScheduled,
171+
hasPOSBeenOpenedAtLeastOnce: hasPOSBeenOpenedAtLeastOnce
154172
)
155173
}
156174
}
@@ -176,7 +194,11 @@ extension GeneralAppSettings {
176194
forKey: .sitesWithAtLeastOneIPPTransactionFinished) ?? Set<Int64>([])
177195
self.isEUShippingNoticeDismissed = try container.decodeIfPresent(Bool.self, forKey: .isEUShippingNoticeDismissed) ?? false
178196
self.isCustomFieldsTopBannerDismissed = try container.decodeIfPresent(Bool.self, forKey: .isCustomFieldsTopBannerDismissed) ?? false
179-
self.isPOSSurveyNotificationScheduled = try container.decodeIfPresent(Bool.self, forKey: .isPOSSurveyNotificationScheduled) ?? false
197+
//swiftlint:disable:next line_length
198+
self.isPOSSurveyPotentialMerchantNotificationScheduled = try container.decodeIfPresent(Bool.self, forKey: .isPOSSurveyPotentialMerchantNotificationScheduled) ?? false
199+
//swiftlint:disable:next line_length
200+
self.isPOSSurveyCurrentMerchantNotificationScheduled = try container.decodeIfPresent(Bool.self, forKey: .isPOSSurveyCurrentMerchantNotificationScheduled) ?? false
201+
self.hasPOSBeenOpenedAtLeastOnce = try container.decodeIfPresent(Bool.self, forKey: .hasPOSBeenOpenedAtLeastOnce) ?? false
180202
// Decode new properties with `decodeIfPresent` and provide a default value if necessary.
181203
}
182204
}

Modules/Sources/Yosemite/Actions/AppSettingsAction.swift

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,15 +369,31 @@ public enum AppSettingsAction: Action {
369369

370370
// MARK: - Point of Sale Surveys
371371

372-
/// Sets the POS survey notification as scheduled
372+
/// Sets the POS survey notification as scheduled for potential merchants
373373
///
374-
case setPOSSurveyNotificationScheduled(onCompletion: (Result<Void, Error>) -> Void)
374+
case setPOSSurveyPotentialMerchantNotificationScheduled(onCompletion: (Result<Void, Error>) -> Void)
375375

376-
/// Gets whether the POS survey notification has been scheduled
376+
/// Gets whether the POS survey notification has been scheduled for potential merchants
377377
///
378-
case getPOSSurveyNotificationScheduled(onCompletion: (Bool) -> Void)
378+
case getPOSSurveyPotentialMerchantNotificationScheduled(onCompletion: (Bool) -> Void)
379379

380-
/// Resets the POS survey notification scheduled state
380+
/// Sets the POS survey notification as scheduled for current merchants
381+
///
382+
case setPOSSurveyCurrentMerchantNotificationScheduled(onCompletion: (Result<Void, Error>) -> Void)
383+
384+
/// Gets whether the POS survey notification has been scheduled for current merchants
385+
///
386+
case getPOSSurveyCurrentMerchantNotificationScheduled(onCompletion: (Bool) -> Void)
387+
388+
/// Sets that POS mode has been opened at least once
389+
///
390+
case setHasPOSBeenOpenedAtLeastOnce(onCompletion: (Result<Void, Error>) -> Void)
391+
392+
/// Gets whether POS mode has been opened at least once
393+
///
394+
case getHasPOSBeenOpenedAtLeastOnce(onCompletion: (Bool) -> Void)
395+
396+
/// Resets all POS survey notification scheduled states
381397
/// At the moment this one is used for testing only. To remove in WOOMOB-1480
382398
case resetPOSSurveyNotificationScheduled(onCompletion: (Result<Void, Error>) -> Void)
383399
}

Modules/Sources/Yosemite/Stores/AppSettingsStore.swift

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,18 @@ public class AppSettingsStore: Store {
293293
setAppPasswordsExperimentSettingEnabled(isOn: value, onCompletion: onCompletion)
294294
case .getAppPasswordsExperimentSettingState(let onCompletion):
295295
getAppPasswordsExperimentSettingEnabled(onCompletion: onCompletion)
296-
case .setPOSSurveyNotificationScheduled(onCompletion: let onCompletion):
297-
setPOSSurveyNotificationScheduled(onCompletion: onCompletion)
298-
case .getPOSSurveyNotificationScheduled(onCompletion: let onCompletion):
299-
getPOSSurveyNotificationScheduled(onCompletion: onCompletion)
296+
case .setPOSSurveyPotentialMerchantNotificationScheduled(onCompletion: let onCompletion):
297+
setPOSSurveyPotentialMerchantNotificationScheduled(onCompletion: onCompletion)
298+
case .getPOSSurveyPotentialMerchantNotificationScheduled(onCompletion: let onCompletion):
299+
getPOSSurveyPotentialMerchantNotificationScheduled(onCompletion: onCompletion)
300+
case .setPOSSurveyCurrentMerchantNotificationScheduled(onCompletion: let onCompletion):
301+
setPOSSurveyCurrentMerchantNotificationScheduled(onCompletion: onCompletion)
302+
case .getPOSSurveyCurrentMerchantNotificationScheduled(onCompletion: let onCompletion):
303+
getPOSSurveyCurrentMerchantNotificationScheduled(onCompletion: onCompletion)
304+
case .setHasPOSBeenOpenedAtLeastOnce(onCompletion: let onCompletion):
305+
setHasPOSBeenOpenedAtLeastOnce(onCompletion: onCompletion)
306+
case .getHasPOSBeenOpenedAtLeastOnce(onCompletion: let onCompletion):
307+
getHasPOSBeenOpenedAtLeastOnce(onCompletion: onCompletion)
300308
case .resetPOSSurveyNotificationScheduled(onCompletion: let onCompletion):
301309
resetPOSSurveyNotificationScheduled(onCompletion: onCompletion)
302310
}
@@ -1299,22 +1307,51 @@ private extension AppSettingsStore {
12991307
// MARK: - Point of Sale surveys
13001308
//
13011309
private extension AppSettingsStore {
1302-
func setPOSSurveyNotificationScheduled(onCompletion: (Result<Void, Error>) -> Void) {
1310+
func setPOSSurveyPotentialMerchantNotificationScheduled(onCompletion: (Result<Void, Error>) -> Void) {
13031311
do {
1304-
try generalAppSettings.setValue(true, for: \.isPOSSurveyNotificationScheduled)
1312+
try generalAppSettings.setValue(true, for: \.isPOSSurveyPotentialMerchantNotificationScheduled)
13051313
onCompletion(.success(()))
13061314
} catch {
13071315
onCompletion(.failure(error))
13081316
}
13091317
}
13101318

1311-
func getPOSSurveyNotificationScheduled(onCompletion: (Bool) -> Void) {
1312-
onCompletion(generalAppSettings.value(for: \.isPOSSurveyNotificationScheduled))
1319+
func getPOSSurveyPotentialMerchantNotificationScheduled(onCompletion: (Bool) -> Void) {
1320+
onCompletion(generalAppSettings.value(for: \.isPOSSurveyPotentialMerchantNotificationScheduled))
13131321
}
13141322

1323+
func setPOSSurveyCurrentMerchantNotificationScheduled(onCompletion: (Result<Void, Error>) -> Void) {
1324+
do {
1325+
try generalAppSettings.setValue(true, for: \.isPOSSurveyCurrentMerchantNotificationScheduled)
1326+
onCompletion(.success(()))
1327+
} catch {
1328+
onCompletion(.failure(error))
1329+
}
1330+
}
1331+
1332+
func getPOSSurveyCurrentMerchantNotificationScheduled(onCompletion: (Bool) -> Void) {
1333+
onCompletion(generalAppSettings.value(for: \.isPOSSurveyCurrentMerchantNotificationScheduled))
1334+
}
1335+
1336+
func setHasPOSBeenOpenedAtLeastOnce(onCompletion: (Result<Void, Error>) -> Void) {
1337+
do {
1338+
try generalAppSettings.setValue(true, for: \.hasPOSBeenOpenedAtLeastOnce)
1339+
onCompletion(.success(()))
1340+
} catch {
1341+
onCompletion(.failure(error))
1342+
}
1343+
}
1344+
1345+
func getHasPOSBeenOpenedAtLeastOnce(onCompletion: (Bool) -> Void) {
1346+
onCompletion(generalAppSettings.value(for: \.hasPOSBeenOpenedAtLeastOnce))
1347+
}
1348+
1349+
// Resets all saved values for POS surveys for easier testing. To be removed in WOOMOB-1480
13151350
func resetPOSSurveyNotificationScheduled(onCompletion: (Result<Void, Error>) -> Void) {
13161351
do {
1317-
try generalAppSettings.setValue(false, for: \.isPOSSurveyNotificationScheduled)
1352+
try generalAppSettings.setValue(false, for: \.isPOSSurveyPotentialMerchantNotificationScheduled)
1353+
try generalAppSettings.setValue(false, for: \.isPOSSurveyCurrentMerchantNotificationScheduled)
1354+
try generalAppSettings.setValue(false, for: \.hasPOSBeenOpenedAtLeastOnce)
13181355
onCompletion(.success(()))
13191356
} catch {
13201357
onCompletion(.failure(error))

0 commit comments

Comments
 (0)