Fix useUserProfileForm reducer
This commit is contained in:
parent
f59ee55be5
commit
3dded16f0a
@ -354,15 +354,15 @@ export function useUserProfileForm(params: ParamsOfUseUserProfileForm): ReturnTy
|
|||||||
return initialState;
|
return initialState;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const [state, dispatchFormAction] = useReducer(function reducer(state: internal.State, params: FormAction): internal.State {
|
const [state, dispatchFormAction] = useReducer(function reducer(state: internal.State, formAction: FormAction): internal.State {
|
||||||
const formFieldState = state.formFieldStates.find(({ attribute }) => attribute.name === params.name);
|
const formFieldState = state.formFieldStates.find(({ attribute }) => attribute.name === formAction.name);
|
||||||
|
|
||||||
assert(formFieldState !== undefined);
|
assert(formFieldState !== undefined);
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
switch (params.action) {
|
switch (formAction.action) {
|
||||||
case "update":
|
case "update":
|
||||||
formFieldState.valueOrValues = params.valueOrValues;
|
formFieldState.valueOrValues = formAction.valueOrValues;
|
||||||
|
|
||||||
apply_formatters: {
|
apply_formatters: {
|
||||||
const { attribute } = formFieldState;
|
const { attribute } = formFieldState;
|
||||||
@ -381,7 +381,7 @@ export function useUserProfileForm(params: ParamsOfUseUserProfileForm): ReturnTy
|
|||||||
}
|
}
|
||||||
|
|
||||||
formFieldState.errors = getErrors({
|
formFieldState.errors = getErrors({
|
||||||
"attributeName": params.name,
|
"attributeName": formAction.name,
|
||||||
"formFieldStates": state.formFieldStates
|
"formFieldStates": state.formFieldStates
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -390,21 +390,21 @@ export function useUserProfileForm(params: ParamsOfUseUserProfileForm): ReturnTy
|
|||||||
break update_password_confirm;
|
break update_password_confirm;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.name !== "password") {
|
if (formAction.name !== "password") {
|
||||||
break update_password_confirm;
|
break update_password_confirm;
|
||||||
}
|
}
|
||||||
|
|
||||||
state = reducer(state, {
|
state = reducer(state, {
|
||||||
"action": "update",
|
"action": "update",
|
||||||
"name": "password-confirm",
|
"name": "password-confirm",
|
||||||
"valueOrValues": params.valueOrValues
|
"valueOrValues": formAction.valueOrValues
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
case "focus lost":
|
case "focus lost":
|
||||||
if (formFieldState.hasLostFocusAtLeastOnce instanceof Array) {
|
if (formFieldState.hasLostFocusAtLeastOnce instanceof Array) {
|
||||||
const { fieldIndex } = params;
|
const { fieldIndex } = formAction;
|
||||||
assert(fieldIndex !== undefined);
|
assert(fieldIndex !== undefined);
|
||||||
formFieldState.hasLostFocusAtLeastOnce[fieldIndex] = true;
|
formFieldState.hasLostFocusAtLeastOnce[fieldIndex] = true;
|
||||||
return;
|
return;
|
||||||
@ -413,10 +413,10 @@ export function useUserProfileForm(params: ParamsOfUseUserProfileForm): ReturnTy
|
|||||||
formFieldState.hasLostFocusAtLeastOnce = true;
|
formFieldState.hasLostFocusAtLeastOnce = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert<Equals<typeof params, never>>(false);
|
assert<Equals<typeof formAction, never>>(false);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
return state;
|
return { ...state };
|
||||||
}, initialState);
|
}, initialState);
|
||||||
|
|
||||||
const formState: FormState = useMemo(
|
const formState: FormState = useMemo(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user