Skip to content

Commit

Permalink
correct billing limit count on workspace billing plan page
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadman97 committed Mar 21, 2024
1 parent 9641b52 commit f5f1ff5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 37 deletions.
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

0 comments on commit f5f1ff5

Please sign in to comment.