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

feat(auth-modal): onSuccess, onDismiss, and onError callbacks #3481

Merged
merged 3 commits into from
Oct 18, 2024

Conversation

miguelpeixe
Copy link
Member

@miguelpeixe miguelpeixe commented Oct 17, 2024

All Submissions:

Changes proposed in this Pull Request:

Adds support for a callback when the auth modal closes without authenticating.

How to test the changes in this Pull Request:

Context and instructions at Automattic/newspack-blocks#1908

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@miguelpeixe miguelpeixe added [Status] Needs Review The issue or pull request needs to be reviewed ras-acc testing labels Oct 17, 2024
@miguelpeixe miguelpeixe self-assigned this Oct 17, 2024
@miguelpeixe miguelpeixe requested a review from a team as a code owner October 17, 2024 14:58
Copy link
Contributor

@chickenn00dle chickenn00dle left a comment

Choose a reason for hiding this comment

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

Approving this one but just noting I had a non-blocking nit/question about this here: Automattic/newspack-blocks#1908 (comment)

@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Oct 17, 2024
@miguelpeixe miguelpeixe changed the title feat(auth-modal): onClose callback feat(auth-modal): onSuccess, onDismiss, and onError callbacks Oct 18, 2024
if ( config.callback ) {
config.callback();
if ( config.onSuccess && typeof config.onSuccess === 'function' ) {
config.onSuccess();
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-blocking suggestion: You can remove the need for these checks throughout the PR (config.onSuccess && ... === 'function') by just calling config?.onSuccess?.()

Copy link
Member Author

@miguelpeixe miguelpeixe Oct 18, 2024

Choose a reason for hiding this comment

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

This will still throw an error if onSuccess is truthy an not a function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, this bit should cause this to resolve as undefined when not a function: onSuccess?.()

Copy link
Member Author

Choose a reason for hiding this comment

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

I double-checked running const notAFn = true; notAFn?.(); in the console and it errored.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right. This won't work on every browser, but our build process will be sure to compile this to something universally compatible. This isn't a blocker though so feel free to keep what you have!

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd rather keep it because the optional chaining operator will not do type validation.

window.location.href = redirect;
};
}

openAuthModal( {
callback,
onSuccess,
onError: onSuccess,
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's rename the callback to something other than onSuccess since its meant to be called even when auth is unsuccessful. callback seemed fine to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated in ba87938

@miguelpeixe
Copy link
Member Author

Thanks for reviewing, @chickenn00dle!

@miguelpeixe miguelpeixe merged commit b81bcbd into epic/ras-acc Oct 18, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ras-acc testing [Status] Approved The pull request has been reviewed and is ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants