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

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

Loading…
Cancel
Save