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
64 lines (57 loc) · 2.25 KB
/
AuthenticateField.js
File metadata and controls
64 lines (57 loc) · 2.25 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
import React from 'react'
import { func, object, oneOfType, shape, string } from 'prop-types'
import { t } from '@lingui/macro'
import { Field } from 'formik'
import { FormControl, FormLabel, HStack, PinInput, PinInputField } from '@chakra-ui/react'
function AuthenticateField({ name = 'twoFactorCode', sendMethod }) {
const codeSendMessage =
sendMethod.toLowerCase() === 'email'
? t`We've sent you an email with an authentication code to sign into Tracker.`
: sendMethod.toLowerCase() === 'phone'
? t`We've sent an SMS to your registered phone number with an authentication code to sign into Tracker.`
: sendMethod.toLowerCase() === 'verifyphone'
? t`We've sent an SMS to your new phone number with an authentication code to confirm this change.`
: ''
return (
<Field name={name}>
{({ field, form }) => (
<FormControl id={name}>
<FormLabel htmlFor={name} fontWeight="bold" textAlign="center">
{codeSendMessage + ' ' + t`Please enter your two factor code below.`}
</FormLabel>
<HStack justify="center">
<PinInput
id={name}
otp
type="number"
autoFocus
name={name}
onChange={(val) => form.setFieldValue(field.name, val)}
>
<PinInputField borderColor="black" isRequired={true} />
<PinInputField borderColor="black" isRequired={true} />
<PinInputField borderColor="black" isRequired={true} />
<PinInputField borderColor="black" isRequired={true} />
<PinInputField borderColor="black" isRequired={true} />
<PinInputField borderColor="black" isRequired={true} />
</PinInput>
</HStack>
</FormControl>
)}
</Field>
)
}
AuthenticateField.propTypes = {
name: string,
inputProps: object,
forwardedRef: oneOfType([func, shape({ current: object })]),
sendMethod: string.isRequired,
}
AuthenticateField.defaultProps = {
name: 'twoFactorCode',
}
const withForwardedRef = React.forwardRef((props, ref) => {
return <AuthenticateField {...props} forwardedRef={ref} />
})
withForwardedRef.displayName = 'AuthenticateField'
export { withForwardedRef as AuthenticateField }