From 51c9c52a6191f3a321b4df8f25148feb424909fd Mon Sep 17 00:00:00 2001 From: simeng-li Date: Mon, 9 Dec 2024 17:45:53 +0800 Subject: [PATCH] refactor(console): replace get sku api (#6861) replace the `api/sku` API using `api/tenants/:tenantId/available-sku --- packages/console/src/hooks/use-logto-skus.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/console/src/hooks/use-logto-skus.ts b/packages/console/src/hooks/use-logto-skus.ts index 211ce9b98..968691244 100644 --- a/packages/console/src/hooks/use-logto-skus.ts +++ b/packages/console/src/hooks/use-logto-skus.ts @@ -1,5 +1,5 @@ import { type Optional } from '@silverhand/essentials'; -import { useMemo } from 'react'; +import { useContext, useMemo } from 'react'; import useSWRImmutable from 'swr/immutable'; import { useCloudApi } from '@/cloud/hooks/use-cloud-api'; @@ -9,6 +9,7 @@ import { featuredPlanIdOrder } from '@/consts/subscriptions'; // Used in the docs // eslint-disable-next-line unused-imports/no-unused-imports import TenantAccess from '@/containers/TenantAccess'; +import { TenantsContext } from '@/contexts/TenantsProvider'; import { LogtoSkuType } from '@/types/skus'; import { sortBy } from '@/utils/sort'; import { addSupportQuota } from '@/utils/subscription'; @@ -19,11 +20,13 @@ import { addSupportQuota } from '@/utils/subscription'; */ const useLogtoSkus = () => { const cloudApi = useCloudApi(); + const { currentTenantId } = useContext(TenantsContext); const useSwrResponse = useSWRImmutable( - isCloud && '/api/skus', + isCloud && currentTenantId && `/api/tenants/${currentTenantId}/available-skus`, async () => - cloudApi.get('/api/skus', { + cloudApi.get('/api/tenants/:tenantId/available-skus', { + params: { tenantId: currentTenantId }, search: { type: LogtoSkuType.Basic }, }) );