vision refactor
This commit is contained in:
parent
73ebc523b7
commit
607f762a40
@ -136,9 +136,35 @@ export default function VisionPage() {
|
||||
entityId = matchingGroup?.id || "";
|
||||
} else if (isMission) {
|
||||
entityName = calendarName.replace("Mission: ", "");
|
||||
// Find matching mission by name
|
||||
const matchingMission = missions.find((m: Mission) => m.name === entityName);
|
||||
entityId = matchingMission?.id || calendar.missionId || "";
|
||||
// Use calendar.missionId first (most reliable), then try to find by name
|
||||
if (calendar.missionId) {
|
||||
entityId = calendar.missionId;
|
||||
// Verify the mission exists in our list
|
||||
const matchingMission = missions.find((m: Mission) => m.id === calendar.missionId);
|
||||
if (!matchingMission) {
|
||||
// If mission not found in our list, still use the missionId from calendar
|
||||
// This can happen if missions haven't loaded yet
|
||||
console.warn('[Vision] Mission from calendar.missionId not found in missions list:', {
|
||||
calendarMissionId: calendar.missionId,
|
||||
availableMissionIds: missions.map((m: Mission) => m.id)
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Fallback: find matching mission by name
|
||||
const matchingMission = missions.find((m: Mission) => m.name === entityName);
|
||||
entityId = matchingMission?.id || "";
|
||||
|
||||
// Debug log for mission calendar matching
|
||||
if (!entityId) {
|
||||
console.warn('[Vision] Mission entityId not found:', {
|
||||
calendarName,
|
||||
entityName,
|
||||
missionIds: missions.map((m: Mission) => m.id),
|
||||
missionNames: missions.map((m: Mission) => m.name),
|
||||
calendarMissionId: calendar.missionId
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Convert events to ScheduledMeeting format
|
||||
@ -304,7 +330,24 @@ export default function VisionPage() {
|
||||
fiveMinutesBeforeStart.setMinutes(fiveMinutesBeforeStart.getMinutes() - 5);
|
||||
|
||||
// Can join if now is between 5 minutes before start and end
|
||||
return now >= fiveMinutesBeforeStart && now <= end;
|
||||
const canJoin = now >= fiveMinutesBeforeStart && now <= end;
|
||||
|
||||
// Debug log
|
||||
if (meeting.date === formatDateLocal(now)) {
|
||||
console.log('[Vision] canJoinMeeting check:', {
|
||||
meetingId: meeting.id,
|
||||
title: meeting.title,
|
||||
now: now.toISOString(),
|
||||
start: start.toISOString(),
|
||||
end: end.toISOString(),
|
||||
fiveMinutesBeforeStart: fiveMinutesBeforeStart.toISOString(),
|
||||
canJoin,
|
||||
nowVsFiveMinBefore: now >= fiveMinutesBeforeStart,
|
||||
nowVsEnd: now <= end
|
||||
});
|
||||
}
|
||||
|
||||
return canJoin;
|
||||
};
|
||||
|
||||
// Check if there's an active meeting for a group or mission (5 minutes before start until end)
|
||||
@ -361,7 +404,28 @@ export default function VisionPage() {
|
||||
const getTodayMeetings = (): ScheduledMeeting[] => {
|
||||
const today = new Date();
|
||||
const todayStr = formatDateLocal(today);
|
||||
return scheduledMeetings.filter(meeting => meeting.date === todayStr);
|
||||
const todayMeetings = scheduledMeetings.filter(meeting => meeting.date === todayStr);
|
||||
|
||||
// Debug log
|
||||
console.log('[Vision] Today meetings:', {
|
||||
todayStr,
|
||||
totalMeetings: scheduledMeetings.length,
|
||||
todayMeetingsCount: todayMeetings.length,
|
||||
todayMeetings: todayMeetings.map(m => ({
|
||||
id: m.id,
|
||||
title: m.title,
|
||||
date: m.date,
|
||||
time: m.time,
|
||||
type: m.type,
|
||||
entityId: m.entityId,
|
||||
entityName: m.entityName,
|
||||
start: m.start,
|
||||
end: m.end,
|
||||
canJoin: canJoinMeeting(m)
|
||||
}))
|
||||
});
|
||||
|
||||
return todayMeetings;
|
||||
};
|
||||
|
||||
// Get meetings for a specific date
|
||||
@ -525,10 +589,28 @@ export default function VisionPage() {
|
||||
await Promise.all(eventPromises);
|
||||
|
||||
// Refresh meetings from database after creation
|
||||
const refreshCalendarsResponse = await fetch("/api/calendars");
|
||||
// Use refresh=true to bypass cache and ensure immediate update
|
||||
const refreshCalendarsResponse = await fetch("/api/calendars?refresh=true");
|
||||
if (refreshCalendarsResponse.ok) {
|
||||
const calendarsData = await refreshCalendarsResponse.json();
|
||||
const meetings = convertCalendarsToMeetings(calendarsData);
|
||||
|
||||
// Debug log
|
||||
console.log('[Vision] Refreshed meetings after creation:', {
|
||||
totalMeetings: meetings.length,
|
||||
meetings: meetings.map(m => ({
|
||||
id: m.id,
|
||||
title: m.title,
|
||||
date: m.date,
|
||||
time: m.time,
|
||||
type: m.type,
|
||||
entityId: m.entityId,
|
||||
entityName: m.entityName,
|
||||
start: m.start,
|
||||
end: m.end
|
||||
}))
|
||||
});
|
||||
|
||||
setScheduledMeetings(meetings);
|
||||
}
|
||||
setShowMeetingDialog(false);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user