vision refactor
This commit is contained in:
parent
53c5b0e8a9
commit
5f953f9ff8
@ -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
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="flex items-center gap-2"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setSelectedDate(new Date());
|
||||
handleOpenMeetingDialog("mission", mission.id, mission.name);
|
||||
}}
|
||||
title="Planifier une réunion"
|
||||
>
|
||||
<Calendar className="h-4 w-4" />
|
||||
</Button>
|
||||
{canPlanMeetingForMission(mission) && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="flex items-center gap-2"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setSelectedDate(new Date());
|
||||
handleOpenMeetingDialog("mission", mission.id, mission.name);
|
||||
}}
|
||||
title="Planifier une réunion"
|
||||
>
|
||||
<Calendar className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user