courrier multi account
This commit is contained in:
parent
0d6c4a1be9
commit
4d01953b7a
@ -65,7 +65,7 @@ function SimplifiedLoadingFix() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface Account {
|
interface Account {
|
||||||
id: number | string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
email: string;
|
email: string;
|
||||||
color: string;
|
color: string;
|
||||||
@ -128,8 +128,8 @@ export default function CourrierPage() {
|
|||||||
|
|
||||||
// Email accounts for the sidebar
|
// Email accounts for the sidebar
|
||||||
const [accounts, setAccounts] = useState<Account[]>([
|
const [accounts, setAccounts] = useState<Account[]>([
|
||||||
{ id: 0, name: 'All', email: '', color: 'bg-gray-500' },
|
{ id: 'all-accounts', name: 'All', email: '', color: 'bg-gray-500' },
|
||||||
{ id: 1, name: 'Loading...', email: '', color: 'bg-blue-500', folders: mailboxes }
|
{ id: 'loading-account', name: 'Loading...', email: '', color: 'bg-blue-500', folders: mailboxes }
|
||||||
]);
|
]);
|
||||||
const [selectedAccount, setSelectedAccount] = useState<Account | null>(null);
|
const [selectedAccount, setSelectedAccount] = useState<Account | null>(null);
|
||||||
|
|
||||||
@ -178,8 +178,8 @@ export default function CourrierPage() {
|
|||||||
if (!accounts || accounts.length === 0) {
|
if (!accounts || accounts.length === 0) {
|
||||||
console.warn('Accounts array is empty, restoring defaults');
|
console.warn('Accounts array is empty, restoring defaults');
|
||||||
setAccounts([
|
setAccounts([
|
||||||
{ id: 0, name: 'All', email: '', color: 'bg-gray-500' },
|
{ id: 'all-accounts', name: 'All', email: '', color: 'bg-gray-500' },
|
||||||
{ id: 1, name: 'Loading...', email: '', color: 'bg-blue-500', folders: mailboxes }
|
{ id: 'loading-account', name: 'Loading...', email: '', color: 'bg-blue-500', folders: mailboxes }
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}, [accounts, mailboxes]);
|
}, [accounts, mailboxes]);
|
||||||
@ -229,7 +229,7 @@ export default function CourrierPage() {
|
|||||||
|
|
||||||
// Update accounts with the default email as fallback
|
// Update accounts with the default email as fallback
|
||||||
const updatedAccounts: Account[] = [
|
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
|
// Check if we have multiple accounts returned
|
||||||
@ -238,7 +238,7 @@ export default function CourrierPage() {
|
|||||||
|
|
||||||
// Add each account from the server
|
// Add each account from the server
|
||||||
data.allAccounts.forEach((account: any, index: number) => {
|
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
|
// Force include some hardcoded folders if none are present
|
||||||
const fallbackFolders = ['INBOX', 'Sent', 'Drafts', 'Trash', 'Junk'];
|
const fallbackFolders = ['INBOX', 'Sent', 'Drafts', 'Trash', 'Junk'];
|
||||||
@ -253,17 +253,17 @@ export default function CourrierPage() {
|
|||||||
console.log(`[DEBUG] Using folders for ${account.email}:`, folderList);
|
console.log(`[DEBUG] Using folders for ${account.email}:`, folderList);
|
||||||
|
|
||||||
const accountWithFolders = {
|
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,
|
name: account.display_name || account.email,
|
||||||
email: account.email,
|
email: account.email,
|
||||||
color: account.color || 'bg-blue-500',
|
color: account.color || 'bg-blue-500',
|
||||||
folders: folderList
|
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);
|
updatedAccounts.push(accountWithFolders);
|
||||||
});
|
});
|
||||||
} else if (data.email) {
|
} 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) {
|
if (data.allAccounts && Array.isArray(data.allAccounts) && data.allAccounts.length === 1) {
|
||||||
const singleAccount = data.allAccounts[0];
|
const singleAccount = data.allAccounts[0];
|
||||||
console.log('[DEBUG] Single account detected:',
|
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);
|
console.log(`[DEBUG] Using folders for single account ${singleAccount.email}:`, accountFolders);
|
||||||
|
|
||||||
updatedAccounts.push({
|
updatedAccounts.push({
|
||||||
id: singleAccount.id || 1,
|
id: singleAccount.id || 'account-1',
|
||||||
name: singleAccount.display_name || singleAccount.email,
|
name: singleAccount.display_name || singleAccount.email,
|
||||||
email: singleAccount.email,
|
email: singleAccount.email,
|
||||||
color: singleAccount.color || 'bg-blue-500',
|
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);
|
console.log(`[DEBUG] Using folders for fallback account ${data.email}:`, folderList);
|
||||||
|
|
||||||
updatedAccounts.push({
|
updatedAccounts.push({
|
||||||
id: 1,
|
id: 'default-account',
|
||||||
name: data.displayName || data.email,
|
name: data.displayName || data.email,
|
||||||
email: data.email,
|
email: data.email,
|
||||||
color: 'bg-blue-500',
|
color: 'bg-blue-500',
|
||||||
@ -654,7 +654,7 @@ export default function CourrierPage() {
|
|||||||
|
|
||||||
// Update accounts list
|
// Update accounts list
|
||||||
const newAccountObj = {
|
const newAccountObj = {
|
||||||
id: Date.now(), // temporary ID
|
id: `account-${Date.now()}`, // generate unique string ID
|
||||||
name: formValues.display_name,
|
name: formValues.display_name,
|
||||||
email: formValues.email,
|
email: formValues.email,
|
||||||
color: `bg-blue-500`, // Default color class
|
color: `bg-blue-500`, // Default color class
|
||||||
@ -800,7 +800,7 @@ export default function CourrierPage() {
|
|||||||
setSelectedAccount(account);
|
setSelectedAccount(account);
|
||||||
|
|
||||||
// Force the account to have folders if it doesn't already
|
// 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 = {
|
const accountWithFolders = {
|
||||||
...account,
|
...account,
|
||||||
folders: ['INBOX', 'Sent', 'Drafts', 'Trash', 'Junk']
|
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 */}
|
{/* Show folders for this account if it's selected and folders are shown */}
|
||||||
{((selectedAccount?.id === account.id && showFolders) ||
|
{((selectedAccount?.id === account.id && showFolders) ||
|
||||||
(!selectedAccount && account.id !== 0 && account.folders)) && (
|
(!selectedAccount && account.id !== 'all-accounts' && account.folders)) && (
|
||||||
<div className="pl-4 mt-1 mb-2 space-y-0.5 border-l border-gray-200 folder-container">
|
<div className="pl-4 mt-1 mb-2 space-y-0.5 border-l border-gray-200 folder-container">
|
||||||
{account.folders && account.folders.length > 0 ? (
|
{account.folders && account.folders.length > 0 ? (
|
||||||
account.folders.map((folder, folderIndex) => (
|
account.folders.map((folder, folderIndex) => (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user