Skip to content

Commit

Permalink
fix(console): fix the plan title for subscription plan selector
Browse files Browse the repository at this point in the history
  • Loading branch information
darcyYe committed Jul 26, 2024
1 parent 33a1ac1 commit a47821c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/console/src/components/PlanName/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { conditional } from '@silverhand/essentials';
import { type TFuncKey } from 'i18next';
import { useTranslation } from 'react-i18next';

import { ReservedPlanName } from '@/types/subscriptions';
import { ReservedPlanName, ReservedSkuId } from '@/types/subscriptions';

const registeredPlanNamePhraseMap: Record<
string,
Expand All @@ -15,6 +15,16 @@ const registeredPlanNamePhraseMap: Record<
[ReservedPlanName.Enterprise]: 'enterprise',
};

const registeredSkuIdNamePhraseMap: Record<
string,
TFuncKey<'translation', 'admin_console.subscription'> | undefined
> = {
quotaKey: undefined,
[ReservedSkuId.Free]: 'free_plan',
[ReservedSkuId.Pro]: 'pro_plan',
[ReservedSkuId.Enterprise]: 'enterprise',
};

type Props = {
/** Temporarily use optional for backward compatibility. */
readonly skuId?: string;
Expand All @@ -26,7 +36,7 @@ type Props = {
function PlanName({ skuId, name }: Props) {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console.subscription' });
const planNamePhrase =
conditional(skuId && registeredPlanNamePhraseMap[skuId]) ?? registeredPlanNamePhraseMap[name];
conditional(skuId && registeredSkuIdNamePhraseMap[skuId]) ?? registeredPlanNamePhraseMap[name];

/**
* Note: fallback to the plan name if the phrase is not registered.
Expand Down
7 changes: 7 additions & 0 deletions packages/console/src/types/subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ export enum ReservedPlanName {
Enterprise = 'Enterprise',
}

// TODO: use `ReservedPlanId` in the future.

Check warning on line 13 in packages/console/src/types/subscriptions.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/console/src/types/subscriptions.ts#L13

[no-warning-comments] Unexpected 'todo' comment: 'TODO: use `ReservedPlanId` in the...'.
export enum ReservedSkuId {
Free = 'free',
Pro = 'pro',
Enterprise = 'enterprise',
}

export type SubscriptionPlanQuota = Omit<
SubscriptionPlanResponse['quota'],
'builtInEmailConnectorEnabled'
Expand Down

0 comments on commit a47821c

Please sign in to comment.