forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmailValidationPage.js
More file actions
93 lines (87 loc) · 2.71 KB
/
EmailValidationPage.js
File metadata and controls
93 lines (87 loc) · 2.71 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import React, { useEffect, useState } from 'react'
import { Trans } from '@lingui/macro'
import { Button, Divider, Stack, Text } from '@chakra-ui/react'
import {
ArrowForwardIcon,
CheckCircleIcon,
WarningIcon,
} from '@chakra-ui/icons'
import { Link as RouteLink, useParams } from 'react-router-dom'
import { useMutation } from '@apollo/client'
import { LoadingMessage } from '../components/LoadingMessage'
import { VERIFY_ACCOUNT } from '../graphql/mutations'
export default function EmailValidationPage() {
const { verifyToken } = useParams()
const [success, setSuccess] = useState(false)
let errorMessage = ''
const [verifyAccount, { loading }] = useMutation(VERIFY_ACCOUNT, {
onError(error) {
errorMessage = error.message
},
onCompleted({ verifyAccount }) {
if (verifyAccount.result.__typename === 'VerifyAccountResult')
setSuccess(true)
else if (verifyAccount.result.__typename === 'VerifyAccountError')
errorMessage = verifyAccount.result.description
else console.log('Incorrect verifyAccount.result typename.')
},
})
useEffect(() => {
verifyAccount({ variables: { verifyToken: verifyToken } })
}, [verifyAccount, verifyToken])
const verifyMessage = () => {
if (success) {
return (
<Stack>
<Stack isInline align="center">
<CheckCircleIcon color="strong" />
<Text fontSize="2xl" textAlign="center" fontWeight="bold">
<Trans>Your account email was successfully verified</Trans>
</Text>
</Stack>
<Text fontSize="xl" textAlign="center">
<Trans>
Your account will be fully activated the next time you log in
</Trans>
</Text>
</Stack>
)
} else {
return (
<Stack>
<Stack isInline align="center">
<WarningIcon color="weak" />
<Text fontSize="2xl" textAlign="center" fontWeight="bold">
<Trans>
Your account email could not be verified at this time. Please
try again.
</Trans>
</Text>
</Stack>
<Text fontSize="xl" textAlign="center">
{errorMessage}
</Text>
</Stack>
)
}
}
return (
<Stack px="8" mx="auto" overflow="hidden" align="center">
{loading ? <LoadingMessage /> : verifyMessage()}
<Divider />
{!loading && (
<Button
as={RouteLink}
to="/"
color="primary"
bg="transparent"
borderColor="primary"
borderWidth="1px"
rightIcon={<ArrowForwardIcon />}
>
<Trans>Continue</Trans>
</Button>
)}
</Stack>
)
}