Skip to content

Commit 0c35176

Browse files
simeng-liCopilot
andauthored
feat(console): update subscription usage card (#7712)
* feat(console): update subscription usage card update tenant subscription usage card to support new add-on quotas * chore: fix typo Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 80ddb69 commit 0c35176

File tree

79 files changed

+736
-163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+736
-163
lines changed

packages/console/src/components/PlanUsage/index.tsx

Lines changed: 32 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,29 @@ import classNames from 'classnames';
44
import dayjs from 'dayjs';
55
import { useContext } from 'react';
66

7-
import {
8-
type NewSubscriptionPeriodicUsage,
9-
type NewSubscriptionCountBasedUsage,
10-
type NewSubscriptionQuota,
11-
type TenantUsageAddOnSkus,
12-
} from '@/cloud/types/router';
7+
import { type NewSubscriptionPeriodicUsage, type TenantUsageAddOnSkus } from '@/cloud/types/router';
138
import { SubscriptionDataContext } from '@/contexts/SubscriptionDataProvider';
149
import DynamicT from '@/ds-components/DynamicT';
15-
import { formatPeriod, isPaidPlan, isProPlan } from '@/utils/subscription';
10+
import { formatPeriod, isPaidPlan } from '@/utils/subscription';
1611

1712
import PlanUsageCard, { type Props as PlanUsageCardProps } from './PlanUsageCard';
1813
import styles from './index.module.scss';
1914
import {
20-
type UsageKey,
2115
usageKeys,
2216
usageKeyPriceMap,
2317
titleKeyMap,
24-
tooltipKeyMap,
25-
enterpriseTooltipKeyMap,
18+
getUsageByKey,
19+
getQuotaByKey,
20+
getToolTipByKey,
21+
shouldHideQuotaNotice,
22+
filterNewUsageKeysForLegacyPro,
2623
} from './utils';
2724

2825
type Props = {
2926
readonly periodicUsage: NewSubscriptionPeriodicUsage | undefined;
3027
readonly usageAddOnSkus?: TenantUsageAddOnSkus;
3128
};
3229

33-
const getUsageByKey = (
34-
key: keyof UsageKey,
35-
{
36-
periodicUsage,
37-
countBasedUsage,
38-
basicQuota,
39-
}: {
40-
periodicUsage: NewSubscriptionPeriodicUsage;
41-
countBasedUsage: NewSubscriptionCountBasedUsage;
42-
basicQuota: NewSubscriptionQuota;
43-
}
44-
) => {
45-
if (key === 'mauLimit' || key === 'tokenLimit') {
46-
return periodicUsage[key];
47-
}
48-
49-
// Show organization usage status in in-use/not-in-use state.
50-
if (key === 'organizationsLimit') {
51-
// If the basic quota is a non-zero number, show the usage in `usage(number-typed) (First {{basicQuota}} included)` format.
52-
if (typeof basicQuota[key] === 'number' && basicQuota[key] !== 0) {
53-
return countBasedUsage[key];
54-
}
55-
56-
return countBasedUsage[key] > 0;
57-
}
58-
59-
return countBasedUsage[key];
60-
};
61-
6230
function PlanUsage({ periodicUsage, usageAddOnSkus }: Props) {
6331
const {
6432
currentSubscriptionQuota,
@@ -80,57 +48,32 @@ function PlanUsage({ periodicUsage, usageAddOnSkus }: Props) {
8048
(key) =>
8149
isPaidTenant || (onlyShowPeriodicUsage && (key === 'mauLimit' || key === 'tokenLimit'))
8250
)
83-
.map((key) => ({
84-
usage: getUsageByKey(key, {
85-
periodicUsage,
86-
countBasedUsage: currentSubscriptionUsage,
87-
basicQuota: currentSubscriptionBasicQuota,
88-
}),
89-
usageKey: 'subscription.usage.usage_description_with_limited_quota',
90-
titleKey: `subscription.usage.${titleKeyMap[key]}`,
91-
unitPrice: usageKeyPriceMap[key],
92-
// Only support tokenLimit for now
93-
usageAddOnSku: cond(key === 'tokenLimit' && usageAddOnSkus?.[key]),
94-
...cond(
95-
// We only show the usage card for MAU and token for Free plan
96-
(key === 'tokenLimit' || key === 'mauLimit' || isPaidTenant) && {
97-
quota: currentSubscriptionQuota[key],
98-
}
99-
),
100-
...cond(
101-
isPaidTenant && {
102-
basicQuota: currentSubscriptionBasicQuota[key],
103-
// Do not show tooltip if the basic quota is null (unlimited) for m2m/API resource add-on.
104-
...cond(
105-
!(
106-
currentSubscriptionBasicQuota[key] === null &&
107-
(key === 'machineToMachineLimit' || key === 'resourcesLimit')
108-
) && {
109-
tooltipKey: `subscription.usage.${
110-
isEnterprisePlan ? enterpriseTooltipKeyMap[key] : tooltipKeyMap[key]
111-
}`,
112-
}
113-
),
114-
// Show tooltip for number-typed basic quota for 'organizationsLimit'.
115-
...cond(
116-
key === 'organizationsLimit' &&
117-
typeof currentSubscriptionBasicQuota[key] === 'number' &&
118-
currentSubscriptionBasicQuota[key] > 0 && {
119-
tooltipKey:
120-
'subscription.usage.organizations.tooltip_for_enterprise_with_numbered_basic_quota',
121-
}
122-
),
123-
}
124-
),
125-
// Hide the quota notice for Pro plans if the basic quota is 0.
126-
// Per current pricing model design, it should apply to `enterpriseSsoLimit`.
127-
...cond(
128-
isProPlan(planId) &&
129-
currentSubscriptionBasicQuota[key] === 0 && {
130-
isQuotaNoticeHidden: true,
51+
// TODO: remove this filter after the pro plan migration is complete.
52+
.filter((key) => {
53+
return filterNewUsageKeysForLegacyPro(key, planId);
54+
})
55+
.map((key) => {
56+
return {
57+
usage: getUsageByKey(key, {
58+
periodicUsage,
59+
countBasedUsage: currentSubscriptionUsage,
60+
basicQuota: currentSubscriptionBasicQuota,
61+
}),
62+
usageKey: 'subscription.usage.usage_description_with_limited_quota',
63+
titleKey: `subscription.usage.${titleKeyMap[key]}`,
64+
unitPrice: usageKeyPriceMap[key],
65+
// Only support tokenLimit for now
66+
usageAddOnSku: cond(key === 'tokenLimit' && usageAddOnSkus?.[key]),
67+
quota: getQuotaByKey(key, currentSubscriptionQuota),
68+
...cond(
69+
isPaidTenant && {
70+
basicQuota: getQuotaByKey(key, currentSubscriptionBasicQuota),
71+
tooltipKey: getToolTipByKey(key, currentSubscriptionBasicQuota, isEnterprisePlan),
13172
}
132-
),
133-
}));
73+
),
74+
isQuotaNoticeHidden: shouldHideQuotaNotice(key, currentSubscriptionBasicQuota, planId),
75+
};
76+
});
13477

13578
return (
13679
<div>

0 commit comments

Comments
 (0)