diff --git a/app/vision/page.tsx b/app/vision/page.tsx index 5aede7d..7791356 100644 --- a/app/vision/page.tsx +++ b/app/vision/page.tsx @@ -37,6 +37,17 @@ interface Mission { id: string; name: string; logoUrl?: string | null; + creator?: { + id: string; + }; + creatorId?: string; + missionUsers?: Array<{ + userId: string; + role: string; + user?: { + id: string; + }; + }>; } interface ScheduledMeeting { @@ -319,6 +330,25 @@ export default function VisionPage() { }); }; + // Check if user can plan a meeting for a mission + const canPlanMeetingForMission = (mission: Mission): boolean => { + if (!session?.user?.id) return false; + const userId = session.user.id; + + // Check if user is the creator + if (mission.creatorId === userId || mission.creator?.id === userId) { + return true; + } + + // Check if user has one of the guardian roles + const guardianRoles = ['gardien-temps', 'gardien-parole', 'gardien-memoire']; + const hasGuardianRole = mission.missionUsers?.some( + (mu) => (mu.userId === userId || mu.user?.id === userId) && guardianRoles.includes(mu.role) + ); + + return !!hasGuardianRole; + }; + // Helper function to format date as YYYY-MM-DD in local timezone const formatDateLocal = (date: Date): string => { const year = date.getFullYear(); @@ -988,19 +1018,21 @@ export default function VisionPage() { Réunion )} - + {canPlanMeetingForMission(mission) && ( + + )}