0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-30 20:33:54 -05:00

fix(console): upcoming billing info not updated when subscription changes (#5223)

This commit is contained in:
Darcy Ye 2024-01-12 11:50:07 +08:00 committed by GitHub
parent 4a517379b3
commit 098cfd7c54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View file

@ -23,7 +23,7 @@ import * as styles from './index.module.scss';
type Props = {
currentSubscriptionPlanId: string;
subscriptionPlans: SubscriptionPlan[];
onSubscriptionUpdated: () => void;
onSubscriptionUpdated: () => Promise<void>;
};
function SwitchPlanActionBar({
@ -67,7 +67,7 @@ function SwitchPlanActionBar({
setCurrentLoadingPlanId(targetPlanId);
if (targetPlanId === ReservedPlanId.Free) {
await cancelSubscription(currentTenantId);
onSubscriptionUpdated();
await onSubscriptionUpdated();
toast.success(
<Trans components={{ name: <PlanName name={targetPlan.name} /> }}>
{t('downgrade_success')}

View file

@ -19,7 +19,11 @@ function Subscription() {
const { subscriptionPlans, currentPlan, currentSubscription, onCurrentSubscriptionUpdated } =
useContext(SubscriptionDataContext);
const { data: subscriptionUsage, isLoading } = useSubscriptionUsage(currentTenantId);
const {
data: subscriptionUsage,
isLoading,
mutate: mutateSubscriptionUsage,
} = useSubscriptionUsage(currentTenantId);
const reservedPlans = pickupFeaturedPlans(subscriptionPlans);
@ -43,7 +47,15 @@ function Subscription() {
<SwitchPlanActionBar
currentSubscriptionPlanId={currentSubscription.planId}
subscriptionPlans={reservedPlans}
onSubscriptionUpdated={onCurrentSubscriptionUpdated}
onSubscriptionUpdated={async () => {
/**
* The upcoming billing info is calculated based on the current subscription usage,
* and the usage is based on the current subscription plan,
* need to manually trigger the usage update while the subscription plan is changed.
*/
onCurrentSubscriptionUpdated();
await mutateSubscriptionUsage();
}}
/>
</div>
);