vision refactor

This commit is contained in:
alma 2026-01-15 20:11:50 +01:00
parent 53c5b0e8a9
commit 5f953f9ff8

View File

@ -37,6 +37,17 @@ interface Mission {
id: string; id: string;
name: string; name: string;
logoUrl?: string | null; logoUrl?: string | null;
creator?: {
id: string;
};
creatorId?: string;
missionUsers?: Array<{
userId: string;
role: string;
user?: {
id: string;
};
}>;
} }
interface ScheduledMeeting { 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 // Helper function to format date as YYYY-MM-DD in local timezone
const formatDateLocal = (date: Date): string => { const formatDateLocal = (date: Date): string => {
const year = date.getFullYear(); const year = date.getFullYear();
@ -988,6 +1018,7 @@ export default function VisionPage() {
Réunion Réunion
</Button> </Button>
)} )}
{canPlanMeetingForMission(mission) && (
<Button <Button
variant="outline" variant="outline"
size="sm" size="sm"
@ -1001,6 +1032,7 @@ export default function VisionPage() {
> >
<Calendar className="h-4 w-4" /> <Calendar className="h-4 w-4" />
</Button> </Button>
)}
</div> </div>
</div> </div>
</div> </div>