-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from shawakash/scan_page
feat: add scan qrcode feature in ui
- Loading branch information
Showing
10 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters