forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQRcodePage.js
More file actions
71 lines (64 loc) · 2.08 KB
/
QRcodePage.js
File metadata and controls
71 lines (64 loc) · 2.08 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
import React from 'react'
import { Trans } from '@lingui/macro'
import { Box, Stack, Text, Button } from '@chakra-ui/core'
import { useHistory } from 'react-router-dom'
import { useQuery } from '@apollo/client'
import { useUserState } from './UserState'
import { GENERATE_OTP_URL } from './graphql/queries'
import QRCode from 'qrcode.react'
import { ErrorBoundary } from 'react-error-boundary'
import { ErrorFallbackMessage } from './ErrorFallbackMessage'
import { LoadingMessage } from './LoadingMessage'
export default function QRcodePage() {
const { currentUser } = useUserState()
const history = useHistory()
// This function generates the URL when the page loads
const { loading, error, data } = useQuery(GENERATE_OTP_URL, {
variables: { email: currentUser.userName },
})
if (loading)
return (
<LoadingMessage>
<Trans>QR Code</Trans>
</LoadingMessage>
)
if (error) return <ErrorFallbackMessage error={error} />
if (data)
return (
<Stack spacing="4" mx="auto" alignItems="center" px="8" overflow="hidden">
<Text textAlign="center" mx="auto" fontSize="2xl">
<Trans>
Scan this QR code with a 2FA app like Authy or Google Authenticator
</Trans>
</Text>
<ErrorBoundary FallbackComponent={ErrorFallbackMessage}>
<Box mt={6} mx="auto">
<QRCode
role="img"
renderAs="svg"
value={String(data.generateOtpUrl)}
size={256}
/>
</Box>
</ErrorBoundary>
<Text mt="6" textAlign="center" mx="auto" fontSize="lg">
<Trans>
Your 2FA app will then have a valid code that you can use when you
sign in.
</Trans>
</Text>
<Stack spacing={4} isInline>
<Button
color="primary"
bg="transparent"
borderColor="primary"
borderWidth="1px"
mb="4"
onClick={history.goBack}
>
<Trans>Back</Trans>
</Button>
</Stack>
</Stack>
)
}