From 272cd34895d2588b5f5b693c4ab09bcc469d9ddb Mon Sep 17 00:00:00 2001 From: Anton Krasovsky Date: Thu, 30 Apr 2026 18:13:45 +0100 Subject: [PATCH] Update Config and Capture webapps to reflect changed counters for freemium billing --- packages/web/src/app/capture/Start.tsx | 6 - packages/web/src/app/capture/Subscription.tsx | 164 ------------------ packages/web/src/app/config/Subscription.tsx | 60 ++----- .../src/features/http-client/freemiumd-api.ts | 14 +- 4 files changed, 17 insertions(+), 227 deletions(-) delete mode 100644 packages/web/src/app/capture/Subscription.tsx diff --git a/packages/web/src/app/capture/Start.tsx b/packages/web/src/app/capture/Start.tsx index a102eaf98..b677e6c86 100644 --- a/packages/web/src/app/capture/Start.tsx +++ b/packages/web/src/app/capture/Start.tsx @@ -5,7 +5,6 @@ import { FileImport } from "../../icons"; import { useAppDispatch, useAppSelector } from "./store"; import { selectFiles } from "./slice"; -import Subscription from "./Subscription"; import GeneralError from "../../features/general-error/GeneralError"; export default function Start() { @@ -61,11 +60,6 @@ export default function Start() { and security.

- {token !== undefined && ( - - - - )} ); diff --git a/packages/web/src/app/capture/Subscription.tsx b/packages/web/src/app/capture/Subscription.tsx deleted file mode 100644 index 53732e995..000000000 --- a/packages/web/src/app/capture/Subscription.tsx +++ /dev/null @@ -1,164 +0,0 @@ -import styled from "styled-components"; - -import { ThemeColorVariables } from "@xliic/common/theme"; -import { getEndpoints } from "@xliic/common/endpoints"; - -import { Banner, ErrorBanner } from "../../components/Banner"; -import { useGetSubscriptionQuery } from "../../features/http-client/freemiumd-api"; -import ProgressBar from "./ProgressBar"; -import Button from "../../new-components/Button"; -import { useAppDispatch, useAppSelector } from "./store"; -import { openLink } from "./slice"; - -export default function Subscription({ - token, - useDevEndpoints, -}: { - token: string; - useDevEndpoints: boolean; -}) { - const { data, error, isLoading } = useGetSubscriptionQuery(token.trim(), { - refetchOnFocus: true, - pollingInterval: 1000 * 60 * 10, // refresh every 10 minutes - }); - - const dispatch = useAppDispatch(); - - const authType = useAppSelector((state) => state.config.data.platformAuthType); - - const { upgradeUrl, stripeBillingUrl } = getEndpoints(useDevEndpoints); - - if (error) { - return ( - - - {error.code} {error.message} - - - ); - } - - if (isLoading || data === undefined) { - return ( - - - - ); - } - - return ( - - {authType === "anond-token" && ( - <> -
- API Contract Generator - Monthly operations left - - {data.monthlyCapture - data.currentCaptureUsage} / {data.monthlyCapture} - - -
-
- Subscription type: {data?.subscriptionKind} - Upgrade or manage your subscription plan - - {data.subscriptionKind === "free" && ( - - )} - {data.subscriptionKind !== "free" && ( - - )} - -
- - )} - {authType === "api-token" && ( - <> -
- Tenant Allowance - Monthly operations left - - {data.monthlyCapture - data.currentCaptureUsage} / {data.monthlyCapture} - - -
-
- Subscription type: {data?.subscriptionKind} -
- To upgrade or change your subscription plan please contact your administrator -
- - )} -
- ); -} - -const Container = styled.div` - display: flex; - flex-direction: column; - gap: 8px; - max-width: 560px; -`; - -const Title = styled.div` - font-weight: 700; -`; - -const Subtitle = styled.div` - font-weight: 400; - font-size: 90%; -`; - -const Counters = styled.div` - font-weight: 600; - font-size: 110%; - > div { - font-size: 80%; - } -`; - -const Section = styled.div` - display: grid; - grid-template-columns: 7fr 3fr; - gap: 4px; - padding-top: 8px; - border-top: 1px solid var(${ThemeColorVariables.border}); - > ${Title} { - grid-column: 1; - grid-row: 1; - } - > ${Subtitle} { - grid-column: 1; - grid-row: 2; - } - > ${Counters} { - grid-column: 2; - grid-row: span 2; - align-self: center; - justify-self: end; - } - > :nth-child(4) { - grid-column: span 2; - grid-row: 3; - } -`; diff --git a/packages/web/src/app/config/Subscription.tsx b/packages/web/src/app/config/Subscription.tsx index 92585a5b4..25e2e21de 100644 --- a/packages/web/src/app/config/Subscription.tsx +++ b/packages/web/src/app/config/Subscription.tsx @@ -44,6 +44,16 @@ export default function Subscription({ ); } + const currentAllowance = data.monthlyOp + data.bonusOp; + const currentUsage = + data.currentAuditUsage + + data.currentScanUsage + + data.currentGraphqlAuditUsage + + data.currentGraphqlScanUsage + + data.currentCaptureUsage; + const currentAllowanceLeftPercentage = + currentAllowance > 0 ? 1 - currentUsage / currentAllowance : 0; + return (
@@ -91,54 +101,12 @@ export default function Subscription({
- Audit - Monthly operation audits left - - {data.monthlyAudit - data.currentAuditUsage} / {data.monthlyAudit} - - -
- -
- Scan - Monthly operation scans left - - {data.monthlyScan - data.currentScanUsage} / {data.monthlyScan} - - -
- -
- GraphQL Audit - Monthly operation audits left - - {data.monthlyGraphqlAudit - data.currentGraphqlAuditUsage} / {data.monthlyGraphqlAudit} - - -
- -
- GraphQL Scan - Monthly operation scans left - - {data.monthlyGraphqlScan - data.currentGraphqlScanUsage} / {data.monthlyGraphqlScan} - - -
- -
- API Contract Generator - Monthly operations left + Usage + Monthly allowance left - {data.monthlyCapture - data.currentCaptureUsage} / {data.monthlyCapture} + {currentAllowance - currentUsage} / {currentAllowance} - +
); diff --git a/packages/web/src/features/http-client/freemiumd-api.ts b/packages/web/src/features/http-client/freemiumd-api.ts index fb5ac8a7a..7a1e9363e 100644 --- a/packages/web/src/features/http-client/freemiumd-api.ts +++ b/packages/web/src/features/http-client/freemiumd-api.ts @@ -10,21 +10,13 @@ export type Subscription = { userEmail: string; subscriptionKind: string; periodStart: string; - monthlyAudit: number; - bonusAuditOp: number; + monthlyOp: number; + bonusOp: number; currentAuditUsage: number; - monthlyScan: number; - bonusScanOp: number; currentScanUsage: number; - monthlyCapture: number; - bonusCaptureOp: number; - currentCaptureUsage: number; - monthlyGraphqlAudit: number; - bonusGraphqlAuditOp: number; currentGraphqlAuditUsage: number; - monthlyGraphqlScan: number; - bonusGraphqlScanOp: number; currentGraphqlScanUsage: number; + currentCaptureUsage: number; }; export const freemiumdApi = createApi({