@@ -16,6 +16,9 @@ import { usePreferredModelWorkspace } from "../hooks/use-preferred-preferred-mod
16
16
import { Select , SelectButton } from "@stacklok/ui-kit" ;
17
17
import { useQueryListAllModelsForAllProviders } from "@/hooks/use-query-list-all-models-for-all-providers" ;
18
18
import { FormButtons } from "@/components/FormButtons" ;
19
+ import { invalidateQueries } from "@/lib/react-query-utils" ;
20
+ import { v1GetWorkspaceMuxesQueryKey } from "@/api/generated/@tanstack/react-query.gen" ;
21
+ import { useQueryClient } from "@tanstack/react-query" ;
19
22
20
23
function MissingProviderBanner ( ) {
21
24
return (
@@ -39,25 +42,30 @@ export function WorkspacePreferredModel({
39
42
workspaceName : string ;
40
43
isArchived : boolean | undefined ;
41
44
} ) {
45
+ const queryClient = useQueryClient ( ) ;
42
46
const { formState, isPending } = usePreferredModelWorkspace ( workspaceName ) ;
43
47
const { mutateAsync } = useMutationPreferredModelWorkspace ( ) ;
44
48
const { data : providerModels = [ ] } = useQueryListAllModelsForAllProviders ( ) ;
45
- const { model, provider_id } = formState . values . preferredModel ;
46
49
const isModelsEmpty = ! isPending && providerModels . length === 0 ;
47
50
48
51
const handleSubmit = ( event : FormEvent ) => {
49
52
event . preventDefault ( ) ;
50
- mutateAsync ( {
51
- path : { workspace_name : workspaceName } ,
52
- body : [
53
- {
54
- matcher : "" ,
55
- provider_id,
56
- model,
57
- matcher_type : MuxMatcherType . CATCH_ALL ,
58
- } ,
59
- ] ,
60
- } ) ;
53
+ mutateAsync (
54
+ {
55
+ path : { workspace_name : workspaceName } ,
56
+ body : [
57
+ {
58
+ matcher : "" ,
59
+ matcher_type : MuxMatcherType . CATCH_ALL ,
60
+ ...formState . values . preferredModel ,
61
+ } ,
62
+ ] ,
63
+ } ,
64
+ {
65
+ onSuccess : ( ) =>
66
+ invalidateQueries ( queryClient , [ v1GetWorkspaceMuxesQueryKey ] ) ,
67
+ } ,
68
+ ) ;
61
69
} ;
62
70
63
71
return (
0 commit comments