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
 | 
			
		||||
                  onClick={() => {
 | 
			
		||||
                    buildMachine({
 | 
			
		||||
                    callServerPromise(buildMachine({
 | 
			
		||||
                      id: machine.id,
 | 
			
		||||
                    });
 | 
			
		||||
                    }), {
 | 
			
		||||
                      loadingText: "Starting machine build process"
 | 
			
		||||
                    })
 | 
			
		||||
                  }}
 | 
			
		||||
                >
 | 
			
		||||
                  Rebuild
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user