-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpage.tsx
More file actions
66 lines (60 loc) · 1.82 KB
/
Copy pathpage.tsx
File metadata and controls
66 lines (60 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { notFound, redirect } from "next/navigation";
import { Meetings } from "@/components/summary/meetings";
import { getCurrentSession } from "@/lib/auth";
import { buildScheduledLabel } from "@/lib/meetings/utils";
import {
getMeetings,
getResponderCountsByMeetingIds,
getScheduledMeetingsByMeetingIds,
} from "@/server/data/meeting/queries";
export default async function Page() {
const session = await getCurrentSession();
if (!session?.user) {
redirect("/auth/login/google");
}
const memberId = session.user.memberId;
if (!memberId) {
notFound();
}
const meetings = await getMeetings(memberId);
const meetingIds = meetings.map((m) => m.id);
const [meetingCounts, scheduledMeetingMap] = await Promise.all([
getResponderCountsByMeetingIds(meetingIds),
getScheduledMeetingsByMeetingIds(
meetings.filter((m) => m.scheduled).map((m) => m.id),
),
]);
const scheduledLabels: Record<string, string> = {};
const scheduledDates: Record<string, number> = {};
for (const [id, sm] of Object.entries(scheduledMeetingMap)) {
scheduledLabels[id] = buildScheduledLabel(
sm.scheduledDate,
sm.scheduledFromTime,
sm.scheduledToTime,
);
scheduledDates[id] = sm.scheduledDate.getTime();
}
const startOfToday = new Date();
startOfToday.setUTCHours(0, 0, 0, 0);
const threeDaysLater = new Date(
startOfToday.getTime() + 3 * 24 * 60 * 60 * 1000,
);
const upcomingMeetingIds = Object.entries(scheduledMeetingMap)
.filter(
([, sm]) =>
sm.scheduledDate >= startOfToday && sm.scheduledDate <= threeDaysLater,
)
.map(([id]) => id);
return (
<div className="px-4 py-8 sm:px-8">
<Meetings
meetings={meetings}
userId={memberId}
meetingCounts={meetingCounts}
scheduledLabels={scheduledLabels}
scheduledDates={scheduledDates}
upcomingMeetingIds={upcomingMeetingIds}
/>
</div>
);
}