1- import  {  Button ,  Typography  }  from  '@mui/material' ; 
2- import  Dialog  from  '@mui/material/Dialog' ; 
3- import  DialogActions  from  '@mui/material/DialogActions' ; 
4- import  DialogContent  from  '@mui/material/DialogContent' ; 
5- import  DialogTitle  from  '@mui/material/DialogTitle' ; 
6- import  CircularProgress  from  '@mui/material/CircularProgress' ; 
1+ import  {  Typography  }  from  '@mui/material' ; 
72import  Box  from  '@mui/material/Box' ; 
8- import  {  Fragment ,   memo ,  useCallback ,   useState  }  from  'react' ; 
3+ import  {  memo ,  useCallback  }  from  'react' ; 
94
105import  {  useAxios  }  from  '../common/AxiosContext' ; 
6+ import  {  ButtonWithConfirm  }  from  '../common/ButtonWithConfirm' ; 
117import  {  API_PREFIX  }  from  './types' ; 
128
139interface  IRemoveEnvironmentButton  { 
1410  name : string ; 
1511  image : string ; 
1612} 
17- const  Loading  =  ( )  =>  ( 
18-   < Box  sx = { {  display : 'flex' ,  justifyContent : 'center'  } } > 
19-     < CircularProgress  /> 
20-   </ Box > 
21- ) ; 
13+ 
2214function  _RemoveEnvironmentButton ( props : IRemoveEnvironmentButton )  { 
2315  const  axios  =  useAxios ( ) ; 
24-   const  [ open ,  setOpen ]  =  useState ( false ) ; 
25-   const  [ removing ,  setRemoving ]  =  useState ( false ) ; 
26-   const  handleOpen  =  ( )  =>  { 
27-     setOpen ( true ) ; 
28-   } ; 
29-   const  handleClose  =  ( 
30-     event ?: any , 
31-     reason ?: 'backdropClick'  |  'escapeKeyDown' 
32-   )  =>  { 
33-     if  ( reason  &&  reason  ===  'backdropClick' )  { 
34-       return ; 
35-     } 
36-     setOpen ( false ) ; 
37-   } ; 
3816
3917  const  removeEnv  =  useCallback ( async  ( )  =>  { 
40-     setRemoving ( true ) ; 
4118    const  response  =  await  axios . request ( { 
4219      method : 'delete' , 
4320      path : API_PREFIX , 
@@ -46,39 +23,23 @@ function _RemoveEnvironmentButton(props: IRemoveEnvironmentButton) {
4623    if  ( response ?. status  ===  'ok' )  { 
4724      window . location . reload ( ) ; 
4825    }  else  { 
49-       handleClose ( ) ; 
5026    } 
51-   } ,  [ props . image ,  axios ,   setRemoving ] ) ; 
27+   } ,  [ props . image ,  axios ] ) ; 
5228
5329  return  ( 
54-     < Fragment > 
55-       < Button  onClick = { handleOpen }  color = "error"  size = "small" > 
56-         Remove
57-       </ Button > 
58- 
59-       < Dialog  open = { open }  onClose = { handleClose }  fullWidth  maxWidth = { 'sm' } > 
60-         < DialogTitle > Remove environment</ DialogTitle > 
61-         < DialogContent > 
62-           { ! removing  &&  ( 
63-             < Box > 
64-               < Typography > 
65-                 Are you sure you want to remove the following environment?
66-               </ Typography > 
67-               < pre > { props . name } </ pre > 
68-             </ Box > 
69-           ) } 
70-           { removing  &&  < Loading  /> } 
71-         </ DialogContent > 
72-         < DialogActions > 
73-           < Button  variant = "contained"  onClick = { handleClose } > 
74-             Cancel
75-           </ Button > 
76-           < Button  variant = "contained"  color = "error"  onClick = { removeEnv } > 
77-             Remove
78-           </ Button > 
79-         </ DialogActions > 
80-       </ Dialog > 
81-     </ Fragment > 
30+     < ButtonWithConfirm 
31+       buttonLabel = "Remove" 
32+       dialogTitle = "Remove environment" 
33+       dialogBody = { 
34+         < Box > 
35+           < Typography > 
36+             Are you sure you want to remove the following environment?
37+           </ Typography > 
38+           < pre > { props . name } </ pre > 
39+         </ Box > 
40+       } 
41+       action = { removeEnv } 
42+     /> 
8243  ) ; 
8344} 
8445
0 commit comments