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

feat: show alert when we automatically apply billing limit upon subscribe #18668

Merged
merged 7 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 5 additions & 2 deletions frontend/src/lib/components/BillingAlertsV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ export function BillingAlertsV2(): JSX.Element | null {
return null
}

const showButton = billingAlert.contactSupport || currentLocation.pathname !== urls.organizationBilling()
const showButton =
billingAlert.action || billingAlert.contactSupport || currentLocation.pathname !== urls.organizationBilling()

const buttonProps = billingAlert.contactSupport
const buttonProps = billingAlert.action
? billingAlert.action
: billingAlert.contactSupport
? {
to: 'mailto:[email protected]',
children: billingAlert.buttonCTA || 'Contact support',
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/billing/BillingLimitInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const BillingLimitInput = ({ product }: { product: BillingProductV2Type }
return null
}
return (
<div className="border-t border-border p-8">
<div className="border-t border-border p-8" data-attr={`billing-limit-input-${product.type.replace('_', '-')}`}>
xrdt marked this conversation as resolved.
Show resolved Hide resolved
<div className="flex">
<div className="flex items-center gap-1">
{!isEditingBillingLimit ? (
Expand Down
40 changes: 40 additions & 0 deletions frontend/src/scenes/billing/billingLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface BillingAlertConfig {
contactSupport?: boolean
buttonCTA?: string
dismissKey?: string
action?: any
xrdt marked this conversation as resolved.
Show resolved Hide resolved
}

const parseBillingResponse = (data: Partial<BillingV2Type>): BillingV2Type => {
Expand Down Expand Up @@ -146,6 +147,45 @@ export const billingLogic = kea<billingLogicType>([
billingAlert: [
(s) => [s.billing, s.preflight, s.projectedTotalAmountUsd],
(billing, preflight, projectedTotalAmountUsd): BillingAlertConfig | undefined => {
if (router.values.searchParams['products']) {
let upgradedProducts = router.values.searchParams['products'].split(',')
upgradedProducts = billing?.products.filter((product) => upgradedProducts.includes(product.type))
const alerts: BillingAlertConfig[] = []
upgradedProducts?.forEach((product: BillingProductV2Type) => {
const currentPlan = product.plans.find((plan) => plan.current_plan)
if (currentPlan?.initial_billing_limit) {
alerts.push({
status: 'warning',
title: 'Billing Limit Automatically Applied',
message: `To protect your and our costs, we've automatically applied a $${currentPlan?.initial_billing_limit} billing limit for ${product.name}.`,
xrdt marked this conversation as resolved.
Show resolved Hide resolved
action: {
onClick: () => {
const element: HTMLElement = document.body.querySelector(
`[data-attr="billing-limit-input-${product.type.replace(
'_',
'-'
)}"] .text-link`
) as HTMLElement
element?.scrollIntoView({ block: 'center', behavior: 'smooth' })
element?.click()
setTimeout(() => {
const inputElement: HTMLElement = document.body.querySelector(
`[data-attr="billing-limit-input-${product.type.replace(
'_',
'-'
)}"] input`
) as HTMLElement
xrdt marked this conversation as resolved.
Show resolved Hide resolved
inputElement?.focus()
}, 0)
},
children: 'Update billing limit',
},
})
}
})
// There should only be one product being upgraded at a time.
return alerts.length ? alerts[0] : undefined
}
if (!billing || !preflight?.cloud) {
return
}
Expand Down
Loading