import React from "react"; import { Loader2, RefreshCw } from "lucide-react"; import { DateTime } from "luxon"; interface AdjustmentItem { id: string; date: string; loginTime: string; logoutTime: string; comment: string; status: string; requestedAt: string; adjustedHours: string; project: { id: string; name: string; }; } interface AdjustmentTableProps { isTracking: boolean; adjustments: AdjustmentItem[]; loading: boolean; lastRefreshed: Date | null; onRefresh: () => Promise; } const AdjustmentsTable: React.FC = ({ isTracking, adjustments, loading, lastRefreshed, onRefresh }) => { const [refreshing, setRefreshing] = React.useState(false); // 🌍 Convert UTC → Local System Time const toLocal = (utcString: string, format: string) => { return DateTime.fromISO(utcString, { zone: "utc" }) .setZone(DateTime.local().zoneName) .toFormat(format); }; const formatTime = (t: string) => toLocal(t, "HH:mm:ss"); const formatDate = (d: string) => toLocal(d, "yyyy-MM-dd"); const handleRefresh = async () => { setRefreshing(true); await onRefresh(); setRefreshing(false); }; const renderSkeleton = () => Array.from({ length: 7 }).map((_, i) => (
)); return ( <>
{loading ? renderSkeleton() : adjustments.length === 0 ? ( ) : adjustments.map((item, idx) => ( ))} {/* {refreshing && adjustments.length > 0 && ( )} */}
# Project Date In → Out Adjusted Hours Status Requested At
No adjustments found
{idx + 1} {item.project?.name || "N/A"} {formatDate(item.date)} {formatTime(item.loginTime)} → {" "} {formatTime(item.logoutTime)} {item.adjustedHours} {item.status} {toLocal(item.requestedAt, "yyyy-MM-dd HH:mm:ss")}
{renderSkeleton()}
{/* FOOTER */}
{adjustments.length} adjustment{adjustments.length !== 1 ? "s" : ""} found
{lastRefreshed && (
Last updated: {toLocal(lastRefreshed.toISOString(), "HH:mm:ss")}
)}
); }; export default AdjustmentsTable;