feat: add loading dialog for when rebuilding machine request was loading

This commit is contained in:
bennykok 2024-01-27 14:19:50 +08:00
parent 5eba792579
commit 72325a4217
2 changed files with 14 additions and 3 deletions

View File

@ -235,9 +235,11 @@ export const columns: ColumnDef<Machine>[] = [
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => {
buildMachine({
callServerPromise(buildMachine({
id: machine.id,
});
}), {
loadingText: "Starting machine build process"
})
}}
>
Rebuild

View File

@ -2,7 +2,13 @@
import { toast } from "sonner";
export async function callServerPromise<T>(result: Promise<T>) {
export async function callServerPromise<T>(result: Promise<T>, props?: {
loadingText: string
}) {
let id: string | number
if (props?.loadingText) {
id = toast.loading(props.loadingText)
}
return result
.then((x) => {
if ((x as { message: string })?.message !== undefined) {
@ -15,5 +21,8 @@ export async function callServerPromise<T>(result: Promise<T>) {
.catch((error) => {
toast.error(error.message);
return null;
}).finally(() => {
if (id != undefined)
toast.dismiss(id)
});
}