mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
fix(console): fix cloud CI failed issue (#6710)
chore: remove useNewSubscriptionData manual updateTenant
This commit is contained in:
parent
83e942a098
commit
b906db730c
2 changed files with 41 additions and 24 deletions
|
@ -1,4 +1,4 @@
|
|||
import { cond, condString, pick } from '@silverhand/essentials';
|
||||
import { cond, pick } from '@silverhand/essentials';
|
||||
import { useContext, useEffect, useMemo } from 'react';
|
||||
import useSWR from 'swr';
|
||||
|
||||
|
@ -21,25 +21,24 @@ import { type NewSubscriptionContext } from './types';
|
|||
const useNewSubscriptionData: () => NewSubscriptionContext & { isLoading: boolean } = () => {
|
||||
const cloudApi = useCloudApi();
|
||||
|
||||
const { currentTenant, updateTenant } = useContext(TenantsContext);
|
||||
const { currentTenant, currentTenantId, updateTenant } = useContext(TenantsContext);
|
||||
const { isLoading: isLogtoSkusLoading, data: fetchedLogtoSkus } = useLogtoSkus();
|
||||
const tenantId = condString(currentTenant?.id);
|
||||
|
||||
const {
|
||||
data: currentSubscription,
|
||||
isLoading: isSubscriptionLoading,
|
||||
mutate: mutateSubscription,
|
||||
} = useSubscription(tenantId);
|
||||
} = useSubscription(currentTenantId);
|
||||
|
||||
const {
|
||||
data: subscriptionUsageData,
|
||||
isLoading: isSubscriptionUsageDataLoading,
|
||||
mutate: mutateSubscriptionQuotaAndUsages,
|
||||
} = useSWR<NewSubscriptionUsageResponse, Error>(
|
||||
isCloud && tenantId && `/api/tenants/${tenantId}/subscription-usage`,
|
||||
isCloud && currentTenantId && `/api/tenants/${currentTenantId}/subscription-usage`,
|
||||
async () =>
|
||||
cloudApi.get('/api/tenants/:tenantId/subscription-usage', {
|
||||
params: { tenantId },
|
||||
params: { tenantId: currentTenantId },
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -52,11 +51,11 @@ const useNewSubscriptionData: () => NewSubscriptionContext & { isLoading: boolea
|
|||
|
||||
useEffect(() => {
|
||||
if (subscriptionUsageData?.quota) {
|
||||
updateTenant(tenantId, {
|
||||
updateTenant(currentTenantId, {
|
||||
quota: pick(subscriptionUsageData.quota, 'mauLimit', 'tokenLimit'),
|
||||
});
|
||||
}
|
||||
}, [tenantId, subscriptionUsageData?.quota, updateTenant]);
|
||||
}, [currentTenantId, subscriptionUsageData?.quota, updateTenant]);
|
||||
|
||||
return useMemo(
|
||||
() => ({
|
||||
|
|
|
@ -118,31 +118,49 @@ function TenantsProvider({ children }: Props) {
|
|||
[currentTenantId, tenants]
|
||||
);
|
||||
|
||||
const memorizedContext = useMemo(
|
||||
() => ({
|
||||
tenants,
|
||||
resetTenants: (tenants: TenantResponse[]) => {
|
||||
const resetTenants = useCallback((tenants: TenantResponse[]) => {
|
||||
setTenants(tenants);
|
||||
setIsInitComplete(true);
|
||||
},
|
||||
prependTenant: (tenant: TenantResponse) => {
|
||||
}, []);
|
||||
|
||||
const prependTenant = useCallback((tenant: TenantResponse) => {
|
||||
setTenants((tenants) => [tenant, ...tenants]);
|
||||
},
|
||||
removeTenant: (tenantId: string) => {
|
||||
}, []);
|
||||
|
||||
const removeTenant = useCallback((tenantId: string) => {
|
||||
setTenants((tenants) => tenants.filter((tenant) => tenant.id !== tenantId));
|
||||
},
|
||||
updateTenant: (tenantId: string, data: Partial<TenantResponse>) => {
|
||||
}, []);
|
||||
|
||||
const updateTenant = useCallback((tenantId: string, data: Partial<TenantResponse>) => {
|
||||
setTenants((tenants) =>
|
||||
tenants.map((tenant) => (tenant.id === tenantId ? { ...tenant, ...data } : tenant))
|
||||
);
|
||||
},
|
||||
}, []);
|
||||
|
||||
const memorizedContext = useMemo(
|
||||
() => ({
|
||||
tenants,
|
||||
resetTenants,
|
||||
prependTenant,
|
||||
removeTenant,
|
||||
updateTenant,
|
||||
isInitComplete,
|
||||
currentTenantId,
|
||||
isDevTenant: currentTenant?.tag === TenantTag.Development,
|
||||
currentTenant,
|
||||
navigateTenant,
|
||||
}),
|
||||
[currentTenant, currentTenantId, isInitComplete, navigateTenant, tenants]
|
||||
[
|
||||
currentTenant,
|
||||
currentTenantId,
|
||||
isInitComplete,
|
||||
navigateTenant,
|
||||
tenants,
|
||||
resetTenants,
|
||||
prependTenant,
|
||||
removeTenant,
|
||||
updateTenant,
|
||||
]
|
||||
);
|
||||
|
||||
return <TenantsContext.Provider value={memorizedContext}>{children}</TenantsContext.Provider>;
|
||||
|
|
Loading…
Reference in a new issue