-
Notifications
You must be signed in to change notification settings - Fork 6
/
DppReader.tsx
59 lines (56 loc) · 1.74 KB
/
DppReader.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { Modal, Text } from "@bbtgnn/polaris-interfacer";
import ProjectDisplay from "components/ProjectDisplay";
import { useTranslation } from "next-i18next";
import Link from "next/link";
import { useState } from "react";
import { QrReader } from "react-qr-reader";
const DppReader = () => {
const [url, setUrl] = useState<string | undefined>(undefined);
const [id, setId] = useState<string | undefined>(undefined);
const [activeLink, setActiveLink] = useState(false);
const { t } = useTranslation("common");
return (
<>
<QrReader
constraints={{
facingMode: "environment",
}}
onResult={(result, error) => {
if (!!error) {
console.info(error);
return;
}
if (!!result) {
//@ts-ignore
const url = result.text;
const id = url.split("/").pop();
const isTypeId = id.match(/^[a-zA-Z0-9]{26}$/);
// const isLegitUrl = url.match(/^https:\/\/dpp\.brickblock\.io\/project\/[a-zA-Z0-9]{26}$/);
if (isTypeId) {
setUrl(url);
setId(id);
setActiveLink(true);
}
}
}}
/>
<Modal fullScreen open={activeLink} onClose={() => setActiveLink(false)} title={t("Project")}>
<Modal.Section>
<div className="flex justify-between">
<div>
<Link href={url!}>
<a>
<ProjectDisplay projectId={id} />
</a>
</Link>
</div>
<Text as="p" variant="bodyMd" color="subdued">
{t("result")}
</Text>
</div>
</Modal.Section>
</Modal>
</>
);
};
export default DppReader;