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 { MutableRefObject, useCallback, useMemo, useState } from 'react';
|
||||||
|
|
||||||
import buildMapToMessageSetter from '../lib/buildMapToMessageSetter';
|
import buildMapToMessageSetter, {
|
||||||
|
buildMessageSetter,
|
||||||
|
} from '../lib/buildMapToMessageSetter';
|
||||||
import buildObjectStateSetterCallback from '../lib/buildObjectStateSetterCallback';
|
import buildObjectStateSetterCallback from '../lib/buildObjectStateSetterCallback';
|
||||||
import { MessageGroupForwardedRefContent } from '../components/MessageGroup';
|
import { MessageGroupForwardedRefContent } from '../components/MessageGroup';
|
||||||
|
|
||||||
@ -45,6 +47,16 @@ const useFormUtils = <
|
|||||||
[ids, messageGroupRef],
|
[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 {
|
return {
|
||||||
buildFinishInputTestBatchFunction,
|
buildFinishInputTestBatchFunction,
|
||||||
buildInputFirstRenderFunction,
|
buildInputFirstRenderFunction,
|
||||||
@ -52,6 +64,7 @@ const useFormUtils = <
|
|||||||
isFormInvalid,
|
isFormInvalid,
|
||||||
msgSetters,
|
msgSetters,
|
||||||
setFormValidity,
|
setFormValidity,
|
||||||
|
setMsgSetter,
|
||||||
setValidity,
|
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<
|
setFormValidity: import('react').Dispatch<
|
||||||
import('react').SetStateAction<FormValidity<M>>
|
import('react').SetStateAction<FormValidity<M>>
|
||||||
>;
|
>;
|
||||||
|
setMsgSetter: (
|
||||||
|
id: keyof M,
|
||||||
|
setter?: MessageSetterFunction,
|
||||||
|
isOverwrite?: boolean,
|
||||||
|
) => void;
|
||||||
setValidity: (key: keyof M, value: boolean) => void;
|
setValidity: (key: keyof M, value: boolean) => void;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user