2023-07-21 15:04:44 +08:00
|
|
|
import useSWR from 'swr';
|
|
|
|
|
|
|
|
import { useCloudApi } from '@/cloud/hooks/use-cloud-api';
|
|
|
|
import { type SubscriptionUsage } from '@/cloud/types/router';
|
|
|
|
import { isCloud, isProduction } from '@/consts/env';
|
|
|
|
|
|
|
|
const useSubscriptionUsage = (tenantId: string) => {
|
|
|
|
const cloudApi = useCloudApi();
|
|
|
|
|
|
|
|
return useSWR<SubscriptionUsage, Error>(
|
|
|
|
/**
|
|
|
|
* Todo: @xiaoyijun remove this condition on subscription features ready.
|
|
|
|
*/
|
|
|
|
!isProduction && isCloud && `/api/tenants/${tenantId}/usage`,
|
|
|
|
async () =>
|
|
|
|
cloudApi.get('/api/tenants/:tenantId/usage', {
|
|
|
|
params: { tenantId },
|
2023-07-24 15:06:59 +08:00
|
|
|
})
|
2023-07-21 15:04:44 +08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default useSubscriptionUsage;
|