11"use client" ;
22
33import { QueryClientProvider , QueryClient } from "@tanstack/react-query" ;
4- import { useState , useEffect } from "react" ;
4+ import { usePathname } from "next/navigation" ;
5+ import { useState , useEffect , useCallback } from "react" ;
56
67import Shell from "@calcom/features/shell/Shell" ;
78import { useLocale } from "@calcom/lib/hooks/useLocale" ;
89import { showToast } from "@calcom/ui/components/toast" ;
910
11+ import { useExternalRedirectHandler } from "@lib/hooks/settings/platform/billing/useExternalRedirectHandler" ;
1012import { useDeleteOAuthClient } from "@lib/hooks/settings/platform/oauth-clients/useDeleteOAuthClient" ;
1113import { useOAuthClients } from "@lib/hooks/settings/platform/oauth-clients/useOAuthClients" ;
1214
@@ -20,13 +22,22 @@ const queryClient = new QueryClient();
2022
2123export default function Platform ( ) {
2224 const { t } = useLocale ( ) ;
23- const [ initialClientId , setInitialClientId ] = useState ( "" ) ;
24- const [ initialClientName , setInitialClientName ] = useState ( "" ) ;
25+ const [ _initialClientId , setInitialClientId ] = useState ( "" ) ;
26+ const [ _initialClientName , setInitialClientName ] = useState ( "" ) ;
27+ const pathname = usePathname ( ) ;
2528
2629 const { data, isLoading : isOAuthClientLoading , refetch : refetchClients } = useOAuthClients ( ) ;
2730
28- const { isUserLoading, isUserBillingDataLoading, isPlatformUser, isPaidUser, userBillingData, userOrgId } =
29- useGetUserAttributes ( ) ;
31+ const {
32+ isUserLoading,
33+ isUserBillingDataLoading,
34+ isPlatformUser,
35+ isPaidUser,
36+ userBillingData,
37+ userOrgId,
38+ refetchTeamBilling,
39+ refetchPlatformUser,
40+ } = useGetUserAttributes ( ) ;
3041
3142 const { mutateAsync, isPending : isDeleting } = useDeleteOAuthClient ( {
3243 onSuccess : ( ) => {
@@ -39,11 +50,24 @@ export default function Platform() {
3950 await mutateAsync ( { id : id } ) ;
4051 } ;
4152
53+ const refetchBillingState = useCallback ( ( ) => {
54+ refetchTeamBilling ( ) ;
55+ refetchPlatformUser ( ) ;
56+ } , [ refetchTeamBilling , refetchPlatformUser ] ) ;
57+
4258 useEffect ( ( ) => {
4359 setInitialClientId ( data [ 0 ] ?. id ) ;
4460 setInitialClientName ( data [ 0 ] ?. name ) ;
4561 } , [ data ] ) ;
4662
63+ useEffect ( ( ) => {
64+ refetchBillingState ( ) ;
65+ } , [ pathname , refetchTeamBilling , refetchPlatformUser , refetchBillingState ] ) ;
66+
67+ useExternalRedirectHandler ( ( ) => {
68+ refetchBillingState ( ) ;
69+ } ) ;
70+
4771 if ( isUserLoading || isOAuthClientLoading ) return < div className = "m-5" > { t ( "loading" ) } </ div > ;
4872
4973 if ( isUserBillingDataLoading && ! userBillingData ) {
0 commit comments