| 1 | import { formatDistanceToNow } from 'date-fns' |
| 2 | import Link from 'next/link |
| 3 | import StatusBadge from '@/components/status-badge |
| 4 | import { Card } |
| 5 | import { currencies } |
| 6 | import { stripHtml } |
| 7 | import type { proposals |
| 8 | import type { Role |
| 9 | |
| 10 | type Proposal |
| 11 | |
| 12 | export default function ProposalCard |
| 13 | proposal, |
| 14 | orgSlug, |
| 15 | projectSlug, |
| 16 | role, |
| 17 | isClientInvolved, |
| 18 | }: { |
| 19 | proposal: Proposal |
| 20 | orgSlug: string |
| 21 | projectSlug: string |
| 22 | role: Role |
| 23 | isClientInvolved?: boolean |
| 24 | }) { |
| 25 | const symbol = |
| 26 | currencies.find((c |
| 27 | proposal.currency |
| 28 | const num = |
| 29 | const amount = |
| 30 | num % 1 === |
| 31 | ? num.toLocaleString( |
| 32 | minimumFractionDigits: 2, |
| 33 | maximumFractionDigits: 2, |
| 34 | }) |
| 35 | : num.toLocaleString( |
| 36 | minimumFractionDigits: 2, |
| 37 | maximumFractionDigits: 4, |
| 38 | }) |
| 39 | |
| 40 | return ( |
| 41 | <Link |
| 42 | className='h-full' |
| 43 | href={`/${orgSlug |
| 44 | > |
| 45 | <Card className=' |
| 46 | <div className='mb-1.5 flex items-center justify-between gap-2 |
| 47 | <StatusBadge |
| 48 | isClientInvolved={isClientInvolved} |
| 49 | role={role} |
| 50 | status={proposal.status |
| 51 | /> |
| 52 | <span className='shrink-0 text-muted-foreground text-xs |
| 53 | {formatDistanceToNow(new Date |
| 54 | addSuffix: true, |
| 55 | })} |
| 56 | </span> |
| 57 | </div> |
| 58 | <h3 className='line-clamp-1 font-semibold |
| 59 | {num > 0 |
| 60 | <p className='mt-1 font-semibold text-lg |
| 61 | {symbol} {amount |
| 62 | </p> |
| 63 | )} |
| 64 | {proposal.body ? |
| 65 | <p className='mt-1 line-clamp-2 flex-1 text-muted-foreground text-sm |
| 66 | {stripHtml(proposal.body |
| 67 | </p> |
| 68 | ) : null} |
| 69 | {proposal.validUntil && |
| 70 | <p className='mt-0.5 text-muted-foreground text-xs |
| 71 | Valid until{' '} |
| 72 | {new Date(proposal |
| 73 | month: 'short', |
| 74 | day: 'numeric', |
| 75 | year: 'numeric', |
| 76 | })} |
| 77 | </p> |
| 78 | )} |
| 79 | </Card> |
| 80 | </Link> |
| 81 | ) |
| 82 | } |