feat: add api generation

This commit is contained in:
BennyKok
2023-12-15 17:58:19 +08:00
parent e77da089d9
commit bbb7f398ab
15 changed files with 1213 additions and 45 deletions
+17
View File
@@ -0,0 +1,17 @@
"use client";
import { toast } from "sonner";
export async function callServerPromise<T>(result: Promise<T>) {
return result
.then((x) => {
if ((x as { message: string })?.message !== undefined) {
toast.success((x as { message: string }).message);
}
return x;
})
.catch((error) => {
toast.error(error.message);
return null;
});
}