@@ -7,6 +7,7 @@ import ApiErrors from 'uiSrc/constants/apiErrors'
7
7
import { ApiEndpoints , BrowserStorageItem } from 'uiSrc/constants'
8
8
import successMessages from 'uiSrc/components/notifications/success-messages'
9
9
import { getApiErrorMessage , isStatusSuccessful , Nullable } from 'uiSrc/utils'
10
+ import { setAppContextInitialState } from 'uiSrc/slices/app/context'
10
11
import { DatabaseInstanceResponse } from 'apiSrc/modules/instances/dto/database-instance.dto'
11
12
12
13
import { AppDispatch , RootState } from './store'
@@ -270,18 +271,25 @@ export function updateInstanceAction({ id, ...payload }: Instance) {
270
271
271
272
// Asynchronous thunk action
272
273
export function deleteInstancesAction ( instances : Instance [ ] ) {
273
- return async ( dispatch : AppDispatch ) => {
274
+ return async ( dispatch : AppDispatch , stateInit : ( ) => RootState ) => {
274
275
dispatch ( setDefaultInstance ( ) )
275
276
276
277
try {
278
+ const state = stateInit ( )
279
+ const instancesIds = map ( instances , 'id' )
277
280
const { status } = await apiService . delete ( ApiEndpoints . INSTANCE , {
278
- data : { ids : map ( instances , 'id' ) } ,
281
+ data : { ids : instancesIds } ,
279
282
} )
280
283
281
284
if ( isStatusSuccessful ( status ) ) {
282
285
dispatch ( setDefaultInstanceSuccess ( ) )
283
286
dispatch < any > ( fetchInstancesAction ( ) )
284
287
288
+ if ( instancesIds . includes ( state . app . context . contextInstanceId ) ) {
289
+ dispatch ( resetConnectedInstance ( ) )
290
+ dispatch ( setAppContextInitialState ( ) )
291
+ }
292
+
285
293
if ( instances . length === 1 ) {
286
294
dispatch (
287
295
addMessageNotification ( successMessages . DELETE_INSTANCE ( first ( instances ) ?. name ?? '' ) )
0 commit comments