forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthenticateField.js
More file actions
91 lines (84 loc) · 2.42 KB
/
AuthenticateField.js
File metadata and controls
91 lines (84 loc) · 2.42 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
import React from 'react'
import { elementType, func, oneOfType, shape, string } from 'prop-types'
import { useLingui } from '@lingui/react'
import { t, Trans } from '@lingui/macro'
import {
FormControl,
FormErrorMessage,
FormLabel,
Icon,
Input,
InputGroup,
InputLeftElement,
Stack,
} from '@chakra-ui/core'
import { useField } from 'formik'
import WithPseudoBox from './withPseudoBox'
const AuthenticateField = WithPseudoBox(function AuthenticateField({
name,
forwardedRef,
sendMethod,
...props
}) {
const [field, meta] = useField(name)
const { i18n } = useLingui()
const codeSendMessage =
sendMethod.toLowerCase() === 'email' ? (
<Trans>
We've sent you an email with an authentication code to sign into
Tracker.
</Trans>
) : sendMethod.toLowerCase() === 'phone' ? (
<Trans>
We've sent an SMS to your registered phone number with an authentication
code to sign into Tracker.
</Trans>
) : sendMethod.toLowerCase() === 'verifyphone' ? (
<Trans>
We've sent an SMS to your new phone number with an authentication code
to confirm this change.
</Trans>
) : (
''
)
return (
<FormControl isInvalid={meta.error && meta.touched}>
<Stack align="center">
<FormLabel
htmlFor="twoFactorCode"
fontWeight="bold"
mb="2"
textAlign={['center', 'left']}
>
{codeSendMessage}
<Trans>Please enter your two factor code below.</Trans>
</FormLabel>
<InputGroup width="fit-content">
<InputLeftElement>
<Icon name="twoFactor" color="gray.300" size="1.25rem" />
</InputLeftElement>
<Input
{...field}
{...props}
id="twoFactorCode"
ref={forwardedRef}
placeholder={i18n._(t`Enter two factor code`)}
autoFocus
inputMode="numeric"
/>
</InputGroup>
<FormErrorMessage>{meta.error}</FormErrorMessage>
</Stack>
</FormControl>
)
})
AuthenticateField.propTypes = {
name: string.isRequired,
forwardedRef: oneOfType([func, shape({ current: elementType })]),
sendMethod: string.isRequired,
}
const withForwardedRef = React.forwardRef((props, ref) => {
return <AuthenticateField {...props} forwardedRef={ref} />
})
withForwardedRef.displayName = 'AuthenticateField'
export default withForwardedRef