-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add domain registration card on dashboard (#20730)
- Loading branch information
1 parent
17ad862
commit c7bf2d3
Showing
7 changed files
with
140 additions
and
9 deletions.
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
...s/Classes/ViewRelated/Blog/Blog Dashboard/Cards/DashboardDomainRegistrationCardCell.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import UIKit | ||
import WordPressFlux | ||
|
||
final class DashboardDomainRegistrationCardCell: BaseDashboardDomainsCardCell { | ||
|
||
// MARK: - View Model | ||
|
||
override var viewModel: DashboardDomainsCardViewModel { | ||
return cardViewModel | ||
} | ||
|
||
private lazy var cardViewModel: DashboardDomainsCardViewModel = { | ||
let onViewTap: () -> Void = { [weak self] in | ||
self?.cardTapped() | ||
} | ||
let onHideThisTap: UIActionHandler = { [weak self] _ in | ||
self?.hideCardTapped() | ||
} | ||
return DashboardDomainsCardViewModel( | ||
strings: .init( | ||
title: Strings.title, | ||
description: Strings.content, | ||
hideThis: Strings.hideThis, | ||
source: Strings.source | ||
), | ||
onViewTap: onViewTap, | ||
onHideThisTap: onHideThisTap | ||
) | ||
}() | ||
|
||
// MARK: - User Interaction | ||
|
||
private func cardTapped() { | ||
guard let props = makeUnwrappedProperties() else { | ||
return | ||
} | ||
WPAnalytics.track(.domainCreditRedemptionTapped) | ||
DomainsDashboardCoordinator.presentDomainsSuggestions( | ||
in: props.presentingViewController, | ||
source: Strings.source, | ||
blog: props.blog | ||
) | ||
} | ||
|
||
private func hideCardTapped() { | ||
guard let props = makeUnwrappedProperties() else { | ||
return | ||
} | ||
let service = BlogDashboardPersonalizationService(siteID: props.siteID.intValue) | ||
service.setEnabled(false, for: .domainRegistration) | ||
} | ||
|
||
// MARK: - Constants | ||
|
||
private static var hasLoggedDomainCreditPromptShownEvent: Bool = false | ||
|
||
// MARK: - View Lifecycle | ||
|
||
override func didMoveToSuperview() { | ||
super.didMoveToSuperview() | ||
guard !Self.hasLoggedDomainCreditPromptShownEvent else { | ||
return | ||
} | ||
WPAnalytics.track(WPAnalyticsStat.domainCreditPromptShown) | ||
Self.hasLoggedDomainCreditPromptShownEvent = true | ||
} | ||
|
||
// MARK: - Helpers | ||
|
||
private func makeUnwrappedProperties() -> Unwrapped? { | ||
return Unwrapped(presentingViewController: presentingViewController, blog: blog) | ||
} | ||
|
||
// MARK: - Supporting Types | ||
|
||
/// Encapsulates the unwrapping logic and returns nil if one of the passed in parameters is nil. | ||
private struct Unwrapped { | ||
let presentingViewController: BlogDashboardViewController | ||
let blog: Blog | ||
let siteID: NSNumber | ||
|
||
init?(presentingViewController: BlogDashboardViewController?, | ||
blog: Blog?) { | ||
guard let presentingViewController, | ||
let blog, | ||
let siteID = blog.dotComID else { | ||
return nil | ||
} | ||
self.presentingViewController = presentingViewController | ||
self.blog = blog | ||
self.siteID = siteID | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Extensions | ||
|
||
extension DashboardDomainRegistrationCardCell { | ||
|
||
private enum Strings { | ||
static let title = NSLocalizedString( | ||
"Register Domain", | ||
comment: "Action to redeem domain credit." | ||
) | ||
static let content = NSLocalizedString( | ||
"All WordPress.com plans include a custom domain name. Register your free premium domain now.", | ||
comment: "Information about redeeming domain credit on site dashboard." | ||
) | ||
static let hideThis = NSLocalizedString( | ||
"domain.dashboard.card.menu.hide", | ||
value: "Hide this", | ||
comment: "Title for a menu action in the context menu on the Jetpack install card." | ||
) | ||
static let source = "domain_registration_dashboard_card" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
WordPress/Classes/ViewRelated/Domains/Domain credit/DomainCreditEligibilityChecker.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class DomainCreditEligibilityChecker: NSObject { | ||
@objc static func canRedeemDomainCredit(blog: Blog) -> Bool { | ||
return (blog.isHostedAtWPcom || blog.isAtomic()) && blog.hasDomainCredit && JetpackFeaturesRemovalCoordinator.jetpackFeaturesEnabled() | ||
return blog.canRegisterDomainWithPaidPlan && JetpackFeaturesRemovalCoordinator.jetpackFeaturesEnabled() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters