@@ -26,6 +26,7 @@ import {
2626} from '@/lib/api/contracts/organization-credentials'
2727import { environmentKeys } from '@/hooks/queries/environment'
2828import { oauthConnectionsKeys } from '@/hooks/queries/oauth/oauth-connections'
29+ import { personalCredentialKeys } from '@/hooks/queries/personal-credentials'
2930import { workspaceCredentialKeys } from '@/hooks/queries/utils/credential-keys'
3031import { workspaceCredentialListQueryOptions } from '@/hooks/queries/utils/fetch-workspace-credentials'
3132import { invalidateSelectorQueries } from '@/hooks/queries/utils/selector-keys'
@@ -60,13 +61,18 @@ export function useWorkspaceCredentials(params: {
6061 } )
6162}
6263
63- export function useWorkspaceCredential ( credentialId ?: string , enabled = true ) {
64+ export function useWorkspaceCredential (
65+ credentialId ?: string ,
66+ enabled = true ,
67+ workspaceId ?: string
68+ ) {
6469 return useQuery < WorkspaceCredential | null > ( {
65- queryKey : workspaceCredentialKeys . detail ( credentialId ) ,
70+ queryKey : workspaceCredentialKeys . detailForWorkspace ( credentialId , workspaceId ) ,
6671 queryFn : async ( { signal } ) => {
6772 if ( ! credentialId ) return null
6873 const data = await requestJson ( getWorkspaceCredentialContract , {
6974 params : { id : credentialId } ,
75+ query : { workspaceId } ,
7076 signal,
7177 } )
7278 return data . credential ?? null
@@ -103,6 +109,7 @@ export function useCreateWorkspaceCredential() {
103109 } ,
104110 onSettled : ( ) =>
105111 Promise . all ( [
112+ queryClient . invalidateQueries ( { queryKey : personalCredentialKeys . lists ( ) } ) ,
106113 queryClient . invalidateQueries ( {
107114 queryKey : workspaceCredentialKeys . lists ( ) ,
108115 } ) ,
@@ -114,7 +121,7 @@ export function useCreateWorkspaceCredential() {
114121 } )
115122}
116123
117- export function useUpdateWorkspaceCredential ( ) {
124+ export function useUpdateWorkspaceCredential ( workspaceId ?: string ) {
118125 const queryClient = useQueryClient ( )
119126
120127 return useMutation ( {
@@ -130,6 +137,7 @@ export function useUpdateWorkspaceCredential() {
130137 return requestJson ( updateWorkspaceCredentialContract , {
131138 params : { id : credentialId } ,
132139 body,
140+ query : { workspaceId } ,
133141 } )
134142 } ,
135143 onMutate : async ( variables ) => {
@@ -142,7 +150,7 @@ export function useUpdateWorkspaceCredential() {
142150 queryKey : workspaceCredentialKeys . lists ( ) ,
143151 } )
144152 const previousDetail = queryClient . getQueryData < WorkspaceCredential | null > (
145- workspaceCredentialKeys . detail ( variables . credentialId )
153+ workspaceCredentialKeys . detailForWorkspace ( variables . credentialId , workspaceId )
146154 )
147155
148156 /** Applies the in-flight edit to one cached credential. */
@@ -163,7 +171,7 @@ export function useUpdateWorkspaceCredential() {
163171 * Discard to restore the pre-save value over the committed one.
164172 */
165173 queryClient . setQueryData < WorkspaceCredential | null > (
166- workspaceCredentialKeys . detail ( variables . credentialId ) ,
174+ workspaceCredentialKeys . detailForWorkspace ( variables . credentialId , workspaceId ) ,
167175 ( old ) => ( old ? withEdit ( old ) : old )
168176 )
169177
@@ -185,13 +193,14 @@ export function useUpdateWorkspaceCredential() {
185193 }
186194 if ( context ?. previousDetail !== undefined ) {
187195 queryClient . setQueryData (
188- workspaceCredentialKeys . detail ( variables . credentialId ) ,
196+ workspaceCredentialKeys . detailForWorkspace ( variables . credentialId , workspaceId ) ,
189197 context . previousDetail
190198 )
191199 }
192200 } ,
193201 onSettled : ( _data , _error , variables ) =>
194202 Promise . all ( [
203+ queryClient . invalidateQueries ( { queryKey : personalCredentialKeys . lists ( ) } ) ,
195204 queryClient . invalidateQueries ( {
196205 queryKey : workspaceCredentialKeys . detail ( variables . credentialId ) ,
197206 } ) ,
@@ -206,15 +215,19 @@ export function useUpdateWorkspaceCredential() {
206215 } )
207216}
208217
209- export function useDeleteWorkspaceCredential ( ) {
218+ export function useDeleteWorkspaceCredential ( workspaceId ?: string ) {
210219 const queryClient = useQueryClient ( )
211220
212221 return useMutation ( {
213222 mutationFn : async ( credentialId : string ) => {
214- return requestJson ( deleteWorkspaceCredentialContract , { params : { id : credentialId } } )
223+ return requestJson ( deleteWorkspaceCredentialContract , {
224+ params : { id : credentialId } ,
225+ query : { workspaceId } ,
226+ } )
215227 } ,
216228 onSettled : ( _data , _error , credentialId ) =>
217229 Promise . all ( [
230+ queryClient . invalidateQueries ( { queryKey : personalCredentialKeys . lists ( ) } ) ,
218231 queryClient . invalidateQueries ( { queryKey : workspaceCredentialKeys . detail ( credentialId ) } ) ,
219232 queryClient . invalidateQueries ( { queryKey : workspaceCredentialKeys . lists ( ) } ) ,
220233 queryClient . invalidateQueries ( { queryKey : OAUTH_CREDENTIALS_KEY } ) ,
0 commit comments