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

refactor: refactor SkuName component to make isEnterprisePlan as input (#6580)

This commit is contained in:
Darcy Ye 2024-09-13 11:42:48 +08:00 committed by GitHub
parent 193b4a4011
commit 560cb23b30
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 46 additions and 31 deletions

View file

@ -113,7 +113,7 @@ function Footer({ selectedType, isLoading, onClickCreate, isThirdParty }: Props)
<Trans <Trans
components={{ components={{
a: <ContactUsPhraseLink />, a: <ContactUsPhraseLink />,
planName: <SkuName skuId={currentSku.id} />, planName: <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />,
}} }}
> >
{t('paywall.applications', { count: currentSubscriptionQuota.applicationsLimit ?? 0 })} {t('paywall.applications', { count: currentSubscriptionQuota.applicationsLimit ?? 0 })}

View file

@ -16,8 +16,11 @@ type Props = {
function Footer({ isCreatingSocialConnector, isCreateButtonDisabled, onClickCreateButton }: Props) { function Footer({ isCreatingSocialConnector, isCreateButtonDisabled, onClickCreateButton }: Props) {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console.upsell.paywall' }); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console.upsell.paywall' });
const { currentSku, currentSubscriptionUsage, currentSubscriptionQuota } = const {
useContext(SubscriptionDataContext); currentSubscription: { planId, isEnterprisePlan },
currentSubscriptionUsage,
currentSubscriptionQuota,
} = useContext(SubscriptionDataContext);
const isSocialConnectorsReachLimit = hasReachedSubscriptionQuotaLimit({ const isSocialConnectorsReachLimit = hasReachedSubscriptionQuotaLimit({
quotaKey: 'socialConnectorsLimit', quotaKey: 'socialConnectorsLimit',
@ -31,7 +34,7 @@ function Footer({ isCreatingSocialConnector, isCreateButtonDisabled, onClickCrea
<Trans <Trans
components={{ components={{
a: <ContactUsPhraseLink />, a: <ContactUsPhraseLink />,
planName: <SkuName skuId={currentSku.id} />, planName: <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />,
}} }}
> >
{t('social_connectors', { {t('social_connectors', {

View file

@ -20,7 +20,9 @@ import SkuName from '../SkuName';
import styles from './index.module.scss'; import styles from './index.module.scss';
function MauExceededModal() { function MauExceededModal() {
const { currentSku } = useContext(SubscriptionDataContext); const {
currentSubscription: { planId, isEnterprisePlan },
} = useContext(SubscriptionDataContext);
const { currentTenant } = useContext(TenantsContext); const { currentTenant } = useContext(TenantsContext);
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
@ -75,7 +77,7 @@ function MauExceededModal() {
<InlineNotification severity="error"> <InlineNotification severity="error">
<Trans <Trans
components={{ components={{
planName: <SkuName skuId={currentSku.id} />, planName: <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />,
}} }}
> >
{t('upsell.mau_exceeded_modal.notification')} {t('upsell.mau_exceeded_modal.notification')}

View file

@ -1,9 +1,7 @@
import { ReservedPlanId } from '@logto/schemas'; import { ReservedPlanId } from '@logto/schemas';
import { type TFuncKey } from 'i18next'; import { type TFuncKey } from 'i18next';
import { useContext } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { SubscriptionDataContext } from '@/contexts/SubscriptionDataProvider';
import { ReservedSkuId } from '@/types/subscriptions'; import { ReservedSkuId } from '@/types/subscriptions';
const registeredSkuIdNamePhraseMap: Record< const registeredSkuIdNamePhraseMap: Record<
@ -20,13 +18,11 @@ const registeredSkuIdNamePhraseMap: Record<
type Props = { type Props = {
readonly skuId: string; readonly skuId: string;
readonly isEnterprisePlan?: boolean;
}; };
function SkuName({ skuId: rawSkuId }: Props) { function SkuName({ skuId: rawSkuId, isEnterprisePlan = false }: Props) {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console.subscription' }); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console.subscription' });
const {
currentSubscription: { isEnterprisePlan },
} = useContext(SubscriptionDataContext);
const skuId = isEnterprisePlan ? ReservedPlanId.Enterprise : rawSkuId; const skuId = isEnterprisePlan ? ReservedPlanId.Enterprise : rawSkuId;
const skuNamePhrase = registeredSkuIdNamePhraseMap[skuId]; const skuNamePhrase = registeredSkuIdNamePhraseMap[skuId];

View file

@ -1,4 +1,4 @@
import { TenantTag, ReservedPlanId } from '@logto/schemas'; import { TenantTag } from '@logto/schemas';
import classNames from 'classnames'; import classNames from 'classnames';
import { useContext, useMemo } from 'react'; import { useContext, useMemo } from 'react';
@ -31,7 +31,6 @@ function TenantDropdownItem({ tenantData, isSelected, onClick }: Props) {
() => logtoSkus.find(({ id }) => id === planId), () => logtoSkus.find(({ id }) => id === planId),
[logtoSkus, planId] [logtoSkus, planId]
); );
const skuId = isEnterprisePlan ? ReservedPlanId.Enterprise : planId;
if (!tenantSubscriptionSku) { if (!tenantSubscriptionSku) {
return null; return null;
@ -49,7 +48,7 @@ function TenantDropdownItem({ tenantData, isSelected, onClick }: Props) {
{tag === TenantTag.Development ? ( {tag === TenantTag.Development ? (
<DynamicT forKey="subscription.no_subscription" /> <DynamicT forKey="subscription.no_subscription" />
) : ( ) : (
<SkuName skuId={skuId} /> <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />
)} )}
</div> </div>
</div> </div>

View file

@ -28,8 +28,11 @@ type Props = {
type CreatePermissionFormData = Pick<CreateScope, 'name' | 'description'>; type CreatePermissionFormData = Pick<CreateScope, 'name' | 'description'>;
function CreatePermissionModal({ resourceId, totalResourceCount, onClose }: Props) { function CreatePermissionModal({ resourceId, totalResourceCount, onClose }: Props) {
const { currentSku, currentSubscriptionQuota, currentSubscriptionResourceScopeUsage } = const {
useContext(SubscriptionDataContext); currentSubscriptionQuota,
currentSubscriptionResourceScopeUsage,
currentSubscription: { planId, isEnterprisePlan },
} = useContext(SubscriptionDataContext);
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { const {
@ -83,7 +86,7 @@ function CreatePermissionModal({ resourceId, totalResourceCount, onClose }: Prop
<Trans <Trans
components={{ components={{
a: <ContactUsPhraseLink />, a: <ContactUsPhraseLink />,
planName: <SkuName skuId={currentSku.id} />, planName: <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />,
}} }}
> >
{t('upsell.paywall.scopes_per_resource', { {t('upsell.paywall.scopes_per_resource', {

View file

@ -47,7 +47,7 @@ function Footer({ isCreationLoading, onClickCreate }: Props) {
<Trans <Trans
components={{ components={{
a: <ContactUsPhraseLink />, a: <ContactUsPhraseLink />,
planName: <SkuName skuId={currentSku.id} />, planName: <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />,
}} }}
> >
{t('upsell.paywall.resources', { {t('upsell.paywall.resources', {

View file

@ -46,7 +46,10 @@ function ProtectedAppForm({
onCreateSuccess, onCreateSuccess,
}: Props) { }: Props) {
const { data } = useSWRImmutable<ProtectedAppsDomainConfig>(isCloud && 'api/systems/application'); const { data } = useSWRImmutable<ProtectedAppsDomainConfig>(isCloud && 'api/systems/application');
const { currentSku, currentSubscriptionQuota } = useContext(SubscriptionDataContext); const {
currentSubscriptionQuota,
currentSubscription: { planId, isEnterprisePlan },
} = useContext(SubscriptionDataContext);
const { hasAppsReachedLimit } = useApplicationsUsage(); const { hasAppsReachedLimit } = useApplicationsUsage();
const defaultDomain = data?.protectedApps.defaultDomain ?? ''; const defaultDomain = data?.protectedApps.defaultDomain ?? '';
const { navigate } = useTenantPathname(); const { navigate } = useTenantPathname();
@ -202,7 +205,7 @@ function ProtectedAppForm({
<Trans <Trans
components={{ components={{
a: <ContactUsPhraseLink />, a: <ContactUsPhraseLink />,
planName: <SkuName skuId={currentSku.id} />, planName: <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />,
}} }}
> >
{t('upsell.paywall.applications', { {t('upsell.paywall.applications', {

View file

@ -24,8 +24,11 @@ type Props = {
function AssignPermissionsModal({ roleId, roleType, onClose }: Props) { function AssignPermissionsModal({ roleId, roleType, onClose }: Props) {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { currentSku, currentSubscriptionRoleScopeUsage, currentSubscriptionQuota } = const {
useContext(SubscriptionDataContext); currentSubscription: { planId, isEnterprisePlan },
currentSubscriptionRoleScopeUsage,
currentSubscriptionQuota,
} = useContext(SubscriptionDataContext);
const [isSubmitting, setIsSubmitting] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false);
const [scopes, setScopes] = useState<ScopeResponse[]>([]); const [scopes, setScopes] = useState<ScopeResponse[]>([]);
@ -79,7 +82,7 @@ function AssignPermissionsModal({ roleId, roleType, onClose }: Props) {
<Trans <Trans
components={{ components={{
a: <ContactUsPhraseLink />, a: <ContactUsPhraseLink />,
planName: <SkuName skuId={currentSku.id} />, planName: <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />,
}} }}
> >
{t('upsell.paywall.scopes_per_role', { {t('upsell.paywall.scopes_per_role', {

View file

@ -20,8 +20,11 @@ type Props = {
function Footer({ roleType, isCreating, onClickCreate }: Props) { function Footer({ roleType, isCreating, onClickCreate }: Props) {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { currentSku, currentSubscriptionQuota, currentSubscriptionUsage } = const {
useContext(SubscriptionDataContext); currentSubscription: { planId, isEnterprisePlan },
currentSubscriptionQuota,
currentSubscriptionUsage,
} = useContext(SubscriptionDataContext);
const hasRoleReachedLimit = hasReachedSubscriptionQuotaLimit({ const hasRoleReachedLimit = hasReachedSubscriptionQuotaLimit({
quotaKey: roleType === RoleType.User ? 'userRolesLimit' : 'machineToMachineRolesLimit', quotaKey: roleType === RoleType.User ? 'userRolesLimit' : 'machineToMachineRolesLimit',
@ -44,7 +47,7 @@ function Footer({ roleType, isCreating, onClickCreate }: Props) {
<Trans <Trans
components={{ components={{
a: <ContactUsPhraseLink />, a: <ContactUsPhraseLink />,
planName: <SkuName skuId={currentSku.id} />, planName: <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />,
}} }}
> >
{/* User roles limit paywall */} {/* User roles limit paywall */}

View file

@ -59,7 +59,7 @@ function CurrentPlan({ periodicUsage: rawPeriodicUsage }: Props) {
<FormCard title="subscription.current_plan" description="subscription.current_plan_description"> <FormCard title="subscription.current_plan" description="subscription.current_plan_description">
<div className={styles.planInfo}> <div className={styles.planInfo}>
<div className={styles.name}> <div className={styles.name}>
<SkuName skuId={currentSkuId} /> <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />
</div> </div>
<div className={styles.description}> <div className={styles.description}>
<PlanDescription skuId={currentSkuId} planId={planId} /> <PlanDescription skuId={currentSkuId} planId={planId} />

View file

@ -26,8 +26,11 @@ type CreateHookPayload = Pick<CreateHook, 'name'> & {
}; };
function CreateForm({ onClose }: Props) { function CreateForm({ onClose }: Props) {
const { currentSku, currentSubscriptionQuota, currentSubscriptionUsage } = const {
useContext(SubscriptionDataContext); currentSubscription: { planId, isEnterprisePlan },
currentSubscriptionQuota,
currentSubscriptionUsage,
} = useContext(SubscriptionDataContext);
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const shouldBlockCreation = hasReachedSubscriptionQuotaLimit({ const shouldBlockCreation = hasReachedSubscriptionQuotaLimit({
@ -70,7 +73,7 @@ function CreateForm({ onClose }: Props) {
<Trans <Trans
components={{ components={{
a: <ContactUsPhraseLink />, a: <ContactUsPhraseLink />,
planName: <SkuName skuId={currentSku.id} />, planName: <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />,
}} }}
> >
{t('upsell.paywall.hooks', { {t('upsell.paywall.hooks', {