Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/Hanaemong/FE into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
abcxj123 committed Jul 9, 2024
2 parents fee638e + 5cf8cb3 commit af3d228
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions src/pages/team/Qrcode.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useEffect, useRef, useState } from "react";
import { Button, ConfirmCard, Topbar } from "../../components";
import QrScanner from "qr-scanner";
import QRCode from "qrcode.react";
import { useLocation, useNavigate } from "react-router-dom";
import { useMutation } from "@tanstack/react-query";
import { transactionApi } from "../../apis/domains/transactionApi";
Expand All @@ -18,11 +17,17 @@ const Qrcode = () => {
const [confirm, setConfirm] = useState<boolean>(false);

const handleScan = (result: QrScanner.ScanResult) => {
const parsedData = JSON.parse(result.data);
console.log(`Scan: ${JSON.stringify(parsedData)}`);
try {
const parsedData = JSON.parse(result.data);
console.log(`Scan: ${JSON.stringify(parsedData)}`);
expense(parsedData.teamId);
} catch (err) {
console.error("Failed to parse QR code data", err);
}
};

const QrOptions = {
preferredCamera: "user",
preferredCamera: "environment",
maxScansPerSecond: 5,
highlightScanRegion: true,
};
Expand All @@ -41,23 +46,9 @@ const Qrcode = () => {

useEffect(() => {
const videoElem = videoRef.current;
const canvas: HTMLCanvasElement = document.querySelector("canvas")!;
if (videoElem) {
const qrScanner = new QrScanner(
videoElem,
(result) => handleScan(result),
QrOptions
);
const qrScanner = new QrScanner(videoElem, handleScan, QrOptions);
qrScanner.start();
QrScanner.scanImage(canvas)
.then((result) => {
console.log(result);
const res = JSON.parse(result);
console.log(res);
expense(res.teamId);
})
.catch((error) => console.log(error || "No QR code found."));

return () => qrScanner.destroy();
}
}, []);
Expand Down Expand Up @@ -107,10 +98,10 @@ const Qrcode = () => {
/>
</>
)}
<QRCode
{/* <QRCode
className="size-24 hidden"
value={JSON.stringify({ teamId: locationState.teamId })}
/>
/> */}
</div>
</div>
</section>
Expand Down

0 comments on commit af3d228

Please sign in to comment.