diff --git a/components/email/EmailPreview.tsx b/components/email/EmailPreview.tsx index 4c6ade51..f1c4722a 100644 --- a/components/email/EmailPreview.tsx +++ b/components/email/EmailPreview.tsx @@ -1,11 +1,14 @@ 'use client'; import { useState } from 'react'; -import { Loader2, Paperclip } from 'lucide-react'; +import { Loader2, Paperclip, User } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { ScrollArea } from '@/components/ui/scroll-area'; import { sanitizeHtml } from '@/lib/utils/email-formatter'; +import { Avatar } from '@/components/ui/avatar'; +import { AvatarFallback, AvatarImage } from '@/components/ui/avatar'; +import { Card } from '@/components/ui/card'; interface EmailAddress { name: string; @@ -78,6 +81,19 @@ export default function EmailPreview({ email, loading = false, onReply }: EmailP ).join(', '); }; + // Get sender initials for avatar + const getSenderInitials = (sender: EmailAddress | undefined) => { + if (!sender) return 'U'; + if (sender.name) { + const parts = sender.name.split(' '); + if (parts.length > 1) { + return `${parts[0][0]}${parts[parts.length - 1][0]}`.toUpperCase(); + } + return sender.name[0].toUpperCase(); + } + return sender.address[0].toUpperCase(); + }; + // Display loading state if (loading) { return ( @@ -101,70 +117,74 @@ export default function EmailPreview({ email, loading = false, onReply }: EmailP ); } + const sender = email.from && email.from.length > 0 ? email.from[0] : undefined; + return ( -
+ {/* Email header */} -
-
-

{email.subject}

-
-
- From: - {formatEmailAddresses(email.from)} +
+
+

{email.subject}

+ +
+ + {getSenderInitials(sender)} + + +
+
+
{sender?.name || sender?.address}
+ {formatDate(email.date)} +
+ +
+ To: {formatEmailAddresses(email.to)} +
+ + {email.cc && email.cc.length > 0 && ( +
+ Cc: {formatEmailAddresses(email.cc)} +
+ )}
- {formatDate(email.date)}
- - {email.to && email.to.length > 0 && ( -
- To: - {formatEmailAddresses(email.to)} -
- )} - - {email.cc && email.cc.length > 0 && ( -
- Cc: - {formatEmailAddresses(email.cc)} + + {/* Action buttons */} + {onReply && ( +
+ + +
)}
- {/* Action buttons */} - {onReply && ( -
- - - -
- )} - {/* Attachments */} {email.attachments && email.attachments.length > 0 && ( -
-
Attachments:
+
+
Attachments
{email.attachments.map((attachment, index) => ( - - + + {attachment.filename} ({Math.round(attachment.size / 1024)}KB) @@ -177,18 +197,20 @@ export default function EmailPreview({ email, loading = false, onReply }: EmailP
{/* Email content */} - - {email.content ? ( -
- ) : ( -

No content available

- )} + +
+ {email.content ? ( +
+ ) : ( +

No content available

+ )} +
-
+ ); } \ No newline at end of file