courrier multi account restore compose
This commit is contained in:
parent
686ea6cb53
commit
8b1a160c21
@ -610,10 +610,10 @@ export default function CourrierPage() {
|
||||
// Update handleMailboxChange to ensure consistent folder naming and prevent race conditions
|
||||
const handleMailboxChange = (folder: string, accountId?: string) => {
|
||||
// Enhanced logging to trace the flow
|
||||
logEmailOp('MAILBOX-CHANGE-V2', `Starting mailbox change to folder=${folder}, accountId=${accountId || 'undefined'}`);
|
||||
logEmailOp('MAILBOX-CHANGE-V3', `Starting mailbox change to folder=${folder}, accountId=${accountId || 'undefined'}`);
|
||||
|
||||
if (!accountId || accountId === 'loading-account') {
|
||||
logEmailOp('MAILBOX-CHANGE-V2', 'No valid accountId provided, using default flow', { folder });
|
||||
logEmailOp('MAILBOX-CHANGE-V3', 'No valid accountId provided, using default flow', { folder });
|
||||
changeFolder(folder);
|
||||
return;
|
||||
}
|
||||
@ -626,7 +626,7 @@ export default function CourrierPage() {
|
||||
|
||||
const account = accounts.find(a => a.id.toString() === accountId.toString());
|
||||
if (!account) {
|
||||
logEmailOp('MAILBOX-CHANGE-V2', `ERROR: Account not found: ${accountId}`);
|
||||
logEmailOp('MAILBOX-CHANGE-V3', `ERROR: Account not found: ${accountId}`);
|
||||
toast({
|
||||
title: "Account not found",
|
||||
description: `The account ${accountId} could not be found.`,
|
||||
@ -636,7 +636,7 @@ export default function CourrierPage() {
|
||||
return;
|
||||
}
|
||||
|
||||
logEmailOp('MAILBOX-CHANGE-V2', `Found account: ${account.email}`, {
|
||||
logEmailOp('MAILBOX-CHANGE-V3', `Found account: ${account.email}`, {
|
||||
folderCount: account.folders?.length || 0,
|
||||
folder: folder
|
||||
});
|
||||
@ -650,12 +650,12 @@ export default function CourrierPage() {
|
||||
folderAccountId = parts[0];
|
||||
baseFolder = parts[1];
|
||||
|
||||
logEmailOp('MAILBOX-CHANGE-V2', `Parsed folder: accountId=${folderAccountId}, baseFolder=${baseFolder}`);
|
||||
logEmailOp('MAILBOX-CHANGE-V3', `Parsed folder: accountId=${folderAccountId}, baseFolder=${baseFolder}`);
|
||||
|
||||
// CRITICAL FIX: If the folder has an account prefix that doesn't match the requested account,
|
||||
// log a warning and ALWAYS use the requested accountId
|
||||
if (folderAccountId !== accountId.toString()) {
|
||||
logEmailOp('MAILBOX-CHANGE-V2', `WARNING: Folder prefix mismatch - FIXING`, {
|
||||
logEmailOp('MAILBOX-CHANGE-V3', `WARNING: Folder prefix mismatch - FIXING`, {
|
||||
folderAccount: folderAccountId,
|
||||
requestedAccount: accountId,
|
||||
originalFolder: folder,
|
||||
@ -668,11 +668,11 @@ export default function CourrierPage() {
|
||||
|
||||
// ALWAYS create a consistent folder name with REQUESTED account prefix
|
||||
const prefixedFolder = `${accountId}:${baseFolder}`;
|
||||
logEmailOp('MAILBOX-CHANGE-V2', `Normalized folder name: ${prefixedFolder}`);
|
||||
logEmailOp('MAILBOX-CHANGE-V3', `Normalized folder name: ${prefixedFolder}`);
|
||||
|
||||
// Check if we're already on this folder to avoid unnecessary refreshes
|
||||
if (currentFolder === prefixedFolder) {
|
||||
logEmailOp('MAILBOX-CHANGE-V2', `Already on folder ${prefixedFolder}, skipping change`);
|
||||
logEmailOp('MAILBOX-CHANGE-V3', `Already on folder ${prefixedFolder}, skipping change`);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
@ -684,17 +684,25 @@ export default function CourrierPage() {
|
||||
...prev,
|
||||
[accountId]: prefixedFolder
|
||||
};
|
||||
logEmailOp('MAILBOX-CHANGE-V2', `Updated selected folders map`, updated);
|
||||
logEmailOp('MAILBOX-CHANGE-V3', `Updated selected folders map`, updated);
|
||||
return updated;
|
||||
});
|
||||
|
||||
// EXTRA SAFETY: Log exactly what we're passing to changeFolder
|
||||
logEmailOp('MAILBOX-CHANGE-V3', `CALLING changeFolder with EXACT PARAMS:`, {
|
||||
folder: prefixedFolder,
|
||||
accountId: accountId,
|
||||
folderType: typeof prefixedFolder,
|
||||
accountIdType: typeof accountId
|
||||
});
|
||||
|
||||
// Now use the changeFolder function from the hook with our properly formatted folder name
|
||||
changeFolder(prefixedFolder, accountId)
|
||||
.then(() => {
|
||||
logEmailOp('MAILBOX-CHANGE-V2', `Successfully changed to folder ${prefixedFolder}`);
|
||||
logEmailOp('MAILBOX-CHANGE-V3', `Successfully changed to folder ${prefixedFolder}`);
|
||||
})
|
||||
.catch(error => {
|
||||
logEmailOp('MAILBOX-CHANGE-V2', `ERROR: Failed to change to folder ${prefixedFolder}`, { error });
|
||||
logEmailOp('MAILBOX-CHANGE-V3', `ERROR: Failed to change to folder ${prefixedFolder}`, { error });
|
||||
toast({
|
||||
title: "Error changing folders",
|
||||
description: `Failed to change to folder ${baseFolder}. ${error instanceof Error ? error.message : String(error)}`,
|
||||
|
||||
@ -109,13 +109,17 @@ export const useCourrier = () => {
|
||||
|
||||
// Try to get cached emails first
|
||||
const currentRequestPage = page;
|
||||
|
||||
// CRITICAL FIX: Use the correct parameter order
|
||||
// Signature is: (userId: string, folder: string, page: number, perPage: number, timeoutMs: number = 100, accountId?: string)
|
||||
console.log(`Getting cached emails for ${currentFolder} with accountId ${accountId || 'default'}`);
|
||||
const cachedEmails = await getCachedEmailsWithTimeout(
|
||||
session.user.id,
|
||||
accountId || 'default',
|
||||
currentFolder,
|
||||
currentRequestPage,
|
||||
perPage,
|
||||
accountId && accountId !== 'all-accounts' && accountId !== 'loading-account' ? accountId : undefined
|
||||
session.user.id, // userId: string
|
||||
currentFolder, // folder: string
|
||||
currentRequestPage, // page: number
|
||||
perPage, // perPage: number
|
||||
100, // timeoutMs: number
|
||||
accountId // accountId?: string
|
||||
);
|
||||
|
||||
if (cachedEmails) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user