import type { FC } from 'react'; import { Button, Divider, Paper, styled, Typography } from '@mui/material'; import CreditCardIcon from '@mui/icons-material/CreditCard'; import { useInstanceStatus } from 'hooks/api/getters/useInstanceStatus/useInstanceStatus'; import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; import { InstanceState } from 'interfaces/instance'; import { formatApiPath } from 'utils/formatPath'; import { useDetailedInvoices } from 'hooks/api/getters/useDetailedInvoices/useDetailedInvoices'; import { formatCurrency } from '../BillingInvoices/BillingInvoice/formatCurrency.js'; import { BillingInfoSkeleton } from './BillingInfoSkeleton.tsx'; const PORTAL_URL = formatApiPath('api/admin/invoices'); type BillingInfoProps = {}; const StyledWrapper = styled(Paper)(({ theme }) => ({ padding: theme.spacing(2), borderRadius: theme.shape.borderRadiusLarge, boxShadow: theme.boxShadows.card, display: 'flex', flexDirection: 'column', gap: theme.spacing(1), })); const StyledRow = styled('div')(({ theme }) => ({ display: 'flex', justifyContent: 'space-between', fontSize: theme.typography.body2.fontSize, })); const StyledItemTitle = styled('span')(({ theme }) => ({ color: theme.palette.text.secondary, whiteSpace: 'nowrap', })); const StyledItemValue = styled('span')(({ theme }) => ({ textAlign: 'right', })); const StyledButton = styled(Button)(({ theme }) => ({ margin: theme.spacing(0, 0, 1, 0), })); const StyledInfoLabel = styled(Typography)(({ theme }) => ({ fontSize: theme.fontSizes.smallBody, color: theme.palette.text.secondary, })); const StyledDivider = styled(Divider)(({ theme }) => ({ margin: theme.spacing(1.5, 0), borderColor: theme.palette.divider, })); const GetInTouch: FC = () => ( Get in touch with us {' '} for any clarification ); export const BillingInfo: FC = () => { const { instanceStatus, loading: instanceStatusLoading } = useInstanceStatus(); const { uiConfig: { billing }, } = useUiConfig(); const { planPrice, planCurrency, loading: invoicesLoading, } = useDetailedInvoices(); if (instanceStatusLoading || invoicesLoading) { return ; } if (!instanceStatus) { return ( Billing details Your billing is managed by Unleash ); } const isPAYG = billing === 'pay-as-you-go'; const inactive = instanceStatus.state !== InstanceState.ACTIVE; const { isCustomBilling } = instanceStatus; if (isCustomBilling) { return ( Billing details Your billing is managed by Unleash ); } return ( Billing details Current plan{' '} {isPAYG ? 'Pay-as-You-Go' : 'Consumption'} Plan price{' '} {planPrice !== undefined ? `${formatCurrency(planPrice, planCurrency)} ${ isPAYG ? 'per seat' : '/ month' }` : '-'} } > {!inactive ? 'Edit billing details' : 'Add billing details'} {inactive ? ( Once we have received your billing information we will upgrade your trial within 1 business day. ) : null} ); };