| 1 | import { formatDistanceToNow } from 'date-fns' |
| 2 | import { AlertTriangleIcon, ChevronRight |
| 3 | import Link from 'next/link |
| 4 | |
| 5 | import { |
| 6 | Accordion, |
| 7 | AccordionContent, |
| 8 | AccordionItem, |
| 9 | AccordionTrigger, |
| 10 | } from '@/components/ui/accordion' |
| 11 | import { Badge } |
| 12 | import type { RouteImpl |
| 13 | import { formatCurrency } |
| 14 | |
| 15 | export interface OverdueInvoice |
| 16 | currency: string |
| 17 | dueDate: Date |
| 18 | id: string |
| 19 | invoiceNumber: string |
| 20 | projectName?: string |
| 21 | projectSlug: string |
| 22 | totalAmount: string |
| 23 | } |
| 24 | |
| 25 | interface Props { |
| 26 | invoices: OverdueInvoice |
| 27 | orgSlug: string |
| 28 | showProjectName?: boolean |
| 29 | } |
| 30 | |
| 31 | export function OverdueInvoicesAccordion({ |
| 32 | invoices, |
| 33 | orgSlug, |
| 34 | showProjectName = false, |
| 35 | }: Props) |
| 36 | if (invoices.length |
| 37 | return null |
| 38 | } |
| 39 | |
| 40 | return ( |
| 41 | <Accordion |
| 42 | className='rounded-lg border border-border bg-background' |
| 43 | collapsible |
| 44 | type='single' |
| 45 | > |
| 46 | <AccordionItem className=' |
| 47 | <AccordionTrigger className=' |
| 48 | <div className='flex items-center gap-3 |
| 49 | <AlertTriangleIcon className=' |
| 50 | <span className='text-sm |
| 51 | </div> |
| 52 | <div className='ml-auto flex items-center gap-2 |
| 53 | <Badge variant=' |
| 54 | </div> |
| 55 | </AccordionTrigger> |
| 56 | <AccordionContent className=' |
| 57 | <div className='divide-y divide-border border-border border-t |
| 58 | {invoices.map(( |
| 59 | <Link |
| 60 | className='flex items-center justify-between gap-3 py-2.5 transition-colors hover:bg-muted/50' |
| 61 | href={ |
| 62 | `/${orgSlug}/${ |
| 63 | } |
| 64 | key={inv.id |
| 65 | > |
| 66 | <div className='min-w-0 flex-1 |
| 67 | <div className='flex items-center gap-2 |
| 68 | <span className='truncate font-medium text-sm |
| 69 | {inv.invoiceNumber} |
| 70 | </span> |
| 71 | {showProjectName && inv |
| 72 | <span className='truncate text-muted-foreground text-xs |
| 73 | · {inv.projectName} |
| 74 | </span> |
| 75 | )} |
| 76 | </div> |
| 77 | <p className='text-destructive text-xs |
| 78 | Due {formatDistanceToNow(inv.dueDate |
| 79 | </p> |
| 80 | </div> |
| 81 | <div className='flex shrink-0 items-center gap-2 |
| 82 | <span className='font-medium text-sm tabular-nums |
| 83 | {formatCurrency(Number(inv |
| 84 | </span> |
| 85 | <ChevronRight className=' |
| 86 | </div> |
| 87 | </Link> |
| 88 | ))} |
| 89 | </div> |
| 90 | </AccordionContent> |
| 91 | </AccordionItem> |
| 92 | </Accordion> |
| 93 | ) |
| 94 | } |