-
Notifications
You must be signed in to change notification settings - Fork 125
/
SummaryPanel.jsx
244 lines (233 loc) · 8.25 KB
/
SummaryPanel.jsx
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
import React, { useState, useContext, useEffect } from 'react';
import { getConfig } from '@edx/frontend-platform';
import {
Alert, Hyperlink, Form, Button, Spinner,
} from '@openedx/paragon';
import { Link, useNavigate } from 'react-router-dom';
import { injectIntl, intlShape, FormattedMessage } from '@edx/frontend-platform/i18n';
import { submitIdVerification } from '../data/service';
import { useNextPanelSlug } from '../routing-utilities';
import BasePanel from './BasePanel';
import IdVerificationContext from '../IdVerificationContext';
import ImagePreview from '../ImagePreview';
import messages from '../IdVerification.messages';
import CameraHelpWithUpload from '../CameraHelpWithUpload';
import SupportedMediaTypes from '../SupportedMediaTypes';
const SummaryPanel = (props) => {
const panelSlug = 'summary';
const nextPanelSlug = useNextPanelSlug(panelSlug);
const {
facePhotoFile,
idPhotoFile,
profileDataManager,
nameOnAccount,
idPhotoName,
stopUserMedia,
setReachedSummary,
} = useContext(IdVerificationContext);
const nameToBeUsed = idPhotoName || nameOnAccount || '';
const [isSubmitting, setIsSubmitting] = useState(false);
const [submissionError, setSubmissionError] = useState(null);
const navigate = useNavigate();
useEffect(() => setReachedSummary(true), [setReachedSummary]);
function renderManagedProfileMessage() {
if (!profileDataManager) {
return null;
}
return (
<p id="profile-manager-warning">
<FormattedMessage
id="id.verification.account.name.summary.alert"
defaultMessage="Your account settings are managed by {managerTitle}. If the name on your photo ID does not match the name on your account, please contact your {profileDataManager} administrator or {support} for help."
description="Alert message informing the user their account data is managed by a third party."
values={{
managerTitle: <strong>{profileDataManager}</strong>,
profileDataManager,
support: (
<Hyperlink destination={getConfig().SUPPORT_URL} target="_blank">
{props.intl.formatMessage(messages['id.verification.support'])}
</Hyperlink>
),
}}
/>
</p>
);
}
// eslint-disable-next-line react/no-unstable-nested-components
const SubmitButton = () => {
const handleClick = async () => {
setIsSubmitting(true);
const verificationData = {
facePhotoFile,
idPhotoFile,
courseRunKey: sessionStorage.getItem('courseRunKey'),
};
if (idPhotoName) {
verificationData.idPhotoName = idPhotoName;
} else {
/**
* If learner has not entered an idPhotoName on the GetNameIdPanel,
* use the current nameOnAccount when submitting IDV.
*/
verificationData.idPhotoName = nameOnAccount;
}
const result = await submitIdVerification(verificationData);
if (result.success) {
stopUserMedia();
navigate(`/id-verification/${nextPanelSlug}`);
} else {
stopUserMedia();
setIsSubmitting(false);
setSubmissionError(result);
}
};
return (
<Button
title="Confirmation"
disabled={isSubmitting}
onClick={handleClick}
data-testid="submit-button"
>
{props.intl.formatMessage(messages['id.verification.review.confirm'])}
</Button>
);
};
function getError() {
if (submissionError.status === 400) {
if (submissionError.message.includes('face_image')) {
return props.intl.formatMessage(messages['id.verification.submission.alert.error.face']);
}
if (submissionError.message.includes('Photo ID image')) {
return props.intl.formatMessage(messages['id.verification.submission.alert.error.id']);
}
if (submissionError.message.includes('Name')) {
return props.intl.formatMessage(messages['id.verification.submission.alert.error.name']);
}
if (submissionError.message.includes('unsupported format')) {
return (
<>
{props.intl.formatMessage(messages['id.verification.submission.alert.error.unsupported'])}
<SupportedMediaTypes />
</>
);
}
}
return (
<FormattedMessage
id="idv.submission.alert.error"
defaultMessage={`
We encountered a technical error while trying to submit ID verification.
This might be a temporary issue, so please try again in a few minutes.
If the problem persists, please go to {support_link} for help.
`}
values={{
support_link: (
<Alert.Link href="https://support.edx.org/hc/en-us">
{props.intl.formatMessage(
messages['id.verification.review.error'],
{ siteName: getConfig().SITE_NAME },
)}
</Alert.Link>
),
}}
/>
);
}
return (
<BasePanel
name={panelSlug}
title={props.intl.formatMessage(messages['id.verification.review.title'])}
>
{submissionError && (
<Alert
variant="danger"
data-testid="submission-error"
dismissible
onClose={() => setSubmissionError(null)}
>
{getError()}
</Alert>
)}
<p>
{props.intl.formatMessage(messages['id.verification.review.description'])}
</p>
<div className="row mb-4">
<div className="col-6">
<label htmlFor="photo-of-face" className="font-weight-bold">
{props.intl.formatMessage(messages['id.verification.review.portrait.label'])}
</label>
<ImagePreview
id="photo-of-face"
src={facePhotoFile}
alt={props.intl.formatMessage(messages['id.verification.review.portrait.alt'])}
/>
<Link
className="btn btn-outline-primary"
to="/id-verification/take-portrait-photo"
state={{ fromSummary: true }}
data-testid="portrait-retake"
>
{props.intl.formatMessage(messages['id.verification.review.portrait.retake'])}
</Link>
</div>
<div className="col-6">
<label htmlFor="photo-of-id/edit" className="font-weight-bold">
{props.intl.formatMessage(messages['id.verification.review.id.label'])}
</label>
<ImagePreview
id="photo-of-id"
src={idPhotoFile}
alt={props.intl.formatMessage(messages['id.verification.review.id.alt'])}
/>
<Link
className="btn btn-outline-primary"
to="/id-verification/take-id-photo"
state={{ fromSummary: true }}
data-testid="id-retake"
>
{props.intl.formatMessage(messages['id.verification.review.id.retake'])}
</Link>
</div>
</div>
<CameraHelpWithUpload />
<div className="form-group">
<label htmlFor="name-to-be-used" className="font-weight-bold">
{props.intl.formatMessage(messages['id.verification.name.label'])}
</label>
{renderManagedProfileMessage()}
<div className="d-flex">
<Form.Control
id="name-to-be-used"
type="text"
disabled
value={nameToBeUsed}
onChange={() => {}}
aria-describedby={profileDataManager ? 'profile-manager-warning' : null}
/>
{!profileDataManager && (
<Link
className="btn btn-link ml-3 px-0"
to="/id-verification/get-name-id"
state={{ fromSummary: true }}
>
<FormattedMessage
id="id.verification.account.name.edit"
defaultMessage="Edit {sr}"
description="Button to edit name, with clarifying information for screen readers."
values={{
sr: <span className="sr-only">Name</span>,
}}
/>
</Link>
)}
</div>
</div>
<SubmitButton />{' '}
{isSubmitting && <Spinner animation="border" variant="primary" />}
</BasePanel>
);
};
SummaryPanel.propTypes = {
intl: intlShape.isRequired,
};
export default injectIntl(SummaryPanel);