From cf1a64a1f35de4132d129c6e46227f2f5088b3d6 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Mon, 27 Nov 2023 10:37:22 -0500 Subject: [PATCH] fix(striker-ui): add success, error callbacks on submission in form utils --- striker-ui/hooks/useFormUtils.ts | 6 ++++++ striker-ui/types/FormUtils.d.ts | 2 ++ 2 files changed, 8 insertions(+) diff --git a/striker-ui/hooks/useFormUtils.ts b/striker-ui/hooks/useFormUtils.ts index ef4a8e1e..31dc7ae7 100644 --- a/striker-ui/hooks/useFormUtils.ts +++ b/striker-ui/hooks/useFormUtils.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); diff --git a/striker-ui/types/FormUtils.d.ts b/striker-ui/types/FormUtils.d.ts index 9fb401db..ed185233 100644 --- a/striker-ui/types/FormUtils.d.ts +++ b/striker-ui/types/FormUtils.d.ts @@ -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;