From cc0a9d8651ad8a33fab0bead01f30c56064ba6de Mon Sep 17 00:00:00 2001 From: faisolavolut Date: Tue, 18 Feb 2025 01:01:02 +0700 Subject: [PATCH] feat: enhance actionToast utility with failed callback and make on_change asynchronous --- components/form/field/TypeUploadSingle.tsx | 2 +- utils/action.tsx | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/components/form/field/TypeUploadSingle.tsx b/components/form/field/TypeUploadSingle.tsx index 532ad37..bccf6cb 100644 --- a/components/form/field/TypeUploadSingle.tsx +++ b/components/form/field/TypeUploadSingle.tsx @@ -85,7 +85,7 @@ export const FieldUploadSingle: FC<{ input.isLocal = true; input.render(); if (typeof on_change === "function") { - on_change({}); + await on_change({}); } return; const formData = new FormData(); diff --git a/utils/action.tsx b/utils/action.tsx index aa6ade0..04ebcf0 100644 --- a/utils/action.tsx +++ b/utils/action.tsx @@ -7,12 +7,21 @@ export const actionToast = async (data: { before?: () => any; success?: () => any; after?: () => any; + failed?: () => any; msg_succes?: string; msg_error?: string; msg_load?: string; }) => { - const { task, before, after, success, msg_succes, msg_error, msg_load } = - data; + const { + task, + before, + after, + success, + msg_succes, + msg_error, + msg_load, + failed, + } = data; try { if (typeof before === "function") before(); @@ -61,6 +70,7 @@ export const actionToast = async (data: { }, 100); } catch (ex: any) { setTimeout(() => { + if (typeof failed === "function") failed(); toast.dismiss(); toast.error(