1+ import { type ResponseError } from '@withtyped/client' ;
12import { useContext , useEffect } from 'react' ;
23import useSWR from 'swr' ;
34
45import { useCloudApi } from '@/cloud/hooks/use-cloud-api' ;
6+ import { type TenantUsageAddOnSkus , type NewSubscriptionPeriodicUsage } from '@/cloud/types/router' ;
57import PageMeta from '@/components/PageMeta' ;
6- import { isCloud } from '@/consts/env' ;
8+ import { isCloud , isDevFeaturesEnabled } from '@/consts/env' ;
79import { SubscriptionDataContext } from '@/contexts/SubscriptionDataProvider' ;
810import { TenantsContext } from '@/contexts/TenantsProvider' ;
911import { pickupFeaturedLogtoSkus } from '@/utils/subscription' ;
@@ -23,14 +25,27 @@ function Subscription() {
2325
2426 const reservedSkus = pickupFeaturedLogtoSkus ( logtoSkus ) ;
2527
26- const { data : periodicUsage , isLoading } = useSWR (
27- isCloud && `/api/tenants/${ currentTenantId } /subscription/periodic-usage` ,
28- async ( ) =>
29- cloudApi . get ( `/api/tenants/:tenantId/subscription/periodic-usage` , {
30- params : { tenantId : currentTenantId } ,
31- } )
28+ const { data : periodicUsage , error : periodicUsageError } = useSWR <
29+ NewSubscriptionPeriodicUsage ,
30+ ResponseError
31+ > ( isCloud && `/api/tenants/${ currentTenantId } /subscription/periodic-usage` , async ( ) =>
32+ cloudApi . get ( `/api/tenants/:tenantId/subscription/periodic-usage` , {
33+ params : { tenantId : currentTenantId } ,
34+ } )
3235 ) ;
3336
37+ const { data : usageAddOnSkus , error : usageAddOnSkusError } = useSWR <
38+ TenantUsageAddOnSkus ,
39+ ResponseError
40+ > ( isCloud && isDevFeaturesEnabled && `/api/tenants/${ currentTenantId } /add-on-skus` , async ( ) =>
41+ cloudApi . get ( `/api/tenants/:tenantId/subscription/add-on-skus` , {
42+ params : { tenantId : currentTenantId } ,
43+ } )
44+ ) ;
45+
46+ const isLoading =
47+ ( ! periodicUsage && ! periodicUsageError ) || ( ! usageAddOnSkus && ! usageAddOnSkusError ) ;
48+
3449 useEffect ( ( ) => {
3550 if ( isCloud ) {
3651 onCurrentSubscriptionUpdated ( ) ;
@@ -55,7 +70,7 @@ function Subscription() {
5570 return (
5671 < div className = { styles . container } >
5772 < PageMeta titleKey = { [ 'tenants.tabs.subscription' , 'tenants.title' ] } />
58- < CurrentPlan periodicUsage = { periodicUsage } />
73+ < CurrentPlan periodicUsage = { periodicUsage } usageAddOnSkus = { usageAddOnSkus } />
5974 < PlanComparisonTable />
6075 < SwitchPlanActionBar
6176 currentSkuId = { currentSku . id }
0 commit comments