fix(striker-ui): add setMsgSetter in FormUtils
This commit is contained in:
parent
77abfdc933
commit
ae07c8b66d
@ -1,6 +1,8 @@
|
||||
import { MutableRefObject, useCallback, useMemo, useState } from 'react';
|
||||
|
||||
import buildMapToMessageSetter from '../lib/buildMapToMessageSetter';
|
||||
import buildMapToMessageSetter, {
|
||||
buildMessageSetter,
|
||||
} from '../lib/buildMapToMessageSetter';
|
||||
import buildObjectStateSetterCallback from '../lib/buildObjectStateSetterCallback';
|
||||
import { MessageGroupForwardedRefContent } from '../components/MessageGroup';
|
||||
|
||||
@ -45,6 +47,16 @@ const useFormUtils = <
|
||||
[ids, messageGroupRef],
|
||||
);
|
||||
|
||||
const setMsgSetter = useCallback(
|
||||
(id: keyof M, setter?: MessageSetterFunction, isOverwrite?: boolean) => {
|
||||
if (!msgSetters[id] || isOverwrite) {
|
||||
msgSetters[id] =
|
||||
setter ?? buildMessageSetter<M>(String(id), messageGroupRef);
|
||||
}
|
||||
},
|
||||
[messageGroupRef, msgSetters],
|
||||
);
|
||||
|
||||
return {
|
||||
buildFinishInputTestBatchFunction,
|
||||
buildInputFirstRenderFunction,
|
||||
@ -52,6 +64,7 @@ const useFormUtils = <
|
||||
isFormInvalid,
|
||||
msgSetters,
|
||||
setFormValidity,
|
||||
setMsgSetter,
|
||||
setValidity,
|
||||
};
|
||||
};
|
||||
|
5
striker-ui/types/FormUtils.d.ts
vendored
5
striker-ui/types/FormUtils.d.ts
vendored
@ -23,5 +23,10 @@ type FormUtils<M extends MapToInputTestID> = {
|
||||
setFormValidity: import('react').Dispatch<
|
||||
import('react').SetStateAction<FormValidity<M>>
|
||||
>;
|
||||
setMsgSetter: (
|
||||
id: keyof M,
|
||||
setter?: MessageSetterFunction,
|
||||
isOverwrite?: boolean,
|
||||
) => void;
|
||||
setValidity: (key: keyof M, value: boolean) => void;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user