Skip to content

Commit

Permalink
Merge pull request #105 from shawakash/scan_page
Browse files Browse the repository at this point in the history
feat: add scan qrcode feature in ui
  • Loading branch information
shawakash authored Feb 14, 2024
2 parents 1063e8e + 68e075a commit 6d2b2f1
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 0 deletions.
10 changes: 10 additions & 0 deletions apps/web/app/txn/scan/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import QRScanner from "./qrcodeScanner";

export default async function ScanPage() {
return (
<div className="flex flex-col justify-center items-center w-screen">
<h1>Scan Page</h1>
<QRScanner />
</div>
);
}
11 changes: 11 additions & 0 deletions apps/web/app/txn/scan/qrcodeInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export function InputFile() {
return (
<div className="grid w-full max-w-sm items-center gap-1.5">
<Label htmlFor="picture">Picture</Label>
<Input id="picture" type="file" />
</div>
)
}
77 changes: 77 additions & 0 deletions apps/web/app/txn/scan/qrcodeScanner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"use client";
import React, { useEffect, useState } from 'react';
import { Html5QrcodeScanner, Html5Qrcode } from "html5-qrcode";
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import { useRouter } from 'next/navigation';
import { toast } from 'sonner';

const QRScanner = () => {
const router = useRouter();
const [result, setResult] = useState<string | null>(null);

useEffect(() => {
const scanner = new Html5QrcodeScanner("qr-reader", {
qrbox: {
width: 250,
height: 250
},
fps: 10,
}, false);

const onSuccess = async (decodedText: string) => {
console.log(`QR code decoded: ${decodedText}`);
router.push(`${decodedText}`);
setResult(decodedText);
};
const onError = (errorMessage: string) => {
toast.error(errorMessage);
};

scanner.render(onSuccess, onError);
return () => {
scanner.clear();
}
}, []);


return (
<Card className='w-2/5'>
<CardHeader>
<CardTitle>Scan the Qrcode</CardTitle>
<CardDescription>Qrcode scanner for transaction</CardDescription>
</CardHeader>
<CardContent>
{result ?
<div className="">Scan Success</div> :
<div id="qr-reader"></div>
}
</CardContent>
<CardFooter>
<div className="relative z-20 flex items-center text-lg font-medium">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
className="mr-2 h-6 w-6"
>
<path d="M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3" />
</svg>
Paybox
</div>
</CardFooter>
</Card>
);
}

export default QRScanner;
3 changes: 3 additions & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@types/node": "20.10.6",
"@types/react": "18.2.46",
"@types/react-dom": "18.2.18",
"@types/react-qr-reader": "^2.1.7",
"autoprefixer": "10.4.16",
"axios": "^1.6.5",
"class-variance-authority": "^0.7.0",
Expand All @@ -44,6 +45,7 @@
"date-fns": "^3.3.1",
"eslint": "8.56.0",
"eslint-config-next": "14.0.4",
"html5-qrcode": "^2.3.8",
"lucide-react": "^0.306.0",
"next": "14.0.4",
"next-auth": "^4.24.5",
Expand All @@ -53,6 +55,7 @@
"react-day-picker": "^8.10.0",
"react-dom": "18.2.0",
"react-hook-form": "^7.49.3",
"react-qr-reader": "^3.0.0-beta-1",
"sonner": "^1.3.1",
"tailwind-merge": "^2.2.0",
"tailwindcss": "3.4.1",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3669,6 +3669,13 @@
dependencies:
"@types/react" "*"

"@types/react-qr-reader@^2.1.7":
version "2.1.7"
resolved "https://registry.yarnpkg.com/@types/react-qr-reader/-/react-qr-reader-2.1.7.tgz#1472a47ddbc0f96ddd246309f35826f01113837e"
integrity sha512-6K6DQeqP7c2oohcfvBpExlOawVsB2/C+7ZZL/fkCkNzYYAKDJnNHnuP3F5ChMl0mpoYEdqkqkllxqfM0VslEiw==
dependencies:
"@types/react" "*"

"@types/react@*", "@types/react@18.2.46":
version "18.2.46"
resolved "https://registry.npmjs.org/@types/react/-/react-18.2.46.tgz"
Expand Down Expand Up @@ -3995,6 +4002,27 @@
dependencies:
argparse "^2.0.1"

"@zxing/browser@0.0.7":
version "0.0.7"
resolved "https://registry.yarnpkg.com/@zxing/browser/-/browser-0.0.7.tgz#5fa7680a867b660f48d3288fdf63e0174ad531c7"
integrity sha512-AepzMgDnD6EjxewqmXpHJsi4S3Gw9ilZJLIbTf6fWuWySEcHBodnGu3p7FWlgq1Sd5QyfPhTum5z3CBkkhMVng==
optionalDependencies:
"@zxing/text-encoding" "^0.9.0"

"@zxing/library@^0.18.3":
version "0.18.6"
resolved "https://registry.yarnpkg.com/@zxing/library/-/library-0.18.6.tgz#717af8c6c1fd982865e21051afdd7b470ae6674c"
integrity sha512-bulZ9JHoLFd9W36pi+7e7DnEYNJhljYjZ1UTsKPOoLMU3qtC+REHITeCRNx40zTRJZx18W5TBRXt5pq2Uopjsw==
dependencies:
ts-custom-error "^3.0.0"
optionalDependencies:
"@zxing/text-encoding" "~0.9.0"

"@zxing/text-encoding@^0.9.0", "@zxing/text-encoding@~0.9.0":
version "0.9.0"
resolved "https://registry.yarnpkg.com/@zxing/text-encoding/-/text-encoding-0.9.0.tgz#fb50ffabc6c7c66a0c96b4c03e3d9be74864b70b"
integrity sha512-U/4aVJ2mxI0aDNI8Uq0wEhMgY+u4CNtEb0om3+y3+niDAsoTCOB33UF0sxpzqzdqXLqmvc+vZyAt4O8pPdfkwA==

JSONStream@^1.3.5:
version "1.3.5"
resolved "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz"
Expand Down Expand Up @@ -7448,6 +7476,11 @@ hosted-git-info@^7.0.0:
dependencies:
lru-cache "^10.0.1"

html5-qrcode@^2.3.8:
version "2.3.8"
resolved "https://registry.yarnpkg.com/html5-qrcode/-/html5-qrcode-2.3.8.tgz#0b0cdf7a9926cfd4be530e13a51db47592adfa0d"
integrity sha512-jsr4vafJhwoLVEDW3n1KvPnCCXWaQfRng0/EEYk1vNcQGcG/htAdhJX0be8YyqMoSz7+hZvOZSTAepsabiuhiQ==

http-cache-semantics@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz#abe02fcb2985460bf0323be664436ec3476a6d5a"
Expand Down Expand Up @@ -10548,6 +10581,15 @@ react-is@^18.0.0:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b"
integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==

react-qr-reader@^3.0.0-beta-1:
version "3.0.0-beta-1"
resolved "https://registry.yarnpkg.com/react-qr-reader/-/react-qr-reader-3.0.0-beta-1.tgz#e04a20876409313439959d8e0ea6df3ba6e36d68"
integrity sha512-5HeFH9x/BlziRYQYGK2AeWS9WiKYZtGGMs9DXy3bcySTX3C9UJL9EwcPnWw8vlf7JP4FcrAlr1SnZ5nsWLQGyw==
dependencies:
"@zxing/browser" "0.0.7"
"@zxing/library" "^0.18.3"
rollup "^2.67.2"

react-remove-scroll-bar@^2.3.3:
version "2.3.4"
resolved "https://registry.npmjs.org/react-remove-scroll-bar/-/react-remove-scroll-bar-2.3.4.tgz"
Expand Down Expand Up @@ -10920,6 +10962,13 @@ rimraf@^4.4.1:
dependencies:
glob "^9.2.0"

rollup@^2.67.2:
version "2.79.1"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-2.79.1.tgz#bedee8faef7c9f93a2647ac0108748f497f081c7"
integrity sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==
optionalDependencies:
fsevents "~2.3.2"

rpc-websockets@^7.5.1:
version "7.9.0"
resolved "https://registry.npmjs.org/rpc-websockets/-/rpc-websockets-7.9.0.tgz"
Expand Down Expand Up @@ -11872,6 +11921,11 @@ ts-api-utils@^1.0.1:
resolved "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.0.3.tgz"
integrity sha512-wNMeqtMz5NtwpT/UZGY5alT+VoKdSsOOP/kqHFcUW1P/VRhH2wJ48+DN2WwUliNbQ976ETwDL0Ifd2VVvgonvg==

ts-custom-error@^3.0.0:
version "3.3.1"
resolved "https://registry.yarnpkg.com/ts-custom-error/-/ts-custom-error-3.3.1.tgz#8bd3c8fc6b8dc8e1cb329267c45200f1e17a65d1"
integrity sha512-5OX1tzOjxWEgsr/YEUWSuPrQ00deKLh6D7OTWcvNHm12/7QPyRh8SYpyWvA4IZv8H/+GQWQEh/kwo95Q9OVW1A==

ts-interface-checker@^0.1.9:
version "0.1.13"
resolved "https://registry.npmjs.org/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz"
Expand Down

0 comments on commit 6d2b2f1

Please sign in to comment.