From b549a7efd6c9e5c042dbb169327f490f933216cb Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Mon, 19 Aug 2024 16:47:12 +0800 Subject: [PATCH] refactor(console,core): remove add on dev feature guard (#6466) --- .../CreateForm/Footer/index.tsx | 14 +- .../ApplicationCreation/CreateForm/index.tsx | 8 +- .../components/ChargeNotification/index.tsx | 5 +- .../CreateConnectorForm/Footer/index.tsx | 92 ++--------- .../components/CreateConnectorForm/index.tsx | 1 - .../FeaturedPlanContent/index.tsx | 34 ---- .../use-featured-plan-content.ts | 77 --------- .../PlanCardItem/index.module.scss | 103 ------------ .../PlanCardItem/index.tsx | 102 ------------ .../FeaturedSkuContent}/index.module.scss | 0 .../SkuCardItem/FeaturedSkuContent/index.tsx | 3 +- .../SkuCardItem/index.tsx | 3 +- .../SelectTenantPlanModal/index.tsx | 72 ++------- .../src/components/FeatureTag/index.tsx | 6 +- .../src/components/MauExceededModal/index.tsx | 2 +- .../PlanUsage/PlanUsageCard/index.tsx | 3 +- .../src/components/PlanUsage/index.tsx | 56 +------ .../TenantDropdownItem/TenantStatusTag.tsx | 8 +- .../TenantDropdownItem/index.tsx | 10 +- packages/console/src/consts/external-links.ts | 3 + packages/console/src/consts/plan-quotas.ts | 25 --- .../console/src/consts/quota-item-phrases.ts | 125 -------------- .../src/hooks/use-api-resources-usage.ts | 58 ++----- packages/console/src/hooks/use-api.ts | 3 +- .../src/hooks/use-applications-usage.ts | 122 +++----------- packages/console/src/hooks/use-subscribe.ts | 45 ++---- .../CreatePermissionModal/index.tsx | 24 +-- .../components/CreateForm/Footer.tsx | 12 +- .../components/CreateForm/index.tsx | 9 +- .../components/ProtectedAppForm/index.tsx | 11 +- .../pages/CheckoutSuccessCallback/index.tsx | 53 +++--- .../pages/CustomizeJwt/CreateButton/index.tsx | 12 +- .../console/src/pages/CustomizeJwt/index.tsx | 12 +- .../EnterpriseSso/SsoCreationModal/index.tsx | 18 +-- .../console/src/pages/EnterpriseSso/index.tsx | 15 +- .../pages/Mfa/MfaForm/UpsellNotice/index.tsx | 3 +- .../console/src/pages/Mfa/MfaForm/index.tsx | 8 +- .../src/pages/Mfa/PageWrapper/index.tsx | 9 +- .../src/pages/OrganizationTemplate/index.tsx | 8 +- .../CreateOrganizationModal/index.tsx | 20 +-- .../console/src/pages/Organizations/index.tsx | 15 +- .../AssignPermissionsModal/index.tsx | 28 +--- .../RoleDetails/RolePermissions/index.tsx | 1 - .../components/CreateRoleForm/Footer.tsx | 57 ++----- .../Roles/components/CreateRoleForm/index.tsx | 7 +- .../AddOnUsageChangesNotification/index.tsx | 3 +- .../MauLimitExceededNotification/index.tsx | 56 +------ .../Subscription/CurrentPlan/index.tsx | 57 ++----- .../DiffQuotaItem/QuotaItemPhrase.tsx | 41 ----- .../PlanQuotaList/DiffQuotaItem/index.tsx | 37 ----- .../PlanQuotaDiffCard/PlanQuotaList/index.tsx | 32 ++-- .../PlanQuotaDiffCard/index.tsx | 25 +-- .../DowngradeConfirmModalContent/index.tsx | 7 +- .../SwitchPlanActionBar/index.tsx | 128 +++++---------- .../TenantSettings/Subscription/index.tsx | 15 +- .../InviteMemberModal/Footer/index.tsx | 10 +- .../TenantMembers/InviteMemberModal/index.tsx | 14 +- .../TenantSettings/TenantMembers/hooks.ts | 82 ++-------- .../index.tsx | 104 +----------- .../Webhooks/CreateFormModal/CreateForm.tsx | 27 +--- .../pages/Webhooks/CreateFormModal/index.tsx | 5 +- packages/console/src/pages/Webhooks/index.tsx | 1 - packages/console/src/utils/quota.ts | 35 ---- packages/console/src/utils/subscription.ts | 47 +----- packages/core/src/libraries/quota.ts | 152 ++---------------- .../src/libraries/sign-in-experience/index.ts | 11 +- .../core/src/middleware/koa-quota-guard.ts | 28 +--- .../src/routes/applications/application.ts | 23 +-- packages/core/src/routes/connector/index.ts | 5 +- packages/core/src/routes/domain.ts | 8 - packages/core/src/routes/hook.ts | 10 +- .../src/routes/logto-config/jwt-customizer.ts | 14 +- .../src/routes/organization-role/index.ts | 21 +-- .../src/routes/organization-scope/index.ts | 21 +-- .../core/src/routes/organization/index.ts | 21 +-- packages/core/src/routes/resource.scope.ts | 5 +- packages/core/src/routes/resource.ts | 10 +- packages/core/src/routes/role.scope.ts | 5 +- packages/core/src/routes/role.ts | 19 +-- .../custom-ui-assets/index.ts | 7 +- .../src/routes/sign-in-experience/index.ts | 9 +- .../core/src/routes/sso-connector/index.ts | 10 +- packages/core/src/routes/subject-token.ts | 7 +- packages/core/src/tenants/Libraries.ts | 2 +- packages/core/src/test-utils/quota.ts | 1 - packages/core/src/utils/subscription/index.ts | 23 +-- packages/core/src/utils/subscription/types.ts | 9 -- 87 files changed, 412 insertions(+), 2037 deletions(-) delete mode 100644 packages/console/src/components/CreateTenantModal/SelectTenantPlanModal/PlanCardItem/FeaturedPlanContent/index.tsx delete mode 100644 packages/console/src/components/CreateTenantModal/SelectTenantPlanModal/PlanCardItem/FeaturedPlanContent/use-featured-plan-content.ts delete mode 100644 packages/console/src/components/CreateTenantModal/SelectTenantPlanModal/PlanCardItem/index.module.scss delete mode 100644 packages/console/src/components/CreateTenantModal/SelectTenantPlanModal/PlanCardItem/index.tsx rename packages/console/src/components/CreateTenantModal/SelectTenantPlanModal/{PlanCardItem/FeaturedPlanContent => SkuCardItem/FeaturedSkuContent}/index.module.scss (100%) delete mode 100644 packages/console/src/pages/TenantSettings/Subscription/DowngradeConfirmModalContent/PlanQuotaDiffCard/PlanQuotaList/DiffQuotaItem/QuotaItemPhrase.tsx diff --git a/packages/console/src/components/ApplicationCreation/CreateForm/Footer/index.tsx b/packages/console/src/components/ApplicationCreation/CreateForm/Footer/index.tsx index f90b97d0a..4fb508a67 100644 --- a/packages/console/src/components/ApplicationCreation/CreateForm/Footer/index.tsx +++ b/packages/console/src/components/ApplicationCreation/CreateForm/Footer/index.tsx @@ -6,7 +6,7 @@ import AddOnNoticeFooter from '@/components/AddOnNoticeFooter'; import ContactUsPhraseLink from '@/components/ContactUsPhraseLink'; import PlanName from '@/components/PlanName'; import QuotaGuardFooter from '@/components/QuotaGuardFooter'; -import { isDevFeaturesEnabled } from '@/consts/env'; +import { addOnPricingExplanationLink } from '@/consts/external-links'; import { machineToMachineAddOnUnitPrice } from '@/consts/subscriptions'; import { SubscriptionDataContext } from '@/contexts/SubscriptionDataProvider'; import Button from '@/ds-components/Button'; @@ -24,7 +24,11 @@ type Props = { }; function Footer({ selectedType, isLoading, onClickCreate, isThirdParty }: Props) { - const { currentPlan, currentSku } = useContext(SubscriptionDataContext); + const { + currentPlan, + currentSku, + currentSubscription: { isAddOnAvailable }, + } = useContext(SubscriptionDataContext); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console.upsell' }); const { hasAppsReachedLimit, @@ -41,7 +45,7 @@ function Footer({ selectedType, isLoading, onClickCreate, isThirdParty }: Props) if ( selectedType === ApplicationType.MachineToMachine && - isDevFeaturesEnabled && + isAddOnAvailable && hasMachineToMachineAppsReachedLimit && planId === ReservedPlanId.Pro && !m2mUpsellNoticeAcknowledged @@ -58,7 +62,7 @@ function Footer({ selectedType, isLoading, onClickCreate, isThirdParty }: Props) , - a: , + a: , }} > {t('add_on.footer.machine_to_machine_app', { @@ -73,7 +77,7 @@ function Footer({ selectedType, isLoading, onClickCreate, isThirdParty }: Props) selectedType === ApplicationType.MachineToMachine && hasMachineToMachineAppsReachedLimit && // For paid plan (pro plan), we don't guard the m2m app creation since it's an add-on feature. - (isDevFeaturesEnabled ? currentSku.id : planId) === ReservedPlanId.Free + currentSku.id === ReservedPlanId.Free ) { return ( diff --git a/packages/console/src/components/ApplicationCreation/CreateForm/index.tsx b/packages/console/src/components/ApplicationCreation/CreateForm/index.tsx index 830939f71..f71a5ed37 100644 --- a/packages/console/src/components/ApplicationCreation/CreateForm/index.tsx +++ b/packages/console/src/components/ApplicationCreation/CreateForm/index.tsx @@ -10,7 +10,6 @@ import Modal from 'react-modal'; import { useSWRConfig } from 'swr'; import { GtagConversionId, reportConversion } from '@/components/Conversion/utils'; -import { isDevFeaturesEnabled } from '@/consts/env'; import { SubscriptionDataContext } from '@/contexts/SubscriptionDataProvider'; import DynamicT from '@/ds-components/DynamicT'; import FormField from '@/ds-components/FormField'; @@ -57,7 +56,7 @@ function CreateForm({ defaultValues: { type: defaultCreateType, isThirdParty: isDefaultCreateThirdParty }, }); const { - currentSubscription: { planId }, + currentSubscription: { isAddOnAvailable }, } = useContext(SubscriptionDataContext); const { user } = useCurrentUser(); const { mutate: mutateGlobal } = useSWRConfig(); @@ -123,12 +122,11 @@ function CreateForm({ title="applications.create" subtitle={subtitleElement} paywall={conditional( - isDevFeaturesEnabled && + isAddOnAvailable && watch('type') === ApplicationType.MachineToMachine && - planId === ReservedPlanId.Pro && ReservedPlanId.Pro )} - hasAddOnTag={isDevFeaturesEnabled && watch('type') === ApplicationType.MachineToMachine} + hasAddOnTag={isAddOnAvailable && watch('type') === ApplicationType.MachineToMachine} size={defaultCreateType ? 'medium' : 'large'} footer={