-
Notifications
You must be signed in to change notification settings - Fork 331
/
Copy pathUVFactorTwoBackupCodeCard.tsx
71 lines (64 loc) · 2.47 KB
/
UVFactorTwoBackupCodeCard.tsx
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 { useSession } from '@clerk/shared/react';
import React from 'react';
import { Col, descriptors, localizationKeys } from '../../customizables';
import { Card, Form, Header, useCardState } from '../../elements';
import { handleError, useFormControl } from '../../utils';
import { useAfterVerification } from './use-after-verification';
type UVFactorTwoBackupCodeCardProps = {
onShowAlternativeMethodsClicked: React.MouseEventHandler;
};
export const UVFactorTwoBackupCodeCard = (props: UVFactorTwoBackupCodeCardProps) => {
const { onShowAlternativeMethodsClicked } = props;
const { session } = useSession();
const { handleVerificationResponse } = useAfterVerification();
const card = useCardState();
const codeControl = useFormControl('code', '', {
type: 'text',
label: localizationKeys('formFieldLabel__backupCode'),
isRequired: true,
});
const handleBackupCodeSubmit: React.FormEventHandler = e => {
e.preventDefault();
return session!
.attemptSecondFactorVerification({ strategy: 'backup_code', code: codeControl.value })
.then(handleVerificationResponse)
.catch(err => handleError(err, [codeControl], card.setError));
};
return (
<Card.Root>
<Card.Content>
<Header.Root showLogo>
<Header.Title localizationKey={localizationKeys('reverification.backupCodeMfa.title')} />
<Header.Subtitle localizationKey={localizationKeys('reverification.backupCodeMfa.subtitle')} />
</Header.Root>
<Card.Alert>{card.error}</Card.Alert>
<Col
elementDescriptor={descriptors.main}
gap={8}
>
<Form.Root onSubmit={handleBackupCodeSubmit}>
<Form.ControlRow elementId={codeControl.id}>
<Form.PlainInput
{...codeControl.props}
autoFocus
onActionClicked={onShowAlternativeMethodsClicked}
/>
</Form.ControlRow>
<Col gap={3}>
<Form.SubmitButton hasArrow />
<Card.Action elementId='alternativeMethods'>
{onShowAlternativeMethodsClicked && (
<Card.ActionLink
localizationKey={localizationKeys('footerActionLink__useAnotherMethod')}
onClick={onShowAlternativeMethodsClicked}
/>
)}
</Card.Action>
</Col>
</Form.Root>
</Col>
</Card.Content>
<Card.Footer />
</Card.Root>
);
};