From bfa8f036bd23290dad4c66316ee72c2200c40b15 Mon Sep 17 00:00:00 2001 From: Taesung Hwang Date: Fri, 26 Jan 2024 16:24:39 -0800 Subject: [PATCH] Hotfix: add hacker count to Admin Dashboard --- .../app/admin/dashboard/AdminDashboard.tsx | 2 ++ .../dashboard/components/HackerCount.tsx | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 apps/site/src/app/admin/dashboard/components/HackerCount.tsx diff --git a/apps/site/src/app/admin/dashboard/AdminDashboard.tsx b/apps/site/src/app/admin/dashboard/AdminDashboard.tsx index f673ce7c..22989bbb 100644 --- a/apps/site/src/app/admin/dashboard/AdminDashboard.tsx +++ b/apps/site/src/app/admin/dashboard/AdminDashboard.tsx @@ -10,6 +10,7 @@ import { isApplicationManager } from "@/lib/admin/authorization"; import UserContext from "@/lib/admin/UserContext"; import ApplicantSummary from "./components/ApplicantSummary"; +import HackerCount from "./components/HackerCount"; function AdminDashboard() { const { role } = useContext(UserContext); @@ -19,6 +20,7 @@ function AdminDashboard() { Admin Dashboard {isApplicationManager(role) && } + ); diff --git a/apps/site/src/app/admin/dashboard/components/HackerCount.tsx b/apps/site/src/app/admin/dashboard/components/HackerCount.tsx new file mode 100644 index 00000000..5189956d --- /dev/null +++ b/apps/site/src/app/admin/dashboard/components/HackerCount.tsx @@ -0,0 +1,33 @@ +import Container from "@cloudscape-design/components/container"; +import dayjs from "dayjs"; +import timezone from "dayjs/plugin/timezone"; +import utc from "dayjs/plugin/utc"; + +import useParticipants, { Role } from "@/lib/admin/useParticipants"; + +dayjs.extend(utc); +dayjs.extend(timezone); + +const EVENT_TIMEZONE = "America/Los_Angeles"; + +const FRIDAY = dayjs(new Date("2024-01-26T12:00:00")).tz(EVENT_TIMEZONE); + +function HackerCount() { + const { participants, loading } = useParticipants(); + + const checkedIn = participants + .filter((participant) => participant.role === Role.Applicant) + .filter((participant) => + participant.checkins.some(([datetime]) => + FRIDAY.isSame(dayjs(datetime).tz(EVENT_TIMEZONE), "date"), + ), + ); + + if (loading) { + return -; + } + + return HackerCount {checkedIn.length}; +} + +export default HackerCount;