From cf70a10ffb7e468df2841e791c17deb8d9be3025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Gr=C3=BCneberg?= Date: Thu, 16 Mar 2023 10:39:26 +0100 Subject: [PATCH] feat: revive overusage banner/upsell --- .../ProjectUsageBars/ProjectUsageBars.tsx | 69 ++++++++++++++----- .../LayoutHeader/LayoutHeader.tsx | 12 ++-- 2 files changed, 59 insertions(+), 22 deletions(-) diff --git a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.tsx b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.tsx index c24fbe5a685..b91e9c99bb9 100644 --- a/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.tsx +++ b/studio/components/interfaces/Settings/ProjectUsageBars/ProjectUsageBars.tsx @@ -14,7 +14,7 @@ import { IconBookOpen, } from 'ui' -import { checkPermissions, useStore } from 'hooks' +import { checkPermissions, useFlag, useStore } from 'hooks' import { formatBytes } from 'lib/helpers' import { PRICING_TIER_PRODUCT_IDS, USAGE_APPROACHING_THRESHOLD } from 'lib/constants' import SparkBar from 'components/ui/SparkBar' @@ -24,6 +24,7 @@ import { USAGE_BASED_PRODUCTS } from 'components/interfaces/Billing/Billing.cons import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext' import { useProjectReadOnlyQuery } from 'data/config/project-read-only-query' import { ProjectUsageResponseUsageKeys, useProjectUsageQuery } from 'data/usage/project-usage-query' +import { getResourcesExceededLimits } from 'components/ui/OveragesBanner/OveragesBanner.utils' interface Props { projectRef?: string @@ -40,6 +41,8 @@ const ProjectUsage: FC = ({ projectRef }) => { connectionString: project?.connectionString, }) + const overusageBadgeEnabled = useFlag('overusageBadge') + const canUpdateSubscription = checkPermissions( PermissionAction.BILLING_WRITE, 'stripe.subscriptions' @@ -51,6 +54,8 @@ const ProjectUsage: FC = ({ projectRef }) => { subscriptionTier === PRICING_TIER_PRODUCT_IDS.TEAM || subscriptionTier === PRICING_TIER_PRODUCT_IDS.ENTERPRISE + const resourcesExceededLimits = getResourcesExceededLimits(usage) + const showUsageExceedMessage = subscriptionTier !== undefined && !projectHasNoLimits const planNames = { @@ -106,16 +111,54 @@ const ProjectUsage: FC = ({ projectRef }) => { {usage && (
- {USAGE_BASED_PRODUCTS.map((product) => { - const isExceededUsage = - showUsageExceedMessage && - product.features - .map((feature) => { - const featureUsage = usage[feature.key as ProjectUsageResponseUsageKeys] - return (featureUsage.usage ?? 0) / featureUsage.limit > 1 - }) - .some((x) => x === true) + {resourcesExceededLimits.length > 0 && + showUsageExceedMessage && + overusageBadgeEnabled && ( +
+ } + title="You are exceeding your plans quota" + description={ +
+ {subscriptionTier === PRICING_TIER_PRODUCT_IDS.FREE ? ( +
+

+ Your project is currently on the Free tier - upgrade to the Pro tier for + a greatly increased quota and continue to scale. +

+

+ See{' '} + + pricing page + {' '} + for a full breakdown of available plans. +

+ + + +
+ ) : ( +
+

+ By default, Pro projects have spend caps to control costs. When enabled, + usage is limited to the plan's quota, with restrictions when limits are + exceeded. To scale beyond Pro limits without restrictions, disable the + spend cap and pay for over-usage beyond the quota. +

+ + + +
+ )} +
+ } + /> +
+ )} + {USAGE_BASED_PRODUCTS.map((product) => { return (
= ({ projectRef }) => {
{product.title}
- {/* Plan Limits */} - - {isExceededUsage && Exceeded usage} - - {/* Usage */} - {/* Line items */} diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx index 90700cd6c35..c7c599a6073 100644 --- a/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx +++ b/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx @@ -2,7 +2,7 @@ import Link from 'next/link' import { observer } from 'mobx-react-lite' import { IS_PLATFORM, PRICING_TIER_PRODUCT_IDS } from 'lib/constants' -import { useParams, useStore } from 'hooks' +import { useFlag, useParams, useStore } from 'hooks' import BreadcrumbsView from './BreadcrumbsView' import OrgDropdown from './OrgDropdown' import ProjectDropdown from './ProjectDropdown' @@ -38,7 +38,8 @@ const LayoutHeader = ({ customHeaderComponents, breadcrumbs = [], headerBorder = const showOverUsageBadge = selectedProject?.subscription_tier !== undefined && !projectHasNoLimits && - resourcesExceededLimits.length > 0 + resourcesExceededLimits.length > 0 && + useFlag('overusageBadge') return (
)} - {/* [Joshen TODO] Temporarily hidden until usage endpoint is sorted out */} - {/* {showOverUsageBadge && ( + {showOverUsageBadge && ( - )} */} + )} )}