From 65d75a02133e7c6508fe87020efd712f9b84bcbf Mon Sep 17 00:00:00 2001 From: alma Date: Sun, 27 Apr 2025 18:39:33 +0200 Subject: [PATCH] courrier multi account --- app/courrier/page.tsx | 358 ++++++++---------------------------------- 1 file changed, 63 insertions(+), 295 deletions(-) diff --git a/app/courrier/page.tsx b/app/courrier/page.tsx index 7f8ab11d..6e9bd4db 100644 --- a/app/courrier/page.tsx +++ b/app/courrier/page.tsx @@ -615,9 +615,8 @@ export default function CourrierPage() {
- {/* Sidebar */} -
+ {/* Sidebar - Force display without conditions */} +
{/* Courrier Title */}
@@ -645,10 +644,6 @@ export default function CourrierPage() { setLoading(true); // Reset to page 1 when manually refreshing setPage(1); - // Trigger a scroll reset - if (typeof window !== 'undefined') { - window.dispatchEvent(new CustomEvent('reset-email-scroll')); - } // Load emails loadEmails().finally(() => setLoading(false)); }} @@ -658,7 +653,7 @@ export default function CourrierPage() {
{/* Scrollable area for accounts and folders */} - +
{/* Accounts Section */}
@@ -687,305 +682,78 @@ export default function CourrierPage() { ShowFolders: {String(showFolders)}
- {/* Form for adding a new account */} - {showAddAccountForm && ( -
-

Add IMAP Account

-
{ - e.preventDefault(); - setLoading(true); - - const formData = new FormData(e.currentTarget); - - // Pull values from form with proper type handling - const formValues = { - email: formData.get('email')?.toString() || '', - password: formData.get('password')?.toString() || '', - host: formData.get('host')?.toString() || '', - port: parseInt(formData.get('port')?.toString() || '993'), - secure: formData.get('secure') === 'on', - display_name: formData.get('display_name')?.toString() || '', - smtp_host: formData.get('smtp_host')?.toString() || '', - smtp_port: formData.get('smtp_port')?.toString() ? - parseInt(formData.get('smtp_port')?.toString() || '587') : undefined, - smtp_secure: formData.get('smtp_secure') === 'on' - }; - - // If display_name is empty, use email - if (!formValues.display_name) { - formValues.display_name = formValues.email; - } - - try { - // First test the connection - const testResponse = await fetch('/api/courrier/test-connection', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - email: formValues.email, - password: formValues.password, - host: formValues.host, - port: formValues.port, - secure: formValues.secure - }) - }); - - const testResult = await testResponse.json(); - - if (!testResponse.ok) { - throw new Error(testResult.error || 'Connection test failed'); - } - - console.log('Connection test successful:', testResult); - - // If connection test is successful, save the account - const saveResponse = await fetch('/api/courrier/account', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify(formValues) - }); - - const saveResult = await saveResponse.json(); - - if (!saveResponse.ok) { - throw new Error(saveResult.error || 'Failed to add account'); - } - - // Update accounts list - const newAccountObj = { - id: `account-${Date.now()}`, // generate unique string ID - name: formValues.display_name, - email: formValues.email, - color: `bg-blue-500`, // Default color class - folders: testResult.details.sampleFolders || ['INBOX', 'Sent', 'Drafts', 'Trash'] // Use discovered folders or defaults - }; - - setAccounts(prev => [...prev, newAccountObj]); - setShowAddAccountForm(false); - toast({ - title: "Account added successfully", - description: `Your email account ${formValues.email} has been added.`, - duration: 5000 - }); - } catch (error) { - console.error('Error adding account:', error); - toast({ - title: "Failed to add account", - description: error instanceof Error ? error.message : 'Unknown error', - variant: "destructive", - duration: 5000 - }); - } finally { - setLoading(false); - } - }}> -
- - - IMAP Settings - SMTP Settings - - - -
- - -
-
- - -
-
- - -
-
- - -
-
-
- - -
-
-
- - -
-
-
-
- - -
- - -
-
-
- - -
-
-
- - -
-
-
-
- Note: SMTP settings are only needed for sending emails -
-
-
- -
- - -
-
-
-
- )} - - {/* Accounts List */} - {accountsDropdownOpen && ( -
- {accounts.map((account) => ( - - ))} -
- )} -
- - {/* Folders Section - conditionally show folders when an account is selected */} - {showFolders && selectedAccount && selectedAccount.folders && ( -
-
- -
- - {/* Debug info */} -
- Selected: {selectedAccount.id || 'none'}
- Has Folders: {String(!!selectedAccount.folders)}
- Folder Count: {selectedAccount.folders.length || 0} -
- - {selectedAccount.folders.map((folder) => ( + {/* Display all accounts */} +
+ {accounts.map((account) => ( ))}
- )} +
- {/* Fallback for no folders or account */} - {(!selectedAccount || !selectedAccount.folders || selectedAccount.folders.length === 0) && ( -
+ {/* Folders Section - Always Display */} +
+
+ +
+ + {/* Debug info */} +
+ Selected: {selectedAccount?.id || 'none'}
+ Has Folders: {String(!!selectedAccount?.folders)}
+ Folder Count: {selectedAccount?.folders?.length || 0} +
+ + {/* Display folders if available */} + {selectedAccount?.folders?.map((folder) => ( + + ))} + + {/* Fallback if no folders */} + {(!selectedAccount?.folders || selectedAccount.folders.length === 0) && (
No folders available for this account.
-
- )} - + )} +
+
{/* Main Content Area - conditionally show email list or detail view */}