@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.
@@ -0,0 +1,1374 @@
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 TextArea from '@propellerads/textarea';
8
+ import ImageUploader, { DIRECTION } from '@propellerads/image-uploader';
9
+
10
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
11
+ try {
12
+ var info = gen[key](arg);
13
+ var value = info.value;
14
+ } catch (error) {
15
+ reject(error);
16
+ return;
17
+ }
18
+
19
+ if (info.done) {
20
+ resolve(value);
21
+ } else {
22
+ Promise.resolve(value).then(_next, _throw);
23
+ }
24
+ }
25
+
26
+ function _asyncToGenerator(fn) {
27
+ return function () {
28
+ var self = this,
29
+ args = arguments;
30
+ return new Promise(function (resolve, reject) {
31
+ var gen = fn.apply(self, args);
32
+
33
+ function _next(value) {
34
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
35
+ }
36
+
37
+ function _throw(err) {
38
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
39
+ }
40
+
41
+ _next(undefined);
42
+ });
43
+ };
44
+ }
45
+
46
+ function _extends() {
47
+ _extends = Object.assign || function (target) {
48
+ for (var i = 1; i < arguments.length; i++) {
49
+ var source = arguments[i];
50
+
51
+ for (var key in source) {
52
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
53
+ target[key] = source[key];
54
+ }
55
+ }
56
+ }
57
+
58
+ return target;
59
+ };
60
+
61
+ return _extends.apply(this, arguments);
62
+ }
63
+
64
+ function _taggedTemplateLiteralLoose(strings, raw) {
65
+ if (!raw) {
66
+ raw = strings.slice(0);
67
+ }
68
+
69
+ strings.raw = raw;
70
+ return strings;
71
+ }
72
+
73
+ var _templateObject, _templateObject2, _templateObject3;
74
+ var StyledKYCErrorLabel = /*#__PURE__*/styled.div(_templateObject || (_templateObject = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n color: ", ";\n margin-top: ", "px;\n margin-bottom: ", "px;\n"])), errorColor, spacing * 2, spacing * 4);
75
+ var StyledKYCErrorLabelIcon = /*#__PURE__*/styled.span(_templateObject2 || (_templateObject2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n justify-content: center;\n width: 14px;\n height: 14px;\n border-radius: 100%;\n background-color: ", ";\n\n &:before {\n font-size: ", ";\n color: ", ";\n content: '!';\n }\n"])), errorColor, fontSmall, white);
76
+ var StyledKYCErrorLabelText = /*#__PURE__*/styled.span(_templateObject3 || (_templateObject3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-left: ", "px;\n"])), spacing * 2);
77
+
78
+ var KYCErrorLabel = function KYCErrorLabel(props) {
79
+ return React.createElement(StyledKYCErrorLabel, null, props.isDocumentPartError ? React.createElement(StyledKYCErrorLabelIcon, null) : React.createElement(Close, {
80
+ color: COLOR.ERROR,
81
+ hoverColor: COLOR.ERROR,
82
+ size: SIZE.SMALL
83
+ }), React.createElement(StyledKYCErrorLabelText, null, props.label));
84
+ };
85
+
86
+ var _templateObject$1, _templateObject2$1, _templateObject3$1, _templateObject4, _templateObject5;
87
+ var StyledKYCSucessScreen = /*#__PURE__*/styled.div(_templateObject$1 || (_templateObject$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n flex-direction: column;\n"])));
88
+ var StyledKYCSucessScreenItem = /*#__PURE__*/styled.span(_templateObject2$1 || (_templateObject2$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-bottom: ", "px;\n"])), spacing * 8);
89
+ var StyledKYCSucessScreenSuppport = /*#__PURE__*/styled.span(_templateObject3$1 || (_templateObject3$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n color: ", ";\n"])), gray50);
90
+ var StyledKYCFailScreen = /*#__PURE__*/styled.div(_templateObject4 || (_templateObject4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n flex-direction: column;\n"])));
91
+ var StyledKYCFailScreenItem = /*#__PURE__*/styled.span(_templateObject5 || (_templateObject5 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-bottom: ", "px;\n"])), spacing * 6);
92
+
93
+ var DOCUMENT_TYPES;
94
+
95
+ (function (DOCUMENT_TYPES) {
96
+ DOCUMENT_TYPES["ID"] = "id";
97
+ DOCUMENT_TYPES["UB"] = "ub";
98
+ DOCUMENT_TYPES["ID_EXTRA"] = "id_extra";
99
+ DOCUMENT_TYPES["CARD"] = "bank_card";
100
+ DOCUMENT_TYPES["PAYMENT_SYSTEM_SCREEN"] = "payment_system_screen";
101
+ DOCUMENT_TYPES["ONLINE_BANKING_STATEMENT"] = "online_banking_statement";
102
+ DOCUMENT_TYPES["COMPANY_REGISTRATION_DOCUMENT"] = "company_registration_document";
103
+ DOCUMENT_TYPES["SELFIE_WITH_ID_CARD"] = "selfie_with_id_card_or_bank_card";
104
+ DOCUMENT_TYPES["FEEDBACK"] = "feedback";
105
+ })(DOCUMENT_TYPES || (DOCUMENT_TYPES = {}));
106
+
107
+ var PART_TYPES;
108
+
109
+ (function (PART_TYPES) {
110
+ PART_TYPES["ID_FRONT"] = "id_front";
111
+ PART_TYPES["ID_BACK"] = "id_back";
112
+ PART_TYPES["UB"] = "ub_item";
113
+ PART_TYPES["CARD"] = "card_item";
114
+ PART_TYPES["PAYMENT_SYSTEM_SCREEN"] = "screen_item";
115
+ PART_TYPES["ONLINE_BANKING_STATEMENT"] = "obs_item";
116
+ PART_TYPES["COMPANY_REGISTRATION_DOCUMENT"] = "crd_item";
117
+ PART_TYPES["SELFIE_WITH_ID_CARD"] = "selfie_item";
118
+ PART_TYPES["FEEDBACK"] = "feedback";
119
+ })(PART_TYPES || (PART_TYPES = {}));
120
+
121
+ var _OPTIONAL_DOCUMENT_PA;
122
+ var MAX_FILE_SIZE = 5242880;
123
+ var MAX_EXTRA_PARTS_COUNT = 15;
124
+ var PDF_MIME_TYPE = 'application/pdf';
125
+ var HEIC_MIME_TYPE = 'image/heic';
126
+ var ACCEPT_FORMATS = ".png,.jpg,.jpe,.jpeg,.pdf,image/png,image/jpeg," + PDF_MIME_TYPE + "," + HEIC_MIME_TYPE;
127
+ var AVAILABLE_EXTRA_PARTS_DOCUMENTS = [DOCUMENT_TYPES.CARD];
128
+ var OPTIONAL_DOCUMENT_PARTS = (_OPTIONAL_DOCUMENT_PA = {}, _OPTIONAL_DOCUMENT_PA[DOCUMENT_TYPES.ID] = {
129
+ parts: [PART_TYPES.ID_BACK]
130
+ }, _OPTIONAL_DOCUMENT_PA[DOCUMENT_TYPES.ID_EXTRA] = {
131
+ parts: [PART_TYPES.ID_BACK]
132
+ }, _OPTIONAL_DOCUMENT_PA);
133
+
134
+ var KYCSucessScreen = function KYCSucessScreen(props) {
135
+ var elementId = props.elementId,
136
+ title = props.title,
137
+ description = props.description,
138
+ support = props.support;
139
+ return React.createElement(StyledKYCSucessScreen, {
140
+ id: elementId
141
+ }, React.createElement(StyledKYCSucessScreenItem, null, React.createElement(SuccessLabel, {
142
+ show: true,
143
+ elementId: elementId + "_success"
144
+ }, title)), description && React.createElement(StyledKYCSucessScreenItem, null, description), support && React.createElement(StyledKYCSucessScreenSuppport, null, support));
145
+ };
146
+
147
+ var KYCFailScreen = function KYCFailScreen(props) {
148
+ var elementId = props.elementId,
149
+ title = props.title,
150
+ support = props.support;
151
+ return React.createElement(StyledKYCFailScreen, {
152
+ id: elementId
153
+ }, React.createElement(StyledKYCFailScreenItem, null, React.createElement(KYCErrorLabel, {
154
+ label: title,
155
+ isDocumentPartError: false
156
+ })), support);
157
+ };
158
+
159
+ var KYCStatusScreen = {
160
+ KYCSucessScreen: KYCSucessScreen,
161
+ KYCFailScreen: KYCFailScreen
162
+ };
163
+
164
+ function createCommonjsModule(fn, module) {
165
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
166
+ }
167
+
168
+ var runtime_1 = createCommonjsModule(function (module) {
169
+ /**
170
+ * Copyright (c) 2014-present, Facebook, Inc.
171
+ *
172
+ * This source code is licensed under the MIT license found in the
173
+ * LICENSE file in the root directory of this source tree.
174
+ */
175
+
176
+ var runtime = (function (exports) {
177
+
178
+ var Op = Object.prototype;
179
+ var hasOwn = Op.hasOwnProperty;
180
+ var undefined$1; // More compressible than void 0.
181
+ var $Symbol = typeof Symbol === "function" ? Symbol : {};
182
+ var iteratorSymbol = $Symbol.iterator || "@@iterator";
183
+ var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
184
+ var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
185
+
186
+ function define(obj, key, value) {
187
+ Object.defineProperty(obj, key, {
188
+ value: value,
189
+ enumerable: true,
190
+ configurable: true,
191
+ writable: true
192
+ });
193
+ return obj[key];
194
+ }
195
+ try {
196
+ // IE 8 has a broken Object.defineProperty that only works on DOM objects.
197
+ define({}, "");
198
+ } catch (err) {
199
+ define = function(obj, key, value) {
200
+ return obj[key] = value;
201
+ };
202
+ }
203
+
204
+ function wrap(innerFn, outerFn, self, tryLocsList) {
205
+ // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
206
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
207
+ var generator = Object.create(protoGenerator.prototype);
208
+ var context = new Context(tryLocsList || []);
209
+
210
+ // The ._invoke method unifies the implementations of the .next,
211
+ // .throw, and .return methods.
212
+ generator._invoke = makeInvokeMethod(innerFn, self, context);
213
+
214
+ return generator;
215
+ }
216
+ exports.wrap = wrap;
217
+
218
+ // Try/catch helper to minimize deoptimizations. Returns a completion
219
+ // record like context.tryEntries[i].completion. This interface could
220
+ // have been (and was previously) designed to take a closure to be
221
+ // invoked without arguments, but in all the cases we care about we
222
+ // already have an existing method we want to call, so there's no need
223
+ // to create a new function object. We can even get away with assuming
224
+ // the method takes exactly one argument, since that happens to be true
225
+ // in every case, so we don't have to touch the arguments object. The
226
+ // only additional allocation required is the completion record, which
227
+ // has a stable shape and so hopefully should be cheap to allocate.
228
+ function tryCatch(fn, obj, arg) {
229
+ try {
230
+ return { type: "normal", arg: fn.call(obj, arg) };
231
+ } catch (err) {
232
+ return { type: "throw", arg: err };
233
+ }
234
+ }
235
+
236
+ var GenStateSuspendedStart = "suspendedStart";
237
+ var GenStateSuspendedYield = "suspendedYield";
238
+ var GenStateExecuting = "executing";
239
+ var GenStateCompleted = "completed";
240
+
241
+ // Returning this object from the innerFn has the same effect as
242
+ // breaking out of the dispatch switch statement.
243
+ var ContinueSentinel = {};
244
+
245
+ // Dummy constructor functions that we use as the .constructor and
246
+ // .constructor.prototype properties for functions that return Generator
247
+ // objects. For full spec compliance, you may wish to configure your
248
+ // minifier not to mangle the names of these two functions.
249
+ function Generator() {}
250
+ function GeneratorFunction() {}
251
+ function GeneratorFunctionPrototype() {}
252
+
253
+ // This is a polyfill for %IteratorPrototype% for environments that
254
+ // don't natively support it.
255
+ var IteratorPrototype = {};
256
+ define(IteratorPrototype, iteratorSymbol, function () {
257
+ return this;
258
+ });
259
+
260
+ var getProto = Object.getPrototypeOf;
261
+ var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
262
+ if (NativeIteratorPrototype &&
263
+ NativeIteratorPrototype !== Op &&
264
+ hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
265
+ // This environment has a native %IteratorPrototype%; use it instead
266
+ // of the polyfill.
267
+ IteratorPrototype = NativeIteratorPrototype;
268
+ }
269
+
270
+ var Gp = GeneratorFunctionPrototype.prototype =
271
+ Generator.prototype = Object.create(IteratorPrototype);
272
+ GeneratorFunction.prototype = GeneratorFunctionPrototype;
273
+ define(Gp, "constructor", GeneratorFunctionPrototype);
274
+ define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
275
+ GeneratorFunction.displayName = define(
276
+ GeneratorFunctionPrototype,
277
+ toStringTagSymbol,
278
+ "GeneratorFunction"
279
+ );
280
+
281
+ // Helper for defining the .next, .throw, and .return methods of the
282
+ // Iterator interface in terms of a single ._invoke method.
283
+ function defineIteratorMethods(prototype) {
284
+ ["next", "throw", "return"].forEach(function(method) {
285
+ define(prototype, method, function(arg) {
286
+ return this._invoke(method, arg);
287
+ });
288
+ });
289
+ }
290
+
291
+ exports.isGeneratorFunction = function(genFun) {
292
+ var ctor = typeof genFun === "function" && genFun.constructor;
293
+ return ctor
294
+ ? ctor === GeneratorFunction ||
295
+ // For the native GeneratorFunction constructor, the best we can
296
+ // do is to check its .name property.
297
+ (ctor.displayName || ctor.name) === "GeneratorFunction"
298
+ : false;
299
+ };
300
+
301
+ exports.mark = function(genFun) {
302
+ if (Object.setPrototypeOf) {
303
+ Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
304
+ } else {
305
+ genFun.__proto__ = GeneratorFunctionPrototype;
306
+ define(genFun, toStringTagSymbol, "GeneratorFunction");
307
+ }
308
+ genFun.prototype = Object.create(Gp);
309
+ return genFun;
310
+ };
311
+
312
+ // Within the body of any async function, `await x` is transformed to
313
+ // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
314
+ // `hasOwn.call(value, "__await")` to determine if the yielded value is
315
+ // meant to be awaited.
316
+ exports.awrap = function(arg) {
317
+ return { __await: arg };
318
+ };
319
+
320
+ function AsyncIterator(generator, PromiseImpl) {
321
+ function invoke(method, arg, resolve, reject) {
322
+ var record = tryCatch(generator[method], generator, arg);
323
+ if (record.type === "throw") {
324
+ reject(record.arg);
325
+ } else {
326
+ var result = record.arg;
327
+ var value = result.value;
328
+ if (value &&
329
+ typeof value === "object" &&
330
+ hasOwn.call(value, "__await")) {
331
+ return PromiseImpl.resolve(value.__await).then(function(value) {
332
+ invoke("next", value, resolve, reject);
333
+ }, function(err) {
334
+ invoke("throw", err, resolve, reject);
335
+ });
336
+ }
337
+
338
+ return PromiseImpl.resolve(value).then(function(unwrapped) {
339
+ // When a yielded Promise is resolved, its final value becomes
340
+ // the .value of the Promise<{value,done}> result for the
341
+ // current iteration.
342
+ result.value = unwrapped;
343
+ resolve(result);
344
+ }, function(error) {
345
+ // If a rejected Promise was yielded, throw the rejection back
346
+ // into the async generator function so it can be handled there.
347
+ return invoke("throw", error, resolve, reject);
348
+ });
349
+ }
350
+ }
351
+
352
+ var previousPromise;
353
+
354
+ function enqueue(method, arg) {
355
+ function callInvokeWithMethodAndArg() {
356
+ return new PromiseImpl(function(resolve, reject) {
357
+ invoke(method, arg, resolve, reject);
358
+ });
359
+ }
360
+
361
+ return previousPromise =
362
+ // If enqueue has been called before, then we want to wait until
363
+ // all previous Promises have been resolved before calling invoke,
364
+ // so that results are always delivered in the correct order. If
365
+ // enqueue has not been called before, then it is important to
366
+ // call invoke immediately, without waiting on a callback to fire,
367
+ // so that the async generator function has the opportunity to do
368
+ // any necessary setup in a predictable way. This predictability
369
+ // is why the Promise constructor synchronously invokes its
370
+ // executor callback, and why async functions synchronously
371
+ // execute code before the first await. Since we implement simple
372
+ // async functions in terms of async generators, it is especially
373
+ // important to get this right, even though it requires care.
374
+ previousPromise ? previousPromise.then(
375
+ callInvokeWithMethodAndArg,
376
+ // Avoid propagating failures to Promises returned by later
377
+ // invocations of the iterator.
378
+ callInvokeWithMethodAndArg
379
+ ) : callInvokeWithMethodAndArg();
380
+ }
381
+
382
+ // Define the unified helper method that is used to implement .next,
383
+ // .throw, and .return (see defineIteratorMethods).
384
+ this._invoke = enqueue;
385
+ }
386
+
387
+ defineIteratorMethods(AsyncIterator.prototype);
388
+ define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
389
+ return this;
390
+ });
391
+ exports.AsyncIterator = AsyncIterator;
392
+
393
+ // Note that simple async functions are implemented on top of
394
+ // AsyncIterator objects; they just return a Promise for the value of
395
+ // the final result produced by the iterator.
396
+ exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
397
+ if (PromiseImpl === void 0) PromiseImpl = Promise;
398
+
399
+ var iter = new AsyncIterator(
400
+ wrap(innerFn, outerFn, self, tryLocsList),
401
+ PromiseImpl
402
+ );
403
+
404
+ return exports.isGeneratorFunction(outerFn)
405
+ ? iter // If outerFn is a generator, return the full iterator.
406
+ : iter.next().then(function(result) {
407
+ return result.done ? result.value : iter.next();
408
+ });
409
+ };
410
+
411
+ function makeInvokeMethod(innerFn, self, context) {
412
+ var state = GenStateSuspendedStart;
413
+
414
+ return function invoke(method, arg) {
415
+ if (state === GenStateExecuting) {
416
+ throw new Error("Generator is already running");
417
+ }
418
+
419
+ if (state === GenStateCompleted) {
420
+ if (method === "throw") {
421
+ throw arg;
422
+ }
423
+
424
+ // Be forgiving, per 25.3.3.3.3 of the spec:
425
+ // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
426
+ return doneResult();
427
+ }
428
+
429
+ context.method = method;
430
+ context.arg = arg;
431
+
432
+ while (true) {
433
+ var delegate = context.delegate;
434
+ if (delegate) {
435
+ var delegateResult = maybeInvokeDelegate(delegate, context);
436
+ if (delegateResult) {
437
+ if (delegateResult === ContinueSentinel) continue;
438
+ return delegateResult;
439
+ }
440
+ }
441
+
442
+ if (context.method === "next") {
443
+ // Setting context._sent for legacy support of Babel's
444
+ // function.sent implementation.
445
+ context.sent = context._sent = context.arg;
446
+
447
+ } else if (context.method === "throw") {
448
+ if (state === GenStateSuspendedStart) {
449
+ state = GenStateCompleted;
450
+ throw context.arg;
451
+ }
452
+
453
+ context.dispatchException(context.arg);
454
+
455
+ } else if (context.method === "return") {
456
+ context.abrupt("return", context.arg);
457
+ }
458
+
459
+ state = GenStateExecuting;
460
+
461
+ var record = tryCatch(innerFn, self, context);
462
+ if (record.type === "normal") {
463
+ // If an exception is thrown from innerFn, we leave state ===
464
+ // GenStateExecuting and loop back for another invocation.
465
+ state = context.done
466
+ ? GenStateCompleted
467
+ : GenStateSuspendedYield;
468
+
469
+ if (record.arg === ContinueSentinel) {
470
+ continue;
471
+ }
472
+
473
+ return {
474
+ value: record.arg,
475
+ done: context.done
476
+ };
477
+
478
+ } else if (record.type === "throw") {
479
+ state = GenStateCompleted;
480
+ // Dispatch the exception by looping back around to the
481
+ // context.dispatchException(context.arg) call above.
482
+ context.method = "throw";
483
+ context.arg = record.arg;
484
+ }
485
+ }
486
+ };
487
+ }
488
+
489
+ // Call delegate.iterator[context.method](context.arg) and handle the
490
+ // result, either by returning a { value, done } result from the
491
+ // delegate iterator, or by modifying context.method and context.arg,
492
+ // setting context.delegate to null, and returning the ContinueSentinel.
493
+ function maybeInvokeDelegate(delegate, context) {
494
+ var method = delegate.iterator[context.method];
495
+ if (method === undefined$1) {
496
+ // A .throw or .return when the delegate iterator has no .throw
497
+ // method always terminates the yield* loop.
498
+ context.delegate = null;
499
+
500
+ if (context.method === "throw") {
501
+ // Note: ["return"] must be used for ES3 parsing compatibility.
502
+ if (delegate.iterator["return"]) {
503
+ // If the delegate iterator has a return method, give it a
504
+ // chance to clean up.
505
+ context.method = "return";
506
+ context.arg = undefined$1;
507
+ maybeInvokeDelegate(delegate, context);
508
+
509
+ if (context.method === "throw") {
510
+ // If maybeInvokeDelegate(context) changed context.method from
511
+ // "return" to "throw", let that override the TypeError below.
512
+ return ContinueSentinel;
513
+ }
514
+ }
515
+
516
+ context.method = "throw";
517
+ context.arg = new TypeError(
518
+ "The iterator does not provide a 'throw' method");
519
+ }
520
+
521
+ return ContinueSentinel;
522
+ }
523
+
524
+ var record = tryCatch(method, delegate.iterator, context.arg);
525
+
526
+ if (record.type === "throw") {
527
+ context.method = "throw";
528
+ context.arg = record.arg;
529
+ context.delegate = null;
530
+ return ContinueSentinel;
531
+ }
532
+
533
+ var info = record.arg;
534
+
535
+ if (! info) {
536
+ context.method = "throw";
537
+ context.arg = new TypeError("iterator result is not an object");
538
+ context.delegate = null;
539
+ return ContinueSentinel;
540
+ }
541
+
542
+ if (info.done) {
543
+ // Assign the result of the finished delegate to the temporary
544
+ // variable specified by delegate.resultName (see delegateYield).
545
+ context[delegate.resultName] = info.value;
546
+
547
+ // Resume execution at the desired location (see delegateYield).
548
+ context.next = delegate.nextLoc;
549
+
550
+ // If context.method was "throw" but the delegate handled the
551
+ // exception, let the outer generator proceed normally. If
552
+ // context.method was "next", forget context.arg since it has been
553
+ // "consumed" by the delegate iterator. If context.method was
554
+ // "return", allow the original .return call to continue in the
555
+ // outer generator.
556
+ if (context.method !== "return") {
557
+ context.method = "next";
558
+ context.arg = undefined$1;
559
+ }
560
+
561
+ } else {
562
+ // Re-yield the result returned by the delegate method.
563
+ return info;
564
+ }
565
+
566
+ // The delegate iterator is finished, so forget it and continue with
567
+ // the outer generator.
568
+ context.delegate = null;
569
+ return ContinueSentinel;
570
+ }
571
+
572
+ // Define Generator.prototype.{next,throw,return} in terms of the
573
+ // unified ._invoke helper method.
574
+ defineIteratorMethods(Gp);
575
+
576
+ define(Gp, toStringTagSymbol, "Generator");
577
+
578
+ // A Generator should always return itself as the iterator object when the
579
+ // @@iterator function is called on it. Some browsers' implementations of the
580
+ // iterator prototype chain incorrectly implement this, causing the Generator
581
+ // object to not be returned from this call. This ensures that doesn't happen.
582
+ // See https://github.com/facebook/regenerator/issues/274 for more details.
583
+ define(Gp, iteratorSymbol, function() {
584
+ return this;
585
+ });
586
+
587
+ define(Gp, "toString", function() {
588
+ return "[object Generator]";
589
+ });
590
+
591
+ function pushTryEntry(locs) {
592
+ var entry = { tryLoc: locs[0] };
593
+
594
+ if (1 in locs) {
595
+ entry.catchLoc = locs[1];
596
+ }
597
+
598
+ if (2 in locs) {
599
+ entry.finallyLoc = locs[2];
600
+ entry.afterLoc = locs[3];
601
+ }
602
+
603
+ this.tryEntries.push(entry);
604
+ }
605
+
606
+ function resetTryEntry(entry) {
607
+ var record = entry.completion || {};
608
+ record.type = "normal";
609
+ delete record.arg;
610
+ entry.completion = record;
611
+ }
612
+
613
+ function Context(tryLocsList) {
614
+ // The root entry object (effectively a try statement without a catch
615
+ // or a finally block) gives us a place to store values thrown from
616
+ // locations where there is no enclosing try statement.
617
+ this.tryEntries = [{ tryLoc: "root" }];
618
+ tryLocsList.forEach(pushTryEntry, this);
619
+ this.reset(true);
620
+ }
621
+
622
+ exports.keys = function(object) {
623
+ var keys = [];
624
+ for (var key in object) {
625
+ keys.push(key);
626
+ }
627
+ keys.reverse();
628
+
629
+ // Rather than returning an object with a next method, we keep
630
+ // things simple and return the next function itself.
631
+ return function next() {
632
+ while (keys.length) {
633
+ var key = keys.pop();
634
+ if (key in object) {
635
+ next.value = key;
636
+ next.done = false;
637
+ return next;
638
+ }
639
+ }
640
+
641
+ // To avoid creating an additional object, we just hang the .value
642
+ // and .done properties off the next function object itself. This
643
+ // also ensures that the minifier will not anonymize the function.
644
+ next.done = true;
645
+ return next;
646
+ };
647
+ };
648
+
649
+ function values(iterable) {
650
+ if (iterable) {
651
+ var iteratorMethod = iterable[iteratorSymbol];
652
+ if (iteratorMethod) {
653
+ return iteratorMethod.call(iterable);
654
+ }
655
+
656
+ if (typeof iterable.next === "function") {
657
+ return iterable;
658
+ }
659
+
660
+ if (!isNaN(iterable.length)) {
661
+ var i = -1, next = function next() {
662
+ while (++i < iterable.length) {
663
+ if (hasOwn.call(iterable, i)) {
664
+ next.value = iterable[i];
665
+ next.done = false;
666
+ return next;
667
+ }
668
+ }
669
+
670
+ next.value = undefined$1;
671
+ next.done = true;
672
+
673
+ return next;
674
+ };
675
+
676
+ return next.next = next;
677
+ }
678
+ }
679
+
680
+ // Return an iterator with no values.
681
+ return { next: doneResult };
682
+ }
683
+ exports.values = values;
684
+
685
+ function doneResult() {
686
+ return { value: undefined$1, done: true };
687
+ }
688
+
689
+ Context.prototype = {
690
+ constructor: Context,
691
+
692
+ reset: function(skipTempReset) {
693
+ this.prev = 0;
694
+ this.next = 0;
695
+ // Resetting context._sent for legacy support of Babel's
696
+ // function.sent implementation.
697
+ this.sent = this._sent = undefined$1;
698
+ this.done = false;
699
+ this.delegate = null;
700
+
701
+ this.method = "next";
702
+ this.arg = undefined$1;
703
+
704
+ this.tryEntries.forEach(resetTryEntry);
705
+
706
+ if (!skipTempReset) {
707
+ for (var name in this) {
708
+ // Not sure about the optimal order of these conditions:
709
+ if (name.charAt(0) === "t" &&
710
+ hasOwn.call(this, name) &&
711
+ !isNaN(+name.slice(1))) {
712
+ this[name] = undefined$1;
713
+ }
714
+ }
715
+ }
716
+ },
717
+
718
+ stop: function() {
719
+ this.done = true;
720
+
721
+ var rootEntry = this.tryEntries[0];
722
+ var rootRecord = rootEntry.completion;
723
+ if (rootRecord.type === "throw") {
724
+ throw rootRecord.arg;
725
+ }
726
+
727
+ return this.rval;
728
+ },
729
+
730
+ dispatchException: function(exception) {
731
+ if (this.done) {
732
+ throw exception;
733
+ }
734
+
735
+ var context = this;
736
+ function handle(loc, caught) {
737
+ record.type = "throw";
738
+ record.arg = exception;
739
+ context.next = loc;
740
+
741
+ if (caught) {
742
+ // If the dispatched exception was caught by a catch block,
743
+ // then let that catch block handle the exception normally.
744
+ context.method = "next";
745
+ context.arg = undefined$1;
746
+ }
747
+
748
+ return !! caught;
749
+ }
750
+
751
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
752
+ var entry = this.tryEntries[i];
753
+ var record = entry.completion;
754
+
755
+ if (entry.tryLoc === "root") {
756
+ // Exception thrown outside of any try block that could handle
757
+ // it, so set the completion value of the entire function to
758
+ // throw the exception.
759
+ return handle("end");
760
+ }
761
+
762
+ if (entry.tryLoc <= this.prev) {
763
+ var hasCatch = hasOwn.call(entry, "catchLoc");
764
+ var hasFinally = hasOwn.call(entry, "finallyLoc");
765
+
766
+ if (hasCatch && hasFinally) {
767
+ if (this.prev < entry.catchLoc) {
768
+ return handle(entry.catchLoc, true);
769
+ } else if (this.prev < entry.finallyLoc) {
770
+ return handle(entry.finallyLoc);
771
+ }
772
+
773
+ } else if (hasCatch) {
774
+ if (this.prev < entry.catchLoc) {
775
+ return handle(entry.catchLoc, true);
776
+ }
777
+
778
+ } else if (hasFinally) {
779
+ if (this.prev < entry.finallyLoc) {
780
+ return handle(entry.finallyLoc);
781
+ }
782
+
783
+ } else {
784
+ throw new Error("try statement without catch or finally");
785
+ }
786
+ }
787
+ }
788
+ },
789
+
790
+ abrupt: function(type, arg) {
791
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
792
+ var entry = this.tryEntries[i];
793
+ if (entry.tryLoc <= this.prev &&
794
+ hasOwn.call(entry, "finallyLoc") &&
795
+ this.prev < entry.finallyLoc) {
796
+ var finallyEntry = entry;
797
+ break;
798
+ }
799
+ }
800
+
801
+ if (finallyEntry &&
802
+ (type === "break" ||
803
+ type === "continue") &&
804
+ finallyEntry.tryLoc <= arg &&
805
+ arg <= finallyEntry.finallyLoc) {
806
+ // Ignore the finally entry if control is not jumping to a
807
+ // location outside the try/catch block.
808
+ finallyEntry = null;
809
+ }
810
+
811
+ var record = finallyEntry ? finallyEntry.completion : {};
812
+ record.type = type;
813
+ record.arg = arg;
814
+
815
+ if (finallyEntry) {
816
+ this.method = "next";
817
+ this.next = finallyEntry.finallyLoc;
818
+ return ContinueSentinel;
819
+ }
820
+
821
+ return this.complete(record);
822
+ },
823
+
824
+ complete: function(record, afterLoc) {
825
+ if (record.type === "throw") {
826
+ throw record.arg;
827
+ }
828
+
829
+ if (record.type === "break" ||
830
+ record.type === "continue") {
831
+ this.next = record.arg;
832
+ } else if (record.type === "return") {
833
+ this.rval = this.arg = record.arg;
834
+ this.method = "return";
835
+ this.next = "end";
836
+ } else if (record.type === "normal" && afterLoc) {
837
+ this.next = afterLoc;
838
+ }
839
+
840
+ return ContinueSentinel;
841
+ },
842
+
843
+ finish: function(finallyLoc) {
844
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
845
+ var entry = this.tryEntries[i];
846
+ if (entry.finallyLoc === finallyLoc) {
847
+ this.complete(entry.completion, entry.afterLoc);
848
+ resetTryEntry(entry);
849
+ return ContinueSentinel;
850
+ }
851
+ }
852
+ },
853
+
854
+ "catch": function(tryLoc) {
855
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
856
+ var entry = this.tryEntries[i];
857
+ if (entry.tryLoc === tryLoc) {
858
+ var record = entry.completion;
859
+ if (record.type === "throw") {
860
+ var thrown = record.arg;
861
+ resetTryEntry(entry);
862
+ }
863
+ return thrown;
864
+ }
865
+ }
866
+
867
+ // The context.catch method must only be called with a location
868
+ // argument that corresponds to a known catch block.
869
+ throw new Error("illegal catch attempt");
870
+ },
871
+
872
+ delegateYield: function(iterable, resultName, nextLoc) {
873
+ this.delegate = {
874
+ iterator: values(iterable),
875
+ resultName: resultName,
876
+ nextLoc: nextLoc
877
+ };
878
+
879
+ if (this.method === "next") {
880
+ // Deliberately forget the last sent value so that we don't
881
+ // accidentally pass it on to the delegate.
882
+ this.arg = undefined$1;
883
+ }
884
+
885
+ return ContinueSentinel;
886
+ }
887
+ };
888
+
889
+ // Regardless of whether this script is executing as a CommonJS module
890
+ // or not, return the runtime object so that we can declare the variable
891
+ // regeneratorRuntime in the outer scope, which allows this module to be
892
+ // injected easily by `bin/regenerator --include-runtime script.js`.
893
+ return exports;
894
+
895
+ }(
896
+ // If this script is executing as a CommonJS module, use module.exports
897
+ // as the regeneratorRuntime namespace. Otherwise create a new empty
898
+ // object. Either way, the resulting object will be used to initialize
899
+ // the regeneratorRuntime variable at the top of this file.
900
+ module.exports
901
+ ));
902
+
903
+ try {
904
+ regeneratorRuntime = runtime;
905
+ } catch (accidentalStrictMode) {
906
+ // This module should not be running in strict mode, so the above
907
+ // assignment should always work unless something is misconfigured. Just
908
+ // in case runtime.js accidentally runs in strict mode, in modern engines
909
+ // we can explicitly access globalThis. In older engines we can escape
910
+ // strict mode using a global Function call. This could conceivably fail
911
+ // if a Content Security Policy forbids using Function, but in that case
912
+ // the proper solution is to fix the accidental strict mode problem. If
913
+ // you've misconfigured your bundler to force strict mode and applied a
914
+ // CSP to forbid Function, and you're not willing to fix either of those
915
+ // problems, please detail your unique predicament in a GitHub issue.
916
+ if (typeof globalThis === "object") {
917
+ globalThis.regeneratorRuntime = runtime;
918
+ } else {
919
+ Function("r", "regeneratorRuntime = r")(runtime);
920
+ }
921
+ }
922
+ });
923
+
924
+ var _templateObject$2, _templateObject2$2, _templateObject3$2, _templateObject4$1, _templateObject5$1, _templateObject6, _templateObject7, _templateObject8, _templateObject9;
925
+ var StyledKYCFormItem = /*#__PURE__*/styled.div(_templateObject$2 || (_templateObject$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-top: ", "px;\n margin-left: ", "px;\n"])), spacing * 4, spacing * 4);
926
+ var StyledKYCFormItemFileTitle = /*#__PURE__*/styled.div(_templateObject2$2 || (_templateObject2$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-bottom: ", "px;\n"])), spacing);
927
+ var StyledKYCFormItemFilePreview = /*#__PURE__*/styled.div(_templateObject3$2 || (_templateObject3$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n background-color: ", ";\n padding: ", "px;\n border-radius: ", "px;\n"])), gray95, spacing * 2, borderRadius);
928
+ var StyledKYCFormItemFilePreviewName = /*#__PURE__*/styled.span(_templateObject4$1 || (_templateObject4$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 100%;\n margin-left: ", "px;\n margin-right: ", "px;\n"])), spacing * 4, spacing * 2);
929
+ var StyledKYCFormItemFilePreviewRemove = /*#__PURE__*/styled.span(_templateObject5$1 || (_templateObject5$1 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n cursor: pointer !important;\n margin-right: ", "px;\n"])), spacing * 2);
930
+ var StyledKYCFormItemFileUploaderContainer = /*#__PURE__*/styled.div(_templateObject6 || (_templateObject6 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n height: 66px;\n"])));
931
+ var StyledKYCFormItemFileExtraPart = /*#__PURE__*/styled.div(_templateObject7 || (_templateObject7 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n flex-direction: column;\n margin-top: ", "px;\n margin-left: ", "px;\n"])), spacing * 4, spacing * 4);
932
+ var StyledKYCDocumentPartImgMiniature = /*#__PURE__*/styled.img(_templateObject8 || (_templateObject8 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: auto;\n height: 50px;\n border-radius: ", "px;\n"])), borderRadius);
933
+ var StyledKYCDocumentPartIconMiniature = /*#__PURE__*/styled.div(_templateObject9 || (_templateObject9 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n justify-content: center;\n min-width: 50px;\n height: 50px;\n border-radius: ", "px;\n background-color: ", ";\n"])), borderRadius, white);
934
+
935
+ var isDocumentExtraPartAvailable = function isDocumentExtraPartAvailable(documentType) {
936
+ return AVAILABLE_EXTRA_PARTS_DOCUMENTS.includes(documentType);
937
+ }; // eslint-disable-next-line max-len
938
+
939
+
940
+ var canAddExtraPart = function canAddExtraPart(documentType, parts) {
941
+ return isDocumentExtraPartAvailable(documentType) && parts.every(function (part) {
942
+ return Boolean(part.data);
943
+ }) && parts.length < MAX_EXTRA_PARTS_COUNT && parts.length > 0;
944
+ };
945
+
946
+ var canRemoveExtraPart = function canRemoveExtraPart(documentType, parts) {
947
+ return AVAILABLE_EXTRA_PARTS_DOCUMENTS.includes(documentType) && parts.length > 1;
948
+ };
949
+
950
+ var getMimeType = function getMimeType(partData) {
951
+ var _partData$match;
952
+
953
+ return partData == null ? void 0 : (_partData$match = partData.match(/[^:]\w+\/[\w-+\d.]+(?=;|,)/)) == null ? void 0 : _partData$match[0];
954
+ };
955
+
956
+ var isPDF = function isPDF(partData) {
957
+ var mimeType = getMimeType(partData);
958
+ return mimeType === PDF_MIME_TYPE;
959
+ };
960
+
961
+ var isHEIC = function isHEIC(partData) {
962
+ var mimeType = getMimeType(partData);
963
+ return mimeType === HEIC_MIME_TYPE;
964
+ };
965
+
966
+ var isFileUniqueInDocument = function isFileUniqueInDocument(file, parts) {
967
+ return parts.every(function (part) {
968
+ return part.data !== (file == null ? void 0 : file.data);
969
+ });
970
+ };
971
+
972
+ var getFileBase64 = /*#__PURE__*/function () {
973
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(file) {
974
+ var reader;
975
+ return runtime_1.wrap(function _callee$(_context) {
976
+ while (1) {
977
+ switch (_context.prev = _context.next) {
978
+ case 0:
979
+ reader = new FileReader();
980
+ return _context.abrupt("return", new Promise(function (resolve, reject) {
981
+ reader.onload = function () {
982
+ return resolve(reader.result);
983
+ };
984
+
985
+ reader.onerror = function (error) {
986
+ return reject(error);
987
+ };
988
+
989
+ reader.readAsDataURL(file);
990
+ }));
991
+
992
+ case 2:
993
+ case "end":
994
+ return _context.stop();
995
+ }
996
+ }
997
+ }, _callee);
998
+ }));
999
+
1000
+ return function getFileBase64(_x) {
1001
+ return _ref.apply(this, arguments);
1002
+ };
1003
+ }();
1004
+
1005
+ var KYCDocumentPartMiniature = function KYCDocumentPartMiniature(props) {
1006
+ var data = props.data;
1007
+ var isPDFPart = isPDF(data);
1008
+ var isHEICPart = isHEIC(data);
1009
+
1010
+ if (isPDFPart || isHEICPart) {
1011
+ return React.createElement(StyledKYCDocumentPartIconMiniature, null, isPDFPart && React.createElement(Pdf, {
1012
+ color: COLOR.GRAY,
1013
+ hoverColor: COLOR.GRAY
1014
+ }), isHEICPart && React.createElement(Insert, {
1015
+ color: COLOR.GRAY,
1016
+ hoverColor: COLOR.GRAY
1017
+ }));
1018
+ }
1019
+
1020
+ return React.createElement(StyledKYCDocumentPartImgMiniature, {
1021
+ src: data
1022
+ });
1023
+ };
1024
+
1025
+ var KYCFormItemFileExtraPart = function KYCFormItemFileExtraPart(props) {
1026
+ var elementId = props.elementId,
1027
+ title = props.title,
1028
+ uploaderLabels = props.uploaderLabels,
1029
+ onFileAdd = props.onFileAdd;
1030
+ return React.createElement(StyledKYCFormItemFileExtraPart, {
1031
+ id: elementId
1032
+ }, title && React.createElement(StyledKYCFormItemFileTitle, null, title), React.createElement(StyledKYCFormItemFileUploaderContainer, null, React.createElement(ImageUploader, {
1033
+ title: uploaderLabels.title,
1034
+ action: uploaderLabels.action,
1035
+ maxSize: MAX_FILE_SIZE,
1036
+ acceptFormats: ACCEPT_FORMATS,
1037
+ elementId: elementId + "_uploader",
1038
+ direction: DIRECTION.ROW,
1039
+ onDrop: onFileAdd
1040
+ })));
1041
+ };
1042
+
1043
+ var KYCFormItemFile = function KYCFormItemFile(props) {
1044
+ var name = props.name,
1045
+ title = props.title,
1046
+ data = props.data,
1047
+ error = props.error,
1048
+ elementId = props.elementId,
1049
+ uploaderLabels = props.uploaderLabels,
1050
+ onFileChange = props.onFileChange,
1051
+ onFileRemove = props.onFileRemove;
1052
+ return React.createElement(StyledKYCFormItem, {
1053
+ id: elementId
1054
+ }, title && React.createElement(StyledKYCFormItemFileTitle, null, title), data ? React.createElement(StyledKYCFormItemFilePreview, null, React.createElement(KYCDocumentPartMiniature, {
1055
+ data: data
1056
+ }), React.createElement(StyledKYCFormItemFilePreviewName, null, name), React.createElement(StyledKYCFormItemFilePreviewRemove, {
1057
+ onClick: onFileRemove
1058
+ }, React.createElement(Delete, {
1059
+ color: COLOR.BLUE,
1060
+ hoverColor: COLOR.BLUE
1061
+ }))) : React.createElement(StyledKYCFormItemFileUploaderContainer, null, React.createElement(ImageUploader, {
1062
+ title: uploaderLabels.title,
1063
+ action: uploaderLabels.action,
1064
+ maxSize: MAX_FILE_SIZE,
1065
+ acceptFormats: ACCEPT_FORMATS,
1066
+ elementId: elementId + "_uploader",
1067
+ direction: DIRECTION.ROW,
1068
+ onDrop: onFileChange
1069
+ })), error && React.createElement(KYCErrorLabel, {
1070
+ label: error,
1071
+ isDocumentPartError: true
1072
+ }));
1073
+ };
1074
+
1075
+ var KYCFormItemText = function KYCFormItemText(props) {
1076
+ var onFeedbackChange = props.onFeedbackChange,
1077
+ _props$value = props.value,
1078
+ value = _props$value === void 0 ? '' : _props$value;
1079
+
1080
+ var handleChange = function handleChange(newValue) {
1081
+ return onFeedbackChange(newValue);
1082
+ };
1083
+
1084
+ return React.createElement(StyledKYCFormItem, null, React.createElement(TextArea, {
1085
+ onChange: handleChange,
1086
+ onBlur: handleChange,
1087
+ value: value,
1088
+ errors: [],
1089
+ name: "kyc-client-comments",
1090
+ elementId: "kyc-feedback-textarea"
1091
+ }));
1092
+ };
1093
+
1094
+ var KYCDocumentParts = {
1095
+ KYCFormItemFileExtraPart: KYCFormItemFileExtraPart,
1096
+ KYCFormItemFile: KYCFormItemFile,
1097
+ KYCFormItemText: KYCFormItemText
1098
+ };
1099
+
1100
+ var _templateObject$3, _templateObject2$3, _templateObject3$3;
1101
+ var StyledKYCFormItem$1 = /*#__PURE__*/styled.div(_templateObject$3 || (_templateObject$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-top: ", "px;\n"])), spacing * 6);
1102
+ var StyledKYCFormItemTitle = /*#__PURE__*/styled.div(_templateObject2$3 || (_templateObject2$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n font-size: ", "px;\n font-weight: bold;\n color: ", ";\n margin-bottom: ", "px;\n"])), fontNormal, black, spacing);
1103
+ var StyledKYCFormItemDescription = /*#__PURE__*/styled.div(_templateObject3$3 || (_templateObject3$3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n font-size: ", "px;\n color: ", ";\n margin-left: ", "px;\n"])), fontSmall, gray50, spacing * 4);
1104
+
1105
+ var getErrorKey = function getErrorKey(documentIndex, partIndex) {
1106
+ return "[" + documentIndex + "].parts[" + partIndex + "].data";
1107
+ };
1108
+
1109
+ var KYCFormItem = function KYCFormItem(props) {
1110
+ var _documentLabelsParts$;
1111
+
1112
+ var type = props.type,
1113
+ index = props.index,
1114
+ uploaderLabels = props.uploaderLabels,
1115
+ documentLabels = props.documentLabels,
1116
+ elementId = props.elementId,
1117
+ parts = props.parts,
1118
+ errors = props.errors,
1119
+ onDocumentChange = props.onDocumentChange;
1120
+
1121
+ var _useState = useState(new Map()),
1122
+ localErrors = _useState[0],
1123
+ setLocalErrors = _useState[1];
1124
+
1125
+ var isAddExtraPartAvailable = canAddExtraPart(type, parts);
1126
+ var documentLabelsParts = documentLabels == null ? void 0 : documentLabels.parts;
1127
+
1128
+ var _useState2 = useState(new Map()),
1129
+ fileNames = _useState2[0],
1130
+ setFileNames = _useState2[1];
1131
+
1132
+ var setLocalErrorByPartIndex = function setLocalErrorByPartIndex(partIndex) {
1133
+ var newLocalErrors = new Map(localErrors);
1134
+ newLocalErrors.set(getErrorKey(index, partIndex), uploaderLabels.oversizeError);
1135
+ setLocalErrors(newLocalErrors);
1136
+ };
1137
+
1138
+ var deleteLocalErrorByPartIndex = function deleteLocalErrorByPartIndex(partIndex) {
1139
+ var newLocalErrors = new Map(localErrors);
1140
+ newLocalErrors["delete"](getErrorKey(index, partIndex));
1141
+ setLocalErrors(newLocalErrors);
1142
+ };
1143
+
1144
+ var updateDocumentPart = function updateDocumentPart(part, partIndex, data) {
1145
+ var newPart = _extends({}, part, {
1146
+ data: data
1147
+ });
1148
+
1149
+ var newParts = [].concat(parts);
1150
+ newParts.splice(partIndex, 1, newPart);
1151
+ var newDocument = {
1152
+ type: type,
1153
+ parts: newParts
1154
+ };
1155
+ onDocumentChange(newDocument);
1156
+ };
1157
+
1158
+ var _onFileChange = /*#__PURE__*/function () {
1159
+ var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(partIndex, file) {
1160
+ var part, data, newFileNames;
1161
+ return runtime_1.wrap(function _callee$(_context) {
1162
+ while (1) {
1163
+ switch (_context.prev = _context.next) {
1164
+ case 0:
1165
+ if (file) {
1166
+ _context.next = 3;
1167
+ break;
1168
+ }
1169
+
1170
+ setLocalErrorByPartIndex(partIndex);
1171
+ return _context.abrupt("return");
1172
+
1173
+ case 3:
1174
+ part = parts[partIndex] || parts[0];
1175
+ _context.next = 6;
1176
+ return getFileBase64(file);
1177
+
1178
+ case 6:
1179
+ data = _context.sent;
1180
+ updateDocumentPart(part, partIndex, data);
1181
+ newFileNames = new Map(fileNames);
1182
+ newFileNames.set(data, file.name);
1183
+ setFileNames(newFileNames);
1184
+ deleteLocalErrorByPartIndex(partIndex);
1185
+
1186
+ case 12:
1187
+ case "end":
1188
+ return _context.stop();
1189
+ }
1190
+ }
1191
+ }, _callee);
1192
+ }));
1193
+
1194
+ return function onFileChange(_x, _x2) {
1195
+ return _ref.apply(this, arguments);
1196
+ };
1197
+ }();
1198
+
1199
+ var onPartRemove = function onPartRemove(partIndex) {
1200
+ var newParts = parts.filter(function (item, idx) {
1201
+ return idx !== partIndex;
1202
+ });
1203
+ var newDocument = {
1204
+ type: type,
1205
+ parts: newParts
1206
+ };
1207
+ onDocumentChange(newDocument);
1208
+ };
1209
+
1210
+ var _onFileRemove = function onFileRemove(partIndex) {
1211
+ var isRemoveExtraPartAvailable = canRemoveExtraPart(type, parts);
1212
+
1213
+ if (isRemoveExtraPartAvailable) {
1214
+ onPartRemove(partIndex);
1215
+ return;
1216
+ }
1217
+
1218
+ var part = parts[partIndex];
1219
+ updateDocumentPart(part, partIndex);
1220
+ var removedPart = parts[partIndex];
1221
+ var newFileNames = new Map(fileNames);
1222
+
1223
+ if (removedPart != null && removedPart.data && isFileUniqueInDocument(removedPart, parts)) {
1224
+ newFileNames["delete"](removedPart == null ? void 0 : removedPart.data);
1225
+ }
1226
+
1227
+ setFileNames(newFileNames);
1228
+ deleteLocalErrorByPartIndex(partIndex);
1229
+ };
1230
+
1231
+ var getFileName = function getFileName(key) {
1232
+ if (!key) {
1233
+ return undefined;
1234
+ }
1235
+
1236
+ return fileNames.get(key);
1237
+ };
1238
+
1239
+ var _onFeedbackChange = function onFeedbackChange(partIndex, data) {
1240
+ var part = parts[partIndex] || parts[0];
1241
+ updateDocumentPart(part, partIndex, data);
1242
+ };
1243
+
1244
+ return React.createElement(StyledKYCFormItem$1, {
1245
+ id: elementId
1246
+ }, React.createElement(StyledKYCFormItemTitle, null, index + 1, ".", documentLabels == null ? void 0 : documentLabels.title), (documentLabels == null ? void 0 : documentLabels.description) && React.createElement(StyledKYCFormItemDescription, null, documentLabels == null ? void 0 : documentLabels.description), parts.map(function (part, partIndex) {
1247
+ var itemKey = "kyc-form_item_file_" + part.type;
1248
+ var isExtraPartAvailable = isDocumentExtraPartAvailable(type);
1249
+ var partLabels = documentLabelsParts == null ? void 0 : documentLabelsParts[part.type];
1250
+ var partTitle = isExtraPartAvailable ? undefined : partLabels == null ? void 0 : partLabels.title;
1251
+
1252
+ if (isDocumentExtraPartAvailable(type) && part.data) {
1253
+ var _part$data;
1254
+
1255
+ itemKey = itemKey + "_" + ((_part$data = part.data) == null ? void 0 : _part$data.substr(-32));
1256
+
1257
+ if (!isFileUniqueInDocument(part, parts)) {
1258
+ itemKey = itemKey + "_" + partIndex;
1259
+ }
1260
+ }
1261
+
1262
+ var partError = errors == null ? void 0 : errors[getErrorKey(index, partIndex)];
1263
+ var localPartError = localErrors.get(getErrorKey(index, partIndex));
1264
+
1265
+ if (part.type === PART_TYPES.FEEDBACK) {
1266
+ return React.createElement(KYCDocumentParts.KYCFormItemText, {
1267
+ key: itemKey,
1268
+ value: part.data,
1269
+ onFeedbackChange: function onFeedbackChange(value) {
1270
+ return _onFeedbackChange(partIndex, value);
1271
+ }
1272
+ });
1273
+ }
1274
+
1275
+ return React.createElement(KYCDocumentParts.KYCFormItemFile, {
1276
+ title: partTitle,
1277
+ data: part.data,
1278
+ type: part.type,
1279
+ name: getFileName(part.data),
1280
+ uploaderLabels: uploaderLabels,
1281
+ error: localPartError || partError,
1282
+ key: itemKey,
1283
+ elementId: elementId + "_part_" + part.type + "_" + partIndex,
1284
+ onFileChange: function onFileChange(file) {
1285
+ return _onFileChange(partIndex, file);
1286
+ },
1287
+ onFileRemove: function onFileRemove() {
1288
+ return _onFileRemove(partIndex);
1289
+ }
1290
+ });
1291
+ }), isAddExtraPartAvailable && React.createElement(KYCDocumentParts.KYCFormItemFileExtraPart, {
1292
+ elementId: elementId + "_extra",
1293
+ title: documentLabelsParts == null ? void 0 : (_documentLabelsParts$ = documentLabelsParts[parts[0].type]) == null ? void 0 : _documentLabelsParts$.title,
1294
+ uploaderLabels: uploaderLabels,
1295
+ onFileAdd: function onFileAdd(file) {
1296
+ return _onFileChange(parts.length, file);
1297
+ }
1298
+ }));
1299
+ };
1300
+
1301
+ var _templateObject$4, _templateObject2$4, _templateObject3$4, _templateObject4$2;
1302
+ var StyledKYCForm = /*#__PURE__*/styled.div(_templateObject$4 || (_templateObject$4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n width: 100%;\n"])));
1303
+ var StyledKYCFormTitle = /*#__PURE__*/styled.div(_templateObject2$4 || (_templateObject2$4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n font-size: ", "px;\n"])), fontNormal);
1304
+ var StyledKYCFormDocuments = /*#__PURE__*/styled.div(_templateObject3$4 || (_templateObject3$4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 100%;\n margin-bottom: ", "px;\n"])), spacing * 6);
1305
+ var StyledKYCFormButton = /*#__PURE__*/styled.div(_templateObject4$2 || (_templateObject4$2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n justify-content: flex-end;\n width: 100%;\n"])));
1306
+
1307
+ var KYCForm = function KYCForm(props) {
1308
+ var elementId = props.elementId,
1309
+ title = props.title,
1310
+ uploadButtonLabel = props.uploadButtonLabel,
1311
+ uploaderLabels = props.uploaderLabels,
1312
+ documentsLabels = props.documentsLabels,
1313
+ documents = props.documents,
1314
+ errors = props.errors,
1315
+ isLoading = props.isLoading,
1316
+ validator = props.validator,
1317
+ onUploadClick = props.onUploadClick;
1318
+
1319
+ var _useState = useState(documents),
1320
+ userDocuments = _useState[0],
1321
+ setUserDocuments = _useState[1];
1322
+
1323
+ var _useState2 = useState(true),
1324
+ isButtonDisabled = _useState2[0],
1325
+ setButtonDisabled = _useState2[1];
1326
+
1327
+ useEffect(function () {
1328
+ setUserDocuments(documents);
1329
+ }, [documents]);
1330
+ useEffect(function () {
1331
+ var isValid = validator(userDocuments);
1332
+ setButtonDisabled(!isValid);
1333
+ }, [userDocuments, validator]);
1334
+
1335
+ var _onDocumentChange = function onDocumentChange(index, document) {
1336
+ var newDocuments = [].concat(userDocuments);
1337
+ newDocuments.splice(index, 1, document);
1338
+ setUserDocuments(newDocuments);
1339
+ };
1340
+
1341
+ return React.createElement(StyledKYCForm, {
1342
+ id: elementId
1343
+ }, title && React.createElement(StyledKYCFormTitle, null, title), React.createElement(StyledKYCFormDocuments, null, userDocuments.map(function (document, index) {
1344
+ var key = "kyc-form_item_" + document.type + "_" + index;
1345
+ return React.createElement(KYCFormItem, {
1346
+ index: index,
1347
+ type: document.type,
1348
+ parts: document.parts,
1349
+ documentLabels: documentsLabels[document.type],
1350
+ uploaderLabels: uploaderLabels,
1351
+ errors: errors,
1352
+ elementId: elementId + "_item_" + document.type,
1353
+ key: key,
1354
+ onDocumentChange: function onDocumentChange(doc) {
1355
+ return _onDocumentChange(index, doc);
1356
+ }
1357
+ });
1358
+ })), React.createElement(StyledKYCFormButton, null, React.createElement(Button, {
1359
+ elementId: elementId + "_button",
1360
+ type: BUTTON_TYPE.PRIMARY,
1361
+ isDisabled: isButtonDisabled,
1362
+ isLoading: isLoading || false,
1363
+ onClick: function onClick() {
1364
+ return onUploadClick(userDocuments);
1365
+ }
1366
+ }, uploadButtonLabel)));
1367
+ };
1368
+
1369
+ KYCForm.SucessScreen = KYCStatusScreen.KYCSucessScreen;
1370
+ KYCForm.FailScreen = KYCStatusScreen.KYCFailScreen;
1371
+
1372
+ export default KYCForm;
1373
+ export { ACCEPT_FORMATS, AVAILABLE_EXTRA_PARTS_DOCUMENTS, DOCUMENT_TYPES, MAX_EXTRA_PARTS_COUNT, MAX_FILE_SIZE, OPTIONAL_DOCUMENT_PARTS, PART_TYPES, PDF_MIME_TYPE };
1374
+ //# sourceMappingURL=kyc-form.esm.js.map