Agenda refactor
This commit is contained in:
parent
0a16f15aa8
commit
ecb7cd31ad
@ -175,9 +175,8 @@ function CalendarDialog({ open, onClose, onSave, onDelete, onSyncSetup, initialD
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
if (data.success && data.accounts) {
|
||||
// Filter Infomaniak and Microsoft accounts
|
||||
// Filter Microsoft accounts only
|
||||
const syncableAccounts = data.accounts.filter((acc: any) =>
|
||||
(acc.host && acc.host.includes('infomaniak')) ||
|
||||
(acc.host && acc.host.includes('outlook.office365.com') && acc.use_oauth)
|
||||
);
|
||||
setAvailableAccounts(syncableAccounts.map((acc: any) => ({
|
||||
@ -198,13 +197,8 @@ function CalendarDialog({ open, onClose, onSave, onDelete, onSyncSetup, initialD
|
||||
|
||||
setIsDiscovering(true);
|
||||
try {
|
||||
// Determine which endpoint to use based on account type
|
||||
const selectedAccount = availableAccounts.find(acc => acc.id === selectedAccountId);
|
||||
const isMicrosoft = selectedAccount?.host?.includes('outlook.office365.com');
|
||||
|
||||
const endpoint = isMicrosoft
|
||||
? "/api/calendars/sync/discover-microsoft"
|
||||
: "/api/calendars/sync/discover";
|
||||
// Use Microsoft endpoint only
|
||||
const endpoint = "/api/calendars/sync/discover-microsoft";
|
||||
|
||||
const response = await fetch(endpoint, {
|
||||
method: "POST",
|
||||
@ -214,11 +208,11 @@ function CalendarDialog({ open, onClose, onSave, onDelete, onSyncSetup, initialD
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
// Normalize calendar format (Infomaniak uses 'url', Microsoft uses 'id' and 'webLink')
|
||||
// Normalize calendar format (Microsoft uses 'id' and 'webLink')
|
||||
const normalizedCalendars = (data.calendars || []).map((cal: any) => ({
|
||||
id: cal.id,
|
||||
name: cal.name,
|
||||
url: cal.url || cal.webLink || cal.id, // Use url, webLink, or id as fallback
|
||||
url: cal.webLink || cal.id, // Use webLink or id as fallback
|
||||
}));
|
||||
setAvailableCalendars(normalizedCalendars);
|
||||
} else {
|
||||
@ -238,15 +232,12 @@ function CalendarDialog({ open, onClose, onSave, onDelete, onSyncSetup, initialD
|
||||
|
||||
setIsSettingUpSync(true);
|
||||
try {
|
||||
// Determine provider based on selected account
|
||||
// All accounts are Microsoft
|
||||
const selectedAccount = availableAccounts.find(acc => acc.id === selectedAccountId);
|
||||
const isMicrosoft = selectedAccount?.host?.includes('outlook.office365.com');
|
||||
const provider = isMicrosoft ? 'microsoft' : 'infomaniak';
|
||||
const provider = 'microsoft';
|
||||
|
||||
// For Microsoft, use calendar ID instead of URL
|
||||
const externalCalendarId = isMicrosoft
|
||||
? availableCalendars.find(cal => cal.url === selectedCalendarUrl)?.id || selectedCalendarUrl
|
||||
: null;
|
||||
const externalCalendarId = availableCalendars.find(cal => cal.url === selectedCalendarUrl)?.id || selectedCalendarUrl;
|
||||
|
||||
await onSyncSetup(initialData.id, selectedAccountId, selectedCalendarUrl, externalCalendarId, provider);
|
||||
setShowSyncSection(false);
|
||||
@ -450,7 +441,7 @@ function CalendarDialog({ open, onClose, onSave, onDelete, onSyncSetup, initialD
|
||||
{showSyncSection && (
|
||||
<div className="space-y-3 p-3 bg-gray-50 rounded-lg">
|
||||
<div className="space-y-2">
|
||||
<Label className="text-sm text-gray-700">Compte email (Infomaniak)</Label>
|
||||
<Label className="text-sm text-gray-700">Compte email (Microsoft)</Label>
|
||||
<select
|
||||
value={selectedAccountId}
|
||||
onChange={(e) => {
|
||||
@ -1609,7 +1600,7 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
|
||||
mailCredentialId,
|
||||
externalCalendarUrl,
|
||||
externalCalendarId,
|
||||
provider: provider || "infomaniak",
|
||||
provider: provider || "microsoft",
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user