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

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

Loading…
Cancel
Save