Skip to content

Commit 7dc7bc5

Browse files
authored
feat(console): add add-on tag to the role creation modal (#7729)
add the add-on tag to the role creation modal
1 parent ffa1cfe commit 7dc7bc5

File tree

1 file changed

+15
-0
lines changed
  • packages/console/src/pages/Roles/components/CreateRoleForm

1 file changed

+15
-0
lines changed

packages/console/src/pages/Roles/components/CreateRoleForm/index.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@ import { type AdminConsoleKey } from '@logto/phrases';
22
import type { Role, ScopeResponse } from '@logto/schemas';
33
import { RoleType, internalRolePrefix } from '@logto/schemas';
44
import { conditional } from '@silverhand/essentials';
5+
import { useContext } from 'react';
56
import { Controller, useForm } from 'react-hook-form';
67
import { useTranslation } from 'react-i18next';
78

89
import RoleScopesTransfer from '@/components/RoleScopesTransfer';
10+
import { isDevFeaturesEnabled } from '@/consts/env';
11+
import { SubscriptionDataContext } from '@/contexts/SubscriptionDataProvider';
912
import DynamicT from '@/ds-components/DynamicT';
1013
import FormField from '@/ds-components/FormField';
1114
import ModalLayout from '@/ds-components/ModalLayout';
1215
import RadioGroup, { Radio } from '@/ds-components/RadioGroup';
1316
import TextInput from '@/ds-components/TextInput';
1417
import useApi from '@/hooks/use-api';
1518
import { trySubmitSafe } from '@/utils/form';
19+
import { isPaidPlan } from '@/utils/subscription';
1620

1721
import Footer from './Footer';
1822
import styles from './index.module.scss';
@@ -39,6 +43,15 @@ type CreateRolePayload = Pick<Role, 'name' | 'description' | 'type'> & {
3943
function CreateRoleForm({ onClose }: Props) {
4044
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
4145

46+
const {
47+
currentSubscription: { planId, isEnterprisePlan },
48+
currentSubscriptionBasicQuota: { userRolesLimit, machineToMachineRolesLimit },
49+
} = useContext(SubscriptionDataContext);
50+
51+
const isPaidTenant = isPaidPlan(planId, isEnterprisePlan);
52+
// We need to hide the add-on tag for legacy plans who has unlimited roles.
53+
const hasRolesIncluded = userRolesLimit === null && machineToMachineRolesLimit === null;
54+
4255
const {
4356
control,
4457
handleSubmit,
@@ -71,6 +84,8 @@ function CreateRoleForm({ onClose }: Props) {
7184
<ModalLayout
7285
title="roles.create_role_title"
7386
subtitle="roles.create_role_description"
87+
// TODO: remove the dev feature when the new paywall logic is ready;
88+
hasAddOnTag={isDevFeaturesEnabled && isPaidTenant && !hasRolesIncluded}
7489
learnMoreLink={{
7590
href: 'https://docs.logto.io/docs/recipes/rbac/manage-permissions-and-roles#manage-roles',
7691
targetBlank: 'noopener',

0 commit comments

Comments
 (0)