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