diff --git a/packages/ui/src/containers/PasscodeValidation/index.tsx b/packages/ui/src/containers/PasscodeValidation/index.tsx index 316640ca3..0a0c8bd58 100644 --- a/packages/ui/src/containers/PasscodeValidation/index.tsx +++ b/packages/ui/src/containers/PasscodeValidation/index.tsx @@ -13,7 +13,7 @@ import { UserFlow, SearchParameters } from '@/types'; import { getSearchParameters } from '@/utils'; import * as styles from './index.module.scss'; -import { getPasscodeValidationErrorHandlersByFlowAndMethod } from './utils'; +import usePasscodeValidationErrorHandler from './use-passcode-validation-error-handler'; type Props = { type: UserFlow; @@ -44,12 +44,7 @@ const PasscodeValidation = ({ type, method, className, target }: Props) => { }); // Get the flow specific error handler hook - const useFlowErrorHandler = useMemo( - () => getPasscodeValidationErrorHandlersByFlowAndMethod(type, method), - [method, type] - ); - - const { errorHandler } = useFlowErrorHandler(target); + const { errorHandler } = usePasscodeValidationErrorHandler(type, method, target); const verifyPasscodeErrorHandlers: ErrorHandlers = useMemo( () => ({ diff --git a/packages/ui/src/containers/PasscodeValidation/utils.ts b/packages/ui/src/containers/PasscodeValidation/use-passcode-validation-error-handler.ts similarity index 71% rename from packages/ui/src/containers/PasscodeValidation/utils.ts rename to packages/ui/src/containers/PasscodeValidation/use-passcode-validation-error-handler.ts index f0e50e3b3..67ef566c7 100644 --- a/packages/ui/src/containers/PasscodeValidation/utils.ts +++ b/packages/ui/src/containers/PasscodeValidation/use-passcode-validation-error-handler.ts @@ -7,10 +7,9 @@ import useSignInWithEmailErrorHandler from './use-sign-in-with-email-error-handl import useSignInWithSmsErrorHandler from './use-sign-in-with-sms-error-handler'; import useRegisterWithEmailErrorHandler from './user-register-with-email-error-handler'; -export const getPasscodeValidationErrorHandlersByFlowAndMethod = ( - flow: UserFlow, - method: 'email' | 'sms' -) => { +type Method = 'email' | 'sms'; + +const getPasscodeValidationErrorHandlersByFlowAndMethod = (flow: UserFlow, method: Method) => { if (flow === 'sign-in' && method === 'email') { return useSignInWithEmailErrorHandler; } @@ -33,3 +32,12 @@ export const getPasscodeValidationErrorHandlersByFlowAndMethod = ( return useForgotPasswordWithSmsErrorHandler; }; + +const usePassCodeValidationErrorHandler = (type: UserFlow, method: Method, target: string) => { + const useFlowErrorHandler = getPasscodeValidationErrorHandlersByFlowAndMethod(type, method); + const { errorHandler } = useFlowErrorHandler(target); + + return { errorHandler }; +}; + +export default usePassCodeValidationErrorHandler;