@@ -16,7 +16,7 @@ import {
16
16
MenuList ,
17
17
useColorModeValue ,
18
18
} from "@chakra-ui/react" ;
19
- import { useMutation } from "@tanstack/react-query" ;
19
+ import { useMutation , useQueryClient } from "@tanstack/react-query" ;
20
20
21
21
import CopyText from "@/components/CopyText" ;
22
22
import FileTypeIcon from "@/components/FileTypeIcon" ;
@@ -25,6 +25,7 @@ import { APP_PHASE_STATUS, APP_STATUS, Pages } from "@/constants";
25
25
import { formatDate } from "@/utils/format" ;
26
26
import getRegionById from "@/utils/getRegionById" ;
27
27
28
+ import { APP_LIST_QUERY_KEY } from "../../index" ;
28
29
import CreateAppModal from "../CreateAppModal" ;
29
30
import DeleteAppModal from "../DeleteAppModal" ;
30
31
import StatusBadge from "../StatusBadge" ;
@@ -35,15 +36,16 @@ import { TApplicationItem } from "@/apis/typing";
35
36
import { ApplicationControllerUpdateState } from "@/apis/v1/applications" ;
36
37
import useGlobalStore from "@/pages/globalStore" ;
37
38
38
- function List ( props : { appListQuery : any ; setShouldRefetch : any } ) {
39
+ function List ( props : { appListQuery : any } ) {
39
40
const navigate = useNavigate ( ) ;
40
41
const { t } = useTranslation ( ) ;
41
42
42
43
const { setCurrentApp, regions } = useGlobalStore ( ) ;
43
44
44
45
const [ searchKey , setSearchKey ] = useState ( "" ) ;
45
46
46
- const { appListQuery, setShouldRefetch } = props ;
47
+ const queryClient = useQueryClient ( ) ;
48
+ const { appListQuery } = props ;
47
49
const bg = useColorModeValue ( "lafWhite.200" , "lafDark.200" ) ;
48
50
49
51
const updateAppStateMutation = useMutation ( ( params : any ) =>
@@ -173,7 +175,7 @@ function List(props: { appListQuery: any; setShouldRefetch: any }) {
173
175
: APP_STATUS . Restarting ,
174
176
} ) ;
175
177
if ( ! res . error ) {
176
- setShouldRefetch ( true ) ;
178
+ queryClient . invalidateQueries ( APP_LIST_QUERY_KEY ) ;
177
179
}
178
180
} }
179
181
>
@@ -190,11 +192,13 @@ function List(props: { appListQuery: any; setShouldRefetch: any }) {
190
192
display = { "block" }
191
193
onClick = { async ( event : any ) => {
192
194
event ?. preventDefault ( ) ;
193
- await updateAppStateMutation . mutateAsync ( {
195
+ const res = await updateAppStateMutation . mutateAsync ( {
194
196
appid : item . appid ,
195
- state : APP_PHASE_STATUS . Stopped ,
197
+ state : APP_STATUS . Stopped ,
196
198
} ) ;
197
- setShouldRefetch ( true ) ;
199
+ if ( ! res . error ) {
200
+ queryClient . invalidateQueries ( APP_LIST_QUERY_KEY ) ;
201
+ }
198
202
} }
199
203
>
200
204
< a className = "text-primary block" href = "/stop" >
@@ -203,7 +207,10 @@ function List(props: { appListQuery: any; setShouldRefetch: any }) {
203
207
</ MenuItem >
204
208
) }
205
209
206
- < DeleteAppModal item = { item } onSuccess = { ( ) => setShouldRefetch ( true ) } >
210
+ < DeleteAppModal
211
+ item = { item }
212
+ onSuccess = { ( ) => queryClient . invalidateQueries ( APP_LIST_QUERY_KEY ) }
213
+ >
207
214
< MenuItem minH = "40px" display = { "block" } >
208
215
< a className = "block text-error-500" href = "/delete" >
209
216
{ t ( "DeleteApp" ) }
0 commit comments