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: refactor SkuName component to make isEnterprisePlan as input #6580

Merged
merged 1 commit into from
Sep 13, 2024
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 @@ -113,7 +113,7 @@ function Footer({ selectedType, isLoading, onClickCreate, isThirdParty }: Props)
<Trans
components={{
a: <ContactUsPhraseLink />,
planName: <SkuName skuId={currentSku.id} />,
planName: <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />,
}}
>
{t('paywall.applications', { count: currentSubscriptionQuota.applicationsLimit ?? 0 })}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ type Props = {

function Footer({ isCreatingSocialConnector, isCreateButtonDisabled, onClickCreateButton }: Props) {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console.upsell.paywall' });
const { currentSku, currentSubscriptionUsage, currentSubscriptionQuota } =
useContext(SubscriptionDataContext);
const {
currentSubscription: { planId, isEnterprisePlan },
currentSubscriptionUsage,
currentSubscriptionQuota,
} = useContext(SubscriptionDataContext);

const isSocialConnectorsReachLimit = hasReachedSubscriptionQuotaLimit({
quotaKey: 'socialConnectorsLimit',
Expand All @@ -31,7 +34,7 @@ function Footer({ isCreatingSocialConnector, isCreateButtonDisabled, onClickCrea
<Trans
components={{
a: <ContactUsPhraseLink />,
planName: <SkuName skuId={currentSku.id} />,
planName: <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />,
}}
>
{t('social_connectors', {
Expand Down
6 changes: 4 additions & 2 deletions packages/console/src/components/MauExceededModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import SkuName from '../SkuName';
import styles from './index.module.scss';

function MauExceededModal() {
const { currentSku } = useContext(SubscriptionDataContext);
const {
currentSubscription: { planId, isEnterprisePlan },
} = useContext(SubscriptionDataContext);
const { currentTenant } = useContext(TenantsContext);

const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
Expand Down Expand Up @@ -75,7 +77,7 @@ function MauExceededModal() {
<InlineNotification severity="error">
<Trans
components={{
planName: <SkuName skuId={currentSku.id} />,
planName: <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />,
}}
>
{t('upsell.mau_exceeded_modal.notification')}
Expand Down
8 changes: 2 additions & 6 deletions packages/console/src/components/SkuName/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { ReservedPlanId } from '@logto/schemas';
import { type TFuncKey } from 'i18next';
import { useContext } from 'react';
import { useTranslation } from 'react-i18next';

import { SubscriptionDataContext } from '@/contexts/SubscriptionDataProvider';
import { ReservedSkuId } from '@/types/subscriptions';

const registeredSkuIdNamePhraseMap: Record<
Expand All @@ -20,13 +18,11 @@ const registeredSkuIdNamePhraseMap: Record<

type Props = {
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 {
currentSubscription: { isEnterprisePlan },
} = useContext(SubscriptionDataContext);
const skuId = isEnterprisePlan ? ReservedPlanId.Enterprise : rawSkuId;

const skuNamePhrase = registeredSkuIdNamePhraseMap[skuId];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TenantTag, ReservedPlanId } from '@logto/schemas';
import { TenantTag } from '@logto/schemas';
import classNames from 'classnames';
import { useContext, useMemo } from 'react';

Expand Down Expand Up @@ -31,7 +31,6 @@ function TenantDropdownItem({ tenantData, isSelected, onClick }: Props) {
() => logtoSkus.find(({ id }) => id === planId),
[logtoSkus, planId]
);
const skuId = isEnterprisePlan ? ReservedPlanId.Enterprise : planId;

if (!tenantSubscriptionSku) {
return null;
Expand All @@ -49,7 +48,7 @@ function TenantDropdownItem({ tenantData, isSelected, onClick }: Props) {
{tag === TenantTag.Development ? (
<DynamicT forKey="subscription.no_subscription" />
) : (
<SkuName skuId={skuId} />
<SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />
)}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ type Props = {
type CreatePermissionFormData = Pick<CreateScope, 'name' | 'description'>;

function CreatePermissionModal({ resourceId, totalResourceCount, onClose }: Props) {
const { currentSku, currentSubscriptionQuota, currentSubscriptionResourceScopeUsage } =
useContext(SubscriptionDataContext);
const {
currentSubscriptionQuota,
currentSubscriptionResourceScopeUsage,
currentSubscription: { planId, isEnterprisePlan },
} = useContext(SubscriptionDataContext);
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });

const {
Expand Down Expand Up @@ -83,7 +86,7 @@ function CreatePermissionModal({ resourceId, totalResourceCount, onClose }: Prop
<Trans
components={{
a: <ContactUsPhraseLink />,
planName: <SkuName skuId={currentSku.id} />,
planName: <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />,
}}
>
{t('upsell.paywall.scopes_per_resource', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function Footer({ isCreationLoading, onClickCreate }: Props) {
<Trans
components={{
a: <ContactUsPhraseLink />,
planName: <SkuName skuId={currentSku.id} />,
planName: <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />,
}}
>
{t('upsell.paywall.resources', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ function ProtectedAppForm({
onCreateSuccess,
}: Props) {
const { data } = useSWRImmutable<ProtectedAppsDomainConfig>(isCloud && 'api/systems/application');
const { currentSku, currentSubscriptionQuota } = useContext(SubscriptionDataContext);
const {
currentSubscriptionQuota,
currentSubscription: { planId, isEnterprisePlan },
} = useContext(SubscriptionDataContext);
const { hasAppsReachedLimit } = useApplicationsUsage();
const defaultDomain = data?.protectedApps.defaultDomain ?? '';
const { navigate } = useTenantPathname();
Expand Down Expand Up @@ -202,7 +205,7 @@ function ProtectedAppForm({
<Trans
components={{
a: <ContactUsPhraseLink />,
planName: <SkuName skuId={currentSku.id} />,
planName: <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />,
}}
>
{t('upsell.paywall.applications', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ type Props = {

function AssignPermissionsModal({ roleId, roleType, onClose }: Props) {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { currentSku, currentSubscriptionRoleScopeUsage, currentSubscriptionQuota } =
useContext(SubscriptionDataContext);
const {
currentSubscription: { planId, isEnterprisePlan },
currentSubscriptionRoleScopeUsage,
currentSubscriptionQuota,
} = useContext(SubscriptionDataContext);
const [isSubmitting, setIsSubmitting] = useState(false);
const [scopes, setScopes] = useState<ScopeResponse[]>([]);

Expand Down Expand Up @@ -79,7 +82,7 @@ function AssignPermissionsModal({ roleId, roleType, onClose }: Props) {
<Trans
components={{
a: <ContactUsPhraseLink />,
planName: <SkuName skuId={currentSku.id} />,
planName: <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />,
}}
>
{t('upsell.paywall.scopes_per_role', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ type Props = {

function Footer({ roleType, isCreating, onClickCreate }: Props) {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { currentSku, currentSubscriptionQuota, currentSubscriptionUsage } =
useContext(SubscriptionDataContext);
const {
currentSubscription: { planId, isEnterprisePlan },
currentSubscriptionQuota,
currentSubscriptionUsage,
} = useContext(SubscriptionDataContext);

const hasRoleReachedLimit = hasReachedSubscriptionQuotaLimit({
quotaKey: roleType === RoleType.User ? 'userRolesLimit' : 'machineToMachineRolesLimit',
Expand All @@ -44,7 +47,7 @@ function Footer({ roleType, isCreating, onClickCreate }: Props) {
<Trans
components={{
a: <ContactUsPhraseLink />,
planName: <SkuName skuId={currentSku.id} />,
planName: <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />,
}}
>
{/* User roles limit paywall */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function CurrentPlan({ periodicUsage: rawPeriodicUsage }: Props) {
<FormCard title="subscription.current_plan" description="subscription.current_plan_description">
<div className={styles.planInfo}>
<div className={styles.name}>
<SkuName skuId={currentSkuId} />
<SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />
</div>
<div className={styles.description}>
<PlanDescription skuId={currentSkuId} planId={planId} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ type CreateHookPayload = Pick<CreateHook, 'name'> & {
};

function CreateForm({ onClose }: Props) {
const { currentSku, currentSubscriptionQuota, currentSubscriptionUsage } =
useContext(SubscriptionDataContext);
const {
currentSubscription: { planId, isEnterprisePlan },
currentSubscriptionQuota,
currentSubscriptionUsage,
} = useContext(SubscriptionDataContext);
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });

const shouldBlockCreation = hasReachedSubscriptionQuotaLimit({
Expand Down Expand Up @@ -70,7 +73,7 @@ function CreateForm({ onClose }: Props) {
<Trans
components={{
a: <ContactUsPhraseLink />,
planName: <SkuName skuId={currentSku.id} />,
planName: <SkuName skuId={planId} isEnterprisePlan={isEnterprisePlan} />,
}}
>
{t('upsell.paywall.hooks', {
Expand Down
Loading