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

chore: expand frontend to support billing limit as number #23932

Merged
merged 9 commits into from
Jul 30, 2024
2 changes: 1 addition & 1 deletion ee/billing/billing_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class CustomerInfo(TypedDict):
current_total_amount_usd: Optional[str]
current_total_amount_usd_after_discount: Optional[str]
products: Optional[list[CustomerProduct]]
custom_limits_usd: Optional[dict[str, str]]
custom_limits_usd: Optional[dict[str, str | int]]
usage_summary: Optional[dict[str, dict[str, Optional[int]]]]
free_trial_until: Optional[str]
discount_percent: Optional[int]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion frontend/src/lib/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export const WEBHOOK_SERVICES: Record<string, string> = {
export const FEATURE_FLAGS = {
// Experiments / beta features
FUNNELS_CUE_OPT_OUT: 'funnels-cue-opt-out-7301', // owner: @neilkakkar
BILLING_LIMIT: 'billing-limit', // owner: @timgl
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used

KAFKA_INSPECTOR: 'kafka-inspector', // owner: @yakkomajuri
HISTORICAL_EXPORTS_V2: 'historical-exports-v2', // owner @macobo
PERSON_ON_EVENTS_ENABLED: 'person-on-events-enabled', //owner: @EDsCODE
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/scenes/billing/billingLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export const billingLogic = kea<billingLogicType>([
return parseBillingResponse(response)
},

updateBillingLimits: async (limits: { [key: string]: string | null }) => {
updateBillingLimits: async (limits: { [key: string]: string | number | null }) => {
const response = await api.update('api/billing', { custom_limits_usd: limits })

lemonToast.success('Billing limits updated')
Expand Down Expand Up @@ -304,12 +304,12 @@ export const billingLogic = kea<billingLogicType>([
}
let projectedTotal = 0
for (const product of billing.products || []) {
const billingLimit: string =
const billingLimit =
billing?.custom_limits_usd?.[product.type] ||
(product.usage_key ? billing?.custom_limits_usd?.[product.usage_key] || '0' : '0')
(product.usage_key ? billing?.custom_limits_usd?.[product.usage_key] || 0 : 0)
projectedTotal += Math.min(
parseFloat(product.projected_amount_usd || '0'),
parseFloat(billingLimit)
typeof billingLimit === 'number' ? billingLimit : parseFloat(billingLimit)
)
}
return projectedTotal
Expand Down
16 changes: 12 additions & 4 deletions frontend/src/scenes/billing/billingProductLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export const billingProductLogic = kea<billingProductLogicType>([
(billing, product) => {
return (
billing?.custom_limits_usd?.[product.type] ||
(product.usage_key ? billing?.custom_limits_usd?.[product.usage_key] : '')
(product.usage_key ? billing?.custom_limits_usd?.[product.usage_key] : null)
)
},
],
Expand Down Expand Up @@ -197,7 +197,11 @@ export const billingProductLogic = kea<billingProductLogicType>([
productAndAddonTiers,
billing?.discount_percent
)
: convertAmountToUsage(customLimitUsd || '', productAndAddonTiers, billing?.discount_percent)
: convertAmountToUsage(
typeof customLimitUsd === 'number' ? `${customLimitUsd}` : customLimitUsd || '',
productAndAddonTiers,
billing?.discount_percent
)
: 0
},
],
Expand Down Expand Up @@ -252,7 +256,11 @@ export const billingProductLogic = kea<billingProductLogicType>([
actions.setIsEditingBillingLimit(false)
actions.setBillingLimitInput(
values.customLimitUsd
? parseInt(values.customLimitUsd)
? parseInt(
typeof values.customLimitUsd === 'number'
? `${values.customLimitUsd}`
: values.customLimitUsd || ''
)
: props.product.tiers && parseInt(props.product.projected_amount_usd || '0')
? parseInt(props.product.projected_amount_usd || '0') * 1.5
: DEFAULT_BILLING_LIMIT
Expand Down Expand Up @@ -368,7 +376,7 @@ export const billingProductLogic = kea<billingProductLogicType>([
return
}
actions.updateBillingLimits({
[props.product.type]: typeof input === 'number' ? `${input}` : null,
[props.product.type]: input,
})
},
options: {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,7 @@ export interface BillingType {
products: BillingProductV2Type[]

custom_limits_usd?: {
[key: string]: string | null | undefined
[key: string]: string | number | null | undefined
}
billing_period?: {
current_period_start: Dayjs
Expand Down
Loading