Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure frontend does not show overage card for free trial projects #8049

Merged
merged 5 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/src/graph/generated/hooks.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/src/graph/generated/operations.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/src/graph/operators/query.gql
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ query GetBillingDetails($workspace_id: ID!) {
sessionsBillingLimit
errorsBillingLimit
logsBillingLimit
tracesBillingLimit
sessionsDailyAverage
errorsDailyAverage
logsDailyAverage
Expand Down
35 changes: 19 additions & 16 deletions frontend/src/pages/Billing/BillingPageV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import {
import {
getCostCents,
getNextBillingDate,
getQuantity,
PlanSelectStep,
UpdatePlanModal,
} from '@/pages/Billing/UpdatePlanPage'
Expand All @@ -64,6 +63,7 @@ type UsageCardProps = {
planType: PlanType
billingLimitCents: number | undefined
usageAmount: number
usageLimitAmount: number | undefined
includedQuantity: number
isPaying: boolean
enableBillingLimits: boolean | undefined
Expand All @@ -79,6 +79,7 @@ const UsageCard = ({
retentionPeriod,
billingLimitCents,
usageAmount,
usageLimitAmount,
includedQuantity,
isPaying,
enableBillingLimits,
Expand All @@ -95,13 +96,6 @@ const UsageCard = ({
includedQuantity,
)
: 0
const usageLimitAmount = getQuantity(
productType,
rate,
retentionPeriod,
billingLimitCents,
includedQuantity,
)

const costFormatted =
'$ ' +
Expand Down Expand Up @@ -325,6 +319,11 @@ const BillingPageV2 = ({}: BillingPageProps) => {
const logsUsage = data?.billingDetails.logsMeter ?? 0
const tracesUsage = data?.billingDetails.tracesMeter ?? 0

const sessionsLimit = data?.billingDetails.sessionsBillingLimit ?? undefined
const errorsLimit = data?.billingDetails.errorsBillingLimit ?? undefined
const logsLimit = data?.billingDetails.logsBillingLimit ?? undefined
const tracesLimit = data?.billingDetails.tracesBillingLimit ?? undefined

const includedSessions = data?.billingDetails.plan.sessionsLimit ?? 0
const includedErrors = data?.billingDetails.plan.errorsLimit ?? 0
const includedLogs = data?.billingDetails.plan.logsLimit ?? 0
Expand Down Expand Up @@ -379,19 +378,19 @@ const BillingPageV2 = ({}: BillingPageProps) => {
'$ ' +
toDecimal(dinero({ amount: Math.round(totalCents), currency: USD }))

const sessionsLimit = isPaying
const sessionsSpendLimit = isPaying
? data?.workspace?.sessions_max_cents ?? undefined
: 0

const errorsLimit = isPaying
const errorsSpendLimit = isPaying
? data?.workspace?.errors_max_cents ?? undefined
: 0

const logsLimit = isPaying
const logsSpendLimit = isPaying
? data?.workspace?.logs_max_cents ?? undefined
: 0

const tracesLimit = isPaying
const tracesSpendLimit = isPaying
? data?.workspace?.traces_max_cents ?? undefined
: 0

Expand Down Expand Up @@ -569,8 +568,9 @@ const BillingPageV2 = ({}: BillingPageProps) => {
productType={ProductType.Sessions}
rate={sessionsRate}
retentionPeriod={sessionsRetention}
billingLimitCents={sessionsLimit}
billingLimitCents={sessionsSpendLimit}
usageAmount={sessionsUsage}
usageLimitAmount={sessionsLimit}
awsMpSubscription={
data?.billingDetails?.plan.aws_mp_subscription
}
Expand All @@ -589,8 +589,9 @@ const BillingPageV2 = ({}: BillingPageProps) => {
productType={ProductType.Errors}
rate={errorsRate}
retentionPeriod={errorsRetention}
billingLimitCents={errorsLimit}
billingLimitCents={errorsSpendLimit}
usageAmount={errorsUsage}
usageLimitAmount={errorsLimit}
awsMpSubscription={
data?.billingDetails?.plan.aws_mp_subscription
}
Expand All @@ -609,8 +610,9 @@ const BillingPageV2 = ({}: BillingPageProps) => {
productType={ProductType.Logs}
rate={logsRate}
retentionPeriod={logsRetention}
billingLimitCents={logsLimit}
billingLimitCents={logsSpendLimit}
usageAmount={logsUsage}
usageLimitAmount={logsLimit}
awsMpSubscription={
data?.billingDetails?.plan.aws_mp_subscription
}
Expand All @@ -629,8 +631,9 @@ const BillingPageV2 = ({}: BillingPageProps) => {
productType={ProductType.Traces}
rate={tracesRate}
retentionPeriod={tracesRetention}
billingLimitCents={tracesLimit}
billingLimitCents={tracesSpendLimit}
usageAmount={tracesUsage}
usageLimitAmount={tracesLimit}
awsMpSubscription={
data?.billingDetails?.plan.aws_mp_subscription
}
Expand Down
21 changes: 0 additions & 21 deletions frontend/src/pages/Billing/UpdatePlanPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,6 @@ export const getCostCents = (
)
}

export const getQuantity = (
productType: ProductType,
rateCents: number | undefined,
retentionPeriod: RetentionPeriod,
totalCents: number | undefined,
includedQuantity: number,
): number | undefined => {
if (totalCents === undefined) {
return undefined
}

if (!rateCents) {
rateCents =
BASE_UNIT_COST_CENTS[productType] / UNIT_QUANTITY[productType]
}
return Math.floor(
totalCents / (rateCents * RETENTION_MULTIPLIER[retentionPeriod]) +
includedQuantity,
)
}

export const getNextBillingDate = (
isPaying: boolean,
nextInvoiceDate: Date | undefined,
Expand Down
55 changes: 34 additions & 21 deletions frontend/src/pages/Billing/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
PlanType,
ProductType,
RetentionPeriod,
Workspace,
} from '../../../graph/generated/schemas'

/**
Expand Down Expand Up @@ -68,7 +69,8 @@ export const RETENTION_PERIOD_LABELS: { [K in RetentionPeriod]: string } = {
[RetentionPeriod.ThreeYears]: '3 year retention',
}

export const getMeterAmounts = (
type meterArgs = {
workspace: Maybe<Pick<Workspace, 'trial_end_date'>> | undefined
details:
| Maybe<
{ __typename?: 'BillingDetails' } & Pick<
Expand Down Expand Up @@ -100,8 +102,13 @@ export const getMeterAmounts = (
}
>
| undefined
| null,
): { [K in ProductType]: [number, number | undefined] } => {
| null
}

export const getMeterAmounts = ({
details,
workspace,
}: meterArgs): { [K in ProductType]: [number, number | undefined] } => {
if (!details) {
return {
[ProductType.Sessions]: [0, undefined],
Expand All @@ -110,30 +117,33 @@ export const getMeterAmounts = (
[ProductType.Traces]: [0, undefined],
}
}
const canChargeOverage = details.plan.type !== 'Free'
const trialActive = workspace?.trial_end_date
? moment(workspace?.trial_end_date).isAfter(moment())
: false
const canChargeOverage = trialActive || details.plan.type !== 'Free'
const sessionsMeter = details?.meter ?? 0
const sessionsQuota = details?.sessionsBillingLimit
? details.sessionsBillingLimit
: canChargeOverage
? undefined
const sessionsQuota = canChargeOverage
? details?.sessionsBillingLimit
? details.sessionsBillingLimit
: undefined
: details?.plan.sessionsLimit
const errorsMeter = details?.errorsMeter ?? 0
const errorsQuota = details?.errorsBillingLimit
? details.errorsBillingLimit
: canChargeOverage
? undefined
const errorsQuota = canChargeOverage
? details?.errorsBillingLimit
? details.errorsBillingLimit
: undefined
: details?.plan.errorsLimit
const logsMeter = details?.logsMeter ?? 0
const logsQuota = details?.logsBillingLimit
? details.logsBillingLimit
: canChargeOverage
? undefined
const logsQuota = canChargeOverage
? details?.logsBillingLimit
? details.logsBillingLimit
: undefined
: details?.plan.logsLimit
const tracesMeter = details?.tracesMeter ?? 0
const tracesQuota = details?.tracesBillingLimit
? details.tracesBillingLimit
: canChargeOverage
? undefined
const tracesQuota = canChargeOverage
? details?.tracesBillingLimit
? details.tracesBillingLimit
: undefined
: details?.plan.tracesLimit
return {
[ProductType.Sessions]: [sessionsMeter, sessionsQuota],
Expand All @@ -146,7 +156,10 @@ export const getMeterAmounts = (
export const getQuotaPercents = (
data: GetBillingDetailsForProjectQuery,
): [ProductType, number][] => {
const amts = getMeterAmounts(data.billingDetailsForProject)
const amts = getMeterAmounts({
workspace: data.workspace_for_project,
details: data.billingDetailsForProject,
})
const sessionAmts = amts[ProductType.Sessions]
const errorAmts = amts[ProductType.Errors]
const logAmts = amts[ProductType.Logs]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export const LogsOverageCard = () => {
)
}

const meters = getMeterAmounts(data.billingDetails)
const meters = getMeterAmounts({
workspace: data.workspace,
details: data.billingDetails,
})
const meter = meters[ProductType.Logs][0]
const quota = meters[ProductType.Logs][1]
if (quota === undefined || meter < quota) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export const OverageCard = ({ productType }: Props) => {
)
}

const meters = getMeterAmounts(data.billingDetails)
const meters = getMeterAmounts({
workspace: data.workspace,
details: data.billingDetails,
})
const meter = meters[productType][0]
const quota = meters[productType][1]
if (quota === undefined || meter < quota) {
Expand Down
Loading