fix(striker-ui): allow message setter override in submit form

main
Tsu-ba-me 1 year ago
parent 750b0ac7c0
commit 9728f56927
  1. 14
      striker-ui/hooks/useFormUtils.ts
  2. 1
      striker-ui/types/FormUtils.d.ts

@ -85,13 +85,21 @@ const useFormUtils = <
); );
const submitForm = useCallback<SubmitFormFunction>( const submitForm = useCallback<SubmitFormFunction>(
({ body, getErrorMsg, msgKey = 'api', method, successMsg, url }) => { ({
body,
getErrorMsg,
msgKey = 'api',
method,
setMsg = messageGroupRef?.current?.setMessage,
successMsg,
url,
}) => {
setFormSubmitting(true); setFormSubmitting(true);
api api
.request({ data: body, method, url }) .request({ data: body, method, url })
.then(() => { .then(() => {
messageGroupRef?.current?.setMessage?.call(null, msgKey, { setMsg?.call(null, msgKey, {
children: successMsg, children: successMsg,
type: 'info', type: 'info',
}); });
@ -101,7 +109,7 @@ const useFormUtils = <
emsg.children = getErrorMsg(emsg.children); emsg.children = getErrorMsg(emsg.children);
messageGroupRef?.current?.setMessage?.call(null, msgKey, emsg); setMsg?.call(null, msgKey, emsg);
}) })
.finally(() => { .finally(() => {
setFormSubmitting(false); setFormSubmitting(false);

@ -27,6 +27,7 @@ type SubmitFormFunction = (args: {
) => import('react').ReactNode; ) => import('react').ReactNode;
msgKey?: string; msgKey?: string;
method: 'delete' | 'post' | 'put'; method: 'delete' | 'post' | 'put';
setMsg?: import('../components/MessageGroup').MessageGroupForwardedRefContent['setMessage'];
successMsg?: import('react').ReactNode; successMsg?: import('react').ReactNode;
url: string; url: string;
}) => void; }) => void;

Loading…
Cancel
Save