From 43430afddb2804907745d57f625598c8392d8b74 Mon Sep 17 00:00:00 2001 From: simeng-li Date: Tue, 16 Apr 2024 12:02:08 +0800 Subject: [PATCH] feat(core): add customJwt paywall guard to core API (#5708) add customJwt paywall guard to core API --- packages/console/package.json | 2 +- .../console/src/consts/quota-item-phrases.ts | 4 ++ packages/console/src/consts/tenants.ts | 3 +- .../AppConfirmModalProvider/index.tsx | 12 ++--- .../pages/CustomizeJwt/CreateButton/index.tsx | 44 +++++++++++++++++-- packages/core/package.json | 2 +- packages/core/src/libraries/quota.ts | 3 +- .../src/routes/logto-config/jwt-customizer.ts | 9 +++- .../admin-console/subscription/quota-item.ts | 10 +++++ .../de/translation/admin-console/tabs.ts | 2 +- .../admin-console/upsell/paywall.ts | 7 +++ .../admin-console/subscription/quota-item.ts | 6 +++ .../en/translation/admin-console/tabs.ts | 2 +- .../admin-console/upsell/paywall.ts | 5 +++ .../admin-console/subscription/quota-item.ts | 10 +++++ .../es/translation/admin-console/tabs.ts | 2 +- .../admin-console/upsell/paywall.ts | 7 +++ .../admin-console/subscription/quota-item.ts | 10 +++++ .../fr/translation/admin-console/tabs.ts | 2 +- .../admin-console/upsell/paywall.ts | 7 +++ .../admin-console/subscription/quota-item.ts | 10 +++++ .../it/translation/admin-console/tabs.ts | 2 +- .../admin-console/upsell/paywall.ts | 7 +++ .../admin-console/subscription/quota-item.ts | 10 +++++ .../ja/translation/admin-console/tabs.ts | 2 +- .../admin-console/upsell/paywall.ts | 7 +++ .../admin-console/subscription/quota-item.ts | 10 +++++ .../ko/translation/admin-console/tabs.ts | 2 +- .../admin-console/upsell/paywall.ts | 7 +++ .../admin-console/subscription/quota-item.ts | 10 +++++ .../pl-pl/translation/admin-console/tabs.ts | 2 +- .../admin-console/upsell/paywall.ts | 7 +++ .../admin-console/subscription/quota-item.ts | 10 +++++ .../pt-br/translation/admin-console/tabs.ts | 2 +- .../admin-console/upsell/paywall.ts | 7 +++ .../admin-console/subscription/quota-item.ts | 10 +++++ .../pt-pt/translation/admin-console/tabs.ts | 2 +- .../admin-console/upsell/paywall.ts | 7 +++ .../admin-console/subscription/quota-item.ts | 10 +++++ .../ru/translation/admin-console/tabs.ts | 2 +- .../admin-console/upsell/paywall.ts | 7 +++ .../admin-console/subscription/quota-item.ts | 10 +++++ .../tr-tr/translation/admin-console/tabs.ts | 2 +- .../admin-console/upsell/paywall.ts | 7 +++ .../admin-console/subscription/quota-item.ts | 10 +++++ .../zh-cn/translation/admin-console/tabs.ts | 2 +- .../admin-console/upsell/paywall.ts | 7 +++ .../admin-console/subscription/quota-item.ts | 10 +++++ .../zh-hk/translation/admin-console/tabs.ts | 2 +- .../admin-console/upsell/paywall.ts | 7 +++ .../admin-console/subscription/quota-item.ts | 10 +++++ .../zh-tw/translation/admin-console/tabs.ts | 2 +- .../admin-console/upsell/paywall.ts | 7 +++ pnpm-lock.yaml | 12 ++--- 54 files changed, 332 insertions(+), 38 deletions(-) diff --git a/packages/console/package.json b/packages/console/package.json index bae2b102e..f6adf53eb 100644 --- a/packages/console/package.json +++ b/packages/console/package.json @@ -28,7 +28,7 @@ "@fontsource/roboto-mono": "^5.0.0", "@jest/types": "^29.5.0", "@logto/app-insights": "workspace:^1.4.0", - "@logto/cloud": "0.2.5-ab8a489", + "@logto/cloud": "0.2.5-94f7bcc", "@logto/connector-kit": "workspace:^3.0.0", "@logto/core-kit": "workspace:^2.4.0", "@logto/language-kit": "workspace:^1.1.0", diff --git a/packages/console/src/consts/quota-item-phrases.ts b/packages/console/src/consts/quota-item-phrases.ts index a4ade8a7a..fb26ee591 100644 --- a/packages/console/src/consts/quota-item-phrases.ts +++ b/packages/console/src/consts/quota-item-phrases.ts @@ -27,6 +27,7 @@ export const quotaItemPhrasesMap: Record< organizationsEnabled: 'organizations_enabled.name', ssoEnabled: 'sso_enabled.name', tenantMembersLimit: 'tenant_members_limit.name', + customJwtEnabled: 'custom_jwt_enabled.name', }; export const quotaItemUnlimitedPhrasesMap: Record< @@ -54,6 +55,7 @@ export const quotaItemUnlimitedPhrasesMap: Record< organizationsEnabled: 'organizations_enabled.unlimited', ssoEnabled: 'sso_enabled.unlimited', tenantMembersLimit: 'tenant_members_limit.unlimited', + customJwtEnabled: 'custom_jwt_enabled.unlimited', }; export const quotaItemLimitedPhrasesMap: Record< @@ -81,6 +83,7 @@ export const quotaItemLimitedPhrasesMap: Record< organizationsEnabled: 'organizations_enabled.limited', ssoEnabled: 'sso_enabled.limited', tenantMembersLimit: 'tenant_members_limit.limited', + customJwtEnabled: 'custom_jwt_enabled.limited', }; export const quotaItemNotEligiblePhrasesMap: Record< @@ -108,4 +111,5 @@ export const quotaItemNotEligiblePhrasesMap: Record< organizationsEnabled: 'organizations_enabled.not_eligible', ssoEnabled: 'sso_enabled.not_eligible', tenantMembersLimit: 'tenant_members_limit.not_eligible', + customJwtEnabled: 'custom_jwt_enabled.not_eligible', }; diff --git a/packages/console/src/consts/tenants.ts b/packages/console/src/consts/tenants.ts index 119a2678b..77b71d813 100644 --- a/packages/console/src/consts/tenants.ts +++ b/packages/console/src/consts/tenants.ts @@ -1,4 +1,4 @@ -import { TenantTag, ReservedPlanId, defaultManagementApi } from '@logto/schemas'; +import { ReservedPlanId, TenantTag, defaultManagementApi } from '@logto/schemas'; import dayjs from 'dayjs'; import { type TenantResponse } from '@/cloud/types/router'; @@ -67,6 +67,7 @@ export const defaultSubscriptionPlan: SubscriptionPlan = { ticketSupportResponseTime: 48, thirdPartyApplicationsLimit: null, tenantMembersLimit: null, + customJwtEnabled: true, }, }; diff --git a/packages/console/src/contexts/AppConfirmModalProvider/index.tsx b/packages/console/src/contexts/AppConfirmModalProvider/index.tsx index 6fc67a360..00d1fa04e 100644 --- a/packages/console/src/contexts/AppConfirmModalProvider/index.tsx +++ b/packages/console/src/contexts/AppConfirmModalProvider/index.tsx @@ -1,9 +1,9 @@ import type { Nullable } from '@silverhand/essentials'; import { noop } from '@silverhand/essentials'; -import { useState, useRef, useMemo, createContext, useCallback, useEffect } from 'react'; +import { createContext, useCallback, useEffect, useMemo, useRef, useState } from 'react'; -import ConfirmModal from '@/ds-components/ConfirmModal'; import type { ConfirmModalProps } from '@/ds-components/ConfirmModal'; +import ConfirmModal from '@/ds-components/ConfirmModal'; type ModalContentRenderProps = { confirm: (data?: unknown) => void; @@ -108,13 +108,7 @@ function AppConfirmModalProvider({ children }: Props) { {children} { - handleConfirm(); - } - : undefined - } + onConfirm={type === 'confirm' ? handleConfirm : undefined} onCancel={() => { handleCancel(); }} diff --git a/packages/console/src/pages/CustomizeJwt/CreateButton/index.tsx b/packages/console/src/pages/CustomizeJwt/CreateButton/index.tsx index 0391e4d98..6de7cb211 100644 --- a/packages/console/src/pages/CustomizeJwt/CreateButton/index.tsx +++ b/packages/console/src/pages/CustomizeJwt/CreateButton/index.tsx @@ -1,6 +1,11 @@ import { type LogtoJwtTokenKeyType } from '@logto/schemas'; +import { useCallback, useContext } from 'react'; +import { Trans, useTranslation } from 'react-i18next'; +import ContactUsPhraseLink from '@/components/ContactUsPhraseLink'; +import { SubscriptionDataContext } from '@/contexts/SubscriptionDataProvider'; import Button from '@/ds-components/Button'; +import { useConfirmModal } from '@/hooks/use-confirm-modal'; import useTenantPathname from '@/hooks/use-tenant-pathname'; import { getPagePath } from '@/pages/CustomizeJwt/utils/path'; @@ -11,14 +16,47 @@ type Props = { function CreateButton({ tokenType }: Props) { const link = getPagePath(tokenType, 'create'); const { navigate } = useTenantPathname(); + const { show } = useConfirmModal(); + const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); + + const { currentPlan } = useContext(SubscriptionDataContext); + const { + quota: { customJwtEnabled }, + } = currentPlan; + + const onCreateButtonClick = useCallback(async () => { + if (customJwtEnabled) { + navigate(link); + return; + } + + const [confirm] = await show({ + title: 'upsell.paywall.custom_jwt.title', + ModalContent: () => ( + , + }} + > + {t('upsell.paywall.custom_jwt.description')} + + ), + confirmButtonText: 'upsell.upgrade_plan', + confirmButtonType: 'primary', + isCancelButtonVisible: false, + }); + + if (confirm) { + // Navigate to subscription page by default + navigate('/tenant-settings/subscription'); + } + }, [customJwtEnabled, link, navigate, show, t]); return (