11import { ProgressBar } from '@/components/ProgressBar' ;
2- import { useInstanceClient } from '@/config/useInstanceClient' ;
3- import { useRestartInstanceClick } from '@/hooks/useRestartInstanceClick' ;
2+ import { useInstanceClient , useInstanceClientIdParams } from '@/config/useInstanceClient' ;
43import { SchemaLicense } from '@/integrations/api/api.gen' ;
54import { installUsageLicense } from '@/integrations/api/instance/auth/installUsageLicense' ;
65import { getInstanceUserInfo } from '@/integrations/api/instance/status/getInstanceUserInfo' ;
76import { excludeFalsy } from '@/lib/arrays/excludeFalsy' ;
87import { sleep } from '@/lib/sleep' ;
98import { useQueryClient } from '@tanstack/react-query' ;
10- import { useParams } from '@tanstack/react-router' ;
119import { useCallback , useState } from 'react' ;
1210import { toast } from 'sonner' ;
1311
@@ -21,13 +19,9 @@ interface ApplyLicensesClickResponse {
2119}
2220
2321export function useApplyLicensesClick ( { licenses } : ApplyLicensesClickParams ) : ApplyLicensesClickResponse {
22+ const instanceParams = useInstanceClientIdParams ( ) ;
2423 const instanceClient = useInstanceClient ( ) ;
25- const { instanceId } : { instanceId ?: string } = useParams ( { strict : false } ) ;
2624 const queryClient = useQueryClient ( ) ;
27- const { isRestartPending, onRestartClick } = useRestartInstanceClick ( {
28- operation : 'restart_service' ,
29- instanceClient,
30- } ) ;
3125
3226 const [ isApplyLicensesPending , setIsApplyLicensesPending ] = useState ( false ) ;
3327
@@ -100,10 +94,12 @@ export function useApplyLicensesClick({ licenses }: ApplyLicensesClickParams): A
10094 }
10195 }
10296
97+ await queryClient . invalidateQueries ( {
98+ queryKey : [ instanceParams . entityId , 'get_usage_licenses' ] ,
99+ refetchType : 'active' ,
100+ } ) ;
103101 setIsApplyLicensesPending ( false ) ;
104102
105- void queryClient . invalidateQueries ( { queryKey : [ instanceId , 'get_configuration' ] , refetchType : 'active' } ) ;
106-
107103 const licenseWord = licenses . length === 1 ? 'License' : 'Licenses' ;
108104 if ( canceled ) {
109105 toast . error ( 'Cancelled' , {
@@ -118,13 +114,12 @@ export function useApplyLicensesClick({ licenses }: ApplyLicensesClickParams): A
118114 } else if ( licenses . length === licensesApplied ) {
119115 toast . success ( 'Success' , {
120116 id : toastId ,
121- description : `${ licenseWord } applied!\nPlease restart your instance. ` ,
117+ description : `${ licenseWord } applied!` ,
122118 duration : 0 ,
123119 action : {
124- label : 'Restart ' ,
120+ label : 'OK ' ,
125121 onClick : ( ) => {
126122 toast . dismiss ( toastId ) ;
127- onRestartClick ( ) ;
128123 } ,
129124 } ,
130125 } ) ;
@@ -143,10 +138,10 @@ export function useApplyLicensesClick({ licenses }: ApplyLicensesClickParams): A
143138 } ,
144139 } ) ;
145140 }
146- } , [ instanceClient , instanceId , licenses , onRestartClick , queryClient ] ) ;
141+ } , [ instanceClient , instanceParams . entityId , licenses , queryClient ] ) ;
147142
148143 return {
149144 onApplyLicensesClick,
150- isApplyLicensesPending : isApplyLicensesPending || isRestartPending ,
145+ isApplyLicensesPending,
151146 } ;
152147}
0 commit comments