Skip to content

Commit 0bb524a

Browse files
authored
refactor(elements): Refactor code to relevant locations (clerk#2513)
* refactor(elements): Move code to relevant sections in the codebase * chore(elements): Add changeset * chore(elements): Force slash in import paths
1 parent 57e0972 commit 0bb524a

20 files changed

Lines changed: 74 additions & 80 deletions

.changeset/moody-pears-trade.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/elements/.eslintrc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module.exports = {
22
root: true,
33
extends: ['custom/browser', 'custom/typescript', 'custom/jest', 'custom/react'],
4-
// rules: {},
4+
rules: {
5+
'import/no-unresolved': [2, { ignore: ['^~/'] }],
6+
},
57
// overrides: [],
68
};

packages/elements/src/common/strategy.tsx

Lines changed: 0 additions & 25 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use client';
2-
import { useNextRouter } from './internals/router';
2+
3+
import { useNextRouter } from '~/react/router/next';
34

45
/** Common Components */
5-
export { Errors, Field, FieldState, Form, Input, Label, Submit } from './common/form';
6-
export { SocialProviders } from './common/social-providers';
6+
export { Errors, Field, FieldState, Form, Input, Label, Submit } from '~/react/common/form';
7+
export { SocialProviders } from '~/react/common/social-providers';
78

89
/** Sign In Components */
910
export {
@@ -14,8 +15,8 @@ export {
1415
SignInSSOCallback,
1516
SignInStrategies,
1617
SignInStrategy,
17-
} from './sign-in';
18+
} from '~/react/sign-in';
1819

1920
/** Hooks */
20-
export { useSignInFlow, useSignInFlowSelector } from './internals/machines/sign-in.context';
21+
export { useSignInFlow, useSignInFlowSelector } from '~/internals/machines/sign-in.context';
2122
export { useNextRouter };

packages/elements/src/internals/machines/form.context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createActorContext } from '@xstate/react';
22
import type { SnapshotFrom } from 'xstate';
33

4-
import { FormMachine } from './form.machine';
4+
import { FormMachine } from '~/internals/machines/form.machine';
55

66
export type SnapshotState = SnapshotFrom<typeof FormMachine>;
77

packages/elements/src/internals/machines/form.machine.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { isClerkAPIResponseError } from '@clerk/shared/error';
22
import type { MachineContext } from 'xstate';
33
import { assign, enqueueActions, setup } from 'xstate';
44

5-
import { ClerkElementsError, ClerkElementsFieldError } from '../errors/error';
5+
import { ClerkElementsError, ClerkElementsFieldError } from '~/internals/errors/error';
6+
67
import type { FieldDetails } from './form.types';
78

89
export interface FormMachineContext extends MachineContext {

packages/elements/src/internals/machines/form.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ClerkElementsFieldError } from '../errors/error';
1+
import type { ClerkElementsFieldError } from '~/internals/errors/error';
22

33
export type FieldDetails = {
44
name?: string;

packages/elements/src/internals/machines/sign-in.actors.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import type {
1212
} from '@clerk/types';
1313
import { fromPromise } from 'xstate';
1414

15-
import { ClerkElementsRuntimeError } from '../errors/error';
16-
import type { ClerkRouter } from '../router';
15+
import { ClerkElementsRuntimeError } from '~/internals/errors/error';
16+
import type { ClerkRouter } from '~/react/router';
17+
1718
import type { SignInMachineContext } from './sign-in.machine';
1819
import type { WithClerk, WithClient, WithParams } from './sign-in.types';
1920
import { assertIsDefined } from './utils/assert';

packages/elements/src/internals/machines/sign-in.context.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import type React from 'react';
44
import { createContext, useCallback, useContext, useEffect, useMemo } from 'react';
55
import type { SnapshotFrom } from 'xstate';
66

7+
import { ClerkElementsRuntimeError } from '~/internals/errors/error';
78
import {
89
getEnabledThirdPartyProviders,
910
isAuthenticatableOauthStrategy,
1011
isWeb3Strategy,
11-
} from '../../utils/third-party-strategies';
12-
import { ClerkElementsRuntimeError } from '../errors/error';
12+
} from '~/utils/third-party-strategies';
13+
1314
import { SignInMachine } from './sign-in.machine';
1415
import type { SignInStrategyName } from './sign-in.types';
1516
import { matchStrategy } from './utils/strategies';
@@ -70,15 +71,15 @@ export function useStrategy(name: SignInStrategyName) {
7071
};
7172
}
7273

73-
export const useSignInState = () => {
74+
export const useSignInStateMatcher = () => {
7475
return useSignInFlowSelector(
7576
state => state,
76-
// (prev, next) => prev.value === next.value && prev.tags === next.tags,
77+
(prev, next) => prev.value === next.value,
7778
);
7879
};
7980

8081
export function useSignInStrategies(_preferred?: SignInStrategy) {
81-
const state = useSignInState();
82+
const state = useSignInStateMatcher();
8283
const current = useSignInFlowSelector(clerkCurrentStrategy);
8384

8485
const shouldRender = state.matches('FirstFactor') || state.matches('SecondFactor');

packages/elements/src/internals/machines/sign-in.machine.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import type {
1414
import type { ActorRefFrom, ErrorActorEvent, MachineContext } from 'xstate';
1515
import { and, assertEvent, assign, not, or, sendTo, setup } from 'xstate';
1616

17-
import type { ClerkRouter } from '../router';
17+
import type { ClerkRouter } from '~/react/router';
18+
1819
import type { FormMachine } from './form.machine';
1920
import { waitForClerk } from './shared.actors';
2021
import {
@@ -401,7 +402,6 @@ export const SignInMachine = setup({
401402
Failure: {
402403
type: 'final',
403404
target: '#SignIn.DeterminingState',
404-
reenter: true,
405405
},
406406
},
407407
},
@@ -501,7 +501,6 @@ export const SignInMachine = setup({
501501
Failure: {
502502
type: 'final',
503503
target: '#SignIn.DeterminingState',
504-
reenter: true,
505504
},
506505
},
507506
},

0 commit comments

Comments
 (0)