2
0

🐛 (billing) Fix crash when having a draft invoice

This commit is contained in:
Baptiste Arnaud
2023-02-16 16:24:56 +01:00
parent 44cb14d0cb
commit d805ea9c10
3 changed files with 30 additions and 23 deletions

View File

@ -16,7 +16,7 @@ export const BillingContent = () => {
return (
<Stack spacing="10" w="full">
<UsageContent workspace={workspace} />
<Stack spacing="2">
<Stack spacing="4">
<CurrentSubscriptionContent
plan={workspace.plan}
stripeId={workspace.stripeId}

View File

@ -18,6 +18,7 @@ import { Workspace } from 'db'
import Link from 'next/link'
import React from 'react'
import { useInvoicesQuery } from './queries/useInvoicesQuery'
import { isDefined } from 'utils'
type Props = {
workspace: Workspace
@ -44,27 +45,33 @@ export const InvoicesList = ({ workspace }: Props) => {
</Tr>
</Thead>
<Tbody>
{invoices?.map((invoice) => (
<Tr key={invoice.id}>
<Td>
<FileIcon />
</Td>
<Td>{invoice.id}</Td>
<Td>{new Date(invoice.date * 1000).toDateString()}</Td>
<Td>{getFormattedPrice(invoice.amount, invoice.currency)}</Td>
<Td>
<IconButton
as={Link}
size="xs"
icon={<DownloadIcon />}
variant="outline"
href={invoice.url}
target="_blank"
aria-label={'Download invoice'}
/>
</Td>
</Tr>
))}
{invoices
?.filter((invoice) => isDefined(invoice.url))
.map((invoice) => (
<Tr key={invoice.id}>
<Td>
<FileIcon />
</Td>
<Td>{invoice.id}</Td>
<Td>{new Date(invoice.date * 1000).toDateString()}</Td>
<Td>
{getFormattedPrice(invoice.amount, invoice.currency)}
</Td>
<Td>
{invoice.url && (
<IconButton
as={Link}
size="xs"
icon={<DownloadIcon />}
variant="outline"
href={invoice.url}
target="_blank"
aria-label={'Download invoice'}
/>
)}
</Td>
</Tr>
))}
{isLoading &&
Array.from({ length: 3 }).map((_, idx) => (
<Tr key={idx}>

View File

@ -4,7 +4,7 @@ import { env } from 'utils'
type Invoice = {
id: string
url: string
url: string | null
date: number
currency: string
amount: number