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

Add example for how to customize Sign Up #552

Merged
merged 28 commits into from
Oct 26, 2021
Merged

Add example for how to customize Sign Up #552

merged 28 commits into from
Oct 26, 2021

Conversation

ericclemmons
Copy link
Contributor

@ericclemmons ericclemmons commented Oct 21, 2021

Issue #, if available: Fixes #246, #248, #254, #260, #279

Description of changes:

Based on #532

  • Introduces createSignUpMachine so we can share dynamic services.

    There will need to be an equivalent for each actor that will eventually accept customized services!

  • Adds React example for preferred_username and a custom "Terms & Conditions".

  • Introduces validateCustomSignUp that internally validateSignUp calls alongside default fields.

  • Introduces (but not documented) validatePreferredUsername and validateConfirmPassword, which are our (internal) services that can eventually be overridden.

  • Removed delete mutations & instead favor an allowlist for signUp.

Docs

sign-up-fields.mp4

Tests

custom-sign-up-fields.mp4

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ericclemmons ericclemmons temporarily deployed to ci October 21, 2021 17:54 Inactive
@ericclemmons ericclemmons temporarily deployed to ci October 21, 2021 17:54 Inactive
@ericclemmons ericclemmons temporarily deployed to ci October 21, 2021 17:54 Inactive
@ericclemmons ericclemmons temporarily deployed to ci October 26, 2021 16:54 Inactive
@ericclemmons ericclemmons temporarily deployed to ci October 26, 2021 16:54 Inactive
@ericclemmons ericclemmons temporarily deployed to ci October 26, 2021 16:54 Inactive
@ericclemmons ericclemmons added Documentation An issue or a feature-request for our Amplify UI Doc site or AWS Amplify docs feature-request Request a new feature labels Oct 26, 2021
Copy link
Contributor

@Milan-Shah Milan-Shah left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@ErikCH ErikCH left a comment

Choose a reason for hiding this comment

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

Thanks for the tour!

Copy link
Contributor

@eddiekeller eddiekeller left a comment

Choose a reason for hiding this comment

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

Take my approval with a grain of salt! Things look good with the walkthrough you showed, but I can't pull down the change locally to test for myself since my laptop apparently doesn't like this project anymore and keeps crashing.

My comments are just nits/idle thoughts. Overall, looks like a solid approach to me.

components: {
// Customize `Authenticator.SignUp.FormFields`
SignUp: {
FormFields() {
Copy link
Contributor

Choose a reason for hiding this comment

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

^^ I think this would definitely be the way to go. Not gonna block on it since this is just an example, but if we want it to be cleaner, I think this is a good choice.

@@ -12,7 +12,9 @@ export function ConfirmSignUp() {
const { isPending, resendCode, submitForm, updateForm } = useAuthenticator();

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const { name, value } = event.target;
let { checked, name, type, value } = event.target;
if (type === 'checkbox' && !checked) value = undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it would be worth having an enum for the possible types here?

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 type showed up because of the HTMLInputElement, if that's what you mean. But this behavior of checked is specific to checkboxes & radio fields.

Comment on lines 11 to +14
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const { name, value } = event.target;
let { checked, name, type, value } = event.target;
if (type === 'checkbox' && !checked) value = undefined;

Copy link
Contributor

Choose a reason for hiding this comment

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

Seeing these changes reminded me of how I wanted to pull out these handleChange functions into a utility file. Making the same edit over and over gets annoying, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was for about 2 minutes, but then I realized that we'd probably actually move the handleChange from the form to individual primitive's onChange event:

https://ui.docs.amplify.aws/ui/primitives/checkboxfield?platform=react#controlled-component

So that's probably the future cleanup to have. I don't know if Angular or Vue will need that, or if those frameworks correctly handle checkboxes? 🤔

@ericclemmons ericclemmons temporarily deployed to ci October 26, 2021 19:40 Inactive
@ericclemmons ericclemmons temporarily deployed to ci October 26, 2021 19:40 Inactive
@ericclemmons ericclemmons temporarily deployed to ci October 26, 2021 19:40 Inactive
@ericclemmons ericclemmons temporarily deployed to ci October 26, 2021 19:41 Inactive
@ericclemmons ericclemmons temporarily deployed to ci October 26, 2021 19:41 Inactive
@ericclemmons ericclemmons temporarily deployed to ci October 26, 2021 19:41 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation An issue or a feature-request for our Amplify UI Doc site or AWS Amplify docs feature-request Request a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Props or option to disable sign-up Submit button until user checks Agreement of site's Terms and Conditions
4 participants