Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show "Verify you email" if needed before creating a site #24281

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions WordPress/Classes/System/WordPressAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class WordPressAppDelegate: UIResponder, UIApplicationDelegate {

if let account = try? WPAccount.lookupDefaultWordPressComAccount(in: ContextManager.shared.mainContext) {
BlogSyncFacade().syncBlogs(for: account, success: { /* Do nothing */ }, failure: { _ in /* Do nothing */ })
AccountService(coreDataStack: ContextManager.shared).updateUserDetails(for: account, success: nil, failure: nil)
}

return true
Expand Down Expand Up @@ -179,6 +180,10 @@ class WordPressAppDelegate: UIResponder, UIApplicationDelegate {
updateFeatureFlags()
updateRemoteConfig()

if let account = try? WPAccount.lookupDefaultWordPressComAccount(in: ContextManager.shared.mainContext) {
AccountService(coreDataStack: ContextManager.shared).updateUserDetails(for: account, success: nil, failure: nil)
}

#if IS_JETPACK
// JetpackWindowManager is only available in the Jetpack target.
if let windowManager = windowManager as? JetpackWindowManager {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ struct AddSiteController {
}

func showDotComSiteCreationScreen() {
if let account = try? WPAccount.lookupDefaultWordPressComAccount(in: ContextManager.shared.mainContext),
account.needsEmailVerification {
VerifyEmailModal.present(on: viewController)
return
}
Comment on lines +18 to +22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is an issue here. The needsEmailVerification will be checked just locally from Core Data. So, if I verify the email and keep the app open, but also if I dismiss the verify email modal and reopen it, we do not check again if the email has been verified, so I'm stuck there. Therefore, I would suggest verifying every time the user taps to create a new site if the email needs verification. Additionally, add a button in VerifyEmailView that allows the user to confirm they verified their email. This way, we can check remotely again if the email has been verified, and this view can be dismissed.


JetpackFeaturesRemovalCoordinator.presentSiteCreationOverlayIfNeeded(in: viewController, source: source, onDidDismiss: { [weak viewController] in
guard JetpackFeaturesRemovalCoordinator.siteCreationPhase() != .two else {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ class JetpackFeaturesRemovalCoordinator: NSObject {
source: String,
onWillDismiss: JetpackOverlayDismissCallback? = nil,
onDidDismiss: JetpackOverlayDismissCallback? = nil) {
if let account = try? WPAccount.lookupDefaultWordPressComAccount(in: ContextManager.shared.mainContext),
account.needsEmailVerification {
VerifyEmailModal.present(on: viewController)
return
}

let phase = siteCreationPhase()
let coordinator = JetpackDefaultOverlayCoordinator()
//
Expand Down
33 changes: 31 additions & 2 deletions WordPress/Classes/ViewRelated/Me/Me Main/VerifyEmailRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,33 @@ final class VerifyEmailCell: UITableViewCell {
}
}

struct VerifyEmailModal: View {
@Environment(\.dismiss) var dismiss

var body: some View {
NavigationStack {
VerifyEmailView(largeTitle: true, fillVerticalSpace: false)
.padding(.bottom, 44)
.toolbar {
ToolbarItem {
Button(SharedStrings.Button.close, role: .cancel) {
dismiss()
}
}
}
}
}

static func present(on viewController: UIViewController) {
let modal = UIHostingController(rootView: Self())
viewController.present(modal, animated: true)
}
}

private struct VerifyEmailView: View {
var largeTitle: Bool = false
var fillVerticalSpace: Bool = true

@StateObject private var viewModel = VerifyEmailViewModel()

var body: some View {
Expand All @@ -44,13 +70,15 @@ private struct VerifyEmailView: View {
Text(Strings.verifyEmailTitle)
}
.foregroundStyle(Color(uiColor: #colorLiteral(red: 0.8392476439, green: 0.2103677094, blue: 0.2182099223, alpha: 1)))
.font(.subheadline.weight(.semibold))
.font((largeTitle ? Font.title : .subheadline).weight(.semibold))

Text(viewModel.state.message)
.font(.callout)
.foregroundStyle(.primary)

Spacer()
if fillVerticalSpace {
Spacer()
}

Button {
viewModel.sendVerificationEmail()
Expand All @@ -67,6 +95,7 @@ private struct VerifyEmailView: View {
}
.buttonStyle(.borderless)
.disabled(!viewModel.state.isButtonEnabled)
.padding(.top, fillVerticalSpace ? 0 : 8)
}
.padding()
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
Expand Down