Skip to content

Commit 3df60ab

Browse files
authored
[Woo POS][Surveys] Add CurrentMerchant case, and handle opening survey (#16236)
2 parents d3161bf + 1027420 commit 3df60ab

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

WooCommerce/Classes/Notifications/LocalNotification.swift

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct LocalNotification {
2323
case blazeAbandonedCampaignCreationReminder
2424
case productImageBackgroundUpload
2525
case pointOfSalePotentialMerchant
26+
case pointOfSaleCurrentMerchant
2627
case unknown(siteID: Int64)
2728

2829
var identifier: String {
@@ -35,6 +36,8 @@ struct LocalNotification {
3536
return "product_image_background_upload"
3637
case .pointOfSalePotentialMerchant:
3738
return "point_of_sale_potential_merchant"
39+
case .pointOfSaleCurrentMerchant:
40+
return "point_of_sale_current_merchant"
3841
case let .unknown(siteID):
3942
return "unknown_" + "\(siteID)"
4043
}
@@ -64,8 +67,15 @@ struct LocalNotification {
6467

6568
/// Holds `userInfo` dictionary keys
6669
enum UserInfoKey {
67-
static let storeName = "storeName"
70+
// periphery:ignore - will be removed on PR-16128
6871
static let isIAPAvailable = WooAnalyticsEvent.LocalNotification.Key.isIAPAvailable
72+
static let surveyURL = "surveyURL"
73+
}
74+
75+
// periphery:ignore - real survey links to be added in WOOMOB-1497
76+
enum SurveyURL {
77+
static let pointOfSalePotentialMerchant = "https://automattic.survey.fm/woo-app-general-feedback-test-survey"
78+
static let pointOfSaleCurrentMerchant = "https://automattic.survey.fm/woo-app-general-feedback-test-survey"
6979
}
7080
}
7181

@@ -101,6 +111,9 @@ extension LocalNotification {
101111
case .pointOfSalePotentialMerchant:
102112
title = Localization.PointOfSalePotentialMerchant.title
103113
body = Localization.PointOfSalePotentialMerchant.body
114+
case .pointOfSaleCurrentMerchant:
115+
title = Localization.PointOfSaleCurrentMerchant.title
116+
body = Localization.PointOfSaleCurrentMerchant.body
104117
case .unknown:
105118
title = ""
106119
body = ""
@@ -165,5 +178,17 @@ extension LocalNotification {
165178
comment: "Message body of the local notification sent to potential Point of Sale merchants"
166179
)
167180
}
181+
enum PointOfSaleCurrentMerchant {
182+
static let title = NSLocalizedString(
183+
"localNotification.PointOfSaleCurrentMerchant.title",
184+
value: "How’s POS working for you?",
185+
comment: "Title of the local notification for current POS merchants survey."
186+
)
187+
static let body = NSLocalizedString(
188+
"localNotification.PointOfSaleCurrentMerchant.body",
189+
value: "Share your experience in a quick 2-minute survey and help us improve.",
190+
comment: "Body of the local notification for current POS merchants survey."
191+
)
192+
}
168193
}
169194
}

WooCommerce/Classes/Notifications/PushNotificationsManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ extension PushNotificationsManager {
264264
// Check if this is a local notification
265265
if !content.isRemoteNotification {
266266
// Display local notifications with banner and sound when app is in foreground
267-
return [.banner, .sound]
267+
return [.banner, .sound, .list]
268268
}
269269
}
270270

WooCommerce/Classes/ViewRelated/AppCoordinator.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Combine
22
import Experiments
3+
import SafariServices
34
import UIKit
45
import WordPressAuthenticator
56
import Yosemite
@@ -131,9 +132,31 @@ private extension AppCoordinator {
131132
return
132133
}
133134

135+
let posSurveyScenarios = [
136+
LocalNotification.Scenario.pointOfSalePotentialMerchant.identifier,
137+
LocalNotification.Scenario.pointOfSaleCurrentMerchant.identifier,
138+
]
139+
140+
if posSurveyScenarios.contains(identifier),
141+
let surveyURLString = userInfo[LocalNotification.UserInfoKey.surveyURL] as? String,
142+
let surveyURL = URL(string: surveyURLString) {
143+
presentSurveyWebView(url: surveyURL)
144+
}
145+
134146
analytics.track(event: .LocalNotification.tapped(type: LocalNotification.Scenario.identifierForAnalytics(identifier),
135147
userInfo: userInfo))
136148
}
149+
150+
private func presentSurveyWebView(url: URL) {
151+
let safariViewController = SFSafariViewController(url: url)
152+
// POS mode is presented via a UIHostingController as full-screen view on top of the tabBarController, so
153+
// we have to target the topmost VC if we want to present a web view on top of this when tapping on the local notification.
154+
if let topmostPresentedViewController = window.topmostPresentedViewController {
155+
topmostPresentedViewController.present(safariViewController, animated: true)
156+
} else {
157+
tabBarController.present(safariViewController, animated: true)
158+
}
159+
}
137160
}
138161

139162
// MARK: Theme install

0 commit comments

Comments
 (0)