Files
Julian Domke d85e9b8616 feat(billing): use new upcoming invoice data (#53342)
Makes use of the new data returned from the upcoming invoice endpoint
and wraps it in an accordion-based layout.

The current implementation is fairly bare-bones, so discussed with
@kevcodez that we roll out this version first (which should already be
an improvement), then talk to a designer on the team to get it polished.

Ran `pnpm api:codegen:prod` from the root of the repo.

The $10.01 in Compute Credits are an upstream data issue on Orb 😢 

## Testing

If you'd like to test this in the browser, these are the steps:

1. checkout commit, launch local stack, create org + project; upgrade to
paid
2. reach out to me so I can set up some usage and credits for your
project/org
3. click around the upcoming invoice


https://github.com/user-attachments/assets/6a814560-5d05-479a-a3f8-d658532b91c1

<img width="1180" height="235" alt="Screenshot 2026-11-13 at 10 03 01"
src="https://github.com/user-attachments/assets/682083b7-77ea-4da8-a599-36f5063e922b"
/>
<img width="910" height="235" alt="Screenshot 2026-11-13 at 10 02 59"
src="https://github.com/user-attachments/assets/59903f2a-2af4-4e18-8d97-35baee7401e0"
/>

<img width="815" height="140" alt="Screenshot 2026-11-13 at 12 03 17"
src="https://github.com/user-attachments/assets/4370d10a-dc5a-4010-b03e-dcf0b23140d1"
/>
<img width="507" height="143" alt="Screenshot 2026-11-13 at 12 03 21"
src="https://github.com/user-attachments/assets/3243855e-b02a-4e93-8139-5a7dfaad3230"
/>
2026-11-27 13:24:54 +01:00

102 lines
4.0 KiB
TypeScript

import { useParams } from 'common'
import dayjs from 'dayjs'
import {
PageSection,
PageSectionContent,
PageSectionDescription,
PageSectionMeta,
PageSectionSummary,
PageSectionTitle,
} from 'ui-patterns/PageSection'
import { UpcomingInvoice } from './UpcomingInvoice/UpcomingInvoice'
import { InlineLink } from '@/components/ui/InlineLink'
import { NoPermission } from '@/components/ui/NoPermission'
import { SparkBar } from '@/components/ui/SparkBar'
import { useOrgSubscriptionQuery } from '@/data/subscriptions/org-subscription-query'
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
import { MANAGED_BY } from '@/lib/constants/infrastructure'
const BillingBreakdown = () => {
const { slug: orgSlug } = useParams()
const { data: selectedOrganization } = useSelectedOrganizationQuery()
const { isSuccess: isPermissionsLoaded, can: canReadSubscriptions } = useAsyncCheckPermissionsV2(
FGA_PERMISSIONS.ORGANIZATION.BILLING_READ
)
const { data: subscription } = useOrgSubscriptionQuery(
{ orgSlug },
{ enabled: canReadSubscriptions }
)
const invoiceFeatureEnabled = useIsFeatureEnabled('billing:invoices')
const billingCycleStart = dayjs.unix(subscription?.current_period_start ?? 0).utc()
const billingCycleEnd = dayjs.unix(subscription?.current_period_end ?? 0).utc()
const daysToCycleEnd = billingCycleEnd.diff(dayjs(), 'days')
const daysWithinCycle = billingCycleEnd.diff(billingCycleStart, 'days')
return (
<PageSection orientation="horizontal">
<PageSectionMeta>
<PageSectionSummary className="gap-4">
<PageSectionTitle>Upcoming Invoice</PageSectionTitle>
{selectedOrganization?.managed_by !== MANAGED_BY.AWS_MARKETPLACE && (
<SparkBar
type="horizontal"
value={daysWithinCycle - daysToCycleEnd}
max={daysWithinCycle}
barClass="bg-foreground"
labelBottom={`${billingCycleStart.format('MMMM DD')} - ${billingCycleEnd.format('MMMM DD')}`}
bgClass="bg-surface-300"
labelBottomClass="text-foreground-light! p-1 m-0"
labelTop={
subscription
? `${daysToCycleEnd} ${daysToCycleEnd === 1 ? 'day' : 'days'} left`
: ''
}
labelTopClass="p-1 m-0"
/>
)}
<PageSectionDescription className="space-y-2">
{selectedOrganization?.managed_by === MANAGED_BY.AWS_MARKETPLACE ? (
<>
<p>
AWS Marketplace sends two invoices each month: one for your fixed subscription
fee, billed on the day you subscribed, and one for your usage charges from the
previous month, billed by the 3rd.
</p>
<p>
For a more detailed breakdown, visit the{' '}
<InlineLink href={`/org/${orgSlug}/usage`}>usage page.</InlineLink>
</p>
</>
) : (
<p>
Your upcoming invoice will continue to update until the end of your billing cycle on{' '}
{billingCycleEnd.format('MMMM DD')}. For a more detailed breakdown, visit the{' '}
<InlineLink href={`/org/${orgSlug}/usage`}>usage page.</InlineLink>
</p>
)}
<p>Add-on changes or new projects may take up to an hour to appear.</p>
</PageSectionDescription>
</PageSectionSummary>
</PageSectionMeta>
<PageSectionContent className="flex flex-col gap-6">
{isPermissionsLoaded && !canReadSubscriptions ? (
<NoPermission resourceText="view this organization's upcoming invoice" />
) : invoiceFeatureEnabled ? (
<UpcomingInvoice slug={orgSlug} />
) : null}
</PageSectionContent>
</PageSection>
)
}
export default BillingBreakdown