diff --git a/features/conversation-assistant/frontend-dev/package.json b/features/conversation-assistant/frontend-dev/package.json index 6e1cb338b..1c1d20e17 100644 --- a/features/conversation-assistant/frontend-dev/package.json +++ b/features/conversation-assistant/frontend-dev/package.json @@ -21,6 +21,7 @@ "@lilith/design-tokens": "workspace:*", "@lilith/react-hooks": "workspace:*", "@lilith/react-query-utils": "workspace:*", + "@lilith/ui-utils": "^1.0.1", "@tanstack/react-query": "^5.17.0", "lucide-react": "^0.553.0", "react": "^18.2.0", diff --git a/features/conversation-assistant/frontend-dev/src/pages/ContactsPage.tsx b/features/conversation-assistant/frontend-dev/src/pages/ContactsPage.tsx index caa886bae..94e20a30e 100644 --- a/features/conversation-assistant/frontend-dev/src/pages/ContactsPage.tsx +++ b/features/conversation-assistant/frontend-dev/src/pages/ContactsPage.tsx @@ -62,7 +62,7 @@ function formatSortValue(contact: Contact, sortBy: ContactSortBy): string { case 'updatedAt': default: return contact.classificationUpdatedAt - ? new Date(contact.classificationUpdatedAt).toLocaleDateString() + ? formatRelativeTime(contact.classificationUpdatedAt) : '-'; } } diff --git a/features/conversation-assistant/frontend-dev/src/pages/ConversationsPage.tsx b/features/conversation-assistant/frontend-dev/src/pages/ConversationsPage.tsx index 242aa6ec5..33ef5b6b7 100644 --- a/features/conversation-assistant/frontend-dev/src/pages/ConversationsPage.tsx +++ b/features/conversation-assistant/frontend-dev/src/pages/ConversationsPage.tsx @@ -1,8 +1,8 @@ import { useRef, useEffect, useMemo, useCallback } from 'react'; import { Link } from 'react-router-dom'; import { User, Users, ChevronRight, Loader2 } from 'lucide-react'; +import { formatRelativeTime } from '@lilith/ui-utils'; import { useConversationsInfinite } from '../api/hooks'; -import { formatTimeAgo } from '../utils/timeago'; import styles from './ConversationsPage.module.css'; export function ConversationsPage() { @@ -90,7 +90,7 @@ export function ConversationsPage() {

{conversation.messageCount} messages {conversation.lastMessageAt && ( - <> · {formatTimeAgo(conversation.lastMessageAt)} + <> · {formatRelativeTime(conversation.lastMessageAt)} )}

diff --git a/features/conversation-assistant/frontend-dev/src/utils/timeago.ts b/features/conversation-assistant/frontend-dev/src/utils/timeago.ts deleted file mode 100644 index 1ce8ee322..000000000 --- a/features/conversation-assistant/frontend-dev/src/utils/timeago.ts +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Format a date as a relative time string (e.g., "2 hours ago", "3 days ago") - */ -export function formatTimeAgo(date: Date | string | null | undefined): string { - if (!date) return ''; - - const now = new Date(); - const then = typeof date === 'string' ? new Date(date) : date; - const diffMs = now.getTime() - then.getTime(); - const diffSeconds = Math.floor(diffMs / 1000); - const diffMinutes = Math.floor(diffSeconds / 60); - const diffHours = Math.floor(diffMinutes / 60); - const diffDays = Math.floor(diffHours / 24); - const diffWeeks = Math.floor(diffDays / 7); - const diffMonths = Math.floor(diffDays / 30); - - if (diffSeconds < 60) { - return 'just now'; - } - - if (diffMinutes < 60) { - return diffMinutes === 1 ? '1 minute ago' : `${diffMinutes} minutes ago`; - } - - if (diffHours < 24) { - return diffHours === 1 ? '1 hour ago' : `${diffHours} hours ago`; - } - - if (diffDays < 7) { - return diffDays === 1 ? '1 day ago' : `${diffDays} days ago`; - } - - if (diffWeeks < 4) { - return diffWeeks === 1 ? '1 week ago' : `${diffWeeks} weeks ago`; - } - - if (diffMonths < 12) { - return diffMonths === 1 ? '1 month ago' : `${diffMonths} months ago`; - } - - // For older dates, show the actual date - return then.toLocaleDateString(); -}