Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(console): extract shared quota between featured plan and comparison table #5543

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import { cond } from '@silverhand/essentials';
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';

import {
freePlanAuditLogsRetentionDays,
freePlanM2mLimit,
freePlanMauLimit,
freePlanPermissionsLimit,
freePlanRoleLimit,
proPlanAuditLogsRetentionDays,
} from '@/consts/subscriptions';

type ContentData = {
title: string;
isAvailable: boolean;
Expand All @@ -19,11 +28,11 @@ const useFeaturedPlanContent = (planId: string) => {

return [
{
title: t(`mau.${planPhraseKey}`, { ...cond(isFreePlan && { count: 50_000 }) }),
title: t(`mau.${planPhraseKey}`, { ...cond(isFreePlan && { count: freePlanMauLimit }) }),
isAvailable: true,
},
{
title: t(`m2m.${planPhraseKey}`, { ...cond(isFreePlan && { count: 1 }) }),
title: t(`m2m.${planPhraseKey}`, { ...cond(isFreePlan && { count: freePlanM2mLimit }) }),
isAvailable: true,
},
{
Expand All @@ -42,8 +51,8 @@ const useFeaturedPlanContent = (planId: string) => {
title: t(`role_and_permissions.${planPhraseKey}`, {
...cond(
isFreePlan && {
roleCount: 1,
permissionCount: 1,
roleCount: freePlanRoleLimit,
permissionCount: freePlanPermissionsLimit,
}
),
}),
Expand All @@ -54,7 +63,9 @@ const useFeaturedPlanContent = (planId: string) => {
isAvailable: !isFreePlan,
},
{
title: t('audit_logs', { count: isFreePlan ? 3 : 14 }),
title: t('audit_logs', {
count: isFreePlan ? freePlanAuditLogsRetentionDays : proPlanAuditLogsRetentionDays,
}),
isAvailable: true,
},
];
Expand Down
10 changes: 10 additions & 0 deletions packages/console/src/consts/subscriptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { ReservedPlanId } from '@logto/schemas';

/**
* Shared quota limits between the featured plan content in the `CreateTenantModal` and the `PlanComparisonTable`.
*/
export const freePlanMauLimit = 50_000;
export const freePlanM2mLimit = 1;
export const freePlanRoleLimit = 1;
export const freePlanPermissionsLimit = 1;
export const freePlanAuditLogsRetentionDays = 3;
export const proPlanAuditLogsRetentionDays = 14;

/**
* In console, only featured plans are shown in the plan selection component.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import { type TFuncKey } from 'i18next';
import { Fragment, useMemo } from 'react';
import { useTranslation } from 'react-i18next';

import {
freePlanAuditLogsRetentionDays,
freePlanM2mLimit,
freePlanMauLimit,
freePlanPermissionsLimit,
freePlanRoleLimit,
proPlanAuditLogsRetentionDays,
} from '@/consts/subscriptions';
import DynamicT from '@/ds-components/DynamicT';

import TableDataWrapper from './TableDataWrapper';
Expand Down Expand Up @@ -113,8 +121,8 @@ function PlanComparisonTable() {

// Audit logs
const auditLogRetention = t('audit_logs.retention');
const freePlanLogRetention = t('days', { count: 3 });
const paidPlanLogRetention = t('days', { count: 14 });
const freePlanLogRetention = t('days', { count: freePlanAuditLogsRetentionDays });
const paidPlanLogRetention = t('days', { count: proPlanAuditLogsRetentionDays });

// Webhooks
const webhooks = t('hooks.hooks');
Expand All @@ -130,7 +138,10 @@ function PlanComparisonTable() {
title: 'quota.title',
rows: [
{ name: basePrice, data: ['0', proPlanBasePrice, contact] },
{ name: `${mauLimit}|${mauLimitTip}`, data: ['50,000', unlimited, contact] },
{
name: `${mauLimit}|${mauLimitTip}`,
data: [freePlanMauLimit.toLocaleString(), unlimited, contact],
},
{
name: `${includedTokens}|${includedTokensTip}`,
data: ['500,000', `${proPlanIncludedTokens}|${proPlanIncludedTokensTip}`, contact],
Expand All @@ -144,7 +155,7 @@ function PlanComparisonTable() {
{
name: m2mApps,
data: [
'1',
`${freePlanM2mLimit}`,
`${proPlanM2mAppLimit}|${paidQuotaLimitTip}|${proPlanM2mAppPrice}`,
contact,
],
Expand Down Expand Up @@ -197,9 +208,9 @@ function PlanComparisonTable() {
title: 'user_management.title',
rows: [
{ name: userManagement, data: ['✓', '✓', '✓'] },
{ name: userRoles, data: ['1', unlimited, contact] },
{ name: userRoles, data: [`${freePlanRoleLimit}`, unlimited, contact] },
{ name: m2mRoles, data: ['1', unlimited, contact] },
{ name: permissionsPerRole, data: ['1', unlimited, contact] },
{ name: permissionsPerRole, data: [`${freePlanPermissionsLimit}`, unlimited, contact] },
],
},
{
Expand Down
Loading