mirror of
https://github.com/logto-io/logto.git
synced 2025-04-07 23:01:25 -05:00
feat(console): handle subscription related request errors (#4209)
This commit is contained in:
parent
b97b89a34b
commit
aded22954e
7 changed files with 71 additions and 30 deletions
|
@ -34,18 +34,19 @@ function SelectTenantPlanModal({ tenantData, onClose }: Props) {
|
|||
|
||||
const handleSelectPlan = async (plan: SubscriptionPlan) => {
|
||||
const { id: planId } = plan;
|
||||
if (planId === ReservedPlanId.free) {
|
||||
try {
|
||||
try {
|
||||
if (planId === ReservedPlanId.free) {
|
||||
const { name, tag } = tenantData;
|
||||
const newTenant = await cloudApi.post('/api/tenants', { body: { name, tag } });
|
||||
|
||||
onClose(newTenant);
|
||||
} catch (error: unknown) {
|
||||
toast.error(error instanceof Error ? error.message : String(error));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void subscribe({ planId, tenantData });
|
||||
await subscribe({ planId, tenantData });
|
||||
} catch (error: unknown) {
|
||||
toast.error(error instanceof Error ? error.message : String(error));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { toast } from 'react-hot-toast';
|
||||
import useSWR from 'swr';
|
||||
|
||||
import { useCloudApi } from '@/cloud/hooks/use-cloud-api';
|
||||
|
@ -11,7 +12,12 @@ const useInvoices = (tenantId: string) => {
|
|||
* Todo: @xiaoyijun remove this condition on subscription features ready.
|
||||
*/
|
||||
!isProduction && isCloud && `/api/tenants/${tenantId}/invoices`,
|
||||
async () => cloudApi.get('/api/tenants/:tenantId/invoices', { params: { tenantId } })
|
||||
async () => cloudApi.get('/api/tenants/:tenantId/invoices', { params: { tenantId } }),
|
||||
{
|
||||
onError: (error: unknown) => {
|
||||
toast.error(error instanceof Error ? error.message : String(error));
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const { data: invoicesResponse } = swrResponse;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { type Optional } from '@silverhand/essentials';
|
||||
import { useMemo } from 'react';
|
||||
import { toast } from 'react-hot-toast';
|
||||
import useSWRImmutable from 'swr/immutable';
|
||||
|
||||
import { useCloudApi } from '@/cloud/hooks/use-cloud-api';
|
||||
|
@ -16,7 +17,12 @@ const useSubscriptionPlans = () => {
|
|||
* Todo: @xiaoyijun remove this condition on subscription features ready.
|
||||
*/
|
||||
!isProduction && isCloud && '/api/subscription-plans',
|
||||
async () => cloudApi.get('/api/subscription-plans')
|
||||
async () => cloudApi.get('/api/subscription-plans'),
|
||||
{
|
||||
onError: (error: unknown) => {
|
||||
toast.error(error instanceof Error ? error.message : String(error));
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const { data: subscriptionPlansResponse } = useSwrResponse;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { toast } from 'react-hot-toast';
|
||||
import useSWR from 'swr';
|
||||
|
||||
import { useCloudApi } from '@/cloud/hooks/use-cloud-api';
|
||||
|
@ -15,7 +16,12 @@ const useSubscriptionUsage = (tenantId: string) => {
|
|||
async () =>
|
||||
cloudApi.get('/api/tenants/:tenantId/usage', {
|
||||
params: { tenantId },
|
||||
})
|
||||
}),
|
||||
{
|
||||
onError: (error: unknown) => {
|
||||
toast.error(error instanceof Error ? error.message : String(error));
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { toast } from 'react-hot-toast';
|
||||
import useSWR from 'swr';
|
||||
|
||||
import { useCloudApi } from '@/cloud/hooks/use-cloud-api';
|
||||
|
@ -14,7 +15,12 @@ const useSubscription = (tenantId: string) => {
|
|||
async () =>
|
||||
cloudApi.get('/api/tenants/:tenantId/subscription', {
|
||||
params: { tenantId },
|
||||
})
|
||||
}),
|
||||
{
|
||||
onError: (error: unknown) => {
|
||||
toast.error(error instanceof Error ? error.message : String(error));
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { useContext } from 'react';
|
||||
import { toast } from 'react-hot-toast';
|
||||
|
||||
import { subscriptionPage } from '@/consts/pages';
|
||||
import { ReservedPlanId } from '@/consts/subscriptions';
|
||||
|
@ -32,12 +33,16 @@ function MauLimitExceededNotification({ activeUsers, currentPlan, className }: P
|
|||
severity="error"
|
||||
action="subscription.upgrade_pro"
|
||||
className={className}
|
||||
onClick={() => {
|
||||
void subscribe({
|
||||
planId: ReservedPlanId.pro,
|
||||
tenantId: currentTenantId,
|
||||
callbackPage: subscriptionPage,
|
||||
});
|
||||
onClick={async () => {
|
||||
try {
|
||||
await subscribe({
|
||||
planId: ReservedPlanId.pro,
|
||||
tenantId: currentTenantId,
|
||||
callbackPage: subscriptionPage,
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
toast.error(error instanceof Error ? error.message : String(error));
|
||||
}
|
||||
}}
|
||||
>
|
||||
<DynamicT forKey="subscription.overfill_quota_warning" />
|
||||
|
|
|
@ -54,13 +54,19 @@ function SwitchPlanActionBar({
|
|||
callbackPage: subscriptionPage,
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
// Todo @xiaoyijun check if the error is not eligible downgrade error or not
|
||||
await show({
|
||||
ModalContent: () => <NotEligibleDowngradeModalContent targetPlan={targetPlan} />,
|
||||
title: 'subscription.downgrade_modal.not_eligible',
|
||||
confirmButtonText: 'general.got_it',
|
||||
confirmButtonType: 'primary',
|
||||
});
|
||||
/**
|
||||
* Note: this is a temporary solution to handle the case when the user tries to downgrade but the quota limit is exceeded.
|
||||
* Need a better solution to handle this case by sharing the error type between the console and cloud. - LOG-6608
|
||||
*/
|
||||
if (error instanceof Error && error.message.includes('Exceeded quota limit')) {
|
||||
await show({
|
||||
ModalContent: () => <NotEligibleDowngradeModalContent targetPlan={targetPlan} />,
|
||||
title: 'subscription.downgrade_modal.not_eligible',
|
||||
confirmButtonText: 'general.got_it',
|
||||
confirmButtonType: 'primary',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
toast.error(error instanceof Error ? error.message : String(error));
|
||||
}
|
||||
|
@ -106,17 +112,22 @@ function SwitchPlanActionBar({
|
|||
}
|
||||
type={isDowngrade ? 'default' : 'primary'}
|
||||
disabled={isCurrentPlan}
|
||||
onClick={() => {
|
||||
onClick={async () => {
|
||||
if (isDowngrade) {
|
||||
void onDowngradeClick(planId);
|
||||
await onDowngradeClick(planId);
|
||||
|
||||
return;
|
||||
}
|
||||
void subscribe({
|
||||
tenantId: currentTenantId,
|
||||
planId,
|
||||
callbackPage: subscriptionPage,
|
||||
});
|
||||
|
||||
try {
|
||||
await subscribe({
|
||||
tenantId: currentTenantId,
|
||||
planId,
|
||||
callbackPage: subscriptionPage,
|
||||
});
|
||||
} catch (error: unknown) {
|
||||
toast.error(error instanceof Error ? error.message : String(error));
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue