'use client'; /* EngagementRecentEntries — phase 08 (D-18..D-21). * Purpose: Collapsible list of up to 10 recent time entries. Tap-to-expand * reveals full notes, title, company, and start timestamp. Local Set * state tracks expanded IDs — period changes do not reset expansion (D-20). */ import { useState } from 'react'; import { Card, CardContent } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible'; import { useUserTimezone, formatInUserTimezone } from '@/lib/hooks/use-user-timezone'; export interface RecentTimeEntry { entry_date: string; hours_worked: number; billable: boolean | null; notes: string | null; title: string | null; start_date_time: string | null; end_date_time: string | null; company_name: string | null; } export interface EngagementRecentEntriesProps { entries: RecentTimeEntry[]; // caller passes recentEntries.slice(0, 10) } export function EngagementRecentEntries({ entries }: EngagementRecentEntriesProps) { const tz = useUserTimezone(); const [expandedIds, setExpandedIds] = useState>(new Set()); const toggle = (id: string) => { setExpandedIds((prev) => { const next = new Set(prev); if (next.has(id)) next.delete(id); else next.add(id); return next; }); }; // ID derivation: caller doesn't pass an explicit id, so derive a stable string per row. const idFor = (e: RecentTimeEntry, i: number) => `${e.entry_date}|${e.start_date_time ?? ''}|${i}`; return (

Recent time entries

{entries.length === 0 ? (

No time entries in the last 30 days

) : (
    {entries.slice(0, 10).map((entry, i) => { const id = idFor(entry, i); const open = expandedIds.has(id); const dateLabel = formatInUserTimezone(entry.entry_date, tz, { month: 'short', day: 'numeric' }); const isBillable = entry.billable !== false; // null defaults true const oneLine = entry.notes ? entry.notes.split('\n')[0]?.slice(0, 80) ?? '' : (entry.title ?? ''); return (
  • toggle(id)}> {entry.title &&

    Title: {entry.title}

    } {entry.company_name &&

    Company: {entry.company_name}

    } {entry.notes &&

    {entry.notes}

    } {entry.start_date_time && (

    Started:{' '} {formatInUserTimezone(entry.start_date_time, tz, { month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' })}

    )}
  • ); })}
)}
); }