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.render();
if (typeof on_change === "function") {
on_change({});
await on_change({});
}
return;
const formData = new FormData();

View File

@ -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(
<div className="flex flex-col w-full">