Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Hackathon Check-In Scanner #130

Merged
merged 6 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adds better error handling
  • Loading branch information
christianhelp committed Oct 22, 2024
commit 56591dc665778536f5e19e0e7e9d61924f3c9e99
7 changes: 1 addition & 6 deletions apps/web/src/actions/admin/scanner-admin-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,9 @@ export const checkInUserToHackathon = adminAction
.schema(z.string())
.action(async ({ parsedInput: user }) => {
// Set checkinTimestamp
try {
await db
.update(userCommonData)
.set({ checkinTimestamp: sql`now()` })
.where(eq(userCommonData.clerkID, user));
} catch (e) {
console.log("Error updating checkinTimestamp: ", e);
return { success: false, message: "Error checking in the user!" };
}
return { success: true };
});
);
30 changes: 16 additions & 14 deletions apps/web/src/components/admin/scanner/CheckinScanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,22 @@ export default function CheckinScanner({
const path = usePathname();
const router = useRouter();

function handleUseActionFeedback(hasErrored = false) {
toast.dismiss();
(hasErrored) ? toast.error("Failed to Check User Into Hackathon") : toast.success("Successfully Checked User Into Hackathon!");
router.replace(`${path}`);
}

const { execute: runCheckInUserToHackathon, result: checkInResult } =
useAction(checkInUserToHackathon);
useAction(checkInUserToHackathon,{
onSuccess: () => {
handleUseActionFeedback();
},
onError: () =>{
handleUseActionFeedback(true);
}
});

useEffect(() => {
if (
checkInResult &&
checkInResult.data &&
!checkInResult.data.success
) {
alert(
`${checkInResult.data?.message ?? "Error checking in user To the hackathon"}`,
);
}
}, [checkInResult]);
function handleScanCreate() {
const params = new URLSearchParams(searchParams.toString());
const timestamp = parseInt(params.get("createdAt") as string);
Expand All @@ -75,10 +77,10 @@ export default function CheckinScanner({
if (checkedIn) {
return alert("User Already Checked in!");
} else {
toast.loading('Checking User In');
runCheckInUserToHackathon(scanUser.clerkID);
}
toast.success("Successfully Scanned User In");
router.replace(`${path}`);
router.replace(path);
}

const drawerTitle = checkedIn
Expand Down