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 ( Upcoming Invoice {selectedOrganization?.managed_by !== MANAGED_BY.AWS_MARKETPLACE && ( )} {selectedOrganization?.managed_by === MANAGED_BY.AWS_MARKETPLACE ? ( <>

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.

For a more detailed breakdown, visit the{' '} usage page.

) : (

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{' '} usage page.

)}

Add-on changes or new projects may take up to an hour to appear.

{isPermissionsLoaded && !canReadSubscriptions ? ( ) : invoiceFeatureEnabled ? ( ) : null}
) } export default BillingBreakdown