@@ -3,6 +3,7 @@ import { createLogger } from '@sim/logger'
33import { keepPreviousData , useMutation , useQuery , useQueryClient } from '@tanstack/react-query'
44import type { WorkspaceEnvironmentData } from '@/lib/environment/api'
55import { fetchPersonalEnvironment , fetchWorkspaceEnvironment } from '@/lib/environment/api'
6+ import { workspaceCredentialKeys } from '@/hooks/queries/credentials'
67import { API_ENDPOINTS } from '@/stores/constants'
78import type { EnvironmentVariable } from '@/stores/settings/environment'
89import { useEnvironmentStore } from '@/stores/settings/environment'
@@ -106,8 +107,9 @@ export function useSavePersonalEnvironment() {
106107 logger . info ( 'Saved personal environment variables' )
107108 return transformedVariables
108109 } ,
109- onSuccess : ( ) => {
110+ onSettled : ( ) => {
110111 queryClient . invalidateQueries ( { queryKey : environmentKeys . personal ( ) } )
112+ queryClient . invalidateQueries ( { queryKey : workspaceCredentialKeys . lists ( ) } )
111113 } ,
112114 } )
113115}
@@ -138,11 +140,12 @@ export function useUpsertWorkspaceEnvironment() {
138140 logger . info ( `Upserted workspace environment variables for workspace: ${ workspaceId } ` )
139141 return await response . json ( )
140142 } ,
141- onSuccess : ( _data , variables ) => {
143+ onSettled : ( _data , _error , variables ) => {
142144 queryClient . invalidateQueries ( {
143145 queryKey : environmentKeys . workspace ( variables . workspaceId ) ,
144146 } )
145147 queryClient . invalidateQueries ( { queryKey : environmentKeys . personal ( ) } )
148+ queryClient . invalidateQueries ( { queryKey : workspaceCredentialKeys . lists ( ) } )
146149 } ,
147150 } )
148151}
@@ -173,11 +176,12 @@ export function useRemoveWorkspaceEnvironment() {
173176 logger . info ( `Removed ${ keys . length } workspace environment keys for workspace: ${ workspaceId } ` )
174177 return await response . json ( )
175178 } ,
176- onSuccess : ( _data , variables ) => {
179+ onSettled : ( _data , _error , variables ) => {
177180 queryClient . invalidateQueries ( {
178181 queryKey : environmentKeys . workspace ( variables . workspaceId ) ,
179182 } )
180183 queryClient . invalidateQueries ( { queryKey : environmentKeys . personal ( ) } )
184+ queryClient . invalidateQueries ( { queryKey : workspaceCredentialKeys . lists ( ) } )
181185 } ,
182186 } )
183187}
0 commit comments