diff --git a/.changeset/clever-bananas-turn.md b/.changeset/clever-bananas-turn.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/clever-bananas-turn.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/packages/clerk-js/src/ui/components/SignIn/strategies/factorSortingUtils.tsx b/packages/clerk-js/src/ui/components/SignIn/strategies/factorSortingUtils.tsx deleted file mode 100644 index 77373e2ce97..00000000000 --- a/packages/clerk-js/src/ui/components/SignIn/strategies/factorSortingUtils.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import type { SignInFactor, SignInStrategy } from '@clerk/types'; - -const makeSortingOrderMap = (arr: T[]): Record => - arr.reduce((acc, k, i) => { - acc[k] = i; - return acc; - }, {} as Record); - -const STRATEGY_SORT_ORDER_PASSWORD_PREF = makeSortingOrderMap([ - 'password', - 'email_link', - 'email_code', - 'phone_code', -] as SignInStrategy[]); - -const STRATEGY_SORT_ORDER_OTP_PREF = makeSortingOrderMap([ - 'email_link', - 'email_code', - 'phone_code', - 'password', -] as SignInStrategy[]); - -const STRATEGY_SORT_ORDER_ALL_STRATEGIES_BUTTONS = makeSortingOrderMap([ - 'email_link', - 'email_code', - 'phone_code', - 'password', -] as SignInStrategy[]); - -const makeSortingFunction = - (sortingMap: Record) => - (a: SignInFactor, b: SignInFactor): number => { - const orderA = sortingMap[a.strategy]; - const orderB = sortingMap[b.strategy]; - if (orderA === undefined || orderB === undefined) { - return 0; - } - return orderA - orderB; - }; - -export const passwordPrefFactorComparator = makeSortingFunction(STRATEGY_SORT_ORDER_PASSWORD_PREF); -export const otpPrefFactorComparator = makeSortingFunction(STRATEGY_SORT_ORDER_OTP_PREF); -export const allStrategiesButtonsComparator = makeSortingFunction(STRATEGY_SORT_ORDER_ALL_STRATEGIES_BUTTONS); diff --git a/packages/clerk-js/src/ui/components/SignIn/utils.ts b/packages/clerk-js/src/ui/components/SignIn/utils.ts index 18b29c1beac..cbd90311c91 100644 --- a/packages/clerk-js/src/ui/components/SignIn/utils.ts +++ b/packages/clerk-js/src/ui/components/SignIn/utils.ts @@ -2,7 +2,7 @@ import { titleize } from '@clerk/shared'; import type { PreferredSignInStrategy, SignInFactor, SignInResource, SignInStrategy } from '@clerk/types'; import { PREFERRED_SIGN_IN_STRATEGIES } from '../../common/constants'; -import { otpPrefFactorComparator, passwordPrefFactorComparator } from './strategies/factorSortingUtils'; +import { otpPrefFactorComparator, passwordPrefFactorComparator } from '../../utils/factorSorting'; const FONT_SIZE_STEP = 2; diff --git a/packages/clerk-js/src/ui/components/SignIn/strategies/factorSortingUtils.test.tsx b/packages/clerk-js/src/ui/utils/__tests__/factorSorting.test.ts similarity index 98% rename from packages/clerk-js/src/ui/components/SignIn/strategies/factorSortingUtils.test.tsx rename to packages/clerk-js/src/ui/utils/__tests__/factorSorting.test.ts index 7883ee5de90..2d08b87648a 100644 --- a/packages/clerk-js/src/ui/components/SignIn/strategies/factorSortingUtils.test.tsx +++ b/packages/clerk-js/src/ui/utils/__tests__/factorSorting.test.ts @@ -4,7 +4,7 @@ import { allStrategiesButtonsComparator, otpPrefFactorComparator, passwordPrefFactorComparator, -} from './factorSortingUtils'; +} from '../factorSorting'; describe('otpPrefFactorComparator(a,b)', function () { it('sorts an array of factors based on the otp pref sorter', function () {