diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 4b134c61..d364f301 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -358,17 +358,24 @@ export default function CourrierPage() { ? account.folders : []; + // Only add folders that actually exist for this account + const validFolders = accountFolders.filter((folder: string) => { + // Remove any account prefix if present + const baseFolder = folder.includes(':') ? folder.split(':')[1] : folder; + return baseFolder && baseFolder.trim() !== ''; + }); + updatedAccounts.push({ id: account.id, name: account.display_name || account.email, email: account.email, color: account.color || 'bg-blue-500', - folders: accountFolders + folders: validFolders }); console.log(`[DEBUG] Added account with folders:`, { id: account.id, email: account.email, - folders: accountFolders + folders: validFolders }); }); } else { @@ -612,9 +619,14 @@ export default function CourrierPage() { // Update the folder button rendering to show selected state based on account const renderFolderButton = (folder: string, accountId: string) => { + // Remove account prefix from folder name for comparison + const baseFolder = folder.includes(':') ? folder.split(':')[1] : folder; + const isSelected = selectedFolders[accountId] === folder; const account = accounts.find(a => a.id === accountId); - const isVisible = account?.folders?.includes(folder) || false; + + // Check if this folder belongs to this account + const isVisible = account?.folders?.includes(baseFolder) || false; if (!isVisible) return null; @@ -623,12 +635,12 @@ export default function CourrierPage() { key={folder} variant="ghost" className={`w-full justify-start text-xs py-1 h-7 ${isSelected ? 'bg-gray-100' : ''}`} - onClick={() => handleMailboxChange(folder, accountId)} + onClick={() => handleMailboxChange(baseFolder, accountId)} >