| 1 | import { differenceInDays, format, formatDistanceToNow, isPast } from 'date-fns' |
| 2 | import { AlertTriangleIcon, CircleCheckIcon |
| 3 | import Link from 'next/link |
| 4 | import { Card } |
| 5 | import { cn } |
| 6 | import type { projects |
| 7 | import ProjectBanner from './project-banner |
| 8 | import ProjectStatusBadge from './project-status-badge |
| 9 | |
| 10 | function DueDateBadge({ dueDate |
| 11 | const now = |
| 12 | const overdue = |
| 13 | const daysLeft = |
| 14 | const urgent = |
| 15 | |
| 16 | return ( |
| 17 | <div |
| 18 | className={cn( |
| 19 | 'inline-flex items-center gap-1.5 rounded-md px-2 py-0.5 font-medium text-xs', |
| 20 | overdue && 'bg-destructive/10 text-destructive' |
| 21 | urgent && |
| 22 | !overdue && |
| 23 | 'bg-amber-500/10 text-amber-600 dark:text-amber-400', |
| 24 | !(overdue || urgent |
| 25 | )} |
| 26 | > |
| 27 | {overdue ? ( |
| 28 | <AlertTriangleIcon className=' |
| 29 | ) : urgent ? |
| 30 | <ClockIcon className=' |
| 31 | ) : ( |
| 32 | <CircleCheckIcon className=' |
| 33 | )} |
| 34 | <span> |
| 35 | {overdue |
| 36 | ? `Overdue by ${formatDistanceToNow( |
| 37 | : `Due ${format( |
| 38 | </span> |
| 39 | </div> |
| 40 | ) |
| 41 | } |
| 42 | |
| 43 | export default function ProjectCard |
| 44 | project, |
| 45 | orgSlug, |
| 46 | inert = false, |
| 47 | }: { |
| 48 | project: typeof |
| 49 | orgSlug: string |
| 50 | inert?: boolean |
| 51 | }) { |
| 52 | return ( |
| 53 | <Link className=' |
| 54 | <Card className=' |
| 55 | <ProjectBanner seed={ |
| 56 | <div className='flex flex-1 flex-col p-4 |
| 57 | <div className='flex items-center justify-between gap-2 |
| 58 | <h3 className='truncate font-semibold |
| 59 | <span className='shrink-0 font-mono text-muted-foreground text-xs |
| 60 | {project.slug} |
| 61 | </span> |
| 62 | </div> |
| 63 | <p className='mt-1.5 line-clamp-2 flex-1 text-muted-foreground text-sm |
| 64 | {project.description || |
| 65 | </p> |
| 66 | <div className='mt-1.5 flex max-h-6 flex-row items-end gap-2 |
| 67 | {project.dueDate && |
| 68 | (project.status === |
| 69 | project.status === |
| 70 | <div className='mt-3 |
| 71 | <DueDateBadge |
| 72 | dueDate={new Date |
| 73 | /> |
| 74 | </div> |
| 75 | )} |
| 76 | <ProjectStatusBadge status={ |
| 77 | </div> |
| 78 | </div> |
| 79 | </Card> |
| 80 | </Link> |
| 81 | ) |
| 82 | } |