Skip to content

Commit

Permalink
refactor(elements): Merge SignIn/SignUp changes (#4314)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmilewski authored Oct 10, 2024
1 parent 6520328 commit 4dafbc6
Show file tree
Hide file tree
Showing 21 changed files with 849 additions and 1,281 deletions.
57 changes: 25 additions & 32 deletions packages/elements/src/internals/machines/shared/shared.actions.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import type { SignInStrategy } from '@clerk/types';

import type {
SignUpContinueContext,
SignUpContinueEvents,
SignUpStartContext,
SignUpStartRedirectEvent,
SignUpVerificationContext,
SignUpVerificationEvents,
} from '~/internals/machines/sign-up';
import type { SignUpVerificationEvents } from '~/internals/machines/sign-up';
import type { ThirdPartyMachineContext, ThirdPartyMachineEvent } from '~/internals/machines/third-party';
import type { BaseRouterLoadingStep } from '~/internals/machines/types';

type SendToLoadingProps = {
context: ThirdPartyMachineContext | SignUpStartContext | SignUpContinueContext | SignUpVerificationContext;
event: ThirdPartyMachineEvent | SignUpStartRedirectEvent | SignUpContinueEvents | SignUpVerificationEvents;
context: ThirdPartyMachineContext;
event: ThirdPartyMachineEvent | SignUpVerificationEvents;
};

export function sendToLoading({ context, event }: SendToLoadingProps): void {
Expand Down Expand Up @@ -51,29 +44,29 @@ export function sendToLoading({ context, event }: SendToLoadingProps): void {
step,
strategy,
});
} else if (context.loadingStep === 'continue') {
step = 'continue';
strategy = undefined;
action = 'action' in event ? event.action : undefined;
context.parent.send({
type: 'LOADING',
isLoading: true,
step,
strategy,
action,
});
} else if (context.loadingStep === 'start') {
step = 'start';
strategy = undefined;
action = 'action' in event ? event.action : undefined;
// } else if (context.loadingStep === 'continue') {
// step = 'continue';
// strategy = undefined;
// action = 'action' in event ? event.action : undefined;
// context.parent.send({
// type: 'LOADING',
// isLoading: true,
// step,
// strategy,
// action,
// });
// } else if (context.loadingStep === 'start') {
// step = 'start';
// strategy = undefined;
// action = 'action' in event ? event.action : undefined;

context.parent.send({
type: 'LOADING',
isLoading: true,
step,
strategy,
action,
});
// context.parent.send({
// type: 'LOADING',
// isLoading: true,
// step,
// strategy,
// action,
// });
} else {
step = context.loadingStep;
strategy = undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const SignInRouterMachine = setup({
delayedReset: raise({ type: 'RESET' }, { delay: 3000 }), // Reset machine after 3s delay.
// Continues to the next valid step in the sign-in flow
goToNextStep: raise(({ event }) => {
assertActorEventDone(event);
assertActorEventDone<SignInResource>(event);
return { type: 'NEXT', resource: event?.output } as SignInRouterNextEvent;
}),
// goToNextStep: enqueueActions(({ context, enqueue, event }) => {
Expand Down
20 changes: 4 additions & 16 deletions packages/elements/src/internals/machines/sign-in/router.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,11 @@ export type SignInRouterSessionSetActiveEvent = {
id: string;
};

export type SignInVerificationSubmitEvent = {
type: 'SUBMIT';
action: 'submit';
};
export type SignInVerificationFactorUpdateEvent = {
type: 'STRATEGY.UPDATE';
factor: SignInFactor | undefined;
};
export type SignInVerificationSubmitEvent = { type: 'SUBMIT'; action: 'submit' };
export type SignInVerificationFactorUpdateEvent = { type: 'STRATEGY.UPDATE'; factor: SignInFactor | undefined };
export type SignInVerificationRetryEvent = { type: 'RETRY' };
export type SignInVerificationStrategyRegisterEvent = {
type: 'STRATEGY.REGISTER';
factor: SignInStrategyName;
};
export type SignInVerificationStrategyUnregisterEvent = {
type: 'STRATEGY.UNREGISTER';
factor: SignInStrategyName;
};
export type SignInVerificationStrategyRegisterEvent = { type: 'STRATEGY.REGISTER'; factor: SignInStrategyName };
export type SignInVerificationStrategyUnregisterEvent = { type: 'STRATEGY.UNREGISTER'; factor: SignInStrategyName };

export interface SignInRouterInitEvent extends BaseRouterInput {
type: 'INIT';
Expand Down
14 changes: 14 additions & 0 deletions packages/elements/src/internals/machines/sign-up/actors/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export { startAttempt } from './start-attempt';
export { startAttemptWeb3 } from './start-attempt-web3';
export { verificationAttempt } from './verification-attempt';
export { verificationAttemptEmailLink } from './verification-attempt-email-link';
export { verificationPrepare } from './verification-prepare';

export type { StartAttemptInput, StartAttemptOutput, StartAttemptParams } from './start-attempt';
export type { StartAttemptWeb3Input, StartAttemptWeb3Output } from './start-attempt-web3';
export type { VerificationAttemptInput, VerificationAttemptOutput } from './verification-attempt';
export type {
VerificationAttemptEmailLinkEvents,
VerificationAttemptEmailLinkInput,
} from './verification-attempt-email-link';
export type { VerificationPrepareInput, VerificationPrepareOutput } from './verification-prepare';
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ClerkElementsRuntimeError } from '~/internals/errors';
export type StartAttemptWeb3Input = { clerk: LoadedClerk; strategy: Web3Strategy };
export type StartAttemptWeb3Output = SignUpResource;

export const startAttempt = fromPromise<StartAttemptWeb3Output, StartAttemptWeb3Input>(({ input }) => {
export const startAttemptWeb3 = fromPromise<StartAttemptWeb3Output, StartAttemptWeb3Input>(({ input }) => {
const { clerk, strategy } = input;

if (strategy === 'web3_metamask_signature') {
Expand Down
110 changes: 0 additions & 110 deletions packages/elements/src/internals/machines/sign-up/continue.machine.ts

This file was deleted.

43 changes: 0 additions & 43 deletions packages/elements/src/internals/machines/sign-up/continue.types.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/elements/src/internals/machines/sign-up/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
export { SignUpContinueMachine, SignUpContinueMachineId } from './continue.machine';
export { SignUpRouterMachine, SignUpRouterMachineId } from './router.machine';
export { SignUpStartMachine, SignUpStartMachineId } from './start.machine';
export { SignUpVerificationMachine, SignUpVerificationMachineId } from './verification.machine';

export type { TSignUpContinueMachine } from './continue.machine';
export type { TSignUpRouterMachine } from './router.machine';
export type { TSignUpStartMachine } from './start.machine';
export type { TSignUpVerificationMachine } from './verification.machine';

export type * from './continue.types';
export type * from './router.types';
export type * from './start.types';
export type * from './verification.types';
Loading

0 comments on commit 4dafbc6

Please sign in to comment.