courrier multi account restore compose
This commit is contained in:
parent
337afd405e
commit
6c39027229
@ -850,17 +850,23 @@ export default function CourrierPage() {
|
|||||||
|
|
||||||
console.log('Connection test successful:', testResult);
|
console.log('Connection test successful:', testResult);
|
||||||
|
|
||||||
// If connection test is successful, save the account
|
// Only declare realAccounts once before using for color assignment
|
||||||
const realAccounts = accounts.filter(a => a.id !== 'loading-account');
|
const realAccounts = accounts.filter(a => a.id !== 'loading-account');
|
||||||
const newAccountObj = {
|
const saveResponse = await fetch('/api/courrier/account', {
|
||||||
id: `account-${Date.now()}`,
|
method: 'POST',
|
||||||
name: formValues.display_name,
|
headers: {
|
||||||
email: formValues.email,
|
'Content-Type': 'application/json'
|
||||||
color: colorPalette[realAccounts.length % colorPalette.length],
|
},
|
||||||
folders: testResult.details.sampleFolders || ['INBOX', 'Sent', 'Drafts', 'Trash']
|
body: JSON.stringify(formValues)
|
||||||
};
|
});
|
||||||
|
const saveResult = await saveResponse.json();
|
||||||
setAccounts(prev => [...prev, newAccountObj]);
|
if (!saveResponse.ok) {
|
||||||
|
throw new Error(saveResult.error || 'Failed to add account');
|
||||||
|
}
|
||||||
|
const realAccount = saveResult.account;
|
||||||
|
realAccount.color = colorPalette[realAccounts.length % colorPalette.length];
|
||||||
|
realAccount.folders = testResult.details.sampleFolders || ['INBOX', 'Sent', 'Drafts', 'Trash'];
|
||||||
|
setAccounts(prev => [...prev, realAccount]);
|
||||||
setShowAddAccountForm(false);
|
setShowAddAccountForm(false);
|
||||||
toast({
|
toast({
|
||||||
title: "Account added successfully",
|
title: "Account added successfully",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user