From 9728f56927fe85f69763beefa7de91456d24fc6d Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Mon, 3 Jul 2023 00:08:31 -0400 Subject: [PATCH] fix(striker-ui): allow message setter override in submit form --- striker-ui/hooks/useFormUtils.ts | 14 +++++++++++--- striker-ui/types/FormUtils.d.ts | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/striker-ui/hooks/useFormUtils.ts b/striker-ui/hooks/useFormUtils.ts index ce7a8121..ef4a8e1e 100644 --- a/striker-ui/hooks/useFormUtils.ts +++ b/striker-ui/hooks/useFormUtils.ts @@ -85,13 +85,21 @@ const useFormUtils = < ); const submitForm = useCallback( - ({ body, getErrorMsg, msgKey = 'api', method, successMsg, url }) => { + ({ + body, + getErrorMsg, + msgKey = 'api', + method, + setMsg = messageGroupRef?.current?.setMessage, + successMsg, + url, + }) => { setFormSubmitting(true); api .request({ data: body, method, url }) .then(() => { - messageGroupRef?.current?.setMessage?.call(null, msgKey, { + setMsg?.call(null, msgKey, { children: successMsg, type: 'info', }); @@ -101,7 +109,7 @@ const useFormUtils = < emsg.children = getErrorMsg(emsg.children); - messageGroupRef?.current?.setMessage?.call(null, msgKey, emsg); + setMsg?.call(null, msgKey, emsg); }) .finally(() => { setFormSubmitting(false); diff --git a/striker-ui/types/FormUtils.d.ts b/striker-ui/types/FormUtils.d.ts index 2341f3ab..9fb401db 100644 --- a/striker-ui/types/FormUtils.d.ts +++ b/striker-ui/types/FormUtils.d.ts @@ -27,6 +27,7 @@ type SubmitFormFunction = (args: { ) => import('react').ReactNode; msgKey?: string; method: 'delete' | 'post' | 'put'; + setMsg?: import('../components/MessageGroup').MessageGroupForwardedRefContent['setMessage']; successMsg?: import('react').ReactNode; url: string; }) => void;