mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
refactor(ui): refactor the hooks
refactor the hooks
This commit is contained in:
parent
2fc4ec9410
commit
b85a4e4ada
2 changed files with 14 additions and 11 deletions
|
@ -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(
|
||||
() => ({
|
||||
|
|
|
@ -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;
|
Loading…
Reference in a new issue