import { PermissionAction } from '@supabase/shared-types/out/constants' import { useParams } from 'common' import dayjs from 'dayjs' import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader' import { UpcomingInvoice } from './UpcomingInvoice' import { ScaffoldSection, ScaffoldSectionContent, ScaffoldSectionDetail, } from '@/components/layouts/Scaffold' import AlertError from '@/components/ui/AlertError' 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 { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions' 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 } = useAsyncCheckPermissions( PermissionAction.BILLING_READ, 'stripe.subscriptions' ) const { data: subscription, error: subscriptionError, isPending: isLoadingSubscription, isError: isErrorSubscription, } = 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 ? ( ) : ( <> {isLoadingSubscription && (
)} {isErrorSubscription && ( )} {invoiceFeatureEnabled && } )}
) } export default BillingBreakdown