From 4d01953b7a4e8d1bb348665ef7376e501eeaee61 Mon Sep 17 00:00:00 2001 From: alma Date: Sun, 27 Apr 2025 17:35:34 +0200 Subject: [PATCH] courrier multi account --- app/courrier/page.tsx | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 6d4786bf..b2b24720 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -65,7 +65,7 @@ function SimplifiedLoadingFix() { } interface Account { - id: number | string; + id: string; name: string; email: string; color: string; @@ -128,8 +128,8 @@ export default function CourrierPage() { // Email accounts for the sidebar const [accounts, setAccounts] = useState([ - { id: 0, name: 'All', email: '', color: 'bg-gray-500' }, - { id: 1, name: 'Loading...', email: '', color: 'bg-blue-500', folders: mailboxes } + { id: 'all-accounts', name: 'All', email: '', color: 'bg-gray-500' }, + { id: 'loading-account', name: 'Loading...', email: '', color: 'bg-blue-500', folders: mailboxes } ]); const [selectedAccount, setSelectedAccount] = useState(null); @@ -178,8 +178,8 @@ export default function CourrierPage() { if (!accounts || accounts.length === 0) { console.warn('Accounts array is empty, restoring defaults'); setAccounts([ - { id: 0, name: 'All', email: '', color: 'bg-gray-500' }, - { id: 1, name: 'Loading...', email: '', color: 'bg-blue-500', folders: mailboxes } + { id: 'all-accounts', name: 'All', email: '', color: 'bg-gray-500' }, + { id: 'loading-account', name: 'Loading...', email: '', color: 'bg-blue-500', folders: mailboxes } ]); } }, [accounts, mailboxes]); @@ -229,7 +229,7 @@ export default function CourrierPage() { // Update accounts with the default email as fallback const updatedAccounts: Account[] = [ - { id: 0, name: 'All', email: '', color: 'bg-gray-500' } + { id: 'all-accounts', name: 'All', email: '', color: 'bg-gray-500' } ]; // Check if we have multiple accounts returned @@ -238,7 +238,7 @@ export default function CourrierPage() { // Add each account from the server data.allAccounts.forEach((account: any, index: number) => { - console.log(`[DEBUG] Processing account: ${account.email}, display_name: ${account.display_name}, has folders: ${account.folders ? account.folders.length : 0}`); + console.log(`[DEBUG] Processing account: ${account.email}, id: ${account.id}, display_name: ${account.display_name}, has folders: ${account.folders ? account.folders.length : 0}`); // Force include some hardcoded folders if none are present const fallbackFolders = ['INBOX', 'Sent', 'Drafts', 'Trash', 'Junk']; @@ -253,17 +253,17 @@ export default function CourrierPage() { console.log(`[DEBUG] Using folders for ${account.email}:`, folderList); const accountWithFolders = { - id: account.id || index + 1, + id: account.id || `account-${index + 1}`, // Use the database ID or generate a stable ID name: account.display_name || account.email, email: account.email, color: account.color || 'bg-blue-500', folders: folderList }; - console.log(`[DEBUG] Adding account with ${accountWithFolders.folders.length} folders:`, accountWithFolders.folders); + console.log(`[DEBUG] Adding account with id ${accountWithFolders.id} and ${accountWithFolders.folders.length} folders:`, accountWithFolders.folders); updatedAccounts.push(accountWithFolders); }); } else if (data.email) { - // Check if we have accounts from the API + // Check if we have a single account from the API if (data.allAccounts && Array.isArray(data.allAccounts) && data.allAccounts.length === 1) { const singleAccount = data.allAccounts[0]; console.log('[DEBUG] Single account detected:', @@ -282,7 +282,7 @@ export default function CourrierPage() { console.log(`[DEBUG] Using folders for single account ${singleAccount.email}:`, accountFolders); updatedAccounts.push({ - id: singleAccount.id || 1, + id: singleAccount.id || 'account-1', name: singleAccount.display_name || singleAccount.email, email: singleAccount.email, color: singleAccount.color || 'bg-blue-500', @@ -302,7 +302,7 @@ export default function CourrierPage() { console.log(`[DEBUG] Using folders for fallback account ${data.email}:`, folderList); updatedAccounts.push({ - id: 1, + id: 'default-account', name: data.displayName || data.email, email: data.email, color: 'bg-blue-500', @@ -654,7 +654,7 @@ export default function CourrierPage() { // Update accounts list const newAccountObj = { - id: Date.now(), // temporary ID + id: `account-${Date.now()}`, // generate unique string ID name: formValues.display_name, email: formValues.email, color: `bg-blue-500`, // Default color class @@ -800,7 +800,7 @@ export default function CourrierPage() { setSelectedAccount(account); // Force the account to have folders if it doesn't already - if (account.id !== 0 && (!account.folders || account.folders.length === 0)) { + if (account.id !== 'all-accounts' && (!account.folders || account.folders.length === 0)) { const accountWithFolders = { ...account, folders: ['INBOX', 'Sent', 'Drafts', 'Trash', 'Junk'] @@ -830,7 +830,7 @@ export default function CourrierPage() { {/* Show folders for this account if it's selected and folders are shown */} {((selectedAccount?.id === account.id && showFolders) || - (!selectedAccount && account.id !== 0 && account.folders)) && ( + (!selectedAccount && account.id !== 'all-accounts' && account.folders)) && (
{account.folders && account.folders.length > 0 ? ( account.folders.map((folder, folderIndex) => (