fix(striker-ui): add success, error callbacks on submission in form utils

main
Tsu-ba-me 1 year ago
parent 35469d2895
commit cf1a64a1f3
  1. 6
      striker-ui/hooks/useFormUtils.ts
  2. 2
      striker-ui/types/FormUtils.d.ts

@ -90,6 +90,8 @@ const useFormUtils = <
getErrorMsg, getErrorMsg,
msgKey = 'api', msgKey = 'api',
method, method,
onError,
onSuccess,
setMsg = messageGroupRef?.current?.setMessage, setMsg = messageGroupRef?.current?.setMessage,
successMsg, successMsg,
url, url,
@ -103,6 +105,8 @@ const useFormUtils = <
children: successMsg, children: successMsg,
type: 'info', type: 'info',
}); });
onSuccess?.call(null);
}) })
.catch((apiError) => { .catch((apiError) => {
const emsg = handleAPIError(apiError); const emsg = handleAPIError(apiError);
@ -110,6 +114,8 @@ const useFormUtils = <
emsg.children = getErrorMsg(emsg.children); emsg.children = getErrorMsg(emsg.children);
setMsg?.call(null, msgKey, emsg); setMsg?.call(null, msgKey, emsg);
onError?.call(null);
}) })
.finally(() => { .finally(() => {
setFormSubmitting(false); setFormSubmitting(false);

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

Loading…
Cancel
Save