| 1 | 'use client' |
| 2 | |
| 3 | import { Clock, DollarSign, TrendingUp } from 'lucide-react' |
| 4 | import { Card, CardContent |
| 5 | import type { TimeEntry |
| 6 | |
| 7 | interface TimeSummaryCardProps { |
| 8 | entries: TimeEntry |
| 9 | } |
| 10 | |
| 11 | function getMonday(d: |
| 12 | const date = |
| 13 | const day = |
| 14 | const diff = |
| 15 | date.setDate(diff |
| 16 | date.setHours(0, |
| 17 | return date |
| 18 | } |
| 19 | |
| 20 | function formatMinutesAsHours(minutes: |
| 21 | return (minutes / |
| 22 | } |
| 23 | |
| 24 | export function TimeSummaryCard({ |
| 25 | const monday = |
| 26 | const sunday = |
| 27 | sunday.setDate(sunday |
| 28 | |
| 29 | const thisWeekEntries = |
| 30 | const d = |
| 31 | return d >= |
| 32 | }) |
| 33 | |
| 34 | const totalMinutes = |
| 35 | (sum, e) |
| 36 | 0 |
| 37 | ) |
| 38 | const billableMinutes = |
| 39 | .filter((e) |
| 40 | .reduce((sum, |
| 41 | |
| 42 | const reqCounts: |
| 43 | for (const entry |
| 44 | const key = |
| 45 | if (!reqCounts[key |
| 46 | reqCounts[key] = |
| 47 | } |
| 48 | reqCounts[key].minutes |
| 49 | } |
| 50 | |
| 51 | const topRequirement = |
| 52 | .sort((a, |
| 53 | .at(0) |
| 54 | |
| 55 | return ( |
| 56 | <Card className=' |
| 57 | <CardHeader className=' |
| 58 | <CardTitle className=' |
| 59 | </CardHeader> |
| 60 | <CardContent> |
| 61 | <div className='space-y-3 |
| 62 | <div className='flex items-center gap-3 |
| 63 | <div className='flex size-9 items-center justify-center rounded-md bg-primary/10 |
| 64 | <Clock className=' |
| 65 | </div> |
| 66 | <div> |
| 67 | <p className='font-bold text-2xl |
| 68 | {formatMinutesAsHours(totalMinutes)} |
| 69 | </p> |
| 70 | <p className='text-muted-foreground text-xs |
| 71 | </div> |
| 72 | </div> |
| 73 | |
| 74 | <div className='flex items-center gap-3 |
| 75 | <div className='flex size-9 items-center justify-center rounded-md bg-green-500/10 |
| 76 | <DollarSign className=' |
| 77 | </div> |
| 78 | <div> |
| 79 | <p className='font-semibold text-lg |
| 80 | {formatMinutesAsHours(billableMinutes)} |
| 81 | </p> |
| 82 | <p className='text-muted-foreground text-xs |
| 83 | </div> |
| 84 | </div> |
| 85 | |
| 86 | {topRequirement && ( |
| 87 | <div className='flex items-center gap-3 |
| 88 | <div className='flex size-9 items-center justify-center rounded-md bg-blue-500/10 |
| 89 | <TrendingUp className=' |
| 90 | </div> |
| 91 | <div className='min-w-0 |
| 92 | <p className='truncate font-medium text-sm |
| 93 | {topRequirement.title} |
| 94 | </p> |
| 95 | <p className='text-muted-foreground text-xs |
| 96 | Top requirement ·{' '} |
| 97 | {formatMinutesAsHours(topRequirement.minutes |
| 98 | </p> |
| 99 | </div> |
| 100 | </div> |
| 101 | )} |
| 102 | </div> |
| 103 | </CardContent> |
| 104 | </Card> |
| 105 | ) |
| 106 | } |