@@ -11,6 +11,10 @@ import type { User } from "db/types";
1111import { auth } from "@clerk/nextjs/server" ;
1212import { notFound } from "next/navigation" ;
1313import { getAllUsers , getUser } from "db/functions" ;
14+ import Link from "next/link" ;
15+ import { getRequestContext } from "@cloudflare/next-on-pages" ;
16+ import { formatInTimeZone } from "date-fns-tz" ;
17+ import { getClientTimeZone } from "@/lib/utils/client/shared" ;
1418
1519export default async function Page ( ) {
1620 const { userId } = await auth ( ) ;
@@ -19,15 +23,24 @@ export default async function Page() {
1923 const adminUser = await getUser ( userId ) ;
2024 if (
2125 ! adminUser ||
22- ( adminUser . role !== "admin" && adminUser . role !== "super_admin" )
26+ ( adminUser . role !== "admin" &&
27+ adminUser . role !== "super_admin" &&
28+ adminUser . role !== "volunteer" )
2329 ) {
2430 return notFound ( ) ;
2531 }
2632
2733 const allUsers = ( await getAllUsers ( ) ) ?? [ ] ;
2834
29- const { rsvpCount, checkinCount, recentSignupCount } =
30- getRecentRegistrationData ( allUsers ) ;
35+ const {
36+ rsvpCount,
37+ checkinCount,
38+ recentSignupCount,
39+ recentRegisteredUsers,
40+ } = getRecentRegistrationData ( allUsers ) ;
41+ const { cf } = getRequestContext ( ) ;
42+
43+ const timezone = getClientTimeZone ( cf . timezone ) ;
3144
3245 return (
3346 < div className = "mx-auto h-16 w-full max-w-7xl pt-44" >
@@ -49,7 +62,6 @@ export default async function Page() {
4962 < div className = "text-2xl font-bold" >
5063 { allUsers . length }
5164 </ div >
52- { /* <p className="text-xs text-muted-foreground">+20.1% from last month</p> */ }
5365 </ CardContent >
5466 </ Card >
5567 < Card >
@@ -61,7 +73,6 @@ export default async function Page() {
6173 </ CardHeader >
6274 < CardContent >
6375 < div className = "text-2xl font-bold" > { 0 } </ div >
64- { /* <p className="text-xs text-muted-foreground">+20.1% from last month</p> */ }
6576 </ CardContent >
6677 </ Card >
6778 < Card >
@@ -73,7 +84,6 @@ export default async function Page() {
7384 </ CardHeader >
7485 < CardContent >
7586 < div className = "text-2xl font-bold" > { rsvpCount } </ div >
76- { /* <p className="text-xs text-muted-foreground">+20.1% from last month</p> */ }
7787 </ CardContent >
7888 </ Card >
7989 < Card >
@@ -85,7 +95,6 @@ export default async function Page() {
8595 </ CardHeader >
8696 < CardContent >
8797 < div className = "text-2xl font-bold" > { checkinCount } </ div >
88- { /* <p className="text-xs text-muted-foreground">+20.1% from last month</p> */ }
8998 </ CardContent >
9099 </ Card >
91100 </ div >
@@ -105,7 +114,6 @@ export default async function Page() {
105114 days.
106115 </ CardDescription >
107116 </ div >
108-
109117 < User2 />
110118 </ CardHeader >
111119 < CardContent >
@@ -119,10 +127,32 @@ export default async function Page() {
119127 Recent Registrations
120128 </ CardTitle > { " " }
121129 </ div >
122-
123130 < TimerReset />
124131 </ CardHeader >
125- < CardContent > </ CardContent >
132+ < CardContent >
133+ < div className = "flex flex-col space-y-2" >
134+ { recentRegisteredUsers . map ( ( user ) => (
135+ < div
136+ key = { user . clerkID }
137+ className = "flex items-center justify-between"
138+ >
139+ < Link
140+ href = { `/admin/users/${ user . clerkID } ` }
141+ className = "hover:underline"
142+ >
143+ { user . firstName } { user . lastName }
144+ </ Link >
145+ < span className = "text-sm text-gray-500" >
146+ { formatInTimeZone (
147+ user . signupTime ,
148+ timezone ,
149+ "MMMM dd h:mm a" ,
150+ ) }
151+ </ span >
152+ </ div >
153+ ) ) }
154+ </ div >
155+ </ CardContent >
126156 </ Card >
127157 </ div >
128158 </ div >
@@ -134,6 +164,9 @@ function getRecentRegistrationData(users: User[]) {
134164
135165 let rsvpCount = 0 ;
136166 let checkinCount = 0 ;
167+
168+ const recentRegisteredUsers : User [ ] = [ ] ;
169+ let recentRegisteredUsersCount = 0 ;
137170 let recentSignupCount : DateNumberMap = { } ;
138171
139172 for ( let i = 0 ; i < 7 ; i ++ ) {
@@ -154,10 +187,21 @@ function getRecentRegistrationData(users: User[]) {
154187
155188 const stamp = user . signupTime . toISOString ( ) . split ( "T" ) [ 0 ] ;
156189
157- if ( recentSignupCount [ stamp ] != undefined ) recentSignupCount [ stamp ] ++ ;
190+ if ( recentSignupCount [ stamp ] != undefined ) {
191+ if ( recentRegisteredUsersCount < 10 ) {
192+ recentRegisteredUsers . push ( user ) ;
193+ recentRegisteredUsersCount ++ ;
194+ }
195+ recentSignupCount [ stamp ] ++ ;
196+ }
158197 }
159198
160- return { rsvpCount, checkinCount, recentSignupCount } ;
199+ return {
200+ rsvpCount,
201+ checkinCount,
202+ recentSignupCount,
203+ recentRegisteredUsers,
204+ } ;
161205}
162206
163207export const runtime = "edge" ;
0 commit comments