feat: enhance actionToast utility with failed callback and make on_change asynchronous

This commit is contained in:
faisolavolut 2025-02-18 01:01:02 +07:00
parent 0518f3b033
commit cc0a9d8651
2 changed files with 13 additions and 3 deletions

View File

@ -85,7 +85,7 @@ export const FieldUploadSingle: FC<{
input.isLocal = true; input.isLocal = true;
input.render(); input.render();
if (typeof on_change === "function") { if (typeof on_change === "function") {
on_change({}); await on_change({});
} }
return; return;
const formData = new FormData(); const formData = new FormData();

View File

@ -7,12 +7,21 @@ export const actionToast = async (data: {
before?: () => any; before?: () => any;
success?: () => any; success?: () => any;
after?: () => any; after?: () => any;
failed?: () => any;
msg_succes?: string; msg_succes?: string;
msg_error?: string; msg_error?: string;
msg_load?: string; msg_load?: string;
}) => { }) => {
const { task, before, after, success, msg_succes, msg_error, msg_load } = const {
data; task,
before,
after,
success,
msg_succes,
msg_error,
msg_load,
failed,
} = data;
try { try {
if (typeof before === "function") before(); if (typeof before === "function") before();
@ -61,6 +70,7 @@ export const actionToast = async (data: {
}, 100); }, 100);
} catch (ex: any) { } catch (ex: any) {
setTimeout(() => { setTimeout(() => {
if (typeof failed === "function") failed();
toast.dismiss(); toast.dismiss();
toast.error( toast.error(
<div className="flex flex-col w-full"> <div className="flex flex-col w-full">