diff --git a/WordPress/Classes/ViewRelated/Site Creation/Final Assembly/SiteAssemblyWizardContent.swift b/WordPress/Classes/ViewRelated/Site Creation/Final Assembly/SiteAssemblyWizardContent.swift index 23308ad3e444..dd40bb58336b 100644 --- a/WordPress/Classes/ViewRelated/Site Creation/Final Assembly/SiteAssemblyWizardContent.swift +++ b/WordPress/Classes/ViewRelated/Site Creation/Final Assembly/SiteAssemblyWizardContent.swift @@ -159,12 +159,17 @@ final class SiteAssemblyWizardContent: UIViewController { case .success(let domain): self.contentView.siteName = domain self.contentView.isFreeDomain = false - case .failure: + self.contentView.status = .succeeded + case .failure(let error): self.contentView.isFreeDomain = true - // TODO: We should discuss how to handle domain purchasing errors - break + switch error { + case .unsupportedRedirect, .internal, .invalidInput, .other: + self.installDomainCheckoutErrorStateViewController(domain: domain, site: site) + self.contentView.status = .failed + case .canceled: + self.contentView.status = .succeeded + } } - self.contentView.status = .succeeded } } @@ -185,30 +190,63 @@ final class SiteAssemblyWizardContent: UIViewController { private func installErrorStateViewController(with type: ErrorStateViewType) { var configuration = ErrorStateViewConfiguration.configuration(type: type) - configuration.contactSupportActionHandler = { [weak self] in + configuration.retryActionHandler = { [weak self] in guard let self = self else { return } - self.contactSupportTapped() + self.retryTapped() } + self.installErrorStateViewController(with: configuration) + } + + private func installDomainCheckoutErrorStateViewController(domain: DomainSuggestion, site: Blog) { + var configuration = ErrorStateViewConfiguration.configuration(type: .domainCheckoutFailed) + configuration.retryActionHandler = { [weak self] in - guard let self = self else { + guard let self else { return } - self.retryTapped() + self.contentView.status = .inProgress + self.attemptDomainPurchasing(domain: domain, site: site) } - configuration.dismissalActionHandler = { [weak self] in - guard let self = self else { - return + self.installErrorStateViewController(with: configuration) + } + + private func installErrorStateViewController(with configuration: ErrorStateViewConfiguration) { + var configuration = configuration + + if configuration.contactSupportActionHandler == nil { + configuration.contactSupportActionHandler = { [weak self] in + guard let self = self else { + return + } + self.contactSupportTapped() } - self.dismissTapped() } + if configuration.dismissalActionHandler == nil { + configuration.dismissalActionHandler = { [weak self] in + guard let self = self else { + return + } + self.dismissTapped() + } + } + + // Remove previous error state view controller + if let errorStateViewController { + errorStateViewController.willMove(toParent: nil) + errorStateViewController.view?.removeFromSuperview() + errorStateViewController.removeFromParent() + errorStateViewController.didMove(toParent: nil) + } + + // Install new error state view controller let errorStateViewController = ErrorStateViewController(with: configuration) - contentView.errorStateView = errorStateViewController.view + self.contentView.errorStateView = errorStateViewController.view errorStateViewController.willMove(toParent: self) addChild(errorStateViewController) @@ -223,9 +261,8 @@ final class SiteAssemblyWizardContent: UIViewController { private extension SiteAssemblyWizardContent { func contactSupportTapped() { // TODO : capture analytics event via #10335 - let supportVC = SupportTableViewController() - supportVC.showFromTabBar() + supportVC.show(from: self) } func dismissTapped(viaDone: Bool = false, completion: (() -> Void)? = nil) { diff --git a/WordPress/Classes/ViewRelated/Site Creation/Shared/ErrorStates/ErrorStateViewConfiguration.swift b/WordPress/Classes/ViewRelated/Site Creation/Shared/ErrorStates/ErrorStateViewConfiguration.swift index 7dd9b61d5d03..143cc5f0c91b 100644 --- a/WordPress/Classes/ViewRelated/Site Creation/Shared/ErrorStates/ErrorStateViewConfiguration.swift +++ b/WordPress/Classes/ViewRelated/Site Creation/Shared/ErrorStates/ErrorStateViewConfiguration.swift @@ -13,6 +13,7 @@ enum ErrorStateViewType { case general case networkUnreachable case siteLoading + case domainCheckoutFailed } // MARK: ErrorViewConfiguration @@ -53,7 +54,7 @@ struct ErrorStateViewConfiguration { extension ErrorStateViewType { var localizedTitle: String { switch self { - case .general, .siteLoading: + case .general, .siteLoading, .domainCheckoutFailed: return NSLocalizedString("There was a problem", comment: "This primary message message is displayed if a user encounters a general error.") case .networkUnreachable: @@ -69,6 +70,12 @@ extension ErrorStateViewType { comment: "This secondary message is displayed if a user encounters a general error.") case .networkUnreachable: return nil + case .domainCheckoutFailed: + return NSLocalizedString( + "site.creation.assembly.step.domain.checkout.error.subtitle", + value: "Your website has been created successfully, but we encountered an issue while preparing your custom domain for checkout. Please try again or contact support for assistance.", + comment: "The error message to show in the 'Site Creation > Assembly Step' when the domain checkout fails for unknown reasons." + ) } } } diff --git a/WordPress/Classes/ViewRelated/Support/SupportTableViewController.swift b/WordPress/Classes/ViewRelated/Support/SupportTableViewController.swift index f6a34a5be7ad..e5fd018e0cab 100644 --- a/WordPress/Classes/ViewRelated/Support/SupportTableViewController.swift +++ b/WordPress/Classes/ViewRelated/Support/SupportTableViewController.swift @@ -71,6 +71,18 @@ class SupportTableViewController: UITableViewController { createUserActivity() } + func show(from presentingViewController: UIViewController) { + let navigationController = UINavigationController.init(rootViewController: self) + + if WPDeviceIdentification.isiPad() { + navigationController.modalTransitionStyle = .crossDissolve + navigationController.modalPresentationStyle = .formSheet + } + + presentingViewController.present(navigationController, animated: true) + } + + // TODO: Refactor this method to use the general `show(from:)` method @objc func showFromTabBar() { let navigationController = UINavigationController.init(rootViewController: self)