1- import {
2- Alert ,
3- Box ,
4- Button ,
5- Dialog ,
6- DialogActions ,
7- DialogContent ,
8- DialogTitle ,
9- FormLabel ,
10- LinearProgress ,
11- TextField ,
12- } from "@mui/material" ;
1+ import { Alert , Button , Dialog , DialogActions , DialogContent , DialogTitle , FormLabel , TextField } from "@mui/material" ;
132import React , { useState , useEffect } from "react" ;
143import { commandApi , errorHandlerApi } from "../../../../services" ;
4+ import { useAsyncOperation } from "../../../../services/hooks" ;
5+ import { AsyncOperationBanner } from "../../../../components" ;
156import type { Command } from "../../interfaces" ;
167
178export interface AddSubcommandDialogProps {
@@ -33,11 +24,12 @@ const AddSubcommandDialog: React.FC<AddSubcommandDialogProps> = ({
3324 open,
3425 onClose,
3526} ) => {
36- const [ updating , setUpdating ] = useState < boolean > ( false ) ;
3727 const [ invalidText , setInvalidText ] = useState < string | undefined > ( undefined ) ;
3828 const [ commandGroupName , setCommandGroupName ] = useState < string > ( "" ) ;
3929 const [ refArgsOptions , setRefArgsOptions ] = useState < { var : string ; options : string } [ ] > ( [ ] ) ;
4030
31+ const createSubresourceOperation = useAsyncOperation ( commandApi . createSubresource ) ;
32+
4133 useEffect ( ( ) => {
4234 setCommandGroupName ( defaultGroupNames . join ( " " ) ) ;
4335 setRefArgsOptions ( subArgOptions ) ;
@@ -103,10 +95,8 @@ const AddSubcommandDialog: React.FC<AddSubcommandDialogProps> = ({
10395 return ;
10496 }
10597
106- setUpdating ( true ) ;
107-
10898 try {
109- await commandApi . createSubresource ( urls [ 0 ] , {
99+ await createSubresourceOperation . execute ( urls [ 0 ] , {
110100 ...data ,
111101 arg : argVar ,
112102 } ) ;
@@ -115,7 +105,6 @@ const AddSubcommandDialog: React.FC<AddSubcommandDialogProps> = ({
115105 console . error ( err ) ;
116106 const message = errorHandlerApi . getErrorMessage ( err ) ;
117107 setInvalidText ( `ResponseError: ${ message } ` ) ;
118- setUpdating ( false ) ;
119108 }
120109 } ;
121110
@@ -180,14 +169,10 @@ const AddSubcommandDialog: React.FC<AddSubcommandDialogProps> = ({
180169 { refArgsOptions . map ( buildRefArgText ) }
181170 </ >
182171 ) }
172+ < AsyncOperationBanner operation = { createSubresourceOperation } />
183173 </ DialogContent >
184174 < DialogActions >
185- { updating && (
186- < Box sx = { { width : "100%" } } >
187- < LinearProgress color = "secondary" />
188- </ Box >
189- ) }
190- { ! updating && (
175+ { ! createSubresourceOperation . loading && (
191176 < >
192177 < Button onClick = { handleClose } > Cancel</ Button >
193178 < Button onClick = { handleAddSubresource } > Add Subcommands</ Button >
0 commit comments