fix(striker-ui): add input unmount function builder to form utils

main
Tsu-ba-me 2 years ago
parent b00afbe7cf
commit f6b7a2df5a
  1. 12
      striker-ui/hooks/useFormUtils.ts
  2. 7
      striker-ui/types/FormUtils.d.ts

@ -18,14 +18,14 @@ const useFormUtils = <
const setMessage = useCallback( const setMessage = useCallback(
(key: keyof M, message?: Message) => { (key: keyof M, message?: Message) => {
messageGroupRef.current.setMessage?.call(null, String(key), message); messageGroupRef?.current?.setMessage?.call(null, String(key), message);
}, },
[messageGroupRef], [messageGroupRef],
); );
const setMessageRe = useCallback( const setMessageRe = useCallback(
(re: RegExp, message?: Message) => { (re: RegExp, message?: Message) => {
messageGroupRef.current.setMessageRe?.call(null, re, message); messageGroupRef?.current?.setMessageRe?.call(null, re, message);
}, },
[messageGroupRef], [messageGroupRef],
); );
@ -73,6 +73,13 @@ const useFormUtils = <
[setValidity], [setValidity],
); );
const buildInputUnmountFunction = useCallback(
(key: keyof M) => () => {
unsetKey(key);
},
[unsetKey],
);
const isFormInvalid = useMemo( const isFormInvalid = useMemo(
() => Object.values(formValidity).some((isInputValid) => !isInputValid), () => Object.values(formValidity).some((isInputValid) => !isInputValid),
[formValidity], [formValidity],
@ -81,6 +88,7 @@ const useFormUtils = <
return { return {
buildFinishInputTestBatchFunction, buildFinishInputTestBatchFunction,
buildInputFirstRenderFunction, buildInputFirstRenderFunction,
buildInputUnmountFunction,
formValidity, formValidity,
isFormInvalid, isFormInvalid,
setFormValidity, setFormValidity,

@ -14,9 +14,16 @@ type InputFirstRenderFunctionBuilder<M extends MapToInputTestID> = (
key: keyof M, key: keyof M,
) => InputFirstRenderFunction; ) => InputFirstRenderFunction;
type InputUnmountFunction = () => void;
type InputUnmountFunctionBuilder<M extends MapToInputTestID> = (
key: keyof M,
) => InputUnmountFunction;
type FormUtils<M extends MapToInputTestID> = { type FormUtils<M extends MapToInputTestID> = {
buildFinishInputTestBatchFunction: InputTestBatchFinishCallbackBuilder<M>; buildFinishInputTestBatchFunction: InputTestBatchFinishCallbackBuilder<M>;
buildInputFirstRenderFunction: InputFirstRenderFunctionBuilder<M>; buildInputFirstRenderFunction: InputFirstRenderFunctionBuilder<M>;
buildInputUnmountFunction: InputUnmountFunctionBuilder<M>;
formValidity: FormValidity<M>; formValidity: FormValidity<M>;
isFormInvalid: boolean; isFormInvalid: boolean;
setFormValidity: import('react').Dispatch< setFormValidity: import('react').Dispatch<

Loading…
Cancel
Save