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

feat: scan qr #73

Merged
merged 4 commits into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"postcss": "8.4.24",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-qr-reader": "3.0.0-beta-1",
"tailwindcss": "3.3.2"
},
"devDependencies": {
Expand Down
55 changes: 55 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions src/pages/scan.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React, { useState } from 'react';
import { QrReader } from 'react-qr-reader';
import { motion } from 'framer-motion';
import { XMarkIcon } from '@heroicons/react/24/solid';
import Link from 'next/link';
import { useRouter } from 'next/router';

function Scan() {
const [data, setData] = useState('');
const [showModal, setShowModal] = useState(false);

const handleScanResult = (result: any, error: any) => {
if (result) {
setData(result.text);
setShowModal(true);
}
if (error) {
console.info(error);
}
};

const router = useRouter();

return (
<div className="flex flex-col items-center justify-center">
<div className="relative w-full">
<QrReader
className="bg-black"
onResult={handleScanResult}
constraints={{ facingMode: 'environment' }}
/>
<motion.div
className="absolute left-1/2 top-1/2 h-48 w-48 max-w-md -translate-x-1/2 -translate-y-1/2 transform rounded-3xl border-4 border-white"
animate={{ opacity: [0.25, 0.5, 1, 0.5, 0.25] }}
transition={{ duration: 1, repeat: Infinity }}
></motion.div>
<button
className="absolute right-0 top-0 mr-4 mt-4"
onClick={() => router.back()}
>
<XMarkIcon className="h-6 w-6 rounded-sm bg-white bg-opacity-50 text-white" />
</button>
</div>
<div className="flex w-full items-center justify-center bg-black">
<div className="h-64 w-full rounded-t-2xl bg-white p-8 text-center">
{showModal ? (
<div className="grid">
<Link
href={data}
className="truncate text-left text-blue-500"
>
{data}
</Link>
<p className="text-left text-sm text-gray-500">
Tap here to open the link
</p>
</div>
) : (
<p className="break-all text-black">
Please scan a QR code
</p>
)}
</div>
</div>
</div>
);
}

export default Scan;