feat: add loading dialog for when rebuilding machine request was loading
This commit is contained in:
parent
5eba792579
commit
72325a4217
@ -235,9 +235,11 @@ export const columns: ColumnDef<Machine>[] = [
|
|||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
buildMachine({
|
callServerPromise(buildMachine({
|
||||||
id: machine.id,
|
id: machine.id,
|
||||||
});
|
}), {
|
||||||
|
loadingText: "Starting machine build process"
|
||||||
|
})
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Rebuild
|
Rebuild
|
||||||
|
@ -2,7 +2,13 @@
|
|||||||
|
|
||||||
import { toast } from "sonner";
|
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
|
return result
|
||||||
.then((x) => {
|
.then((x) => {
|
||||||
if ((x as { message: string })?.message !== undefined) {
|
if ((x as { message: string })?.message !== undefined) {
|
||||||
@ -15,5 +21,8 @@ export async function callServerPromise<T>(result: Promise<T>) {
|
|||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
toast.error(error.message);
|
toast.error(error.message);
|
||||||
return null;
|
return null;
|
||||||
|
}).finally(() => {
|
||||||
|
if (id != undefined)
|
||||||
|
toast.dismiss(id)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user