From 366a7dc351bf13a3c4eecf1740b0deb75c244ca8 Mon Sep 17 00:00:00 2001 From: James Ritchie Date: Tue, 28 Nov 2023 12:07:09 +0000 Subject: [PATCH] Usage bar chart now supports a paying customer option and optional billing limit. Also added more usage examples to storybook --- .../app/components/billing/UsageBar.tsx | 49 ++++++++----- .../components/stories/UsageBar.stories.tsx | 71 ++++++++++++++----- 2 files changed, 83 insertions(+), 37 deletions(-) diff --git a/apps/webapp/app/components/billing/UsageBar.tsx b/apps/webapp/app/components/billing/UsageBar.tsx index 08a8f2c55..c4a0be4b9 100644 --- a/apps/webapp/app/components/billing/UsageBar.tsx +++ b/apps/webapp/app/components/billing/UsageBar.tsx @@ -3,9 +3,10 @@ import { Paragraph } from "../primitives/Paragraph"; type UsageBarProps = { numberOfCurrentRuns: number; - billingLimit: number; + billingLimit?: number | undefined; tierRunLimit: number; projectedRuns: number; + subscribedToPaidTier?: boolean; }; export function UsageBar({ @@ -13,9 +14,15 @@ export function UsageBar({ billingLimit, tierRunLimit, projectedRuns, + subscribedToPaidTier = false, }: UsageBarProps) { //create a maximum range for the progress bar - const getLargestNumber = Math.max(numberOfCurrentRuns, tierRunLimit, billingLimit, projectedRuns); + const getLargestNumber = Math.max( + numberOfCurrentRuns, + tierRunLimit, + projectedRuns, + billingLimit ?? -Infinity + ); const maxRange = Math.round(getLargestNumber * 1.15); //convert the freeRunLimit into a percentage @@ -25,7 +32,8 @@ export function UsageBar({ const projectedRunsPercentage = Math.round((projectedRuns / maxRange) * 100); //convert the BillingLimit into a percentage - const billingLimitPercentage = Math.round((billingLimit / maxRange) * 100); + const billingLimitPercentage = + billingLimit !== undefined ? Math.round((billingLimit / maxRange) * 100) : 0; const usagePercentage = Math.round((numberOfCurrentRuns / maxRange) * 100); @@ -33,23 +41,25 @@ export function UsageBar({ return (
+ {billingLimit && ( +
+ +
+ )}
-
-
- - + {text} {value} diff --git a/apps/webapp/app/components/stories/UsageBar.stories.tsx b/apps/webapp/app/components/stories/UsageBar.stories.tsx index e1624cc46..b5b34a14e 100644 --- a/apps/webapp/app/components/stories/UsageBar.stories.tsx +++ b/apps/webapp/app/components/stories/UsageBar.stories.tsx @@ -1,5 +1,6 @@ import type { Meta, StoryObj } from "@storybook/react"; import { UsageBar } from "../billing/UsageBar"; +import { Paragraph } from "../primitives/Paragraph"; const meta: Meta = { title: "Billing/UsageBar", @@ -16,25 +17,57 @@ export const JobsUsageBar: Story = { function UsageProgressBar() { return ( -
- - - +
+ + + + + + + + + + + + + + + + + + +
+ ); +} + +function UsageBarWrapper({ title, children }: { title: string; children: React.ReactNode }) { + return ( +
+ {title} + {children}
); }