Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
23.6
-----

* [***] [internal][Jetpack-only] [***] Added paid domain selection, plan selection, and checkout screens in site creation flow [#21688]

23.5
-----
Expand All @@ -11,7 +12,6 @@
* [*] (Internal) Remove .nativePhotoPicker feature flag and the disabled code [#21681](https://github.com/wordpress-mobile/WordPress-iOS/pull/21681)
* [*] [WordPress-only] fixes an issue where users attempting to create a .com site in the post-sign-up flow are presented with two consecutive overlays. [#21752]
* [**] [Jetpack-only] Reader: Improvement of core UI elements, including feed cards, tag and site headers, buttons and recommendation sections. [#21772]
* [***] [internal][Jetpack-only] [***] Added paid domain selection, plan selection, and checkout screens in site creation flow [#21688]

23.4
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ final class PlanStep: WizardStep {

internal var content: UIViewController {
let viewModel = PlanWizardContentViewModel(siteCreator: creator)
return PlanWizardContent(viewModel: viewModel) { [weak self] planId in
return PlanWizardContent(viewModel: viewModel) { [weak self] planId, domainName in
self?.creator.planId = planId
self?.creator.addressFromPlanSelection = domainName
self?.delegate?.nextStep()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import UIKit

final class PlanWizardContent: WebKitViewController {
typealias PlanSelectionCallback = (Int?) -> Void
typealias PlanId = Int
typealias DomainName = String
typealias PlanSelectionCallback = (PlanId?, DomainName?) -> Void

private let viewModel: PlanWizardContentViewModel
private let completion: PlanSelectionCallback
Expand Down Expand Up @@ -29,7 +31,7 @@ final class PlanWizardContent: WebKitViewController {
}

if viewModel.isPlanSelected(url) {
completion(viewModel.selectedPlanId(from: url))
completion(viewModel.selectedPlanId(from: url), viewModel.selectedDomainName(from: url))
decisionHandler(.cancel)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct PlanWizardContentViewModel {
var queryItems: [URLQueryItem] = []

if let domainSuggestion = siteCreator.address, !domainSuggestion.isFree {
queryItems.append(.init(name: Constants.paidDomainNameParameter, value: domainSuggestion.domainName))
queryItems.append(.init(name: Constants.InputParameter.paidDomainName, value: domainSuggestion.domainName))
}

components.queryItems = queryItems
Expand All @@ -25,22 +25,33 @@ struct PlanWizardContentViewModel {
}

func selectedPlanId(from url: URL) -> Int? {
guard let planId = parameterValue(from: url, key: Constants.planIdParameter) else {
guard let planId = parameterValue(from: url, key: Constants.OutputParameter.planId) else {
return nil
}

return Int(planId)
}

func selectedPlanSlug(from url: URL) -> String? {
return parameterValue(from: url, key: Constants.planSlugParameter)
return parameterValue(from: url, key: Constants.OutputParameter.planSlug)
}

enum Constants {
func selectedDomainName(from url: URL) -> String? {
return parameterValue(from: url, key: Constants.OutputParameter.domainName)
}

struct Constants {
static let plansWebAddress = "https://wordpress.com/jetpack-app/plans"
static let planIdParameter = "plan_id"
static let planSlugParameter = "plan_slug"
static let paidDomainNameParameter = "paid_domain_name"

struct InputParameter {
static let paidDomainName = "paid_domain_name"
}

struct OutputParameter {
static let planId = "plan_id"
static let planSlug = "plan_slug"
static let domainName = "domain_name"
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@
import Foundation
import WordPressKit

extension DomainSuggestion {
var subdomain: String {
return domainName.components(separatedBy: ".").first ?? ""
}

var isWordPress: Bool {
return domainName.contains("wordpress.com")
}
}

// MARK: - SiteCreationRequestAssemblyError

enum SiteCreationRequestAssemblyError: Error {
Expand All @@ -31,6 +21,8 @@ final class SiteCreator {
var information: SiteInformation?
var address: DomainSuggestion?
var planId: Int?
/// Users can opt for a free domain name in Plans selection
var addressFromPlanSelection: String?

/// Generates the final object that will be posted to the backend
///
Expand Down Expand Up @@ -66,19 +58,43 @@ final class SiteCreator {
domainPurchasingEnabled && planId != nil
}

/// Returns the domain suggestion if there's one,
/// Returns domain name selected in plan seletion
/// - otherwise the domain suggestion selected in domain view if there's one,
/// - otherwise a site name if there's one,
/// - otherwise an empty string.
private var siteURLString: String {

guard let domainSuggestion = address else {
guard let domainName = addressFromPlanSelection ?? address?.domainName else {
return information?.title ?? ""
}
return domainSuggestion.isWordPress ? domainSuggestion.subdomain : domainSuggestion.domainName


return domainName.isWordPress ? domainName.subdomain : domainName
}

private enum Strings {
static let defaultDesignSlug = "default"
static let siteCreationFlowForNoAddress = "with-design-picker"
}
}

// MARK: - Helper Extensions

extension String {
var subdomain: String {
return components(separatedBy: ".").first ?? ""
}

var isWordPress: Bool {
return contains("wordpress.com")
}
}

extension DomainSuggestion {
var subdomain: String {
return domainName.subdomain
}

var isWordPress: Bool {
return domainName.isWordPress
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ final class PlanWizardContentViewModelTests: XCTestCase {

func testIsPlanSelectedWithPlanSlugParameters() {
var components = URLComponents(string: PlanWizardContentViewModel.Constants.plansWebAddress)!
components.queryItems = [.init(name: PlanWizardContentViewModel.Constants.planSlugParameter, value: "free_plan")]
components.queryItems = [.init(name: PlanWizardContentViewModel.Constants.OutputParameter.planSlug, value: "free_plan")]

XCTAssertTrue(sut.isPlanSelected(components.url!))
}

func testIsPlanSelectedWithPlanSlugAndPlanIdParameters() {
var components = URLComponents(string: PlanWizardContentViewModel.Constants.plansWebAddress)!
components.queryItems = [
.init(name: PlanWizardContentViewModel.Constants.planSlugParameter, value: "paid_plan"),
.init(name: PlanWizardContentViewModel.Constants.planIdParameter, value: "1009")
.init(name: PlanWizardContentViewModel.Constants.OutputParameter.planSlug, value: "paid_plan"),
.init(name: PlanWizardContentViewModel.Constants.OutputParameter.planId, value: "1009")
]

XCTAssertTrue(sut.isPlanSelected(components.url!))
Expand All @@ -46,7 +46,7 @@ final class PlanWizardContentViewModelTests: XCTestCase {

func testSelectedPlanId() {
var components = URLComponents(string: PlanWizardContentViewModel.Constants.plansWebAddress)!
components.queryItems = [.init(name: PlanWizardContentViewModel.Constants.planIdParameter, value: "125")]
components.queryItems = [.init(name: PlanWizardContentViewModel.Constants.OutputParameter.planId, value: "125")]

XCTAssertEqual(sut.selectedPlanId(from: components.url!), 125)
}
Expand All @@ -55,7 +55,7 @@ final class PlanWizardContentViewModelTests: XCTestCase {
var components = URLComponents(string: PlanWizardContentViewModel.Constants.plansWebAddress)!
components.queryItems = [
.init(name: "parameter", value: "5"),
.init(name: PlanWizardContentViewModel.Constants.planIdParameter, value: "125"),
.init(name: PlanWizardContentViewModel.Constants.OutputParameter.planId, value: "125"),
.init(name: "parameter2", value: "abc")
]

Expand All @@ -70,7 +70,7 @@ final class PlanWizardContentViewModelTests: XCTestCase {

let url = URLComponents(url: sut.url, resolvingAgainstBaseURL: true)

let parameter = url?.queryItems?.first(where: { $0.name == PlanWizardContentViewModel.Constants.paidDomainNameParameter })
let parameter = url?.queryItems?.first(where: { $0.name == PlanWizardContentViewModel.Constants.InputParameter.paidDomainName })
XCTAssertEqual(parameter?.value, domainName)
}

Expand All @@ -80,7 +80,7 @@ final class PlanWizardContentViewModelTests: XCTestCase {

let url = URLComponents(url: sut.url, resolvingAgainstBaseURL: true)

let parameter = url?.queryItems?.first(where: { $0.name == PlanWizardContentViewModel.Constants.paidDomainNameParameter })
let parameter = url?.queryItems?.first(where: { $0.name == PlanWizardContentViewModel.Constants.InputParameter.paidDomainName })
XCTAssertEqual(parameter, nil)
}
}