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
67 lines (59 loc) · 1.71 KB
/
AuthenticateField.js
File metadata and controls
67 lines (59 loc) · 1.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
import React from 'react'
import { func, object, oneOfType, shape, string } from 'prop-types'
import { t } from '@lingui/macro'
import { FormField } from './FormField'
import { TwoFactorIcon } from '../../theme/Icons'
function AuthenticateField({
name,
forwardedRef,
sendMethod,
inputProps,
...props
}) {
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 (
<FormField
name={name}
label={
codeSendMessage + ' ' + t`Please enter your two factor code below.`
}
leftElement={<TwoFactorIcon color="gray.300" size="1.25rem" />}
placeholder={t`Enter two factor code`}
ref={forwardedRef}
autoFocus
autoComplete="off"
inputMode="numeric"
w="auto"
align="center"
inputProps={inputProps}
{...props}
/>
)
}
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 }