Skip to content

Commit 0058a77

Browse files
authored
Merge pull request #4994 from woocommerce/issue/4383-store-picker-error-actions
2 parents eeb0be6 + dfc942f commit 0058a77

File tree

1 file changed

+48
-13
lines changed

1 file changed

+48
-13
lines changed

WooCommerce/Classes/Authentication/Epilogue/StorePickerError.swift

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,62 @@
11
import SwiftUI
2+
import SafariServices
23

34
/// Hosting controller wrapper for `StorePickerError`
45
///
56
final class StorePickerErrorHostingController: UIHostingController<StorePickerError> {
7+
8+
/// Creates an `StorePickerErrorHostingController` with preconfigured button actions.
9+
///
10+
static func createWithActions(presenting: UIViewController) -> StorePickerErrorHostingController {
11+
let viewController = StorePickerErrorHostingController()
12+
viewController.setActions(troubleshootingAction: {
13+
let safariViewController = SFSafariViewController(url: WooConstants.URLs.troubleshootErrorLoadingData.asURL())
14+
viewController.present(safariViewController, animated: true)
15+
},
16+
contactSupportAction: {
17+
presenting.dismiss(animated: true) {
18+
ZendeskManager.shared.showNewRequestIfPossible(from: presenting)
19+
}
20+
},
21+
dismissAction: {
22+
presenting.dismiss(animated: true)
23+
})
24+
return viewController
25+
}
26+
627
init() {
728
super.init(rootView: StorePickerError())
829
}
930

1031
required dynamic init?(coder aDecoder: NSCoder) {
1132
fatalError("init(coder:) has not been implemented")
1233
}
13-
}
1434

35+
/// Actions are set in a separate function because most of the time, they will require to access `self` to be able to present new view controllers.
36+
///
37+
func setActions(troubleshootingAction: @escaping () -> Void, contactSupportAction: @escaping () -> Void, dismissAction: @escaping () -> Void) {
38+
self.rootView.troubleshootingAction = troubleshootingAction
39+
self.rootView.contactSupportAction = contactSupportAction
40+
self.rootView.dismissAction = dismissAction
41+
}
42+
}
1543

1644
/// Generic Store Picker error view that allows the user to contact support.
1745
///
1846
struct StorePickerError: View {
47+
48+
/// Closure invoked when the "Troubleshooting" button is pressed
49+
///
50+
var troubleshootingAction: () -> Void = {}
51+
52+
/// Closure invoked when the "Contact Support" button is pressed
53+
///
54+
var contactSupportAction: () -> Void = {}
55+
56+
/// Closure invoked when the "Back To Sites" button is pressed
57+
///
58+
var dismissAction: () -> Void = {}
59+
1960
var body: some View {
2061
VStack(alignment: .center, spacing: Layout.mainVerticalSpacing) {
2162
// Title
@@ -32,22 +73,16 @@ struct StorePickerError: View {
3273

3374
VStack(spacing: Layout.buttonsSpacing) {
3475
// Primary Button
35-
Button(Localization.troubleshoot) {
36-
print("Troubleshooting Tips tapped")
37-
}
38-
.buttonStyle(PrimaryButtonStyle())
76+
Button(Localization.troubleshoot, action: troubleshootingAction)
77+
.buttonStyle(PrimaryButtonStyle())
3978

4079
// Secondary button
41-
Button(Localization.contact) {
42-
print("Contact support tapped")
43-
}
44-
.buttonStyle(SecondaryButtonStyle())
80+
Button(Localization.contact, action: contactSupportAction)
81+
.buttonStyle(SecondaryButtonStyle())
4582

4683
// Dismiss button
47-
Button(Localization.back) {
48-
print("Back to site")
49-
}
50-
.buttonStyle(LinkButtonStyle())
84+
Button(Localization.back, action: dismissAction)
85+
.buttonStyle(LinkButtonStyle())
5186
}
5287
}
5388
.padding([.leading, .trailing, .bottom])

0 commit comments

Comments
 (0)