-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArchiveItem.tsx
More file actions
232 lines (219 loc) · 9.15 KB
/
ArchiveItem.tsx
File metadata and controls
232 lines (219 loc) · 9.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import React from "react";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow
} from "@/components/ui/table";
import { Calendar, Clock, Edit, RotateCcw, FileText } from "lucide-react";
import { formatDuration, formatDurationLong, formatTime, formatDate, generateDailySummary } from "@/utils/timeUtil";
import { DayRecord } from "@/contexts/TimeTrackingContext";
import { useTimeTracking } from "@/hooks/useTimeTracking";
interface ArchiveItemProps {
day: DayRecord;
onEdit: (day: DayRecord) => void;
}
export const ArchiveItem: React.FC<ArchiveItemProps> = ({ day, onEdit }) => {
const {
restoreArchivedDay,
isDayStarted,
getHoursWorkedForDay,
getRevenueForDay,
getBillableHoursForDay,
getNonBillableHoursForDay,
projects,
categories
} = useTimeTracking();
const handleRestore = () => {
if (isDayStarted) {
if (
!confirm(
'You currently have an active day. Restoring to this day will replace your current work. Continue restoring?'
)
) {
return;
}
}
restoreArchivedDay(day.id);
};
return (
<Card className="print:shadow-none print:mb-4">
<CardHeader className="print:pb-2">
<div className="flex items-center justify-between">
<CardTitle className="flex items-center space-x-2">
{formatDate(day.startTime)}
</CardTitle>
<div className="flex space-x-2 print:hidden">
<Button
onClick={handleRestore}
variant="ghost"
size="sm"
className="flex items-center space-x-2 text-blue-600 hover:text-blue-700"
>
<RotateCcw className="w-4 h-4 hidden md:block" />
Restore
</Button>
<Button
onClick={() => onEdit(day)}
variant="default"
size="sm"
className="flex items-center space-x-2"
>
<Edit className="w-4 h-4 hidden md:block" />
Edit
</Button>
</div>
</div>
</CardHeader>
<CardContent className="print:pt-0">
<div className="space-y-4">
{/* Day Summary */}
<div className="space-y-2">
<div className="flex items-center justify-between text-sm print:text-base">
<div className="flex items-center space-x-4">
<span className="text-gray-600 print:text-black">
Started: {formatTime(day.startTime)}
</span>
<span className="text-gray-600 print:text-black">
Ended: {formatTime(day.endTime)}
</span>
</div>
<div className="flex items-center space-x-2">
<Clock className="w-4 h-4 text-green-600 print:text-black" />
<span className="font-semibold text-green-600 print:text-black">
{formatDurationLong(day.totalDuration)}
</span>
</div>
</div>
{/* Hours Worked and Revenue */}
<div className="space-y-2 border-t pt-2">
<div className="flex items-center justify-between text-sm print:text-base">
<div className="flex items-center space-x-4">
<span className="text-blue-600 print:text-black font-medium">
Total <span className="hidden md:d-inline-flex">Hours: </span>{getHoursWorkedForDay(day).toFixed(2)}h
</span>
<span className="text-green-600 print:text-black font-medium">
Billable: {getBillableHoursForDay(day).toFixed(2)}h
</span>
<span className="text-gray-600 print:text-black font-medium">
Non-billable: {getNonBillableHoursForDay(day).toFixed(2)}h
</span>
</div>
{getRevenueForDay(day) > 0 && (
<span className="text-green-600 print:text-black font-semibold">
Revenue: ${getRevenueForDay(day).toFixed(2)}
</span>
)}
</div>
</div>
</div>
{/* Daily Summary */}
{(() => {
const descriptions = day.tasks
.filter((task) => task.description)
.map((task) => task.description!);
const summary = generateDailySummary(descriptions);
if (!summary) return null;
return (
<div className="space-y-2 border-t pt-4">
<h4 className="font-medium text-gray-900 flex items-center mb-2">
<FileText className="w-4 h-4 mr-2" />
Daily Summary
</h4>
<div className="bg-gray-50 dark:bg-gray-800 p-4 rounded-md print:bg-white print:border print:border-gray-300">
<p className="text-sm text-gray-700 dark:text-gray-300 print:text-gray-800 leading-relaxed">
{summary}
</p>
</div>
</div>
);
})()}
{/* Tasks Table */}
<div className="print:mt-2">
<h4 className="font-medium text-gray-900 print:hidden mb-2">
Tasks ({day.tasks.length})
</h4>
<Table>
<TableHeader>
<TableRow className="print:border-black">
<TableHead className="print:text-black print:font-bold">
Task
</TableHead>
<TableHead className="print:text-black print:font-bold">
Project
</TableHead>
<TableHead className="print:text-black print:font-bold">
Start<span className="hidden md:d-inline-flex"> Time</span>
</TableHead>
<TableHead className="print:text-black print:font-bold">
End<span className="hidden md:d-inline-flex"> Time</span>
</TableHead>
<TableHead className="print:text-black print:font-bold">
Duration
</TableHead>
<TableHead className="print:text-black print:font-bold">
Value
</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{day.tasks.map((task) => {
const project = projects.find((p) => p.name === task.project);
const category = categories.find((c) => c.name === task.category);
const taskHours = task.duration ? task.duration / (1000 * 60 * 60) : 0;
// Check if both the project and category are billable
const projectIsBillable = project?.isBillable !== false;
const categoryIsBillable = category?.isBillable !== false;
const isBillable = projectIsBillable && categoryIsBillable;
const taskValue = isBillable && project?.hourlyRate && task.duration ?
taskHours * project.hourlyRate : 0;
return (
<TableRow key={task.id} className="print:border-black">
<TableCell className="font-medium print:text-black">
{task.title}
<div className="font-medium text-sm italic text-gray-400 hidden md:block print:text-gray-600">
{task.description}
</div>
</TableCell>
<TableCell className="print:text-black">
{task.project || '-'}
{project?.hourlyRate && (
<div className="text-xs text-gray-500 print:text-gray-600">
${project.hourlyRate}/hr
</div>
)}
</TableCell>
<TableCell className="print:text-black">
{formatTime(task.startTime)}
</TableCell>
<TableCell className="print:text-black">
{task.endTime ? formatTime(task.endTime) : '-'}
</TableCell>
<TableCell className="print:text-black">
{formatDuration(task.duration || 0)}
<div className="text-xs text-gray-500 print:text-gray-600">
{taskHours.toFixed(2)}h
</div>
</TableCell>
<TableCell className="print:text-black">
{taskValue > 0 ? (
<span className="font-medium text-green-600 print:text-black">
${taskValue.toFixed(2)}
</span>
) : '-'}
</TableCell>
</TableRow>
);
})}
</TableBody>
</Table>
</div>
</div>
</CardContent>
</Card>
);
};