-
Notifications
You must be signed in to change notification settings - Fork 409
fix(elements): Progressive sign up ticket flow #4318
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@clerk/elements": patch | ||
| --- | ||
|
|
||
| Fixes a bug during a ticket-based sign-up where the form could not be submitted if additional fields were needed. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -343,8 +343,10 @@ export const SignUpRouterMachine = setup({ | |
| }, | ||
| on: { | ||
| 'RESET.STEP': { | ||
| target: 'Start', | ||
| reenter: true, | ||
|
Comment on lines
-346
to
-347
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was causing the child machine to be re-created, and subsequently it would move right back to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There might be a better spot to put this that makes the intent more explicit. The underlying attempt actor was getting canceled, and subsequently re-created, by the reinitialization of the start machine. Changing this to only updating the form ref (which is what triggers |
||
| actions: enqueueActions(({ enqueue, context }) => { | ||
| enqueue('clearFormErrors'); | ||
| enqueue.sendTo('start', { type: 'SET_FORM', formRef: context.formRef }); | ||
| }), | ||
| }, | ||
| NEXT: [ | ||
| { | ||
|
|
@@ -355,6 +357,7 @@ export const SignUpRouterMachine = setup({ | |
| guard: and(['hasTicket', 'statusNeedsContinue']), | ||
| actions: { type: 'navigateInternal', params: { path: '/' } }, | ||
| target: 'Start', | ||
| reenter: true, | ||
| }, | ||
| { | ||
| guard: 'statusNeedsVerification', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| import type { SignUpResource, Web3Strategy } from '@clerk/types'; | ||
| import { assertEvent, enqueueActions, fromPromise, not, sendTo, setup } from 'xstate'; | ||
| import type { DoneActorEvent } from 'xstate'; | ||
| import { and, assertEvent, assign, enqueueActions, fromPromise, not, sendTo, setup } from 'xstate'; | ||
|
|
||
| import { SIGN_UP_DEFAULT_BASE_PATH } from '~/internals/constants'; | ||
| import { ClerkElementsRuntimeError } from '~/internals/errors'; | ||
| import type { FormFields } from '~/internals/machines/form'; | ||
| import type { SetFormEvent } from '~/internals/machines/shared'; | ||
| import { sendToLoading } from '~/internals/machines/shared'; | ||
| import { fieldsToSignUpParams } from '~/internals/machines/sign-up/utils'; | ||
| import { ThirdPartyMachine } from '~/internals/machines/third-party'; | ||
|
|
@@ -48,8 +50,14 @@ export const SignUpStartMachine = setup({ | |
| thirdParty: ThirdPartyMachine, | ||
| }, | ||
| actions: { | ||
| sendToNext: ({ context }) => context.parent.send({ type: 'NEXT' }), | ||
| sendToNext: ({ context, event }) => | ||
| context.parent.send({ type: 'NEXT', resource: (event as unknown as DoneActorEvent<SignUpResource>).output }), | ||
| sendToLoading, | ||
| setFormRef: assign(({ event }) => { | ||
| return { | ||
| formRef: (event as unknown as SetFormEvent).formRef, | ||
| }; | ||
| }), | ||
| setFormDisabledTicketFields: enqueueActions(({ context, enqueue }) => { | ||
| if (!context.ticket) { | ||
| return; | ||
|
|
@@ -90,6 +98,8 @@ export const SignUpStartMachine = setup({ | |
| }, | ||
| }, | ||
| guards: { | ||
| isMissingRequirements: ({ context }) => | ||
| context.parent.getSnapshot().context.clerk?.client?.signUp?.status === 'missing_requirements', | ||
| hasTicket: ({ context }) => Boolean(context.ticket), | ||
| isExampleMode: ({ context }) => Boolean(context.parent.getSnapshot().context.exampleMode), | ||
| }, | ||
|
|
@@ -105,11 +115,20 @@ export const SignUpStartMachine = setup({ | |
| }), | ||
| entry: 'setDefaultFormValues', | ||
| initial: 'Init', | ||
| on: { | ||
| SET_FORM: { | ||
| actions: 'setFormRef', | ||
| }, | ||
| }, | ||
| states: { | ||
| Init: { | ||
| description: | ||
| 'Handle ticket, if present; Else, default to Pending state. Per tickets, `Attempting` makes a `signUp.create` request allowing for an incomplete sign up to contain progressively filled fields on the Start step.', | ||
| always: [ | ||
| { | ||
| guard: and(['hasTicket', 'isMissingRequirements']), | ||
| target: 'Pending', | ||
| }, | ||
|
Comment on lines
+128
to
+131
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the sign up attempt is missing requirements, users need to be able to submit the form, so we move to |
||
| { | ||
| guard: 'hasTicket', | ||
| target: 'Attempting', | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this matters in practice (field shouldn't get updated if disabled), but if this does happen, we want to retain the existing disabled value.