From 343a88e6abb70c26e2579725ca22c767cc9f9e08 Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Fri, 1 Dec 2023 17:20:47 +0800 Subject: [PATCH] feat(console,phrases): add SSO paywall for console (#5025) --- packages/console/src/consts/plan-quotas.ts | 8 +---- .../console/src/pages/EnterpriseSso/index.tsx | 32 +++++++++++++------ packages/console/src/types/subscriptions.ts | 2 -- packages/console/src/utils/subscription.ts | 7 +--- .../admin-console/subscription/quota-table.ts | 2 +- .../admin-console/subscription/quota-table.ts | 2 +- .../admin-console/subscription/quota-table.ts | 2 +- .../admin-console/subscription/quota-table.ts | 2 +- .../admin-console/subscription/quota-table.ts | 2 +- .../admin-console/subscription/quota-table.ts | 2 +- .../admin-console/subscription/quota-table.ts | 2 +- .../admin-console/subscription/quota-table.ts | 2 +- .../admin-console/subscription/quota-table.ts | 2 +- .../admin-console/subscription/quota-table.ts | 2 +- .../admin-console/subscription/quota-table.ts | 2 +- .../admin-console/subscription/quota-table.ts | 2 +- .../admin-console/subscription/quota-table.ts | 2 +- .../admin-console/subscription/quota-table.ts | 2 +- .../admin-console/subscription/quota-table.ts | 2 +- 19 files changed, 39 insertions(+), 40 deletions(-) diff --git a/packages/console/src/consts/plan-quotas.ts b/packages/console/src/consts/plan-quotas.ts index 0dfa23838..bdaa63837 100644 --- a/packages/console/src/consts/plan-quotas.ts +++ b/packages/console/src/consts/plan-quotas.ts @@ -77,12 +77,6 @@ export const ticketSupportResponseTimeMap: Record = [ReservedPlanId.Pro]: 48, }; -export const ssoEnabledMap: EnabledFeatureMap = { - [ReservedPlanId.Free]: false, - [ReservedPlanId.Hobby]: true, - [ReservedPlanId.Pro]: true, -}; - /** * Note: this is only for display purpose. * @@ -170,4 +164,4 @@ export const planQuotaItemOrder = Object.values(planTableGroupKeyMap).flat(); * - Related quota items will have a "Coming soon" tag in the plan selection component. * - Related quota items will be hidden from the downgrade plan notification modal. */ -export const comingSoonQuotaKeys: Array = ['ssoEnabled']; +export const comingSoonQuotaKeys: Array = []; diff --git a/packages/console/src/pages/EnterpriseSso/index.tsx b/packages/console/src/pages/EnterpriseSso/index.tsx index 283ea0028..27547fdfc 100644 --- a/packages/console/src/pages/EnterpriseSso/index.tsx +++ b/packages/console/src/pages/EnterpriseSso/index.tsx @@ -1,6 +1,7 @@ import { withAppInsights } from '@logto/app-insights/react'; -import { type SsoConnectorWithProviderConfig } from '@logto/schemas'; +import { type SsoConnectorWithProviderConfig, ReservedPlanId } from '@logto/schemas'; import { conditional } from '@silverhand/essentials'; +import { useContext, useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { useLocation } from 'react-router-dom'; import useSWR from 'swr'; @@ -11,11 +12,15 @@ import EnterpriseSsoConnectorEmpty from '@/assets/images/sso-connector-empty.svg import ItemPreview from '@/components/ItemPreview'; import ListPage from '@/components/ListPage'; import { defaultPageSize } from '@/consts'; +import { isCloud } from '@/consts/env'; +import { subscriptionPage } from '@/consts/pages'; +import { TenantsContext } from '@/contexts/TenantsProvider'; import Button from '@/ds-components/Button'; import TablePlaceholder from '@/ds-components/Table/TablePlaceholder'; import Tag from '@/ds-components/Tag'; import type { RequestError } from '@/hooks/use-api'; import useSearchParametersWatcher from '@/hooks/use-search-parameters-watcher'; +import useSubscriptionPlan from '@/hooks/use-subscription-plan'; import useTenantPathname from '@/hooks/use-tenant-pathname'; import { buildUrl } from '@/utils/url'; @@ -32,10 +37,18 @@ function EnterpriseSsoConnectors() { const { pathname } = useLocation(); const { navigate } = useTenantPathname(); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); + const { currentTenantId, isDevTenant } = useContext(TenantsContext); + const { data: currentPlan } = useSubscriptionPlan(currentTenantId); const [{ page }, updateSearchParameters] = useSearchParametersWatcher({ page: 1, }); + const isSsoEnabled = !isCloud || currentPlan?.quota.ssoEnabled; + + const handleButtonClick = useCallback(() => { + navigate(isSsoEnabled ? createEnterpriseSsoPathname : subscriptionPage); + }, [isSsoEnabled, navigate]); + const url = buildUrl('api/sso-connectors', { page: String(page), page_size: String(pageSize), @@ -51,16 +64,17 @@ function EnterpriseSsoConnectors() { return ( { - navigate(createEnterpriseSsoPathname); - }, + title: isSsoEnabled ? 'enterprise_sso.create' : 'upsell.upgrade_plan', + onClick: handleButtonClick, + icon: conditional(isSsoEnabled && ), } )} table={{ @@ -135,13 +149,11 @@ function EnterpriseSsoConnectors() { description="enterprise_sso.placeholder_description" action={