mirror of
https://github.com/logto-io/logto.git
synced 2025-01-06 20:40:08 -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 { getSearchParameters } from '@/utils';
|
||||||
|
|
||||||
import * as styles from './index.module.scss';
|
import * as styles from './index.module.scss';
|
||||||
import { getPasscodeValidationErrorHandlersByFlowAndMethod } from './utils';
|
import usePasscodeValidationErrorHandler from './use-passcode-validation-error-handler';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
type: UserFlow;
|
type: UserFlow;
|
||||||
|
@ -44,12 +44,7 @@ const PasscodeValidation = ({ type, method, className, target }: Props) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get the flow specific error handler hook
|
// Get the flow specific error handler hook
|
||||||
const useFlowErrorHandler = useMemo(
|
const { errorHandler } = usePasscodeValidationErrorHandler(type, method, target);
|
||||||
() => getPasscodeValidationErrorHandlersByFlowAndMethod(type, method),
|
|
||||||
[method, type]
|
|
||||||
);
|
|
||||||
|
|
||||||
const { errorHandler } = useFlowErrorHandler(target);
|
|
||||||
|
|
||||||
const verifyPasscodeErrorHandlers: ErrorHandlers = useMemo(
|
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 useSignInWithSmsErrorHandler from './use-sign-in-with-sms-error-handler';
|
||||||
import useRegisterWithEmailErrorHandler from './user-register-with-email-error-handler';
|
import useRegisterWithEmailErrorHandler from './user-register-with-email-error-handler';
|
||||||
|
|
||||||
export const getPasscodeValidationErrorHandlersByFlowAndMethod = (
|
type Method = 'email' | 'sms';
|
||||||
flow: UserFlow,
|
|
||||||
method: 'email' | 'sms'
|
const getPasscodeValidationErrorHandlersByFlowAndMethod = (flow: UserFlow, method: Method) => {
|
||||||
) => {
|
|
||||||
if (flow === 'sign-in' && method === 'email') {
|
if (flow === 'sign-in' && method === 'email') {
|
||||||
return useSignInWithEmailErrorHandler;
|
return useSignInWithEmailErrorHandler;
|
||||||
}
|
}
|
||||||
|
@ -33,3 +32,12 @@ export const getPasscodeValidationErrorHandlersByFlowAndMethod = (
|
||||||
|
|
||||||
return useForgotPasswordWithSmsErrorHandler;
|
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