diff --git a/app/vision/page.tsx b/app/vision/page.tsx index b8ec6dc..56e46f4 100644 --- a/app/vision/page.tsx +++ b/app/vision/page.tsx @@ -50,6 +50,7 @@ interface ScheduledMeeting { start: string; // ISO datetime string for start end: string; // ISO datetime string for end isAllDay?: boolean; + location?: string; // Jitsi URL for Vision meetings } type ConferenceType = "group" | "mission" | null; @@ -81,6 +82,7 @@ export default function VisionPage() { location: string; description: string; recurrence: "none" | "daily" | "weekly" | "monthly"; + isVideoConference: boolean; }>({ type: "", entityId: "", @@ -92,6 +94,7 @@ export default function VisionPage() { location: "", description: "", recurrence: "none", + isVideoConference: false, }); // Redirect if not authenticated @@ -149,6 +152,7 @@ export default function VisionPage() { start: event.start, end: event.end, isAllDay: event.isAllDay || false, + location: event.location || undefined, // Include Jitsi URL if available }); }); }); @@ -243,18 +247,29 @@ export default function VisionPage() { fetchData(); }, [session, status, toast]); - // Handle conference selection - const handleConferenceClick = (type: ConferenceType, id: string, name: string) => { + // Generate Jitsi URL (shared function used by both handleConferenceClick and form) + const generateJitsiUrl = (type: "group" | "mission", id: string): string => { const baseUrl = process.env.NEXT_PUBLIC_IFRAME_CONFERENCE_URL || 'https://vision.slm-lab.net'; - - let url: string; if (type === "group") { // URL format: https://vision.slm-lab.net/Groupe-{groupId} - url = `${baseUrl}/Groupe-${id}`; + return `${baseUrl}/Groupe-${id}`; } else { // URL format: https://vision.slm-lab.net/{missionId} - url = `${baseUrl}/${id}`; + return `${baseUrl}/${id}`; } + }; + + // Handle conference selection + const handleConferenceClick = (type: ConferenceType, id: string, name: string, jitsiUrl?: string) => { + // If Jitsi URL is provided (from meeting location), use it directly + if (jitsiUrl) { + setSelectedConference({ type, id, name }); + setJitsiUrl(jitsiUrl); + return; + } + + // Otherwise, generate URL from type and id using shared function + const url = generateJitsiUrl(type, id); setSelectedConference({ type, id, name }); setJitsiUrl(url); @@ -322,10 +337,17 @@ export default function VisionPage() { location: "", description: "", recurrence: "none", + isVideoConference: false, }); setShowMeetingDialog(true); }; + // Generate Jitsi URL based on meeting form (uses shared function) + const getJitsiUrl = (): string => { + if (!meetingForm.type || !meetingForm.entityId) return ""; + return generateJitsiUrl(meetingForm.type, meetingForm.entityId); + }; + // Handle save meeting const handleSaveMeeting = async () => { if (!meetingForm.type || !meetingForm.entityId || !meetingForm.start || !meetingForm.end) { @@ -411,6 +433,9 @@ export default function VisionPage() { } } + // Determine location: use Jitsi URL if video conference is enabled, otherwise use manual location + const locationToSave = meetingForm.isVideoConference ? getJitsiUrl() : (meetingForm.location || null); + // Create all events via API const eventPromises = eventsToCreate.map(async ({ start, end }) => { const response = await fetch("/api/events", { @@ -424,7 +449,7 @@ export default function VisionPage() { start: start.toISOString(), end: end.toISOString(), allDay: meetingForm.allDay, - location: meetingForm.location || null, + location: locationToSave, calendarId: targetCalendar.id, }), }); @@ -458,6 +483,7 @@ export default function VisionPage() { location: "", description: "", recurrence: "none", + isVideoConference: false, }); toast({ title: "Succès", @@ -611,7 +637,7 @@ export default function VisionPage() {