Skip to content

Commit

Permalink
incrementing event counts
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinmonisit committed Mar 22, 2024
1 parent de384b5 commit 84d6075
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/dashboard/components/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default function PopupDialog(props: {
setOpen(false);
}}
>
Yep! Form my team!
Yep!
</button>
<button
type="button"
Expand Down
1 change: 0 additions & 1 deletion app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export default function Dashboard() {
const [savingUserProfile, setSavingUserProfile] = useState<boolean>(false);
const [submittingTeamForm, setSubmittingTeamForm] = useState<boolean>(false);
const [userProfileSubmitText, setUserProfileSubmitText] = useState<string>("Save");
const [showQR, setShowQR] = useState<boolean>(false);

const [displayTeamFormFinalSubmissionWarning, setDisplayTeamFormFinalSubmissionWarning] = useState<boolean>(false);
const [teamSubmissionError, setTeamSubmissionError] = useState<string>("");
Expand Down
58 changes: 43 additions & 15 deletions app/dashboard/views/organizerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import './organizerView.css';
import QrReaderWrapper from "../components/QRreader";
import CheckInScan from './checkInScan';
import EventScan from './eventScan';
import { AttendEventScan, GetUser } from '@/app/lib/actions';
import { AttendEventScan, GetUser, SetUser } from '@/app/lib/actions';
import PopupDialog from '../components/dialog';
import { set } from 'zod';

type STATUS = "SUCCESSFUL" | "FAILED" | "PENDING" | "AWAITING SCAN" | "AWAITING RESPONSE";
type ScannerTab = "CHECK IN" | "EVENT";
Expand Down Expand Up @@ -80,29 +81,50 @@ function OrganizerView() {
const [latestScannedEmail, setLatestScannedEmail] = useState<string>("");
const [scannedName, setScannedName] = useState<string>("");

const resetScanLog = () => {
setScannedName("");
setLatestScannedEmail("");
setScanResponse("");;
setStatus("AWAITING SCAN");
}

const handleOnScan = async (
result: string,
forceAttendance: boolean = false
) => {
setScannedName("");
setStatus("AWAITING RESPONSE");
setLatestScannedEmail(result);
if (scannerTab === "CHECK IN") {
const resp = await GetUser(result);
if (typeof resp.response === 'string') {
if (resp.response.includes('error')) {
setStatus("FAILED");
return;
}

const resp = await GetUser(result);
if (typeof resp.response === 'string') {
if (resp.response.includes('error')) {
setStatus("FAILED");
return;
}
}
const userData = resp.response as unknown as Record<any, any>;
const now = new Date();
setScannedName(userData.first_name + " " + userData.last_name);

const userData = resp.response as unknown as Record<any, any>;
const now = new Date();
setScannedName(userData.first_name + " " + userData.last_name);
if (scannerTab === "CHECK IN") {
if (userData.registration_status === "confirmed"
|| userData.registration_status == "checked_in"
|| now > timeWhenAllHackersCanComeThrough) {

const resp = await SetUser(
{ 'day_of.checkIn': true, 'registration_status': 'checked-in' },
result
);

if (resp.error !== '') {
setStatus("FAILED");
setScanResponse(resp.error);
return;
}

setStatus("SUCCESSFUL");

} else {
setStatus("PENDING");
}
Expand All @@ -123,11 +145,11 @@ function OrganizerView() {
* I just know that it's the error code for multiple attendance.
*/
const multipleAttendanceStatus = 402;
if (resp.status == multipleAttendanceStatus) {
if (resp.status == multipleAttendanceStatus && !forceAttendance) {
setShowForceAttendance(true);
return;
}


if (resp.error !== '') {
setStatus("FAILED");
setScanResponse(resp.error);
Expand All @@ -154,14 +176,20 @@ function OrganizerView() {
<button
className={`bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded ${scannerTab === "CHECK IN" ? "bg-blue-700" : ""
}`}
onClick={() => setScannerTab("CHECK IN")}
onClick={() => {
setScannerTab("CHECK IN");
resetScanLog();
}}
>
Check In
</button>
<button
className={`bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded ${scannerTab === "EVENT" ? "bg-blue-700" : ""
}`}
onClick={() => setScannerTab("EVENT")}
onClick={() => {
setScannerTab("EVENT");
resetScanLog();
}}
>
Event
</button>
Expand Down
37 changes: 29 additions & 8 deletions app/lib/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ export async function AttendEventScan(

const resp = await fetch(ENDPOINTS.attend, {
method: 'POST',
cache: 'no-store',
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -585,18 +586,26 @@ export async function AttendEventScan(

if (!resp.ok) {
error_message = `An error occured when attempting to attend event. Invalid response.`;
return {
error: error_message,
response: '',
status: 500,
};
}

const json = await resp.json();
const { statusCode: status, body: jsonBody } = json as AttendEventResponse;
response_status = status;
if (status === 404) {
const { statusCode, body: jsonBody } = json as AttendEventResponse;

response_status = statusCode;
if (statusCode === 404) {
error_message = `User ${scannedEmail} not found. Please try again.`;
} else if (status === 402) {
} else if (statusCode === 402) {
error_message = `User ${scannedEmail} is already checked in to ${event}!`;
}

if (status === 200 && typeof jsonBody !== 'string') {
console.log('statusCode: ', statusCode, 'jsonBody: ', jsonBody);

if (statusCode === 200 && typeof jsonBody !== 'string') {
response_message = `${
jsonBody!.email
} successfully logged in to ${event}!`;
Expand All @@ -605,10 +614,24 @@ export async function AttendEventScan(
error_message = 'Invalid user session. Please login.';
}

const field = `day_of.${event}`;
const mongoQuery: { $inc: { [key: string]: number } } = {
$inc: {},
};

mongoQuery['$inc'][field] = 1;

const resp = await SetUser({ $inc: { field: 1 } }, scannedEmail);

if (resp.error !== '') {
error_message = resp.error;
response_status = 500;
}

return {
status: response_status,
error: error_message,
response: response_message,
status: response_status,
};
}

Expand Down Expand Up @@ -646,8 +669,6 @@ export async function UploadTeamSubmission(
team_members: member_emails,
};

console.log(postBody);

const resp = await fetch(ENDPOINTS.makeTeam, {
method: 'POST',
cache: 'no-store',
Expand Down

0 comments on commit 84d6075

Please sign in to comment.