@propellerads/kyc-form 1.0.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/KYCDocumentParts/index.d.ts +7 -0
- package/dist/KYCDocumentParts/style.d.ts +10 -0
- package/dist/KYCDocumentParts/types.d.ts +34 -0
- package/dist/KYCErrorLabel/index.d.ts +3 -0
- package/dist/KYCErrorLabel/style.d.ts +4 -0
- package/dist/KYCErrorLabel/types.d.ts +7 -0
- package/dist/KYCFormItem/index.d.ts +3 -0
- package/dist/KYCFormItem/style.d.ts +4 -0
- package/dist/KYCFormItem/types.d.ts +13 -0
- package/dist/KYCStatusScreen/index.d.ts +9 -0
- package/dist/KYCStatusScreen/style.d.ts +6 -0
- package/dist/KYCStatusScreen/types.d.ts +21 -0
- package/dist/allowJavaScriptModules.d.ts +1 -0
- package/dist/constants.d.ts +15 -0
- package/dist/document.types.d.ts +31 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +8 -0
- package/dist/kyc-form.cjs.development.js +1384 -0
- package/dist/kyc-form.cjs.development.js.map +1 -0
- package/dist/kyc-form.cjs.production.min.js +2 -0
- package/dist/kyc-form.cjs.production.min.js.map +1 -0
- package/dist/kyc-form.esm.js +1374 -0
- package/dist/kyc-form.esm.js.map +1 -0
- package/dist/labels.types.d.ts +35 -0
- package/dist/style.d.ts +5 -0
- package/dist/types.d.ts +17 -0
- package/dist/utils.d.ts +9 -0
- package/package.json +21 -15
- package/dist/index.esm.js +0 -404
- package/dist/index.esm.min.js +0 -404
package/dist/index.esm.min.js
DELETED
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect } from 'react';
|
|
2
|
-
import Button, { BUTTON_TYPE } from '@propellerads/button';
|
|
3
|
-
import SuccessLabel from '@propellerads/success-label';
|
|
4
|
-
import { Close, COLOR, SIZE, Delete, Pdf, Insert } from '@propellerads/icon';
|
|
5
|
-
import styled from 'styled-components';
|
|
6
|
-
import { errorColor, spacing, fontSmall, white, gray50, gray95, borderRadius, fontNormal, black } from '@propellerads/stylevariables';
|
|
7
|
-
import ImageUploader, { DIRECTION } from '@propellerads/image-uploader';
|
|
8
|
-
|
|
9
|
-
const StyledKYCErrorLabel = styled.div `
|
|
10
|
-
display: flex;
|
|
11
|
-
align-items: center;
|
|
12
|
-
color: ${errorColor};
|
|
13
|
-
margin-top: ${spacing * 2}px;
|
|
14
|
-
margin-bottom: ${spacing * 4}px;
|
|
15
|
-
`;
|
|
16
|
-
const StyledKYCErrorLabelIcon = styled.span `
|
|
17
|
-
display: flex;
|
|
18
|
-
align-items: center;
|
|
19
|
-
justify-content: center;
|
|
20
|
-
width: 14px;
|
|
21
|
-
height: 14px;
|
|
22
|
-
border-radius: 100%;
|
|
23
|
-
background-color: ${errorColor};
|
|
24
|
-
|
|
25
|
-
&:before {
|
|
26
|
-
font-size: ${fontSmall};
|
|
27
|
-
color: ${white};
|
|
28
|
-
content: '!';
|
|
29
|
-
}
|
|
30
|
-
`;
|
|
31
|
-
const StyledKYCErrorLabelText = styled.span `
|
|
32
|
-
margin-left: ${spacing * 2}px;
|
|
33
|
-
`;
|
|
34
|
-
|
|
35
|
-
const KYCErrorLabel = (props) => {
|
|
36
|
-
return (React.createElement(StyledKYCErrorLabel, null,
|
|
37
|
-
props.isDocumentPartError ? (React.createElement(StyledKYCErrorLabelIcon, null)) : (React.createElement(Close, { color: COLOR.ERROR, hoverColor: COLOR.ERROR, size: SIZE.SMALL })),
|
|
38
|
-
React.createElement(StyledKYCErrorLabelText, null, props.label)));
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const StyledKYCSucessScreen = styled.div `
|
|
42
|
-
display: flex;
|
|
43
|
-
flex-direction: column;
|
|
44
|
-
`;
|
|
45
|
-
const StyledKYCSucessScreenItem = styled.span `
|
|
46
|
-
margin-bottom: ${spacing * 8}px;
|
|
47
|
-
`;
|
|
48
|
-
const StyledKYCSucessScreenSuppport = styled.span `
|
|
49
|
-
color: ${gray50};
|
|
50
|
-
`;
|
|
51
|
-
const StyledKYCFailScreen = styled.div `
|
|
52
|
-
display: flex;
|
|
53
|
-
flex-direction: column;
|
|
54
|
-
`;
|
|
55
|
-
const StyledKYCFailScreenItem = styled.span `
|
|
56
|
-
margin-bottom: ${spacing * 6}px;
|
|
57
|
-
`;
|
|
58
|
-
|
|
59
|
-
var DOCUMENT_TYPES;
|
|
60
|
-
(function (DOCUMENT_TYPES) {
|
|
61
|
-
DOCUMENT_TYPES["ID"] = "id";
|
|
62
|
-
DOCUMENT_TYPES["UB"] = "ub";
|
|
63
|
-
DOCUMENT_TYPES["ID_EXTRA"] = "id_extra";
|
|
64
|
-
DOCUMENT_TYPES["CARD"] = "bank_card";
|
|
65
|
-
DOCUMENT_TYPES["PAYMENT_SYSTEM_SCREEN"] = "payment_system_screen";
|
|
66
|
-
DOCUMENT_TYPES["ONLINE_BANKING_STATEMENT"] = "online_banking_statement";
|
|
67
|
-
DOCUMENT_TYPES["COMPANY_REGISTRATION_DOCUMENT"] = "company_registration_document";
|
|
68
|
-
DOCUMENT_TYPES["SELFIE_WITH_ID_CARD"] = "selfie_with_id_card_or_bank_card";
|
|
69
|
-
})(DOCUMENT_TYPES || (DOCUMENT_TYPES = {}));
|
|
70
|
-
var PART_TYPES;
|
|
71
|
-
(function (PART_TYPES) {
|
|
72
|
-
PART_TYPES["ID_FRONT"] = "id_front";
|
|
73
|
-
PART_TYPES["ID_BACK"] = "id_back";
|
|
74
|
-
PART_TYPES["UB"] = "ub_item";
|
|
75
|
-
PART_TYPES["CARD"] = "card_item";
|
|
76
|
-
PART_TYPES["PAYMENT_SYSTEM_SCREEN"] = "screen_item";
|
|
77
|
-
PART_TYPES["ONLINE_BANKING_STATEMENT"] = "obs_item";
|
|
78
|
-
PART_TYPES["COMPANY_REGISTRATION_DOCUMENT"] = "crd_item";
|
|
79
|
-
PART_TYPES["SELFIE_WITH_ID_CARD"] = "selfie_item";
|
|
80
|
-
})(PART_TYPES || (PART_TYPES = {}));
|
|
81
|
-
|
|
82
|
-
const MAX_FILE_SIZE = 5242880;
|
|
83
|
-
const MAX_EXTRA_PARTS_COUNT = 15;
|
|
84
|
-
const PDF_MIME_TYPE = 'application/pdf';
|
|
85
|
-
const HEIC_MIME_TYPE = 'image/heic';
|
|
86
|
-
const ACCEPT_FORMATS = `.png,.jpg,.jpe,.jpeg,.pdf,image/png,image/jpeg,${PDF_MIME_TYPE},${HEIC_MIME_TYPE}`;
|
|
87
|
-
const AVAILABLE_EXTRA_PARTS_DOCUMENTS = [
|
|
88
|
-
DOCUMENT_TYPES.CARD,
|
|
89
|
-
];
|
|
90
|
-
const OPTIONAL_DOCUMENT_PARTS = {
|
|
91
|
-
[DOCUMENT_TYPES.ID]: {
|
|
92
|
-
parts: [PART_TYPES.ID_BACK],
|
|
93
|
-
},
|
|
94
|
-
[DOCUMENT_TYPES.ID_EXTRA]: {
|
|
95
|
-
parts: [PART_TYPES.ID_BACK],
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const KYCSucessScreen = (props) => {
|
|
100
|
-
const { elementId, title, description, support, } = props;
|
|
101
|
-
return (React.createElement(StyledKYCSucessScreen, { id: elementId },
|
|
102
|
-
React.createElement(StyledKYCSucessScreenItem, null,
|
|
103
|
-
React.createElement(SuccessLabel, { show: true, elementId: `${elementId}_success` }, title)),
|
|
104
|
-
description && (React.createElement(StyledKYCSucessScreenItem, null, description)),
|
|
105
|
-
support && (React.createElement(StyledKYCSucessScreenSuppport, null, support))));
|
|
106
|
-
};
|
|
107
|
-
const KYCFailScreen = (props) => {
|
|
108
|
-
const { elementId, title, support, } = props;
|
|
109
|
-
return (React.createElement(StyledKYCFailScreen, { id: elementId },
|
|
110
|
-
React.createElement(StyledKYCFailScreenItem, null,
|
|
111
|
-
React.createElement(KYCErrorLabel, { label: title, isDocumentPartError: false })),
|
|
112
|
-
support));
|
|
113
|
-
};
|
|
114
|
-
var KYCStatusScreen = {
|
|
115
|
-
KYCSucessScreen,
|
|
116
|
-
KYCFailScreen,
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const StyledKYCFormItemFile = styled.div `
|
|
120
|
-
margin-top: ${spacing * 4}px;
|
|
121
|
-
margin-left: ${spacing * 4}px;
|
|
122
|
-
`;
|
|
123
|
-
const StyledKYCFormItemFileTitle = styled.div `
|
|
124
|
-
margin-bottom: ${spacing}px;
|
|
125
|
-
`;
|
|
126
|
-
const StyledKYCFormItemFilePreview = styled.div `
|
|
127
|
-
display: flex;
|
|
128
|
-
align-items: center;
|
|
129
|
-
background-color: ${gray95};
|
|
130
|
-
padding: ${spacing * 2}px;
|
|
131
|
-
border-radius: ${borderRadius}px;
|
|
132
|
-
`;
|
|
133
|
-
const StyledKYCFormItemFilePreviewName = styled.span `
|
|
134
|
-
width: 100%;
|
|
135
|
-
margin-left: ${spacing * 4}px;
|
|
136
|
-
margin-right: ${spacing * 2}px;
|
|
137
|
-
`;
|
|
138
|
-
const StyledKYCFormItemFilePreviewRemove = styled.span `
|
|
139
|
-
cursor: pointer !important;
|
|
140
|
-
margin-right: ${spacing * 2}px;
|
|
141
|
-
`;
|
|
142
|
-
const StyledKYCFormItemFileUploaderContainer = styled.div `
|
|
143
|
-
height: 66px;
|
|
144
|
-
`;
|
|
145
|
-
const StyledKYCFormItemFileExtraPart = styled.div `
|
|
146
|
-
display: flex;
|
|
147
|
-
flex-direction: column;
|
|
148
|
-
margin-top: ${spacing * 4}px;
|
|
149
|
-
margin-left: ${spacing * 4}px;
|
|
150
|
-
`;
|
|
151
|
-
const StyledKYCDocumentPartImgMiniature = styled.img `
|
|
152
|
-
width: auto;
|
|
153
|
-
height: 50px;
|
|
154
|
-
border-radius: ${borderRadius}px;
|
|
155
|
-
`;
|
|
156
|
-
const StyledKYCDocumentPartIconMiniature = styled.div `
|
|
157
|
-
display: flex;
|
|
158
|
-
align-items: center;
|
|
159
|
-
justify-content: center;
|
|
160
|
-
min-width: 50px;
|
|
161
|
-
height: 50px;
|
|
162
|
-
border-radius: ${borderRadius}px;
|
|
163
|
-
background-color: ${white};
|
|
164
|
-
`;
|
|
165
|
-
|
|
166
|
-
const isDocumentExtraPartAvailable = (documentType) => {
|
|
167
|
-
return AVAILABLE_EXTRA_PARTS_DOCUMENTS.includes(documentType);
|
|
168
|
-
};
|
|
169
|
-
const canAddExtraPart = (documentType, parts) => {
|
|
170
|
-
return isDocumentExtraPartAvailable(documentType)
|
|
171
|
-
&& parts.every((part) => Boolean(part.data))
|
|
172
|
-
&& parts.length < MAX_EXTRA_PARTS_COUNT
|
|
173
|
-
&& parts.length > 0;
|
|
174
|
-
};
|
|
175
|
-
const canRemoveExtraPart = (documentType, parts) => {
|
|
176
|
-
return AVAILABLE_EXTRA_PARTS_DOCUMENTS.includes(documentType) && parts.length > 1;
|
|
177
|
-
};
|
|
178
|
-
const isDocumentsValid = (documents) => {
|
|
179
|
-
return documents.every((document) => {
|
|
180
|
-
return document.parts.every((part) => {
|
|
181
|
-
var _a, _b;
|
|
182
|
-
const isPartOptional = !!((_b = (_a = OPTIONAL_DOCUMENT_PARTS[document.type]) === null || _a === void 0 ? void 0 : _a.parts) === null || _b === void 0 ? void 0 : _b.find((value) => value === part.type));
|
|
183
|
-
return isPartOptional || Boolean(part.data);
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
};
|
|
187
|
-
const getMimeType = (partData) => {
|
|
188
|
-
var _a;
|
|
189
|
-
return (_a = partData === null || partData === void 0 ? void 0 : partData.match(/[^:]\w+\/[\w-+\d.]+(?=;|,)/)) === null || _a === void 0 ? void 0 : _a[0];
|
|
190
|
-
};
|
|
191
|
-
const isPDF = (partData) => {
|
|
192
|
-
const mimeType = getMimeType(partData);
|
|
193
|
-
return mimeType === PDF_MIME_TYPE;
|
|
194
|
-
};
|
|
195
|
-
const isHEIC = (partData) => {
|
|
196
|
-
const mimeType = getMimeType(partData);
|
|
197
|
-
return mimeType === HEIC_MIME_TYPE;
|
|
198
|
-
};
|
|
199
|
-
const isFileUniqueInDocument = (file, parts) => {
|
|
200
|
-
return parts.every((part) => part.data !== (file === null || file === void 0 ? void 0 : file.data));
|
|
201
|
-
};
|
|
202
|
-
const getFileBase64 = async (file) => {
|
|
203
|
-
const reader = new FileReader();
|
|
204
|
-
return new Promise((resolve, reject) => {
|
|
205
|
-
reader.onload = () => resolve(reader.result);
|
|
206
|
-
reader.onerror = (error) => reject(error);
|
|
207
|
-
reader.readAsDataURL(file);
|
|
208
|
-
});
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
const KYCDocumentPartMiniature = (props) => {
|
|
212
|
-
const isPDFPart = isPDF(props.data);
|
|
213
|
-
const isHEICPart = isHEIC(props.data);
|
|
214
|
-
if (isPDFPart || isHEICPart) {
|
|
215
|
-
return (React.createElement(StyledKYCDocumentPartIconMiniature, null,
|
|
216
|
-
isPDFPart && (React.createElement(Pdf, { color: COLOR.GRAY, hoverColor: COLOR.GRAY })),
|
|
217
|
-
isHEICPart && (React.createElement(Insert, { color: COLOR.GRAY, hoverColor: COLOR.GRAY }))));
|
|
218
|
-
}
|
|
219
|
-
return (React.createElement(StyledKYCDocumentPartImgMiniature, { src: props.data }));
|
|
220
|
-
};
|
|
221
|
-
const KYCFormItemFileExtraPart = (props) => {
|
|
222
|
-
const { elementId, title, uploaderLabels, onFileAdd, } = props;
|
|
223
|
-
return (React.createElement(StyledKYCFormItemFileExtraPart, { id: elementId },
|
|
224
|
-
title && (React.createElement(StyledKYCFormItemFileTitle, null, title)),
|
|
225
|
-
React.createElement(StyledKYCFormItemFileUploaderContainer, null,
|
|
226
|
-
React.createElement(ImageUploader, { title: uploaderLabels.title, action: uploaderLabels.action, maxSize: MAX_FILE_SIZE, acceptFormats: ACCEPT_FORMATS, elementId: `${elementId}_uploader`, direction: DIRECTION.ROW, onDrop: onFileAdd }))));
|
|
227
|
-
};
|
|
228
|
-
const KYCFormItemFile = (props) => {
|
|
229
|
-
const { name, title, data, error, elementId, uploaderLabels, onFileChange, onFileRemove, } = props;
|
|
230
|
-
return (React.createElement(StyledKYCFormItemFile, { id: elementId },
|
|
231
|
-
title && (React.createElement(StyledKYCFormItemFileTitle, null, title)),
|
|
232
|
-
data ? (React.createElement(StyledKYCFormItemFilePreview, null,
|
|
233
|
-
React.createElement(KYCDocumentPartMiniature, { data: data }),
|
|
234
|
-
React.createElement(StyledKYCFormItemFilePreviewName, null, name),
|
|
235
|
-
React.createElement(StyledKYCFormItemFilePreviewRemove, { onClick: onFileRemove },
|
|
236
|
-
React.createElement(Delete, { color: COLOR.BLUE, hoverColor: COLOR.BLUE })))) : (React.createElement(StyledKYCFormItemFileUploaderContainer, null,
|
|
237
|
-
React.createElement(ImageUploader, { title: uploaderLabels.title, action: uploaderLabels.action, maxSize: MAX_FILE_SIZE, acceptFormats: ACCEPT_FORMATS, elementId: `${elementId}_uploader`, direction: DIRECTION.ROW, onDrop: onFileChange }))),
|
|
238
|
-
error && (React.createElement(KYCErrorLabel, { label: error, isDocumentPartError: true }))));
|
|
239
|
-
};
|
|
240
|
-
var KYCDocumentParts = {
|
|
241
|
-
KYCFormItemFileExtraPart,
|
|
242
|
-
KYCFormItemFile,
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
const StyledKYCFormItem = styled.div `
|
|
246
|
-
margin-top: ${spacing * 6}px;
|
|
247
|
-
`;
|
|
248
|
-
const StyledKYCFormItemTitle = styled.div `
|
|
249
|
-
font-size: ${fontNormal}px;
|
|
250
|
-
font-weight: bold;
|
|
251
|
-
color: ${black};
|
|
252
|
-
margin-bottom: ${spacing}px;
|
|
253
|
-
`;
|
|
254
|
-
const StyledKYCFormItemDescription = styled.div `
|
|
255
|
-
font-size: ${fontSmall}px;
|
|
256
|
-
color: ${gray50};
|
|
257
|
-
margin-left: ${spacing * 4}px;
|
|
258
|
-
`;
|
|
259
|
-
|
|
260
|
-
const getErrorKey = (documentIndex, partIndex) => `[${documentIndex}].parts[${partIndex}].data`;
|
|
261
|
-
const KYCFormItem = (props) => {
|
|
262
|
-
var _a;
|
|
263
|
-
const { type, index, uploaderLabels, documentLabels, elementId, parts, errors, onDocumentChange, } = props;
|
|
264
|
-
const [localErrors, setLocalErrors] = useState(new Map());
|
|
265
|
-
const isAddExtraPartAvailable = canAddExtraPart(type, parts);
|
|
266
|
-
const documentLabelsParts = documentLabels === null || documentLabels === void 0 ? void 0 : documentLabels.parts;
|
|
267
|
-
const [fileNames, setFileNames] = useState(new Map());
|
|
268
|
-
const setLocalErrorByPartIndex = (partIndex) => {
|
|
269
|
-
const newLocalErrors = new Map(localErrors);
|
|
270
|
-
newLocalErrors.set(getErrorKey(index, partIndex), uploaderLabels.oversizeError);
|
|
271
|
-
setLocalErrors(newLocalErrors);
|
|
272
|
-
};
|
|
273
|
-
const deleteLocalErrorByPartIndex = (partIndex) => {
|
|
274
|
-
const newLocalErrors = new Map(localErrors);
|
|
275
|
-
newLocalErrors.delete(getErrorKey(index, partIndex));
|
|
276
|
-
setLocalErrors(newLocalErrors);
|
|
277
|
-
};
|
|
278
|
-
const updateDocumentPart = (part, partIndex, data) => {
|
|
279
|
-
const newPart = {
|
|
280
|
-
...part,
|
|
281
|
-
data,
|
|
282
|
-
};
|
|
283
|
-
const newParts = [...parts];
|
|
284
|
-
newParts.splice(partIndex, 1, newPart);
|
|
285
|
-
const newDocument = {
|
|
286
|
-
type,
|
|
287
|
-
parts: newParts,
|
|
288
|
-
};
|
|
289
|
-
onDocumentChange(newDocument);
|
|
290
|
-
};
|
|
291
|
-
const onFileChange = async (partIndex, file) => {
|
|
292
|
-
if (!file) {
|
|
293
|
-
setLocalErrorByPartIndex(partIndex);
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
const part = parts[partIndex] || parts[0];
|
|
297
|
-
const data = await getFileBase64(file);
|
|
298
|
-
updateDocumentPart(part, partIndex, data);
|
|
299
|
-
const newFileNames = new Map(fileNames);
|
|
300
|
-
newFileNames.set(data, file.name);
|
|
301
|
-
setFileNames(newFileNames);
|
|
302
|
-
deleteLocalErrorByPartIndex(partIndex);
|
|
303
|
-
};
|
|
304
|
-
const onPartRemove = (partIndex) => {
|
|
305
|
-
const newParts = parts.filter((item, idx) => idx !== partIndex);
|
|
306
|
-
const newDocument = {
|
|
307
|
-
type,
|
|
308
|
-
parts: newParts,
|
|
309
|
-
};
|
|
310
|
-
onDocumentChange(newDocument);
|
|
311
|
-
};
|
|
312
|
-
const onFileRemove = (partIndex) => {
|
|
313
|
-
const isRemoveExtraPartAvailable = canRemoveExtraPart(type, parts);
|
|
314
|
-
if (isRemoveExtraPartAvailable) {
|
|
315
|
-
onPartRemove(partIndex);
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
const part = parts[partIndex];
|
|
319
|
-
updateDocumentPart(part, partIndex);
|
|
320
|
-
const removedPart = parts[partIndex];
|
|
321
|
-
const newFileNames = new Map(fileNames);
|
|
322
|
-
if ((removedPart === null || removedPart === void 0 ? void 0 : removedPart.data) && isFileUniqueInDocument(removedPart, parts)) {
|
|
323
|
-
newFileNames.delete(removedPart === null || removedPart === void 0 ? void 0 : removedPart.data);
|
|
324
|
-
}
|
|
325
|
-
setFileNames(newFileNames);
|
|
326
|
-
deleteLocalErrorByPartIndex(partIndex);
|
|
327
|
-
};
|
|
328
|
-
const getFileName = (key) => {
|
|
329
|
-
if (!key) {
|
|
330
|
-
return undefined;
|
|
331
|
-
}
|
|
332
|
-
return fileNames.get(key);
|
|
333
|
-
};
|
|
334
|
-
return (React.createElement(StyledKYCFormItem, { id: elementId },
|
|
335
|
-
React.createElement(StyledKYCFormItemTitle, null,
|
|
336
|
-
index + 1,
|
|
337
|
-
". ", documentLabels === null || documentLabels === void 0 ? void 0 :
|
|
338
|
-
documentLabels.title),
|
|
339
|
-
(documentLabels === null || documentLabels === void 0 ? void 0 : documentLabels.description) && (React.createElement(StyledKYCFormItemDescription, null, documentLabels === null || documentLabels === void 0 ? void 0 : documentLabels.description)),
|
|
340
|
-
parts.map((part, partIndex) => {
|
|
341
|
-
var _a;
|
|
342
|
-
let itemKey = `kyc-form_item_file_${part.type}`;
|
|
343
|
-
const isExtraPartAvailable = isDocumentExtraPartAvailable(type);
|
|
344
|
-
const partLabels = documentLabelsParts === null || documentLabelsParts === void 0 ? void 0 : documentLabelsParts[part.type];
|
|
345
|
-
const partTitle = isExtraPartAvailable ? undefined : partLabels === null || partLabels === void 0 ? void 0 : partLabels.title;
|
|
346
|
-
if (isDocumentExtraPartAvailable(type) && part.data) {
|
|
347
|
-
itemKey = `${itemKey}_${(_a = part.data) === null || _a === void 0 ? void 0 : _a.substr(-32)}`;
|
|
348
|
-
if (!isFileUniqueInDocument(part, parts)) {
|
|
349
|
-
itemKey = `${itemKey}_${partIndex}`;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
const partError = errors === null || errors === void 0 ? void 0 : errors[getErrorKey(index, partIndex)];
|
|
353
|
-
const localPartError = localErrors.get(getErrorKey(index, partIndex));
|
|
354
|
-
return (React.createElement(KYCDocumentParts.KYCFormItemFile, { title: partTitle, data: part.data, type: part.type, name: getFileName(part.data), uploaderLabels: uploaderLabels, error: localPartError || partError, key: itemKey, elementId: `${elementId}_part_${part.type}_${partIndex}`, onFileChange: (file) => onFileChange(partIndex, file), onFileRemove: () => onFileRemove(partIndex) }));
|
|
355
|
-
}),
|
|
356
|
-
isAddExtraPartAvailable && (React.createElement(KYCDocumentParts.KYCFormItemFileExtraPart, { elementId: `${elementId}_extra`, title: (_a = documentLabelsParts === null || documentLabelsParts === void 0 ? void 0 : documentLabelsParts[parts[0].type]) === null || _a === void 0 ? void 0 : _a.title, uploaderLabels: uploaderLabels, onFileAdd: (file) => onFileChange(parts.length, file) }))));
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
const StyledKYCForm = styled.div `
|
|
360
|
-
display: flex;
|
|
361
|
-
flex-direction: column;
|
|
362
|
-
align-items: flex-start;
|
|
363
|
-
width: 100%;
|
|
364
|
-
`;
|
|
365
|
-
const StyledKYCFormTitle = styled.div `
|
|
366
|
-
font-size: ${fontNormal}px;
|
|
367
|
-
`;
|
|
368
|
-
const StyledKYCFormDocuments = styled.div `
|
|
369
|
-
width: 100%;
|
|
370
|
-
margin-bottom: ${spacing * 6}px;
|
|
371
|
-
`;
|
|
372
|
-
const StyledKYCFormButton = styled.div `
|
|
373
|
-
display: flex;
|
|
374
|
-
justify-content: flex-end;
|
|
375
|
-
width: 100%;
|
|
376
|
-
`;
|
|
377
|
-
|
|
378
|
-
const KYCForm = (props) => {
|
|
379
|
-
const { elementId, title, uploadButtonLabel, uploaderLabels, documentsLabels, documents, errors, isLoading, onUploadClick, } = props;
|
|
380
|
-
const [userDocuments, setUserDocuments] = useState(documents);
|
|
381
|
-
const [isButtonDisabled, setButtonDisabled] = useState(true);
|
|
382
|
-
useEffect(() => {
|
|
383
|
-
setUserDocuments(documents);
|
|
384
|
-
}, [documents]);
|
|
385
|
-
useEffect(() => {
|
|
386
|
-
const isValid = isDocumentsValid(userDocuments);
|
|
387
|
-
setButtonDisabled(!isValid);
|
|
388
|
-
}, [userDocuments]);
|
|
389
|
-
const onDocumentChange = (index, document) => {
|
|
390
|
-
const newDocuments = [...userDocuments];
|
|
391
|
-
newDocuments.splice(index, 1, document);
|
|
392
|
-
setUserDocuments(newDocuments);
|
|
393
|
-
};
|
|
394
|
-
return (React.createElement(StyledKYCForm, { id: elementId },
|
|
395
|
-
title && (React.createElement(StyledKYCFormTitle, null, title)),
|
|
396
|
-
React.createElement(StyledKYCFormDocuments, null, userDocuments.map((document, index) => (React.createElement(KYCFormItem, { index: index, type: document.type, parts: document.parts, documentLabels: documentsLabels[document.type], uploaderLabels: uploaderLabels, errors: errors, elementId: `${elementId}_item_${document.type}`, key: `kyc-form_item_${document.type}_${index}`, onDocumentChange: (document) => onDocumentChange(index, document) })))),
|
|
397
|
-
React.createElement(StyledKYCFormButton, null,
|
|
398
|
-
React.createElement(Button, { elementId: `${elementId}_button`, type: BUTTON_TYPE.PRIMARY, isDisabled: isButtonDisabled, isLoading: isLoading || false, onClick: () => onUploadClick(userDocuments) }, uploadButtonLabel))));
|
|
399
|
-
};
|
|
400
|
-
KYCForm.SucessScreen = KYCStatusScreen.KYCSucessScreen;
|
|
401
|
-
KYCForm.FailScreen = KYCStatusScreen.KYCFailScreen;
|
|
402
|
-
|
|
403
|
-
export default KYCForm;
|
|
404
|
-
export { ACCEPT_FORMATS, AVAILABLE_EXTRA_PARTS_DOCUMENTS, DOCUMENT_TYPES, MAX_EXTRA_PARTS_COUNT, MAX_FILE_SIZE, OPTIONAL_DOCUMENT_PARTS, PART_TYPES, PDF_MIME_TYPE };
|