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 social login options in site credentials login mode #849

Merged
merged 13 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
6 changes: 4 additions & 2 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Nodes with values to reuse in the pipeline.
common_params:
plugins: &common_plugins
- automattic/a8c-ci-toolkit#3.1.0
- automattic/a8c-ci-toolkit#3.2.2
env: &common_env
IMAGE_ID: xcode-15.0.1

Expand All @@ -28,7 +28,9 @@ steps:
- label: "🔬 Validate Podspec"
key: "validate"
command: |
validate_podspec --patch-cocoapods
# This library use deprecated Gravatar API in WordPressUI.
# Allow warning for now, until we are ready to migrate to Gravatar SDK.
validate_podspec --patch-cocoapods --allow-warnings
env: *common_env
plugins: *common_plugins

Expand Down
2 changes: 1 addition & 1 deletion .buildkite/publish-pod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ echo "--- :rubygems: Setting up Gems"
install_gems

echo "--- :cocoapods: Publishing Pod to CocoaPods CDN"
publish_pod --patch-cocoapods $PODSPEC_PATH
publish_pod --patch-cocoapods $PODSPEC_PATH --allow-warnings

echo "--- :cocoapods: Publishing Pod to WP Specs Repo"
publish_private_pod --patch-cocoapods $PODSPEC_PATH $SPECS_REPO "$SPEC_REPO_PUBLIC_DEPLOY_KEY"
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ _None._

### Breaking Changes

_None._
- Show social login options in site credentials login mode [#849]

### New Features

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ open class NUXButtonViewController: UIViewController {
bottomButtonConfig = buttonConfigFor(socialService: socialService, onTap: callback)
}

func setupTertiaryButton(attributedTitle: NSAttributedString, isPrimary: Bool = false, accessibilityIdentifier: String? = nil, onTap callback: @escaping CallBackType) {
tertiaryButton?.isHidden = false
tertiaryButtonConfig = NUXButtonConfig(attributedTitle: attributedTitle, isPrimary: isPrimary, accessibilityIdentifier: accessibilityIdentifier, callback: callback)
}

func setupTertiaryButton(title: String, isPrimary: Bool = false, accessibilityIdentifier: String? = nil, onTap callback: @escaping CallBackType) {
tertiaryButton?.isHidden = false
tertiaryButtonConfig = NUXButtonConfig(title: title, isPrimary: isPrimary, accessibilityIdentifier: accessibilityIdentifier, callback: callback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@ class GetStartedViewController: LoginViewController, NUXKeyboardResponder {
}()

private var showsContinueButtonAtTheBottom: Bool {
screenMode == .signInUsingSiteCredentials ||
switch screenMode {
case .signInUsingSiteCredentials:
configuration.enableSocialLogin == false
case .signInUsingWordPressComOrSocialAccounts:
configuration.enableSocialLogin == false
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get rid of the switch since both cases are the same?

Suggested change
switch screenMode {
case .signInUsingSiteCredentials:
configuration.enableSocialLogin == false
case .signInUsingWordPressComOrSocialAccounts:
configuration.enableSocialLogin == false
}
configuration.enableSocialLogin == false

Copy link
Contributor

Choose a reason for hiding this comment

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

We can also remove this bool and update the code as suggested below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Removed the switch case in faa401b

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can also remove this bool and update the code as suggested below.

Answered in #849 (comment)

}

override open var sourceTag: WordPressSupportSourceTag {
Expand Down Expand Up @@ -811,20 +815,32 @@ private extension GetStartedViewController {

buttonViewController.hideShadowView()

// Add a "Continue" button here as the `continueButton` at the top
// will not be displayed for `signInUsingSiteCredentials` screen mode.
//
buttonViewController.setupTopButton(title: ButtonConfiguration.Continue.title,
isPrimary: true,
accessibilityIdentifier: ButtonConfiguration.Continue.accessibilityIdentifier) { [weak self] in
self?.handleSubmitButtonTapped()
}
if configuration.enableSocialLogin {
configureSocialButtons()

// Setup Sign in with site credentials button
buttonViewController.setupBottomButton(attributedTitle: WPStyleGuide.formattedSignInWithSiteCredentialsString(),
isPrimary: false,
accessibilityIdentifier: ButtonConfiguration.SignInWithSiteCredentials.accessibilityIdentifier) { [weak self] in
self?.handleSiteCredentialsButtonTapped()
// Setup Sign in with site credentials button
buttonViewController.setupTertiaryButton(attributedTitle: WPStyleGuide.formattedSignInWithSiteCredentialsString(),
isPrimary: false,
accessibilityIdentifier: ButtonConfiguration.SignInWithSiteCredentials.accessibilityIdentifier) { [weak self] in
self?.handleSiteCredentialsButtonTapped()
}
} else {
// Add a "Continue" button here as the `continueButton` at the top will be hidden
//
if showsContinueButtonAtTheBottom {
buttonViewController.setupTopButton(title: ButtonConfiguration.Continue.title,
isPrimary: true,
accessibilityIdentifier: ButtonConfiguration.Continue.accessibilityIdentifier) { [weak self] in
self?.handleSubmitButtonTapped()
}
}

// Setup Sign in with site credentials button
buttonViewController.setupBottomButton(attributedTitle: WPStyleGuide.formattedSignInWithSiteCredentialsString(),
isPrimary: false,
accessibilityIdentifier: ButtonConfiguration.SignInWithSiteCredentials.accessibilityIdentifier) { [weak self] in
self?.handleSiteCredentialsButtonTapped()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can simplify this for readability:

if configuration.enableSocialLogin {
    configureSocialButtons()
} else {
    buttonViewController.setupTopButton(title: ButtonConfiguration.Continue.title, 
                                        isPrimary: true, 
                                        accessibilityIdentifier: ButtonConfiguration.Continue.accessibilityIdentifier) { [weak self] in
        self?.handleSubmitButtonTapped()
    }
}


// Setup Sign in with site credentials button
buttonViewController.setupBottomButton(attributedTitle: WPStyleGuide.formattedSignInWithSiteCredentialsString(), 
                                       isPrimary: false, 
                                       accessibilityIdentifier: ButtonConfiguration.SignInWithSiteCredentials.accessibilityIdentifier) { [weak self] in
     self?.handleSiteCredentialsButtonTapped()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The site credentials button needs to be set in the tertiary button when social login is enabled in config. (It is not always the bottom button) So the above code won't work.

Also, keeping the showsContinueButtonAtTheBottom boolean helps to maintain code readability in other places.

}
}

Expand All @@ -835,12 +851,14 @@ private extension GetStartedViewController {

buttonViewController.hideShadowView()

// Add a "Continue" button here as the `continueButton` at the top will be hidden
//
buttonViewController.setupTopButton(title: ButtonConfiguration.Continue.title,
isPrimary: true,
accessibilityIdentifier: ButtonConfiguration.Continue.accessibilityIdentifier) { [weak self] in
self?.handleSubmitButtonTapped()
if showsContinueButtonAtTheBottom {
// Add a "Continue" button here as the `continueButton` at the top will be hidden
//
buttonViewController.setupTopButton(title: ButtonConfiguration.Continue.title,
isPrimary: true,
accessibilityIdentifier: ButtonConfiguration.Continue.accessibilityIdentifier) { [weak self] in
self?.handleSubmitButtonTapped()
}
}
}

Expand Down