Skip to content

Commit 8d6cb77

Browse files
committed
Add LocalNotification initializer for each scenario.
1 parent 77fa1a3 commit 8d6cb77

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

WooCommerce/Classes/Authentication/AuthenticationManager.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -421,14 +421,7 @@ private extension AuthenticationManager {
421421
let wooAuthError = AuthenticationError.make(with: error)
422422
switch wooAuthError {
423423
case .notWPSite, .notValidAddress:
424-
let notification = LocalNotification(title: NSLocalizedString("Problems with logging in?",
425-
comment: "Local notification title when the user encounters an error logging in " +
426-
"with site address."),
427-
body: NSLocalizedString("Get some help!",
428-
comment: "Local notification body when the user encounters an error logging in " +
429-
"with site address."),
430-
scenario: .loginSiteAddressError,
431-
actions: .init(category: .loginError, actions: [.contactSupport]))
424+
let notification = LocalNotification(scenario: .loginSiteAddressError)
432425
ServiceLocator.pushNotesManager.cancelLocalNotification(scenarios: [notification.scenario])
433426
ServiceLocator.pushNotesManager.requestLocalNotification(notification,
434427
// 24 hours from now.

WooCommerce/Classes/Notifications/LocalNotification.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,26 @@ struct LocalNotification {
3737
}
3838
}
3939
}
40+
41+
extension LocalNotification {
42+
init(scenario: Scenario) {
43+
switch scenario {
44+
case .loginSiteAddressError:
45+
self.init(title: Localization.errorLoggingInTitle,
46+
body: Localization.errorLoggingInBody,
47+
scenario: .loginSiteAddressError,
48+
actions: .init(category: .loginError, actions: [.contactSupport]))
49+
}
50+
}
51+
}
52+
53+
private extension LocalNotification {
54+
enum Localization {
55+
static let errorLoggingInTitle = NSLocalizedString("Problems with logging in?",
56+
comment: "Local notification title when the user encounters an error logging in " +
57+
"with site address.")
58+
static let errorLoggingInBody = NSLocalizedString("Get some help!",
59+
comment: "Local notification body when the user encounters an error logging in " +
60+
"with site address.")
61+
}
62+
}

0 commit comments

Comments
 (0)