-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement interim subevent check-in system (#377)
* Temp: progress on subevent check-in * Finish interim subevent check-in system * fix: export Role --------- Co-authored-by: Sam Der <[email protected]>
- Loading branch information
1 parent
f4407d3
commit 2263491
Showing
10 changed files
with
196 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"use client"; | ||
|
||
import { useState } from "react"; | ||
|
||
import ContentLayout from "@cloudscape-design/components/content-layout"; | ||
import Select, { SelectProps } from "@cloudscape-design/components/select"; | ||
|
||
import useEvents from "@/lib/admin/useEvents"; | ||
import useParticipants, { Participant } from "@/lib/admin/useParticipants"; | ||
|
||
import SubeventCheckin from "./components/SubeventCheckin"; | ||
|
||
function Events() { | ||
const [event, setEvent] = useState<SelectProps.Option | null>(null); | ||
|
||
const { | ||
events, | ||
loading: loadingEvents, | ||
checkInParticipantSubevent, | ||
} = useEvents(); | ||
const { participants, loading: loadingParticipants } = useParticipants(); | ||
|
||
const options = events.map(({ name, _id }) => ({ label: name, value: _id })); | ||
|
||
const onConfirm = async (participant: Participant): Promise<boolean> => { | ||
if (event !== null && event.value !== undefined) { | ||
return await checkInParticipantSubevent(event.value, participant._id); | ||
} | ||
return false; | ||
}; | ||
|
||
return ( | ||
<ContentLayout> | ||
<Select | ||
selectedOption={event} | ||
onChange={({ detail }) => setEvent(detail.selectedOption)} | ||
options={options} | ||
statusType={loadingEvents ? "loading" : undefined} | ||
/> | ||
{event && !loadingParticipants && ( | ||
<SubeventCheckin participants={participants} onConfirm={onConfirm} /> | ||
)} | ||
</ContentLayout> | ||
); | ||
} | ||
|
||
export default Events; |
80 changes: 80 additions & 0 deletions
80
apps/site/src/app/admin/events/components/SubeventCheckin.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React, { useCallback, useMemo, useState } from "react"; | ||
|
||
import Button from "@cloudscape-design/components/button"; | ||
import Container from "@cloudscape-design/components/container"; | ||
import Input from "@cloudscape-design/components/input"; | ||
import SpaceBetween from "@cloudscape-design/components/space-between"; | ||
|
||
import BadgeScanner from "@/lib/admin/BadgeScanner"; | ||
import { Participant } from "@/lib/admin/useParticipants"; | ||
|
||
interface SubeventCheckinProps { | ||
participants: Participant[]; | ||
onConfirm: (participant: Participant) => Promise<boolean>; | ||
} | ||
|
||
function SubeventCheckin({ participants, onConfirm }: SubeventCheckinProps) { | ||
const [badgeNumber, setBadgeNumber] = useState(""); | ||
const [showScanner, setShowScanner] = useState(true); | ||
const [error, setError] = useState(""); | ||
|
||
const onScanSuccess = useCallback((decodedText: string) => { | ||
console.log("Scanner found"); | ||
setBadgeNumber(decodedText); | ||
setShowScanner(false); | ||
}, []); | ||
|
||
const participant = participants.filter( | ||
(participant) => participant.badge_number === badgeNumber, | ||
)[0]; | ||
const notFoundMessage = ( | ||
<p> | ||
Participant could not be found, please note down the name of the | ||
participant manually | ||
</p> | ||
); | ||
|
||
const badgeScanner = useMemo( | ||
() => <BadgeScanner onSuccess={onScanSuccess} onError={() => null} />, | ||
[onScanSuccess], | ||
); | ||
|
||
const handleConfirm = async () => { | ||
const okay = await onConfirm(participant); | ||
if (okay) { | ||
console.log("clearing badge number"); | ||
setBadgeNumber(""); | ||
setError(""); | ||
} else { | ||
setError("checkin failed"); | ||
} | ||
}; | ||
|
||
return ( | ||
<Container> | ||
<SpaceBetween direction="horizontal" size="xs"> | ||
<Input | ||
onChange={({ detail }) => setBadgeNumber(detail.value)} | ||
value={badgeNumber} | ||
/> | ||
<Button | ||
iconName="video-on" | ||
variant="icon" | ||
onClick={() => setShowScanner(true)} | ||
iconAlt="Scan with camera" | ||
/> | ||
</SpaceBetween> | ||
{showScanner && badgeScanner} | ||
{badgeNumber !== "" && !participant && notFoundMessage} | ||
{participant && ( | ||
<p> | ||
Participant: {`${participant.first_name} ${participant.last_name}`} | ||
</p> | ||
)} | ||
{error} | ||
<Button onClick={handleConfirm}>Confirm</Button> | ||
</Container> | ||
); | ||
} | ||
|
||
export default SubeventCheckin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as default } from "./Events"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import axios from "axios"; | ||
import useSWR from "swr"; | ||
|
||
export interface Event { | ||
name: string; | ||
_id: string; | ||
} | ||
|
||
const fetcher = async (url: string) => { | ||
const res = await axios.get<Event[]>(url); | ||
return res.data; | ||
}; | ||
|
||
function useEvents() { | ||
const { data, error, isLoading } = useSWR<Event[]>( | ||
"/api/admin/events", | ||
fetcher, | ||
); | ||
|
||
const checkInParticipantSubevent = async ( | ||
event: string, | ||
uid: string, | ||
): Promise<boolean> => { | ||
const res = await axios.post(`/api/admin/event-checkin/${event}`, uid); | ||
console.log(`Checked in ${uid} for ${event}`); | ||
return res.status === 200; | ||
}; | ||
|
||
return { | ||
events: data || [], | ||
loading: isLoading, | ||
error, | ||
checkInParticipantSubevent, | ||
}; | ||
} | ||
|
||
export default useEvents; |