Neah version mail widget?
This commit is contained in:
parent
a768221be9
commit
e85c4d948e
@ -11,12 +11,12 @@ import { fr } from 'date-fns/locale/fr';
|
|||||||
interface Email {
|
interface Email {
|
||||||
id: string;
|
id: string;
|
||||||
subject: string;
|
subject: string;
|
||||||
sender: {
|
from: string;
|
||||||
name: string;
|
fromName?: string;
|
||||||
email: string;
|
|
||||||
};
|
|
||||||
date: string;
|
date: string;
|
||||||
isUnread: boolean;
|
read: boolean;
|
||||||
|
starred: boolean;
|
||||||
|
folder: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EmailResponse {
|
interface EmailResponse {
|
||||||
@ -51,46 +51,22 @@ export function Email() {
|
|||||||
throw new Error(errorData.error || 'Failed to fetch emails');
|
throw new Error(errorData.error || 'Failed to fetch emails');
|
||||||
}
|
}
|
||||||
|
|
||||||
const rawText = await response.text();
|
const data = await response.json();
|
||||||
console.log('Raw API Response:', rawText);
|
console.log('Parsed API Response:', data);
|
||||||
|
|
||||||
let data;
|
|
||||||
try {
|
|
||||||
data = JSON.parse(rawText);
|
|
||||||
console.log('Parsed API Response:', data);
|
|
||||||
} catch (parseError) {
|
|
||||||
console.error('JSON Parse Error:', parseError);
|
|
||||||
throw new Error('Invalid JSON response from server');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
throw new Error(data.error);
|
throw new Error(data.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
let emailsArray = [];
|
const validatedEmails = data.emails.map((email: any) => ({
|
||||||
if (Array.isArray(data)) {
|
|
||||||
emailsArray = data;
|
|
||||||
} else if (data.messages && Array.isArray(data.messages)) {
|
|
||||||
emailsArray = data.messages;
|
|
||||||
} else if (data.emails && Array.isArray(data.emails)) {
|
|
||||||
emailsArray = data.emails;
|
|
||||||
} else {
|
|
||||||
console.error('Unexpected data structure:', data);
|
|
||||||
throw new Error('Invalid response format: emails data not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
const validatedEmails = emailsArray.map(email => ({
|
|
||||||
id: email.id || Date.now().toString(),
|
id: email.id || Date.now().toString(),
|
||||||
accountId: email.accountId || 1,
|
subject: email.subject || '(No subject)',
|
||||||
from: email.from || '',
|
from: email.from || '',
|
||||||
fromName: email.fromName || email.from?.split('@')[0] || 'Unknown',
|
fromName: email.fromName || email.from?.split('@')[0] || 'Unknown',
|
||||||
to: email.to || '',
|
|
||||||
subject: email.subject || '(No subject)',
|
|
||||||
body: email.body || '',
|
|
||||||
date: email.date || new Date().toISOString(),
|
date: email.date || new Date().toISOString(),
|
||||||
read: !!email.read,
|
read: !!email.read,
|
||||||
starred: !!email.starred,
|
starred: !!email.starred,
|
||||||
category: email.category || 'inbox'
|
folder: email.folder || 'INBOX'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
console.log('Processed emails:', validatedEmails);
|
console.log('Processed emails:', validatedEmails);
|
||||||
@ -213,11 +189,11 @@ export function Email() {
|
|||||||
onClick={() => mailUrl && window.open(mailUrl, '_blank')}
|
onClick={() => mailUrl && window.open(mailUrl, '_blank')}
|
||||||
>
|
>
|
||||||
<div className="flex items-center justify-between mb-1">
|
<div className="flex items-center justify-between mb-1">
|
||||||
<span className="text-sm text-gray-600 truncate max-w-[60%]" title={email.sender.name}>
|
<span className="text-sm text-gray-600 truncate max-w-[60%]" title={email.fromName || email.from}>
|
||||||
{email.sender.name}
|
{email.fromName || email.from}
|
||||||
</span>
|
</span>
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
{email.isUnread && <span className="w-1.5 h-1.5 bg-blue-600 rounded-full"></span>}
|
{!email.read && <span className="w-1.5 h-1.5 bg-blue-600 rounded-full"></span>}
|
||||||
<span className="text-xs text-gray-500">{formatDate(email.date)}</span>
|
<span className="text-xs text-gray-500">{formatDate(email.date)}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user