Skip to content
This repository has been archived by the owner on Aug 9, 2023. It is now read-only.

Commit

Permalink
chore: add scan error guard
Browse files Browse the repository at this point in the history
  • Loading branch information
betich committed Aug 3, 2023
1 parent db43a70 commit 8174b07
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
41 changes: 22 additions & 19 deletions src/pages/e-ticket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ const ETicket = () => {
const toast = useToast();
const imageRef = useRef<HTMLDivElement>(null);
const saveImage = () => {
toPng(imageRef.current as HTMLElement, { quality: 0.95 }).then(
(dataUrl: string) => {
const link = document.createElement('a');
link.download = `${user?.firstname || '__'}-${
user?.lastname || '__'
}-e-ticket.png`;
link.href = dataUrl;
link.click();
link.remove();
}
);
// toPng(imageRef.current as HTMLElement, { quality: 0.95 }).then(
// (dataUrl: string) => {
// const link = document.createElement('a');
// link.download = `${user?.firstname || '__'}-${
// user?.lastname || '__'
// }-e-ticket.png`;
// link.href = dataUrl;
// link.click();
// link.remove();
// }
// );
};
useEffect(() => {
if (!isReady) return;
Expand Down Expand Up @@ -58,27 +58,30 @@ const ETicket = () => {
alt="ticket"
/>
<div className="flex flex-col items-center">
<p className="mb-64 mt-24 text-8xl">
<p className="mb-64 mt-12 text-[5.5rem]">
{user?.firstname || 'Null'}
</p>
<div className="mt-9 flex items-center">
<div className="relative bottom-2 right-8">
<div className="relative bottom-2 right-12">
<QRCode
value={user?.id || 'No User'}
size={127}
size={92}
fgColor="#3C415F"
/>
</div>
<div className="relative left-4 top-2 flex flex-col gap-1 text-center text-blue-950">
<div className="relative left-8 top-2 flex flex-col gap-1 text-center text-blue-950">
<p className="text-4xl">
{user?.firstname || ''}
{user?.nickname || ''}
</p>
<p>
{`${user?.firstname} ${user?.lastname}` ||
''}
</p>
<p>{user?.firstname || ''}</p>
</div>
</div>
</div>
</div>
<Button
{/* <Button
content={
<div className="flex items-center justify-center">
<ArrowDownTrayIcon
Expand All @@ -91,7 +94,7 @@ const ETicket = () => {
}
onClick={saveImage}
additionalStyle="mt-10 mb-20 py-2 w-80 rounded-lg bg-pink-400 ring-pink-400/30 ring-4"
/>
/> */}
</div>
</>
);
Expand Down
16 changes: 10 additions & 6 deletions src/pages/scan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ function Scan() {
const router = useRouter();

const checkIn = async (token: string) => {
const { status } = await httpPost('/estamp/' + token, {});
if (status === 200) {
toast?.setToast('success', 'Check in successfully');
} else {
toast?.setToast('error', 'QR Code is invalid');
try {
const { status } = await httpPost('/estamp/' + token, {});
if (status === 200) {
toast?.setToast('success', 'Check in successfully');
} else {
toast?.setToast('error', 'QR Code is invalid');
}
router.push('/walk-rally');
} catch {
toast?.setToast('error', 'There was an error');
}
router.push('/walk-rally');
};

const handleScanResult = (token: any, error: any) => {
Expand Down

0 comments on commit 8174b07

Please sign in to comment.