feat: add api generation
This commit is contained in:
@@ -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;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user