@itcase/forms 1.0.36 → 1.0.37
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/dist/itcase-forms.esm.js
CHANGED
|
@@ -1,2832 +1 @@
|
|
|
1
|
-
import { isPossiblePhoneNumber } from 'libphonenumber-js';
|
|
2
|
-
import React, { useMemo, useEffect, useCallback, useState } from 'react';
|
|
3
|
-
import { setIn, FORM_ERROR, getIn } from 'final-form';
|
|
4
|
-
import { useForm, Field, Form, FormSpy } from 'react-final-form';
|
|
5
|
-
export { Field, useForm, useFormState } from 'react-final-form';
|
|
6
|
-
import PropTypes from 'prop-types';
|
|
7
|
-
import clsx from 'clsx';
|
|
8
|
-
import { Checkbox } from '@itcase/ui/components/Checkbox';
|
|
9
|
-
import { Divider } from '@itcase/ui/components/Divider';
|
|
10
|
-
import { Text } from '@itcase/ui/components/Text';
|
|
11
|
-
import { useDeviceTargetClass } from '@itcase/ui/hooks/useDeviceTargetClass';
|
|
12
|
-
import { useStyles } from '@itcase/ui/hooks/useStyles';
|
|
13
|
-
import { Choice } from '@itcase/ui/components/Choice';
|
|
14
|
-
import { Code } from '@itcase/ui/components/Code';
|
|
15
|
-
import { DatePickerInput } from '@itcase/ui/components/DatePicker';
|
|
16
|
-
import axios from 'axios';
|
|
17
|
-
import { useDropzone } from 'react-dropzone';
|
|
18
|
-
import { fromEvent } from 'file-selector';
|
|
19
|
-
import castArray from 'lodash/castArray';
|
|
20
|
-
import { createFileFromDataURL } from '@itcase/common';
|
|
21
|
-
import { Loader } from '@itcase/ui/components/Loader';
|
|
22
|
-
import { Title } from '@itcase/ui/components/Title';
|
|
23
|
-
import { Input } from '@itcase/ui/components/Input';
|
|
24
|
-
import { Icon } from '@itcase/ui/components/Icon';
|
|
25
|
-
import { RadioButton } from '@itcase/ui/components/RadioButton';
|
|
26
|
-
import { Segmented } from '@itcase/ui/components/Segmented';
|
|
27
|
-
import { Select } from '@itcase/ui/components/Select';
|
|
28
|
-
import { Switch } from '@itcase/ui/components/Switch';
|
|
29
|
-
import { Textarea } from '@itcase/ui/components/Textarea';
|
|
30
|
-
import { Button } from '@itcase/ui/components/Button';
|
|
31
|
-
import { Group as Group$1 } from '@itcase/ui/components/Group';
|
|
32
|
-
import { NotificationItem } from '@itcase/ui/components/Notification';
|
|
33
|
-
import createDecorator from 'final-form-focus';
|
|
34
|
-
|
|
35
|
-
var phoneValidation = function phoneValidation(value, context) {
|
|
36
|
-
if (!value) {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
return isPossiblePhoneNumber(value, 'RU');
|
|
40
|
-
};
|
|
41
|
-
var emailValidation = function emailValidation(value, context) {
|
|
42
|
-
// from https://emailregex.com/
|
|
43
|
-
if (!value) {
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
// eslint-disable-next-line
|
|
47
|
-
var regexp = /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]{2,}(?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/;
|
|
48
|
-
return regexp.test(String(value).toLowerCase());
|
|
49
|
-
};
|
|
50
|
-
var addRequiredFieldsParamToSchema = function addRequiredFieldsParamToSchema(schema) {
|
|
51
|
-
var fields = Object.entries(schema.fields);
|
|
52
|
-
schema.requiredFields = fields.reduce(function (list, _ref) {
|
|
53
|
-
var _validationProps$excl;
|
|
54
|
-
var fieldName = _ref[0],
|
|
55
|
-
validationProps = _ref[1];
|
|
56
|
-
if ((_validationProps$excl = validationProps.exclusiveTests) != null && _validationProps$excl.required) {
|
|
57
|
-
list.push(fieldName);
|
|
58
|
-
}
|
|
59
|
-
return list;
|
|
60
|
-
}, []);
|
|
61
|
-
return schema;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
function _asyncIterator(r) {
|
|
65
|
-
var n,
|
|
66
|
-
t,
|
|
67
|
-
o,
|
|
68
|
-
e = 2;
|
|
69
|
-
for ("undefined" != typeof Symbol && (t = Symbol.asyncIterator, o = Symbol.iterator); e--;) {
|
|
70
|
-
if (t && null != (n = r[t])) return n.call(r);
|
|
71
|
-
if (o && null != (n = r[o])) return new AsyncFromSyncIterator(n.call(r));
|
|
72
|
-
t = "@@asyncIterator", o = "@@iterator";
|
|
73
|
-
}
|
|
74
|
-
throw new TypeError("Object is not async iterable");
|
|
75
|
-
}
|
|
76
|
-
function AsyncFromSyncIterator(r) {
|
|
77
|
-
function AsyncFromSyncIteratorContinuation(r) {
|
|
78
|
-
if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object."));
|
|
79
|
-
var n = r.done;
|
|
80
|
-
return Promise.resolve(r.value).then(function (r) {
|
|
81
|
-
return {
|
|
82
|
-
value: r,
|
|
83
|
-
done: n
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
return AsyncFromSyncIterator = function (r) {
|
|
88
|
-
this.s = r, this.n = r.next;
|
|
89
|
-
}, AsyncFromSyncIterator.prototype = {
|
|
90
|
-
s: null,
|
|
91
|
-
n: null,
|
|
92
|
-
next: function () {
|
|
93
|
-
return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
|
|
94
|
-
},
|
|
95
|
-
return: function (r) {
|
|
96
|
-
var n = this.s.return;
|
|
97
|
-
return void 0 === n ? Promise.resolve({
|
|
98
|
-
value: r,
|
|
99
|
-
done: !0
|
|
100
|
-
}) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
101
|
-
},
|
|
102
|
-
throw: function (r) {
|
|
103
|
-
var n = this.s.return;
|
|
104
|
-
return void 0 === n ? Promise.reject(r) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
105
|
-
}
|
|
106
|
-
}, new AsyncFromSyncIterator(r);
|
|
107
|
-
}
|
|
108
|
-
function _regeneratorRuntime() {
|
|
109
|
-
_regeneratorRuntime = function () {
|
|
110
|
-
return e;
|
|
111
|
-
};
|
|
112
|
-
var t,
|
|
113
|
-
e = {},
|
|
114
|
-
r = Object.prototype,
|
|
115
|
-
n = r.hasOwnProperty,
|
|
116
|
-
o = Object.defineProperty || function (t, e, r) {
|
|
117
|
-
t[e] = r.value;
|
|
118
|
-
},
|
|
119
|
-
i = "function" == typeof Symbol ? Symbol : {},
|
|
120
|
-
a = i.iterator || "@@iterator",
|
|
121
|
-
c = i.asyncIterator || "@@asyncIterator",
|
|
122
|
-
u = i.toStringTag || "@@toStringTag";
|
|
123
|
-
function define(t, e, r) {
|
|
124
|
-
return Object.defineProperty(t, e, {
|
|
125
|
-
value: r,
|
|
126
|
-
enumerable: !0,
|
|
127
|
-
configurable: !0,
|
|
128
|
-
writable: !0
|
|
129
|
-
}), t[e];
|
|
130
|
-
}
|
|
131
|
-
try {
|
|
132
|
-
define({}, "");
|
|
133
|
-
} catch (t) {
|
|
134
|
-
define = function (t, e, r) {
|
|
135
|
-
return t[e] = r;
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
function wrap(t, e, r, n) {
|
|
139
|
-
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
140
|
-
a = Object.create(i.prototype),
|
|
141
|
-
c = new Context(n || []);
|
|
142
|
-
return o(a, "_invoke", {
|
|
143
|
-
value: makeInvokeMethod(t, r, c)
|
|
144
|
-
}), a;
|
|
145
|
-
}
|
|
146
|
-
function tryCatch(t, e, r) {
|
|
147
|
-
try {
|
|
148
|
-
return {
|
|
149
|
-
type: "normal",
|
|
150
|
-
arg: t.call(e, r)
|
|
151
|
-
};
|
|
152
|
-
} catch (t) {
|
|
153
|
-
return {
|
|
154
|
-
type: "throw",
|
|
155
|
-
arg: t
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
e.wrap = wrap;
|
|
160
|
-
var h = "suspendedStart",
|
|
161
|
-
l = "suspendedYield",
|
|
162
|
-
f = "executing",
|
|
163
|
-
s = "completed",
|
|
164
|
-
y = {};
|
|
165
|
-
function Generator() {}
|
|
166
|
-
function GeneratorFunction() {}
|
|
167
|
-
function GeneratorFunctionPrototype() {}
|
|
168
|
-
var p = {};
|
|
169
|
-
define(p, a, function () {
|
|
170
|
-
return this;
|
|
171
|
-
});
|
|
172
|
-
var d = Object.getPrototypeOf,
|
|
173
|
-
v = d && d(d(values([])));
|
|
174
|
-
v && v !== r && n.call(v, a) && (p = v);
|
|
175
|
-
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
176
|
-
function defineIteratorMethods(t) {
|
|
177
|
-
["next", "throw", "return"].forEach(function (e) {
|
|
178
|
-
define(t, e, function (t) {
|
|
179
|
-
return this._invoke(e, t);
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
function AsyncIterator(t, e) {
|
|
184
|
-
function invoke(r, o, i, a) {
|
|
185
|
-
var c = tryCatch(t[r], t, o);
|
|
186
|
-
if ("throw" !== c.type) {
|
|
187
|
-
var u = c.arg,
|
|
188
|
-
h = u.value;
|
|
189
|
-
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
190
|
-
invoke("next", t, i, a);
|
|
191
|
-
}, function (t) {
|
|
192
|
-
invoke("throw", t, i, a);
|
|
193
|
-
}) : e.resolve(h).then(function (t) {
|
|
194
|
-
u.value = t, i(u);
|
|
195
|
-
}, function (t) {
|
|
196
|
-
return invoke("throw", t, i, a);
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
a(c.arg);
|
|
200
|
-
}
|
|
201
|
-
var r;
|
|
202
|
-
o(this, "_invoke", {
|
|
203
|
-
value: function (t, n) {
|
|
204
|
-
function callInvokeWithMethodAndArg() {
|
|
205
|
-
return new e(function (e, r) {
|
|
206
|
-
invoke(t, n, e, r);
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
function makeInvokeMethod(e, r, n) {
|
|
214
|
-
var o = h;
|
|
215
|
-
return function (i, a) {
|
|
216
|
-
if (o === f) throw new Error("Generator is already running");
|
|
217
|
-
if (o === s) {
|
|
218
|
-
if ("throw" === i) throw a;
|
|
219
|
-
return {
|
|
220
|
-
value: t,
|
|
221
|
-
done: !0
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
for (n.method = i, n.arg = a;;) {
|
|
225
|
-
var c = n.delegate;
|
|
226
|
-
if (c) {
|
|
227
|
-
var u = maybeInvokeDelegate(c, n);
|
|
228
|
-
if (u) {
|
|
229
|
-
if (u === y) continue;
|
|
230
|
-
return u;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
234
|
-
if (o === h) throw o = s, n.arg;
|
|
235
|
-
n.dispatchException(n.arg);
|
|
236
|
-
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
237
|
-
o = f;
|
|
238
|
-
var p = tryCatch(e, r, n);
|
|
239
|
-
if ("normal" === p.type) {
|
|
240
|
-
if (o = n.done ? s : l, p.arg === y) continue;
|
|
241
|
-
return {
|
|
242
|
-
value: p.arg,
|
|
243
|
-
done: n.done
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
function maybeInvokeDelegate(e, r) {
|
|
251
|
-
var n = r.method,
|
|
252
|
-
o = e.iterator[n];
|
|
253
|
-
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
|
254
|
-
var i = tryCatch(o, e.iterator, r.arg);
|
|
255
|
-
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
256
|
-
var a = i.arg;
|
|
257
|
-
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
|
258
|
-
}
|
|
259
|
-
function pushTryEntry(t) {
|
|
260
|
-
var e = {
|
|
261
|
-
tryLoc: t[0]
|
|
262
|
-
};
|
|
263
|
-
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
264
|
-
}
|
|
265
|
-
function resetTryEntry(t) {
|
|
266
|
-
var e = t.completion || {};
|
|
267
|
-
e.type = "normal", delete e.arg, t.completion = e;
|
|
268
|
-
}
|
|
269
|
-
function Context(t) {
|
|
270
|
-
this.tryEntries = [{
|
|
271
|
-
tryLoc: "root"
|
|
272
|
-
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
273
|
-
}
|
|
274
|
-
function values(e) {
|
|
275
|
-
if (e || "" === e) {
|
|
276
|
-
var r = e[a];
|
|
277
|
-
if (r) return r.call(e);
|
|
278
|
-
if ("function" == typeof e.next) return e;
|
|
279
|
-
if (!isNaN(e.length)) {
|
|
280
|
-
var o = -1,
|
|
281
|
-
i = function next() {
|
|
282
|
-
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
283
|
-
return next.value = t, next.done = !0, next;
|
|
284
|
-
};
|
|
285
|
-
return i.next = i;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
throw new TypeError(typeof e + " is not iterable");
|
|
289
|
-
}
|
|
290
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
|
291
|
-
value: GeneratorFunctionPrototype,
|
|
292
|
-
configurable: !0
|
|
293
|
-
}), o(GeneratorFunctionPrototype, "constructor", {
|
|
294
|
-
value: GeneratorFunction,
|
|
295
|
-
configurable: !0
|
|
296
|
-
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
|
297
|
-
var e = "function" == typeof t && t.constructor;
|
|
298
|
-
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
|
299
|
-
}, e.mark = function (t) {
|
|
300
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
|
301
|
-
}, e.awrap = function (t) {
|
|
302
|
-
return {
|
|
303
|
-
__await: t
|
|
304
|
-
};
|
|
305
|
-
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
306
|
-
return this;
|
|
307
|
-
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
308
|
-
void 0 === i && (i = Promise);
|
|
309
|
-
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
310
|
-
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
311
|
-
return t.done ? t.value : a.next();
|
|
312
|
-
});
|
|
313
|
-
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
314
|
-
return this;
|
|
315
|
-
}), define(g, "toString", function () {
|
|
316
|
-
return "[object Generator]";
|
|
317
|
-
}), e.keys = function (t) {
|
|
318
|
-
var e = Object(t),
|
|
319
|
-
r = [];
|
|
320
|
-
for (var n in e) r.push(n);
|
|
321
|
-
return r.reverse(), function next() {
|
|
322
|
-
for (; r.length;) {
|
|
323
|
-
var t = r.pop();
|
|
324
|
-
if (t in e) return next.value = t, next.done = !1, next;
|
|
325
|
-
}
|
|
326
|
-
return next.done = !0, next;
|
|
327
|
-
};
|
|
328
|
-
}, e.values = values, Context.prototype = {
|
|
329
|
-
constructor: Context,
|
|
330
|
-
reset: function (e) {
|
|
331
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
|
332
|
-
},
|
|
333
|
-
stop: function () {
|
|
334
|
-
this.done = !0;
|
|
335
|
-
var t = this.tryEntries[0].completion;
|
|
336
|
-
if ("throw" === t.type) throw t.arg;
|
|
337
|
-
return this.rval;
|
|
338
|
-
},
|
|
339
|
-
dispatchException: function (e) {
|
|
340
|
-
if (this.done) throw e;
|
|
341
|
-
var r = this;
|
|
342
|
-
function handle(n, o) {
|
|
343
|
-
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
344
|
-
}
|
|
345
|
-
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
346
|
-
var i = this.tryEntries[o],
|
|
347
|
-
a = i.completion;
|
|
348
|
-
if ("root" === i.tryLoc) return handle("end");
|
|
349
|
-
if (i.tryLoc <= this.prev) {
|
|
350
|
-
var c = n.call(i, "catchLoc"),
|
|
351
|
-
u = n.call(i, "finallyLoc");
|
|
352
|
-
if (c && u) {
|
|
353
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
354
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
355
|
-
} else if (c) {
|
|
356
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
357
|
-
} else {
|
|
358
|
-
if (!u) throw new Error("try statement without catch or finally");
|
|
359
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
},
|
|
364
|
-
abrupt: function (t, e) {
|
|
365
|
-
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
366
|
-
var o = this.tryEntries[r];
|
|
367
|
-
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
368
|
-
var i = o;
|
|
369
|
-
break;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
373
|
-
var a = i ? i.completion : {};
|
|
374
|
-
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
375
|
-
},
|
|
376
|
-
complete: function (t, e) {
|
|
377
|
-
if ("throw" === t.type) throw t.arg;
|
|
378
|
-
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
|
379
|
-
},
|
|
380
|
-
finish: function (t) {
|
|
381
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
382
|
-
var r = this.tryEntries[e];
|
|
383
|
-
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
384
|
-
}
|
|
385
|
-
},
|
|
386
|
-
catch: function (t) {
|
|
387
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
388
|
-
var r = this.tryEntries[e];
|
|
389
|
-
if (r.tryLoc === t) {
|
|
390
|
-
var n = r.completion;
|
|
391
|
-
if ("throw" === n.type) {
|
|
392
|
-
var o = n.arg;
|
|
393
|
-
resetTryEntry(r);
|
|
394
|
-
}
|
|
395
|
-
return o;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
throw new Error("illegal catch attempt");
|
|
399
|
-
},
|
|
400
|
-
delegateYield: function (e, r, n) {
|
|
401
|
-
return this.delegate = {
|
|
402
|
-
iterator: values(e),
|
|
403
|
-
resultName: r,
|
|
404
|
-
nextLoc: n
|
|
405
|
-
}, "next" === this.method && (this.arg = t), y;
|
|
406
|
-
}
|
|
407
|
-
}, e;
|
|
408
|
-
}
|
|
409
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
410
|
-
try {
|
|
411
|
-
var info = gen[key](arg);
|
|
412
|
-
var value = info.value;
|
|
413
|
-
} catch (error) {
|
|
414
|
-
reject(error);
|
|
415
|
-
return;
|
|
416
|
-
}
|
|
417
|
-
if (info.done) {
|
|
418
|
-
resolve(value);
|
|
419
|
-
} else {
|
|
420
|
-
Promise.resolve(value).then(_next, _throw);
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
function _asyncToGenerator(fn) {
|
|
424
|
-
return function () {
|
|
425
|
-
var self = this,
|
|
426
|
-
args = arguments;
|
|
427
|
-
return new Promise(function (resolve, reject) {
|
|
428
|
-
var gen = fn.apply(self, args);
|
|
429
|
-
function _next(value) {
|
|
430
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
431
|
-
}
|
|
432
|
-
function _throw(err) {
|
|
433
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
434
|
-
}
|
|
435
|
-
_next(undefined);
|
|
436
|
-
});
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Sets the `innerError.message` in an `errors` object at the key
|
|
442
|
-
* defined by `innerError.path`.
|
|
443
|
-
* @param {Object} errors The object to set the error in.
|
|
444
|
-
* @param {{ path: string, message: string }} innerError A `yup` field error.
|
|
445
|
-
* @returns {Object} The result of setting the new error message onto `errors`.
|
|
446
|
-
*/
|
|
447
|
-
var setInError = function setInError(errors, innerError) {
|
|
448
|
-
return setIn(errors, innerError.path, innerError.message);
|
|
449
|
-
};
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
* Empty object map with no prototype. Used as default
|
|
453
|
-
* value for reducing the `err.inner` array of errors
|
|
454
|
-
* from a `yup~ValidationError`.
|
|
455
|
-
*/
|
|
456
|
-
var emptyObj = Object.create(null);
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Takes a `yup` validation schema and returns a function that expects
|
|
460
|
-
* a map of values to validate. If the validation passes, the function resolves to `undefined`
|
|
461
|
-
* (signalling that the values are valid). If the validation doesn't pass, it resolves
|
|
462
|
-
* to a map of invalid field names to errors.
|
|
463
|
-
* @param {import('yup').ObjectSchema} schema `yup` schema definition.
|
|
464
|
-
* @returns {(values: Object) => Promise<?Object>} An async function that expects some `values`
|
|
465
|
-
* and resolves to either `undefined` or a map of field names to error messages.
|
|
466
|
-
*/
|
|
467
|
-
|
|
468
|
-
var makeValidate = function makeValidate(schema) {
|
|
469
|
-
return /*#__PURE__*/function () {
|
|
470
|
-
var _validate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(values) {
|
|
471
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
472
|
-
while (1) switch (_context.prev = _context.next) {
|
|
473
|
-
case 0:
|
|
474
|
-
_context.prev = 0;
|
|
475
|
-
_context.next = 3;
|
|
476
|
-
return schema.validate(values, {
|
|
477
|
-
abortEarly: false
|
|
478
|
-
});
|
|
479
|
-
case 3:
|
|
480
|
-
_context.next = 12;
|
|
481
|
-
break;
|
|
482
|
-
case 5:
|
|
483
|
-
_context.prev = 5;
|
|
484
|
-
_context.t0 = _context["catch"](0);
|
|
485
|
-
if (!_context.t0.inner) {
|
|
486
|
-
_context.next = 11;
|
|
487
|
-
break;
|
|
488
|
-
}
|
|
489
|
-
return _context.abrupt("return", _context.t0.inner.reduce(setInError, emptyObj));
|
|
490
|
-
case 11:
|
|
491
|
-
console.warn('itcase-forms schema.validate error: An error not related to the form occurred during validation. Validation ignored.');
|
|
492
|
-
case 12:
|
|
493
|
-
case "end":
|
|
494
|
-
return _context.stop();
|
|
495
|
-
}
|
|
496
|
-
}, _callee, null, [[0, 5]]);
|
|
497
|
-
}));
|
|
498
|
-
function validate(_x) {
|
|
499
|
-
return _validate.apply(this, arguments);
|
|
500
|
-
}
|
|
501
|
-
return validate;
|
|
502
|
-
}();
|
|
503
|
-
};
|
|
504
|
-
function useYupValidationSchema(schema, language) {
|
|
505
|
-
var validate = useMemo(function () {
|
|
506
|
-
return schema && makeValidate(schema);
|
|
507
|
-
}, [schema, language]);
|
|
508
|
-
return validate;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
function FieldWrapperBase(props) {
|
|
512
|
-
var after = props.after,
|
|
513
|
-
afterItem = props.afterItem,
|
|
514
|
-
before = props.before,
|
|
515
|
-
beforeItem = props.beforeItem,
|
|
516
|
-
children = props.children,
|
|
517
|
-
className = props.className,
|
|
518
|
-
desc = props.desc,
|
|
519
|
-
descTextSize = props.descTextSize,
|
|
520
|
-
descTextColor = props.descTextColor,
|
|
521
|
-
descTextWidth = props.descTextWidth,
|
|
522
|
-
divider = props.divider,
|
|
523
|
-
dividerDirection = props.dividerDirection,
|
|
524
|
-
dividerFill = props.dividerFill,
|
|
525
|
-
dividerSize = props.dividerSize,
|
|
526
|
-
dividerWidth = props.dividerWidth,
|
|
527
|
-
fieldClassName = props.fieldClassName,
|
|
528
|
-
id = props.id,
|
|
529
|
-
inputName = props.inputName,
|
|
530
|
-
inputValue = props.inputValue,
|
|
531
|
-
isRequired = props.isRequired,
|
|
532
|
-
label = props.label,
|
|
533
|
-
labelTextSize = props.labelTextSize,
|
|
534
|
-
labelTextColor = props.labelTextColor,
|
|
535
|
-
labelTextWidth = props.labelTextWidth,
|
|
536
|
-
errorMessageTextSize = props.errorMessageTextSize,
|
|
537
|
-
errorMessageTextWeight = props.errorMessageTextWeight,
|
|
538
|
-
errorMessageTextColor = props.errorMessageTextColor,
|
|
539
|
-
message = props.message,
|
|
540
|
-
messageTextSize = props.messageTextSize,
|
|
541
|
-
messageTextColor = props.messageTextColor,
|
|
542
|
-
messageTextWeight = props.messageTextWeight,
|
|
543
|
-
metaActive = props.metaActive,
|
|
544
|
-
metaError = props.metaError,
|
|
545
|
-
metaModifiedSinceLastSubmit = props.metaModifiedSinceLastSubmit,
|
|
546
|
-
metaSubmitError = props.metaSubmitError,
|
|
547
|
-
metaSubmitFailed = props.metaSubmitFailed,
|
|
548
|
-
metaTouched = props.metaTouched,
|
|
549
|
-
metaValid = props.metaValid,
|
|
550
|
-
set = props.set,
|
|
551
|
-
type = props.type,
|
|
552
|
-
hideMessage = props.hideMessage,
|
|
553
|
-
isHidden = props.isHidden,
|
|
554
|
-
Tag = props.tag,
|
|
555
|
-
dataTour = props.dataTour,
|
|
556
|
-
showErrorsOnSubmit = props.showErrorsOnSubmit;
|
|
557
|
-
var error = metaError || !metaModifiedSinceLastSubmit && metaSubmitError || false;
|
|
558
|
-
var showError = useMemo(function () {
|
|
559
|
-
if (showErrorsOnSubmit) {
|
|
560
|
-
return metaSubmitFailed && metaTouched && error;
|
|
561
|
-
} else {
|
|
562
|
-
return metaTouched && error;
|
|
563
|
-
}
|
|
564
|
-
}, [showErrorsOnSubmit, metaSubmitFailed, metaTouched, error]);
|
|
565
|
-
var showValid = useMemo(function () {
|
|
566
|
-
var hasValue = Array.isArray(inputValue) ? inputValue.length : inputValue;
|
|
567
|
-
var isModifiedAfterSubmit = !metaError && metaSubmitError && metaModifiedSinceLastSubmit;
|
|
568
|
-
return hasValue && (metaValid || isModifiedAfterSubmit);
|
|
569
|
-
}, [inputValue, metaValid, metaError, metaSubmitError, metaModifiedSinceLastSubmit]);
|
|
570
|
-
var formFieldClass = useMemo(function () {
|
|
571
|
-
return clsx(className, showError && 'form__item_state_error', showValid && 'form__item_state_success', isRequired && 'form__item_state_required', metaActive && 'form__item_state_focus', inputValue && 'form__item_state_filled');
|
|
572
|
-
}, [className, showError, showValid, isRequired, metaActive, inputValue]);
|
|
573
|
-
var fieldClass = useMemo(function () {
|
|
574
|
-
return clsx(fieldClassName, showError && fieldClassName + "_state_error", showValid && fieldClassName + "_state_success", metaActive && fieldClassName + "_state_focus", inputValue && fieldClassName + "_state_filled");
|
|
575
|
-
}, [fieldClassName, showError, showValid, metaActive, inputValue]);
|
|
576
|
-
var sizeClass = useDeviceTargetClass(props, {
|
|
577
|
-
prefix: 'form-field_size_',
|
|
578
|
-
propsKey: 'size'
|
|
579
|
-
});
|
|
580
|
-
var fillClass = useDeviceTargetClass(props, {
|
|
581
|
-
prefix: 'fill_',
|
|
582
|
-
propsKey: 'fill'
|
|
583
|
-
});
|
|
584
|
-
var inputFillClass = useDeviceTargetClass(props, {
|
|
585
|
-
prefix: 'fill_',
|
|
586
|
-
propsKey: 'inputFill'
|
|
587
|
-
});
|
|
588
|
-
var shapeClass = useDeviceTargetClass(props, {
|
|
589
|
-
prefix: 'form-field_shape_',
|
|
590
|
-
propsKey: 'shape'
|
|
591
|
-
});
|
|
592
|
-
var inputShapeClass = useDeviceTargetClass(props, {
|
|
593
|
-
prefix: 'form-field__item-value_shape_',
|
|
594
|
-
propsKey: 'inputShape'
|
|
595
|
-
});
|
|
596
|
-
var directionClass = useDeviceTargetClass(props, {
|
|
597
|
-
prefix: 'direction_',
|
|
598
|
-
propsKey: 'direction'
|
|
599
|
-
});
|
|
600
|
-
var widthClass = useDeviceTargetClass(props, {
|
|
601
|
-
prefix: 'width_',
|
|
602
|
-
propsKey: 'width'
|
|
603
|
-
});
|
|
604
|
-
var _useStyles = useStyles(props),
|
|
605
|
-
formFieldStyles = _useStyles.styles;
|
|
606
|
-
return /*#__PURE__*/React.createElement(Tag, {
|
|
607
|
-
className: clsx(formFieldClass, 'form__item', 'form-field', type && "form-field_type_" + type, set && "form-field_set_" + set, sizeClass, fillClass, shapeClass, isHidden && "form-field_state_hidden", directionClass, widthClass),
|
|
608
|
-
"data-tour": dataTour,
|
|
609
|
-
style: formFieldStyles
|
|
610
|
-
}, before, label && /*#__PURE__*/React.createElement("div", {
|
|
611
|
-
htmlFor: id,
|
|
612
|
-
className: "form-field__label"
|
|
613
|
-
}, /*#__PURE__*/React.createElement(Text, {
|
|
614
|
-
size: labelTextSize,
|
|
615
|
-
textWeight: labelTextWidth,
|
|
616
|
-
textColor: labelTextColor
|
|
617
|
-
}, label)), desc && /*#__PURE__*/React.createElement("div", {
|
|
618
|
-
className: "form-field__desc"
|
|
619
|
-
}, /*#__PURE__*/React.createElement(Text, {
|
|
620
|
-
size: descTextSize,
|
|
621
|
-
textWeight: descTextWidth,
|
|
622
|
-
textColor: descTextColor
|
|
623
|
-
}, desc)), /*#__PURE__*/React.createElement("div", {
|
|
624
|
-
className: clsx('form-field__content', inputFillClass, inputShapeClass)
|
|
625
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
626
|
-
className: clsx('form-field__content-inner', fieldClass)
|
|
627
|
-
}, beforeItem, children, afterItem), divider && /*#__PURE__*/React.createElement(Divider, {
|
|
628
|
-
className: "form-field__item-divider",
|
|
629
|
-
width: dividerWidth,
|
|
630
|
-
direction: dividerDirection,
|
|
631
|
-
size: dividerSize,
|
|
632
|
-
fill: dividerFill
|
|
633
|
-
})), !hideMessage && /*#__PURE__*/React.createElement("div", {
|
|
634
|
-
className: "form-field__message"
|
|
635
|
-
}, Boolean(showError) && /*#__PURE__*/React.createElement(Text, {
|
|
636
|
-
className: "form-field__message-item form-field__message-item_type-error",
|
|
637
|
-
size: errorMessageTextSize,
|
|
638
|
-
textWeight: errorMessageTextWeight,
|
|
639
|
-
textColor: errorMessageTextColor,
|
|
640
|
-
id: inputName + "-error"
|
|
641
|
-
}, error), Boolean(message) && !showError && /*#__PURE__*/React.createElement(Text, {
|
|
642
|
-
className: "form-field__message-item form-field__message-item_type_message",
|
|
643
|
-
size: messageTextSize,
|
|
644
|
-
textWeight: messageTextWeight,
|
|
645
|
-
textColor: messageTextColor
|
|
646
|
-
}, message), Boolean(!showError) && Boolean(!message) && /*#__PURE__*/React.createElement(Text, {
|
|
647
|
-
className: "form-field__message-item form-field__message-item_type_message",
|
|
648
|
-
size: messageTextSize
|
|
649
|
-
}, "\xA0")), after);
|
|
650
|
-
}
|
|
651
|
-
FieldWrapperBase.defaultProps = {
|
|
652
|
-
tag: 'div',
|
|
653
|
-
type: 'normal',
|
|
654
|
-
errorMessageTextSize: 's',
|
|
655
|
-
errorMessageTextColor: 'errorTextSecondary'
|
|
656
|
-
};
|
|
657
|
-
FieldWrapperBase.propTypes = {
|
|
658
|
-
after: PropTypes.any,
|
|
659
|
-
afterItem: PropTypes.any,
|
|
660
|
-
autoComplete: PropTypes.string,
|
|
661
|
-
before: PropTypes.any,
|
|
662
|
-
beforeItem: PropTypes.any,
|
|
663
|
-
children: PropTypes.any,
|
|
664
|
-
className: PropTypes.string,
|
|
665
|
-
desc: PropTypes.string,
|
|
666
|
-
descTextSize: PropTypes.string,
|
|
667
|
-
descTextColor: PropTypes.string,
|
|
668
|
-
descTextWidth: PropTypes.string,
|
|
669
|
-
dividerDirection: PropTypes.string,
|
|
670
|
-
dividerFill: PropTypes.string,
|
|
671
|
-
dividerSize: PropTypes.string,
|
|
672
|
-
dividerWidth: PropTypes.string,
|
|
673
|
-
fieldClassName: PropTypes.string,
|
|
674
|
-
id: PropTypes.string,
|
|
675
|
-
inputName: PropTypes.string,
|
|
676
|
-
inputOnBlur: PropTypes.func,
|
|
677
|
-
inputOnChange: PropTypes.func,
|
|
678
|
-
inputOnFocus: PropTypes.func,
|
|
679
|
-
inputValue: PropTypes.any,
|
|
680
|
-
isRequired: PropTypes.bool,
|
|
681
|
-
itemType: PropTypes.string,
|
|
682
|
-
label: PropTypes.any,
|
|
683
|
-
labelTextSize: PropTypes.string,
|
|
684
|
-
labelTextColor: PropTypes.string,
|
|
685
|
-
labelTextWidth: PropTypes.string,
|
|
686
|
-
errorMessageTextSize: PropTypes.string,
|
|
687
|
-
errorMessageTextWidth: PropTypes.string,
|
|
688
|
-
errorMessageTextColor: PropTypes.string,
|
|
689
|
-
message: PropTypes.string,
|
|
690
|
-
messageSize: PropTypes.string,
|
|
691
|
-
messageTextColor: PropTypes.string,
|
|
692
|
-
messageTextWidth: PropTypes.string,
|
|
693
|
-
metaActive: PropTypes.bool,
|
|
694
|
-
metaError: PropTypes.string,
|
|
695
|
-
metaModifiedSinceLastSubmit: PropTypes.bool,
|
|
696
|
-
metaSubmitError: PropTypes.string,
|
|
697
|
-
metaSubmitFailed: PropTypes.bool,
|
|
698
|
-
metaTouched: PropTypes.bool,
|
|
699
|
-
metaValid: PropTypes.bool,
|
|
700
|
-
set: PropTypes.string,
|
|
701
|
-
showErrorsOnSubmit: PropTypes.bool,
|
|
702
|
-
type: PropTypes.string
|
|
703
|
-
};
|
|
704
|
-
function FieldWrapper(props) {
|
|
705
|
-
var inputName = props.inputName;
|
|
706
|
-
var _useForm = useForm(),
|
|
707
|
-
change = _useForm.change; // , mutators
|
|
708
|
-
|
|
709
|
-
useEffect(function () {
|
|
710
|
-
return function () {
|
|
711
|
-
change(inputName, undefined);
|
|
712
|
-
};
|
|
713
|
-
}, []);
|
|
714
|
-
return /*#__PURE__*/React.createElement(FieldWrapperBase, props);
|
|
715
|
-
}
|
|
716
|
-
FieldWrapper.propTypes = {
|
|
717
|
-
autoComplete: PropTypes.string,
|
|
718
|
-
children: PropTypes.any,
|
|
719
|
-
className: PropTypes.string,
|
|
720
|
-
fieldClassName: PropTypes.string,
|
|
721
|
-
hint: PropTypes.string,
|
|
722
|
-
inputName: PropTypes.string,
|
|
723
|
-
inputOnBlur: PropTypes.func,
|
|
724
|
-
inputOnChange: PropTypes.func,
|
|
725
|
-
inputOnFocus: PropTypes.func,
|
|
726
|
-
inputValue: PropTypes.any,
|
|
727
|
-
isRequired: PropTypes.bool,
|
|
728
|
-
itemType: PropTypes.string,
|
|
729
|
-
label: PropTypes.any,
|
|
730
|
-
metaActive: PropTypes.bool,
|
|
731
|
-
metaError: PropTypes.string,
|
|
732
|
-
metaModifiedSinceLastSubmit: PropTypes.bool,
|
|
733
|
-
metaSubmitError: PropTypes.string,
|
|
734
|
-
metaSubmitFailed: PropTypes.bool,
|
|
735
|
-
metaTouched: PropTypes.bool,
|
|
736
|
-
metaValid: PropTypes.bool,
|
|
737
|
-
showErrorsOnSubmit: PropTypes.bool
|
|
738
|
-
};
|
|
739
|
-
|
|
740
|
-
var CheckboxField = /*#__PURE__*/React.memo(function CheckboxField(props) {
|
|
741
|
-
var name = props.name,
|
|
742
|
-
isRequired = props.isRequired,
|
|
743
|
-
onChange = props.onChange,
|
|
744
|
-
fieldProps = props.fieldProps,
|
|
745
|
-
inputProps = props.inputProps,
|
|
746
|
-
classNameGroupItem = props.classNameGroupItem,
|
|
747
|
-
hideMessage = props.hideMessage;
|
|
748
|
-
return /*#__PURE__*/React.createElement(Field, {
|
|
749
|
-
name: name,
|
|
750
|
-
type: "checkbox"
|
|
751
|
-
}, function (_ref) {
|
|
752
|
-
var input = _ref.input,
|
|
753
|
-
meta = _ref.meta;
|
|
754
|
-
var onChangeField = useCallback(function (event) {
|
|
755
|
-
input.onChange(event);
|
|
756
|
-
if (onChange) {
|
|
757
|
-
onChange(event.target.checked, input.name);
|
|
758
|
-
}
|
|
759
|
-
}, [onChange]);
|
|
760
|
-
return /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
|
|
761
|
-
className: clsx('form-field_type_checkbox', 'form__item_type_checkbox', classNameGroupItem),
|
|
762
|
-
fieldClassName: "form-checkbox",
|
|
763
|
-
inputName: input.name,
|
|
764
|
-
inputValue: input.checked,
|
|
765
|
-
isRequired: isRequired,
|
|
766
|
-
metaActive: meta.active,
|
|
767
|
-
metaError: meta.error,
|
|
768
|
-
metaModifiedSinceLastSubmit: meta.modifiedSinceLastSubmit,
|
|
769
|
-
metaSubmitError: meta.submitError,
|
|
770
|
-
metaSubmitFailed: meta.submitFailed,
|
|
771
|
-
metaTouched: meta.touched,
|
|
772
|
-
metaValid: meta.valid,
|
|
773
|
-
tag: "label",
|
|
774
|
-
hideMessage: hideMessage
|
|
775
|
-
}, fieldProps), /*#__PURE__*/React.createElement(Checkbox, Object.assign({
|
|
776
|
-
autoComplete: "nope",
|
|
777
|
-
checked: input.checked,
|
|
778
|
-
name: input.name,
|
|
779
|
-
type: "checkbox",
|
|
780
|
-
onBlur: input.onBlur,
|
|
781
|
-
onChange: onChangeField,
|
|
782
|
-
onFocus: input.onFocus
|
|
783
|
-
}, inputProps)));
|
|
784
|
-
});
|
|
785
|
-
});
|
|
786
|
-
CheckboxField.defaultProps = {
|
|
787
|
-
inputProps: {},
|
|
788
|
-
fieldProps: {}
|
|
789
|
-
};
|
|
790
|
-
CheckboxField.propTypes = {
|
|
791
|
-
fieldProps: PropTypes.object,
|
|
792
|
-
inputProps: PropTypes.object,
|
|
793
|
-
isRequired: PropTypes.bool,
|
|
794
|
-
name: PropTypes.string,
|
|
795
|
-
onChange: PropTypes.func
|
|
796
|
-
};
|
|
797
|
-
|
|
798
|
-
var ChoiceField = /*#__PURE__*/React.memo(function ChoiceField(props) {
|
|
799
|
-
var options = props.options,
|
|
800
|
-
classNameGroupItem = props.classNameGroupItem,
|
|
801
|
-
fieldProps = props.fieldProps,
|
|
802
|
-
inputProps = props.inputProps,
|
|
803
|
-
isMultiple = props.isMultiple,
|
|
804
|
-
isRequired = props.isRequired,
|
|
805
|
-
initialValue = props.initialValue,
|
|
806
|
-
label = props.label,
|
|
807
|
-
name = props.name,
|
|
808
|
-
messageType = props.messageType,
|
|
809
|
-
hideMessage = props.hideMessage,
|
|
810
|
-
placeholder = props.placeholder;
|
|
811
|
-
var _useForm = useForm(),
|
|
812
|
-
change = _useForm.change;
|
|
813
|
-
return /*#__PURE__*/React.createElement(Field, {
|
|
814
|
-
name: name,
|
|
815
|
-
initialValue: initialValue
|
|
816
|
-
}, function (_ref) {
|
|
817
|
-
var input = _ref.input,
|
|
818
|
-
meta = _ref.meta;
|
|
819
|
-
var activeOption = useMemo(function () {
|
|
820
|
-
var emptyOption = {
|
|
821
|
-
value: null,
|
|
822
|
-
label: null
|
|
823
|
-
};
|
|
824
|
-
if (input.value) {
|
|
825
|
-
var currentOption = options.find(function (option) {
|
|
826
|
-
return option.value === input.value;
|
|
827
|
-
});
|
|
828
|
-
return currentOption || emptyOption;
|
|
829
|
-
}
|
|
830
|
-
return emptyOption;
|
|
831
|
-
}, [input.value]);
|
|
832
|
-
var setActiveSegment = useCallback(function (option) {
|
|
833
|
-
change(name, option.value);
|
|
834
|
-
}, [change]);
|
|
835
|
-
return /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
|
|
836
|
-
className: clsx('form-field_type_choice', 'form__item_type_choice', classNameGroupItem),
|
|
837
|
-
fieldClassName: "form-choice",
|
|
838
|
-
inputName: input.name,
|
|
839
|
-
inputValue: input.value || [],
|
|
840
|
-
isRequired: isRequired,
|
|
841
|
-
label: label,
|
|
842
|
-
messageType: messageType,
|
|
843
|
-
metaActive: meta.active,
|
|
844
|
-
metaError: meta.error,
|
|
845
|
-
metaModifiedSinceLastSubmit: meta.modifiedSinceLastSubmit,
|
|
846
|
-
metaSubmitError: meta.submitError,
|
|
847
|
-
metaSubmitFailed: meta.submitFailed,
|
|
848
|
-
metaTouched: meta.touched,
|
|
849
|
-
metaValid: meta.valid,
|
|
850
|
-
hideMessage: hideMessage
|
|
851
|
-
}, fieldProps), /*#__PURE__*/React.createElement(Choice, Object.assign({
|
|
852
|
-
className: clsx(meta.active && 'form-choice_state_focus', meta.error && meta.touched && 'form-choice_state_error'),
|
|
853
|
-
options: options,
|
|
854
|
-
inputName: input.name,
|
|
855
|
-
inputValue: input.value || [],
|
|
856
|
-
isMultiple: isMultiple,
|
|
857
|
-
isRequired: isRequired,
|
|
858
|
-
placeholder: placeholder,
|
|
859
|
-
active: activeOption,
|
|
860
|
-
setActiveSegment: setActiveSegment
|
|
861
|
-
}, inputProps)));
|
|
862
|
-
});
|
|
863
|
-
});
|
|
864
|
-
ChoiceField.propTypes = {
|
|
865
|
-
options: PropTypes.array.isRequired,
|
|
866
|
-
name: PropTypes.string.isRequired,
|
|
867
|
-
className: PropTypes.string,
|
|
868
|
-
inputClass: PropTypes.string,
|
|
869
|
-
isMultiple: PropTypes.bool,
|
|
870
|
-
isRequired: PropTypes.bool,
|
|
871
|
-
label: PropTypes.string,
|
|
872
|
-
placeholder: PropTypes.string
|
|
873
|
-
};
|
|
874
|
-
|
|
875
|
-
var CustomField = /*#__PURE__*/React.memo(function CustomField(props) {
|
|
876
|
-
var Component = props.Component,
|
|
877
|
-
isRequired = props.isRequired,
|
|
878
|
-
name = props.name,
|
|
879
|
-
fieldProps = props.fieldProps,
|
|
880
|
-
classNameGroupItem = props.classNameGroupItem,
|
|
881
|
-
hideMessage = props.hideMessage;
|
|
882
|
-
return /*#__PURE__*/React.createElement(Field, {
|
|
883
|
-
name: name
|
|
884
|
-
}, function (_ref) {
|
|
885
|
-
var input = _ref.input,
|
|
886
|
-
meta = _ref.meta;
|
|
887
|
-
return /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
|
|
888
|
-
className: clsx('form-field_type_custom', 'form__item_type_custom', classNameGroupItem),
|
|
889
|
-
fieldClassName: 'form-custom',
|
|
890
|
-
inputName: input.name,
|
|
891
|
-
inputValue: input.value,
|
|
892
|
-
isRequired: isRequired,
|
|
893
|
-
metaActive: meta.active,
|
|
894
|
-
metaError: meta.error,
|
|
895
|
-
metaModifiedSinceLastSubmit: meta.modifiedSinceLastSubmit,
|
|
896
|
-
metaSubmitError: meta.submitError,
|
|
897
|
-
metaSubmitFailed: meta.submitFailed,
|
|
898
|
-
metaTouched: meta.touched,
|
|
899
|
-
metaValid: meta.valid,
|
|
900
|
-
hideMessage: hideMessage
|
|
901
|
-
}, fieldProps), /*#__PURE__*/React.createElement(Component, Object.assign({}, props, {
|
|
902
|
-
input: input,
|
|
903
|
-
meta: meta
|
|
904
|
-
})));
|
|
905
|
-
});
|
|
906
|
-
});
|
|
907
|
-
CustomField.defaultProps = {
|
|
908
|
-
inputProps: {},
|
|
909
|
-
fieldProps: {}
|
|
910
|
-
};
|
|
911
|
-
CustomField.propTypes = {
|
|
912
|
-
name: PropTypes.string.isRequired,
|
|
913
|
-
isRequired: PropTypes.bool,
|
|
914
|
-
fieldProps: PropTypes.object,
|
|
915
|
-
inputProps: PropTypes.object
|
|
916
|
-
};
|
|
917
|
-
|
|
918
|
-
var CodeField = /*#__PURE__*/React.memo(function CodeField(props) {
|
|
919
|
-
var isRequired = props.isRequired,
|
|
920
|
-
name = props.name,
|
|
921
|
-
fieldProps = props.fieldProps,
|
|
922
|
-
inputProps = props.inputProps,
|
|
923
|
-
classNameGroupItem = props.classNameGroupItem,
|
|
924
|
-
hideMessage = props.hideMessage;
|
|
925
|
-
return /*#__PURE__*/React.createElement(Field, {
|
|
926
|
-
name: name
|
|
927
|
-
}, function (_ref) {
|
|
928
|
-
var input = _ref.input,
|
|
929
|
-
meta = _ref.meta;
|
|
930
|
-
return /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
|
|
931
|
-
className: clsx('form-field_type_code', 'form__item_type_code', classNameGroupItem),
|
|
932
|
-
fieldClassName: 'form-code',
|
|
933
|
-
inputName: input.name,
|
|
934
|
-
inputValue: input.value,
|
|
935
|
-
isRequired: isRequired,
|
|
936
|
-
metaActive: meta.active,
|
|
937
|
-
metaError: meta.error,
|
|
938
|
-
metaModifiedSinceLastSubmit: meta.modifiedSinceLastSubmit,
|
|
939
|
-
metaSubmitError: meta.submitError,
|
|
940
|
-
metaSubmitFailed: meta.submitFailed,
|
|
941
|
-
metaTouched: meta.touched,
|
|
942
|
-
metaValid: meta.valid,
|
|
943
|
-
hideMessage: hideMessage
|
|
944
|
-
}, fieldProps), /*#__PURE__*/React.createElement(Code, Object.assign({
|
|
945
|
-
autoComplete: "nope",
|
|
946
|
-
name: input.name,
|
|
947
|
-
value: input.value,
|
|
948
|
-
onBlur: input.onBlur,
|
|
949
|
-
onChange: input.onChange,
|
|
950
|
-
onFocus: input.onFocus
|
|
951
|
-
}, inputProps)));
|
|
952
|
-
});
|
|
953
|
-
});
|
|
954
|
-
CodeField.defaultProps = {
|
|
955
|
-
inputProps: {},
|
|
956
|
-
fieldProps: {}
|
|
957
|
-
};
|
|
958
|
-
CodeField.propTypes = {
|
|
959
|
-
name: PropTypes.string.isRequired,
|
|
960
|
-
isRequired: PropTypes.bool,
|
|
961
|
-
fieldProps: PropTypes.object,
|
|
962
|
-
inputProps: PropTypes.object
|
|
963
|
-
};
|
|
964
|
-
|
|
965
|
-
function DatePickerField(props) {
|
|
966
|
-
var isRequired = props.isRequired,
|
|
967
|
-
fieldProps = props.fieldProps,
|
|
968
|
-
inputProps = props.inputProps,
|
|
969
|
-
datePickerProps = props.datePickerProps,
|
|
970
|
-
name = props.name;
|
|
971
|
-
props.iconSize;
|
|
972
|
-
props.iconBorder;
|
|
973
|
-
props.iconBorderHover;
|
|
974
|
-
props.iconFill;
|
|
975
|
-
props.iconFillHover;
|
|
976
|
-
props.iconRevealableShow;
|
|
977
|
-
props.iconRevealableHide;
|
|
978
|
-
props.iconShape;
|
|
979
|
-
var hideMessage = props.hideMessage,
|
|
980
|
-
onChange = props.onChange,
|
|
981
|
-
classNameGroupItem = props.classNameGroupItem;
|
|
982
|
-
return /*#__PURE__*/React.createElement(Field, {
|
|
983
|
-
name: name
|
|
984
|
-
}, function (_ref) {
|
|
985
|
-
var input = _ref.input,
|
|
986
|
-
meta = _ref.meta;
|
|
987
|
-
var onChangeField = useCallback(function (value) {
|
|
988
|
-
input.onChange(value);
|
|
989
|
-
if (onChange) {
|
|
990
|
-
onChange(value, input.name);
|
|
991
|
-
}
|
|
992
|
-
}, [onChange]);
|
|
993
|
-
return /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
|
|
994
|
-
className: clsx('form-field_type_datepicker', 'form__item_type_datepicker', classNameGroupItem),
|
|
995
|
-
fieldClassName: "form-datepicker",
|
|
996
|
-
inputName: input.name,
|
|
997
|
-
inputValue: input.value || '',
|
|
998
|
-
isRequired: isRequired,
|
|
999
|
-
metaActive: meta.active,
|
|
1000
|
-
metaError: meta.error,
|
|
1001
|
-
metaModifiedSinceLastSubmit: meta.modifiedSinceLastSubmit,
|
|
1002
|
-
metaSubmitError: meta.submitError,
|
|
1003
|
-
metaSubmitFailed: meta.submitFailed,
|
|
1004
|
-
metaTouched: meta.touched,
|
|
1005
|
-
metaValid: meta.valid,
|
|
1006
|
-
hideMessage: hideMessage
|
|
1007
|
-
}, fieldProps), /*#__PURE__*/React.createElement(DatePickerInput, {
|
|
1008
|
-
name: input.name,
|
|
1009
|
-
value: input.value || '',
|
|
1010
|
-
onBlur: input.onBlur,
|
|
1011
|
-
onChange: onChangeField,
|
|
1012
|
-
onFocus: input.onFocus,
|
|
1013
|
-
inputProps: inputProps,
|
|
1014
|
-
datePickerProps: datePickerProps
|
|
1015
|
-
}));
|
|
1016
|
-
});
|
|
1017
|
-
}
|
|
1018
|
-
DatePickerField.defaultProps = {
|
|
1019
|
-
inputProps: {},
|
|
1020
|
-
fieldProps: {}
|
|
1021
|
-
};
|
|
1022
|
-
DatePickerField.propTypes = {
|
|
1023
|
-
fieldProps: PropTypes.object,
|
|
1024
|
-
inputProps: PropTypes.object,
|
|
1025
|
-
isRequired: PropTypes.bool,
|
|
1026
|
-
name: PropTypes.string.isRequired,
|
|
1027
|
-
onChange: PropTypes.func
|
|
1028
|
-
};
|
|
1029
|
-
|
|
1030
|
-
function getFileByURL(_x) {
|
|
1031
|
-
return _getFileByURL.apply(this, arguments);
|
|
1032
|
-
}
|
|
1033
|
-
function _getFileByURL() {
|
|
1034
|
-
_getFileByURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(url) {
|
|
1035
|
-
var _response$headers$con, response, blobObject, dirtyFilename, filename, typeParts, fileType;
|
|
1036
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
1037
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
1038
|
-
case 0:
|
|
1039
|
-
_context3.prev = 0;
|
|
1040
|
-
_context3.next = 3;
|
|
1041
|
-
return axios({
|
|
1042
|
-
url: "/api/" + url + "/",
|
|
1043
|
-
responseType: 'blob'
|
|
1044
|
-
});
|
|
1045
|
-
case 3:
|
|
1046
|
-
response = _context3.sent;
|
|
1047
|
-
blobObject = response.data;
|
|
1048
|
-
dirtyFilename = (_response$headers$con = response.headers['content-disposition']) == null ? void 0 : _response$headers$con.split('filename=')[1]; // Remove double quotes
|
|
1049
|
-
filename = dirtyFilename == null ? void 0 : dirtyFilename.substring(1).slice(0, -1);
|
|
1050
|
-
if (!filename) {
|
|
1051
|
-
typeParts = blobObject.type.split('/');
|
|
1052
|
-
fileType = typeParts[typeParts.length - 1];
|
|
1053
|
-
filename = new Date().getTime() + "." + fileType;
|
|
1054
|
-
}
|
|
1055
|
-
return _context3.abrupt("return", new File([blobObject], filename, {
|
|
1056
|
-
type: blobObject.type
|
|
1057
|
-
}));
|
|
1058
|
-
case 11:
|
|
1059
|
-
_context3.prev = 11;
|
|
1060
|
-
_context3.t0 = _context3["catch"](0);
|
|
1061
|
-
console.log('error: ', _context3.t0);
|
|
1062
|
-
return _context3.abrupt("return", null);
|
|
1063
|
-
case 15:
|
|
1064
|
-
case "end":
|
|
1065
|
-
return _context3.stop();
|
|
1066
|
-
}
|
|
1067
|
-
}, _callee3, null, [[0, 11]]);
|
|
1068
|
-
}));
|
|
1069
|
-
return _getFileByURL.apply(this, arguments);
|
|
1070
|
-
}
|
|
1071
|
-
function convertToFiles(_x2, _x3) {
|
|
1072
|
-
return _convertToFiles.apply(this, arguments);
|
|
1073
|
-
}
|
|
1074
|
-
function _convertToFiles() {
|
|
1075
|
-
_convertToFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(inputValue, isPreviews) {
|
|
1076
|
-
var newFiles, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, value, newFile, isURL;
|
|
1077
|
-
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
1078
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
1079
|
-
case 0:
|
|
1080
|
-
newFiles = [];
|
|
1081
|
-
_iteratorAbruptCompletion = false;
|
|
1082
|
-
_didIteratorError = false;
|
|
1083
|
-
_context4.prev = 3;
|
|
1084
|
-
_iterator = _asyncIterator(castArray(inputValue));
|
|
1085
|
-
case 5:
|
|
1086
|
-
_context4.next = 7;
|
|
1087
|
-
return _iterator.next();
|
|
1088
|
-
case 7:
|
|
1089
|
-
if (!(_iteratorAbruptCompletion = !(_step = _context4.sent).done)) {
|
|
1090
|
-
_context4.next = 21;
|
|
1091
|
-
break;
|
|
1092
|
-
}
|
|
1093
|
-
value = _step.value;
|
|
1094
|
-
newFile = null; // Download image by url and save as File instance
|
|
1095
|
-
isURL = typeof value === 'string' && value.includes('/');
|
|
1096
|
-
if (!(value.image || isURL)) {
|
|
1097
|
-
_context4.next = 16;
|
|
1098
|
-
break;
|
|
1099
|
-
}
|
|
1100
|
-
_context4.next = 14;
|
|
1101
|
-
return getFileByURL(value.image || value);
|
|
1102
|
-
case 14:
|
|
1103
|
-
newFile = _context4.sent;
|
|
1104
|
-
if (newFile) {
|
|
1105
|
-
setFileDataURL(newFile);
|
|
1106
|
-
}
|
|
1107
|
-
case 16:
|
|
1108
|
-
// Convert dataURL to File instance
|
|
1109
|
-
if (value.dataURL) {
|
|
1110
|
-
newFile = createFileFromDataURL(value.name || value.path, value.dataURL);
|
|
1111
|
-
newFile.dataURL = value.dataURL;
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
// Save new File to state
|
|
1115
|
-
if (newFile) {
|
|
1116
|
-
newFile.id = value.id;
|
|
1117
|
-
if (isPreviews) {
|
|
1118
|
-
newFile.preview = URL.createObjectURL(newFile);
|
|
1119
|
-
}
|
|
1120
|
-
newFiles.push(newFile);
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
// else if (value) {
|
|
1124
|
-
// newFiles.push({
|
|
1125
|
-
// name: value,
|
|
1126
|
-
// error: 'File is unavailable',
|
|
1127
|
-
// })
|
|
1128
|
-
// }
|
|
1129
|
-
case 18:
|
|
1130
|
-
_iteratorAbruptCompletion = false;
|
|
1131
|
-
_context4.next = 5;
|
|
1132
|
-
break;
|
|
1133
|
-
case 21:
|
|
1134
|
-
_context4.next = 27;
|
|
1135
|
-
break;
|
|
1136
|
-
case 23:
|
|
1137
|
-
_context4.prev = 23;
|
|
1138
|
-
_context4.t0 = _context4["catch"](3);
|
|
1139
|
-
_didIteratorError = true;
|
|
1140
|
-
_iteratorError = _context4.t0;
|
|
1141
|
-
case 27:
|
|
1142
|
-
_context4.prev = 27;
|
|
1143
|
-
_context4.prev = 28;
|
|
1144
|
-
if (!(_iteratorAbruptCompletion && _iterator["return"] != null)) {
|
|
1145
|
-
_context4.next = 32;
|
|
1146
|
-
break;
|
|
1147
|
-
}
|
|
1148
|
-
_context4.next = 32;
|
|
1149
|
-
return _iterator["return"]();
|
|
1150
|
-
case 32:
|
|
1151
|
-
_context4.prev = 32;
|
|
1152
|
-
if (!_didIteratorError) {
|
|
1153
|
-
_context4.next = 35;
|
|
1154
|
-
break;
|
|
1155
|
-
}
|
|
1156
|
-
throw _iteratorError;
|
|
1157
|
-
case 35:
|
|
1158
|
-
return _context4.finish(32);
|
|
1159
|
-
case 36:
|
|
1160
|
-
return _context4.finish(27);
|
|
1161
|
-
case 37:
|
|
1162
|
-
return _context4.abrupt("return", newFiles);
|
|
1163
|
-
case 38:
|
|
1164
|
-
case "end":
|
|
1165
|
-
return _context4.stop();
|
|
1166
|
-
}
|
|
1167
|
-
}, _callee4, null, [[3, 23, 27, 37], [28,, 32, 36]]);
|
|
1168
|
-
}));
|
|
1169
|
-
return _convertToFiles.apply(this, arguments);
|
|
1170
|
-
}
|
|
1171
|
-
function setFileDataURL(file, resolve) {
|
|
1172
|
-
resolve = resolve || function () {};
|
|
1173
|
-
// Init reader and save his file
|
|
1174
|
-
var reader = new FileReader();
|
|
1175
|
-
reader._readedFile = file;
|
|
1176
|
-
|
|
1177
|
-
// Set handlers
|
|
1178
|
-
reader.onabort = function () {
|
|
1179
|
-
return resolve();
|
|
1180
|
-
};
|
|
1181
|
-
reader.onerror = function () {
|
|
1182
|
-
return resolve();
|
|
1183
|
-
};
|
|
1184
|
-
reader.onload = function (event) {
|
|
1185
|
-
event.target._readedFile.dataURL = reader.result;
|
|
1186
|
-
resolve();
|
|
1187
|
-
};
|
|
1188
|
-
// Run reader
|
|
1189
|
-
if (file instanceof File) {
|
|
1190
|
-
reader.readAsDataURL(file);
|
|
1191
|
-
} else {
|
|
1192
|
-
resolve();
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
var FileInputDropzone = /*#__PURE__*/React.memo(function FileInputDropzone(props) {
|
|
1196
|
-
var inputName = props.inputName,
|
|
1197
|
-
size = props.size,
|
|
1198
|
-
className = props.className,
|
|
1199
|
-
fileErrorText = props.fileErrorText,
|
|
1200
|
-
hintTitleTextSize = props.hintTitleTextSize,
|
|
1201
|
-
removeThumbTextSize = props.removeThumbTextSize,
|
|
1202
|
-
removeThumbTextColor = props.removeThumbTextColor,
|
|
1203
|
-
removeThumbTextWeight = props.removeThumbTextWeight,
|
|
1204
|
-
thumbNameTextSize = props.thumbNameTextSize,
|
|
1205
|
-
thumbNameTextColor = props.thumbNameTextColor,
|
|
1206
|
-
removeThumbTextHoverColor = props.removeThumbTextHoverColor,
|
|
1207
|
-
thumbNameTextWrap = props.thumbNameTextWrap,
|
|
1208
|
-
thumbNameTextWeight = props.thumbNameTextWeight,
|
|
1209
|
-
hintTitleTextColor = props.hintTitleTextColor,
|
|
1210
|
-
hintTitleTextWrap = props.hintTitleTextWrap,
|
|
1211
|
-
thumbColumn = props.thumbColumn,
|
|
1212
|
-
hintTitleTextWeight = props.hintTitleTextWeight,
|
|
1213
|
-
hintDescriptionTextSize = props.hintDescriptionTextSize,
|
|
1214
|
-
hintDescriptionTextColor = props.hintDescriptionTextColor,
|
|
1215
|
-
hintDescriptionTextWrap = props.hintDescriptionTextWrap,
|
|
1216
|
-
hintDescriptionTextWeight = props.hintDescriptionTextWeight,
|
|
1217
|
-
errorMessageTextSize = props.errorMessageTextSize,
|
|
1218
|
-
errorMessageTextWeight = props.errorMessageTextWeight,
|
|
1219
|
-
errorMessageTextColor = props.errorMessageTextColor,
|
|
1220
|
-
inputValue = props.inputValue,
|
|
1221
|
-
maxFiles = props.maxFiles,
|
|
1222
|
-
maxSize = props.maxSize,
|
|
1223
|
-
removeThumbText = props.removeThumbText,
|
|
1224
|
-
hintTitle = props.hintTitle,
|
|
1225
|
-
hintDescription = props.hintDescription,
|
|
1226
|
-
isShowFilename = props.isShowFilename,
|
|
1227
|
-
isPreviews = props.isPreviews;
|
|
1228
|
-
props.loadingText;
|
|
1229
|
-
var _props$dropzoneProps = props.dropzoneProps,
|
|
1230
|
-
dropzoneProps = _props$dropzoneProps === void 0 ? {} : _props$dropzoneProps,
|
|
1231
|
-
onAddFiles = props.onAddFiles,
|
|
1232
|
-
onDeleteFile = props.onDeleteFile;
|
|
1233
|
-
var _useState = useState(''),
|
|
1234
|
-
fileError = _useState[0],
|
|
1235
|
-
setFileError = _useState[1];
|
|
1236
|
-
var _useState2 = useState(false),
|
|
1237
|
-
fileIsLoading = _useState2[0],
|
|
1238
|
-
setFileIsLoading = _useState2[1];
|
|
1239
|
-
// State with instances of "File" type
|
|
1240
|
-
var _useState3 = useState(inputValue ? castArray(inputValue) : []),
|
|
1241
|
-
files = _useState3[0],
|
|
1242
|
-
setFiles = _useState3[1];
|
|
1243
|
-
|
|
1244
|
-
// Save to mobx state
|
|
1245
|
-
var _useForm = useForm(),
|
|
1246
|
-
change = _useForm.change;
|
|
1247
|
-
var changeFormState = useCallback(function (newFiles) {
|
|
1248
|
-
// If max files in dropzone is 1 - return file as it self, else as array of files
|
|
1249
|
-
// ps: for old projects compatibility
|
|
1250
|
-
var toSave = dropzoneProps.maxFiles == 1 ? newFiles[0] : newFiles;
|
|
1251
|
-
change(inputName, toSave);
|
|
1252
|
-
return toSave;
|
|
1253
|
-
}, [dropzoneProps, change]);
|
|
1254
|
-
|
|
1255
|
-
// Create dropzone options
|
|
1256
|
-
var _useDropzone = useDropzone(Object.assign({
|
|
1257
|
-
maxSize: maxSize || 10485760,
|
|
1258
|
-
// 10mb
|
|
1259
|
-
maxFiles: maxFiles || 5
|
|
1260
|
-
}, dropzoneProps, {
|
|
1261
|
-
getFilesFromEvent: function () {
|
|
1262
|
-
var _getFilesFromEvent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
|
|
1263
|
-
var result, newFiles;
|
|
1264
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1265
|
-
while (1) switch (_context.prev = _context.next) {
|
|
1266
|
-
case 0:
|
|
1267
|
-
_context.next = 2;
|
|
1268
|
-
return fromEvent(event);
|
|
1269
|
-
case 2:
|
|
1270
|
-
result = _context.sent;
|
|
1271
|
-
newFiles = result.filter(function (item) {
|
|
1272
|
-
return item instanceof File;
|
|
1273
|
-
}); // Add exists and new files to accepted(or rejected)
|
|
1274
|
-
return _context.abrupt("return", [].concat(files, newFiles));
|
|
1275
|
-
case 5:
|
|
1276
|
-
case "end":
|
|
1277
|
-
return _context.stop();
|
|
1278
|
-
}
|
|
1279
|
-
}, _callee);
|
|
1280
|
-
}));
|
|
1281
|
-
function getFilesFromEvent(_x4) {
|
|
1282
|
-
return _getFilesFromEvent.apply(this, arguments);
|
|
1283
|
-
}
|
|
1284
|
-
return getFilesFromEvent;
|
|
1285
|
-
}(),
|
|
1286
|
-
onDropAccepted: function onDropAccepted(acceptedFiles, event) {
|
|
1287
|
-
// If dropped files has accepted and we need a previews
|
|
1288
|
-
if (isPreviews) {
|
|
1289
|
-
// Add preview to every file
|
|
1290
|
-
acceptedFiles.forEach(function (file) {
|
|
1291
|
-
if (!file.error) {
|
|
1292
|
-
file.preview = URL.createObjectURL(file);
|
|
1293
|
-
}
|
|
1294
|
-
});
|
|
1295
|
-
}
|
|
1296
|
-
// Save to form data (including empty when files are not valid)
|
|
1297
|
-
setFiles(acceptedFiles);
|
|
1298
|
-
setFileError('');
|
|
1299
|
-
|
|
1300
|
-
// Save DataURL for all files
|
|
1301
|
-
var readerPromisesList = acceptedFiles.map(function (file) {
|
|
1302
|
-
return new Promise(function (resolve) {
|
|
1303
|
-
return setFileDataURL(file, resolve);
|
|
1304
|
-
});
|
|
1305
|
-
});
|
|
1306
|
-
// Save files to form values
|
|
1307
|
-
Promise.all(readerPromisesList).then(function () {
|
|
1308
|
-
var filesToSave = changeFormState(acceptedFiles);
|
|
1309
|
-
if (onAddFiles) {
|
|
1310
|
-
onAddFiles(filesToSave, inputName);
|
|
1311
|
-
}
|
|
1312
|
-
});
|
|
1313
|
-
},
|
|
1314
|
-
onDropRejected: function onDropRejected(rejectedFiles, event) {
|
|
1315
|
-
// If dropped files has rejected
|
|
1316
|
-
if (rejectedFiles.length) {
|
|
1317
|
-
var _rejectedFiles$0$erro;
|
|
1318
|
-
var firstFileError = (_rejectedFiles$0$erro = rejectedFiles[0].errors[0]) == null ? void 0 : _rejectedFiles$0$erro.message;
|
|
1319
|
-
// Show error
|
|
1320
|
-
setFileError(firstFileError || 'Error on adding file');
|
|
1321
|
-
} else {
|
|
1322
|
-
// Else clean error
|
|
1323
|
-
setFileError('');
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
})),
|
|
1327
|
-
getRootProps = _useDropzone.getRootProps,
|
|
1328
|
-
getInputProps = _useDropzone.getInputProps;
|
|
1329
|
-
|
|
1330
|
-
// Delete file from dropzone
|
|
1331
|
-
var removeFile = useCallback(function (event, index) {
|
|
1332
|
-
event.stopPropagation();
|
|
1333
|
-
event.preventDefault();
|
|
1334
|
-
var newFiles = [].concat(files);
|
|
1335
|
-
newFiles.splice(index, 1);
|
|
1336
|
-
if (onDeleteFile) {
|
|
1337
|
-
onDeleteFile(files[index], inputName);
|
|
1338
|
-
}
|
|
1339
|
-
changeFormState(newFiles);
|
|
1340
|
-
}, [files, changeFormState, onDeleteFile]);
|
|
1341
|
-
|
|
1342
|
-
//
|
|
1343
|
-
var convertFiledValueAndSaveAsFiles = useCallback( /*#__PURE__*/function () {
|
|
1344
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(newInputValue) {
|
|
1345
|
-
var newFiles;
|
|
1346
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1347
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
1348
|
-
case 0:
|
|
1349
|
-
setFileIsLoading(true);
|
|
1350
|
-
_context2.next = 3;
|
|
1351
|
-
return convertToFiles(newInputValue, isPreviews);
|
|
1352
|
-
case 3:
|
|
1353
|
-
newFiles = _context2.sent;
|
|
1354
|
-
setFileIsLoading(false);
|
|
1355
|
-
setFiles(newFiles);
|
|
1356
|
-
return _context2.abrupt("return", newFiles);
|
|
1357
|
-
case 7:
|
|
1358
|
-
case "end":
|
|
1359
|
-
return _context2.stop();
|
|
1360
|
-
}
|
|
1361
|
-
}, _callee2);
|
|
1362
|
-
}));
|
|
1363
|
-
return function (_x5) {
|
|
1364
|
-
return _ref.apply(this, arguments);
|
|
1365
|
-
};
|
|
1366
|
-
}(), [isPreviews]);
|
|
1367
|
-
useEffect(function () {
|
|
1368
|
-
// First time convert value to Files and save to local and form state
|
|
1369
|
-
convertFiledValueAndSaveAsFiles(inputValue).then(function (newFiles) {
|
|
1370
|
-
return changeFormState(newFiles);
|
|
1371
|
-
});
|
|
1372
|
-
}, []); // eslint-disable-line
|
|
1373
|
-
|
|
1374
|
-
useEffect(function () {
|
|
1375
|
-
// Everytime convert value to Files and save to local state
|
|
1376
|
-
if (!inputValue) {
|
|
1377
|
-
setFiles([]);
|
|
1378
|
-
} else {
|
|
1379
|
-
convertFiledValueAndSaveAsFiles(inputValue);
|
|
1380
|
-
}
|
|
1381
|
-
// only "inputValue"
|
|
1382
|
-
}, [inputValue]); // eslint-disable-line
|
|
1383
|
-
|
|
1384
|
-
useEffect(function () {
|
|
1385
|
-
// Make sure to revoke the data uris to avoid memory leaks, will run on unmount
|
|
1386
|
-
return function () {
|
|
1387
|
-
return files.forEach(function (file) {
|
|
1388
|
-
return URL.revokeObjectURL(file == null ? void 0 : file.preview);
|
|
1389
|
-
});
|
|
1390
|
-
};
|
|
1391
|
-
}, []); // eslint-disable-line
|
|
1392
|
-
|
|
1393
|
-
var fillClass = useDeviceTargetClass(props, {
|
|
1394
|
-
prefix: 'fill_',
|
|
1395
|
-
propsKey: 'fill'
|
|
1396
|
-
});
|
|
1397
|
-
var fillHoverClass = useDeviceTargetClass(props, {
|
|
1398
|
-
prefix: 'fill_hover_',
|
|
1399
|
-
propsKey: 'fillHover'
|
|
1400
|
-
});
|
|
1401
|
-
var borderWidthClass = useDeviceTargetClass(props, {
|
|
1402
|
-
prefix: 'border-width_',
|
|
1403
|
-
propsKey: 'borderWidth'
|
|
1404
|
-
});
|
|
1405
|
-
var borderColorClass = useDeviceTargetClass(props, {
|
|
1406
|
-
prefix: 'border-color_',
|
|
1407
|
-
propsKey: 'borderColor'
|
|
1408
|
-
});
|
|
1409
|
-
var borderColorHoverClass = useDeviceTargetClass(props, {
|
|
1410
|
-
prefix: 'border-color_hover_',
|
|
1411
|
-
propsKey: 'borderColorHover'
|
|
1412
|
-
});
|
|
1413
|
-
var borderTypeClass = useDeviceTargetClass(props, {
|
|
1414
|
-
prefix: 'border_type_',
|
|
1415
|
-
propsKey: 'borderType'
|
|
1416
|
-
});
|
|
1417
|
-
var shapeClass = useDeviceTargetClass(props, {
|
|
1418
|
-
prefix: 'form-dropzone_shape_',
|
|
1419
|
-
propsKey: 'shape'
|
|
1420
|
-
});
|
|
1421
|
-
var thumbBorderWidthClass = useDeviceTargetClass(props, {
|
|
1422
|
-
prefix: 'border-width_',
|
|
1423
|
-
propsKey: 'thumbBorderWidth'
|
|
1424
|
-
});
|
|
1425
|
-
var thumbDirectionClass = useDeviceTargetClass(props, {
|
|
1426
|
-
prefix: 'form-dropzone__thumb_direction_',
|
|
1427
|
-
propsKey: 'thumbDirection'
|
|
1428
|
-
});
|
|
1429
|
-
var thumbBorderColorClass = useDeviceTargetClass(props, {
|
|
1430
|
-
prefix: 'border-color_',
|
|
1431
|
-
propsKey: 'thumbBorderColor'
|
|
1432
|
-
});
|
|
1433
|
-
var thumbBorderColorHoverClass = useDeviceTargetClass(props, {
|
|
1434
|
-
prefix: 'border-color_hover_',
|
|
1435
|
-
propsKey: 'thumbBorderColorHover'
|
|
1436
|
-
});
|
|
1437
|
-
var thumbBorderTypeClass = useDeviceTargetClass(props, {
|
|
1438
|
-
prefix: 'border_type_',
|
|
1439
|
-
propsKey: 'thumbBorderType'
|
|
1440
|
-
});
|
|
1441
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", getRootProps({
|
|
1442
|
-
className: "form-dropzone__dropzone dropzone " + className + " thumbColumn form-dropzone__dropzone_size_" + size + " " + shapeClass
|
|
1443
|
-
}), /*#__PURE__*/React.createElement("input", Object.assign({}, getInputProps(), {
|
|
1444
|
-
name: inputName
|
|
1445
|
-
})), /*#__PURE__*/React.createElement("div", {
|
|
1446
|
-
className: clsx('form-dropzone__dropzone-wrapper', thumbColumn && "form-dropzone__dropzone-wrapper_column_" + thumbColumn, fillClass, fillHoverClass, borderWidthClass, borderColorClass, borderColorHoverClass, borderTypeClass)
|
|
1447
|
-
}, files.map(function (file, i) {
|
|
1448
|
-
return /*#__PURE__*/React.createElement("aside", {
|
|
1449
|
-
className: clsx('form-dropzone__thumb', fillClass, thumbDirectionClass, thumbBorderWidthClass, thumbBorderColorClass, thumbBorderColorHoverClass, thumbBorderTypeClass),
|
|
1450
|
-
key: "" + (file.id || file.name + "_" + i || 'i' + i)
|
|
1451
|
-
}, isPreviews && !file.error && /*#__PURE__*/React.createElement("div", {
|
|
1452
|
-
className: "form-dropzone__thumb-image"
|
|
1453
|
-
}, /*#__PURE__*/React.createElement("img", {
|
|
1454
|
-
className: "form-dropzone__thumb-image-inner",
|
|
1455
|
-
src: file.preview || file.image,
|
|
1456
|
-
onLoad: function onLoad() {
|
|
1457
|
-
// Revoke data uri after image is loaded
|
|
1458
|
-
URL.revokeObjectURL(file.preview);
|
|
1459
|
-
}
|
|
1460
|
-
})), file.error && /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Text, {
|
|
1461
|
-
size: thumbNameTextSize,
|
|
1462
|
-
textColor: thumbNameTextColor,
|
|
1463
|
-
textWrap: thumbNameTextWrap,
|
|
1464
|
-
textWeight: thumbNameTextWeight
|
|
1465
|
-
}, fileErrorText || file.error)), isShowFilename && /*#__PURE__*/React.createElement("div", {
|
|
1466
|
-
className: "form-dropzone__thumb-name"
|
|
1467
|
-
}, /*#__PURE__*/React.createElement(Text, {
|
|
1468
|
-
size: thumbNameTextSize,
|
|
1469
|
-
textColor: thumbNameTextColor,
|
|
1470
|
-
textWrap: thumbNameTextWrap,
|
|
1471
|
-
textWeight: thumbNameTextWeight,
|
|
1472
|
-
className: "form-dropzone__thumb-name-inner"
|
|
1473
|
-
}, file.name)), fileIsLoading && /*#__PURE__*/React.createElement("div", {
|
|
1474
|
-
className: "form-dropzone__thumb-loader"
|
|
1475
|
-
}, /*#__PURE__*/React.createElement(Loader, {
|
|
1476
|
-
fill: "surfacePrimary",
|
|
1477
|
-
height: "fill",
|
|
1478
|
-
itemFill: "surfaceItemAccent",
|
|
1479
|
-
set: "simple",
|
|
1480
|
-
width: "fill"
|
|
1481
|
-
})), /*#__PURE__*/React.createElement("div", {
|
|
1482
|
-
className: "form-dropzone__thumb-remove",
|
|
1483
|
-
onClick: function onClick(event) {
|
|
1484
|
-
return removeFile(event, i);
|
|
1485
|
-
}
|
|
1486
|
-
}, /*#__PURE__*/React.createElement(Text, {
|
|
1487
|
-
size: removeThumbTextSize,
|
|
1488
|
-
textColor: removeThumbTextColor,
|
|
1489
|
-
textWeight: removeThumbTextWeight,
|
|
1490
|
-
textColorHover: removeThumbTextHoverColor,
|
|
1491
|
-
className: "form-dropzone__thumb-remove-text"
|
|
1492
|
-
}, removeThumbText || 'Remove')));
|
|
1493
|
-
}), !files.length ? /*#__PURE__*/React.createElement("div", {
|
|
1494
|
-
className: "form-dropzone__hint"
|
|
1495
|
-
}, /*#__PURE__*/React.createElement(Text, {
|
|
1496
|
-
size: hintTitleTextSize,
|
|
1497
|
-
textColor: hintTitleTextColor,
|
|
1498
|
-
textWrap: hintTitleTextWrap,
|
|
1499
|
-
textWeight: hintTitleTextWeight,
|
|
1500
|
-
className: "form-dropzone__hint-title"
|
|
1501
|
-
}, hintTitle || 'Select a file or drag in form'), /*#__PURE__*/React.createElement(Text, {
|
|
1502
|
-
size: hintDescriptionTextSize,
|
|
1503
|
-
textColor: hintDescriptionTextColor,
|
|
1504
|
-
textWrap: hintDescriptionTextWrap,
|
|
1505
|
-
textWeight: hintDescriptionTextWeight,
|
|
1506
|
-
className: "form-dropzone__hint-text"
|
|
1507
|
-
}, hintDescription)) : /*#__PURE__*/React.createElement("div", {
|
|
1508
|
-
className: "form-dropzone__hint form-dropzone__hint_type_add-more"
|
|
1509
|
-
}, /*#__PURE__*/React.createElement(Text, {
|
|
1510
|
-
size: hintTitleTextSize,
|
|
1511
|
-
textColor: hintTitleTextColor,
|
|
1512
|
-
textWrap: hintTitleTextWrap,
|
|
1513
|
-
textWeight: hintTitleTextWeight,
|
|
1514
|
-
className: "form-dropzone__hint-title"
|
|
1515
|
-
}, hintTitle || 'Select a file or drag in form'), /*#__PURE__*/React.createElement(Text, {
|
|
1516
|
-
size: hintDescriptionTextSize,
|
|
1517
|
-
textColor: hintDescriptionTextColor,
|
|
1518
|
-
textWrap: hintDescriptionTextWrap,
|
|
1519
|
-
textWeight: hintDescriptionTextWeight,
|
|
1520
|
-
className: "form-dropzone__hint-text"
|
|
1521
|
-
}, hintDescription)))), fileError && /*#__PURE__*/React.createElement("div", {
|
|
1522
|
-
className: "form-field__message"
|
|
1523
|
-
}, /*#__PURE__*/React.createElement(Text, {
|
|
1524
|
-
className: "form-field__message-item form-field__message-item_type_message",
|
|
1525
|
-
size: errorMessageTextSize,
|
|
1526
|
-
textWeight: errorMessageTextWeight,
|
|
1527
|
-
textColor: errorMessageTextColor
|
|
1528
|
-
}, fileError)));
|
|
1529
|
-
});
|
|
1530
|
-
FileInputDropzone.propTypes = {
|
|
1531
|
-
dropzoneProps: PropTypes.object,
|
|
1532
|
-
hintDescription: PropTypes.string,
|
|
1533
|
-
hintTitle: PropTypes.string,
|
|
1534
|
-
inputName: PropTypes.string,
|
|
1535
|
-
inputValue: PropTypes.any,
|
|
1536
|
-
isPreviews: PropTypes.bool,
|
|
1537
|
-
isShowFilename: PropTypes.bool,
|
|
1538
|
-
loadingText: PropTypes.string,
|
|
1539
|
-
metaError: PropTypes.string,
|
|
1540
|
-
metaTouched: PropTypes.bool,
|
|
1541
|
-
removeThumbText: PropTypes.string,
|
|
1542
|
-
onAddFiles: PropTypes.func,
|
|
1543
|
-
onDeleteFile: PropTypes.func
|
|
1544
|
-
};
|
|
1545
|
-
|
|
1546
|
-
var FileInput = /*#__PURE__*/React.memo(function FileInput(props) {
|
|
1547
|
-
var name = props.name,
|
|
1548
|
-
shape = props.shape,
|
|
1549
|
-
size = props.size,
|
|
1550
|
-
borderWidth = props.borderWidth,
|
|
1551
|
-
borderColor = props.borderColor,
|
|
1552
|
-
borderColorHover = props.borderColorHover,
|
|
1553
|
-
borderType = props.borderType,
|
|
1554
|
-
label = props.label,
|
|
1555
|
-
thumbBorderWidth = props.thumbBorderWidth,
|
|
1556
|
-
thumbBorderColor = props.thumbBorderColor,
|
|
1557
|
-
thumbBorderColorHover = props.thumbBorderColorHover,
|
|
1558
|
-
thumbBorderType = props.thumbBorderType,
|
|
1559
|
-
removeThumbTextHoverColor = props.removeThumbTextHoverColor,
|
|
1560
|
-
labelTextColor = props.labelTextColor,
|
|
1561
|
-
fill = props.fill,
|
|
1562
|
-
fillHover = props.fillHover,
|
|
1563
|
-
className = props.className,
|
|
1564
|
-
removeThumbText = props.removeThumbText,
|
|
1565
|
-
thumbNameTextSize = props.thumbNameTextSize,
|
|
1566
|
-
thumbNameTextColor = props.thumbNameTextColor,
|
|
1567
|
-
thumbNameTextWrap = props.thumbNameTextWrap,
|
|
1568
|
-
thumbNameTextWeight = props.thumbNameTextWeight,
|
|
1569
|
-
removeThumbTextSize = props.removeThumbTextSize,
|
|
1570
|
-
removeThumbTextColor = props.removeThumbTextColor,
|
|
1571
|
-
removeThumbTextWeight = props.removeThumbTextWeight,
|
|
1572
|
-
hintTitle = props.hintTitle,
|
|
1573
|
-
errorMessageTextSize = props.errorMessageTextSize,
|
|
1574
|
-
errorMessageTextWeight = props.errorMessageTextWeight,
|
|
1575
|
-
errorMessageTextColor = props.errorMessageTextColor,
|
|
1576
|
-
fieldProps = props.fieldProps,
|
|
1577
|
-
hintTitleTextSize = props.hintTitleTextSize,
|
|
1578
|
-
hintTitleTextColor = props.hintTitleTextColor,
|
|
1579
|
-
hintTitleTextWrap = props.hintTitleTextWrap,
|
|
1580
|
-
hintTitleTextWeight = props.hintTitleTextWeight,
|
|
1581
|
-
hintDescriptionTextSize = props.hintDescriptionTextSize,
|
|
1582
|
-
hintDescriptionTextColor = props.hintDescriptionTextColor,
|
|
1583
|
-
hintDescriptionTextWrap = props.hintDescriptionTextWrap,
|
|
1584
|
-
hintDescriptionTextWeight = props.hintDescriptionTextWeight,
|
|
1585
|
-
hideMessage = props.hideMessage,
|
|
1586
|
-
thumbDirection = props.thumbDirection,
|
|
1587
|
-
hintDescription = props.hintDescription,
|
|
1588
|
-
isShowFilename = props.isShowFilename,
|
|
1589
|
-
fileErrorText = props.fileErrorText,
|
|
1590
|
-
dropzoneProps = props.dropzoneProps,
|
|
1591
|
-
maxFiles = props.maxFiles,
|
|
1592
|
-
maxSize = props.maxSize,
|
|
1593
|
-
thumbColumn = props.thumbColumn,
|
|
1594
|
-
isRequired = props.isRequired,
|
|
1595
|
-
isPreviews = props.isPreviews,
|
|
1596
|
-
onAddFiles = props.onAddFiles,
|
|
1597
|
-
onDeleteFile = props.onDeleteFile,
|
|
1598
|
-
classNameGroupItem = props.classNameGroupItem;
|
|
1599
|
-
return /*#__PURE__*/React.createElement(Field, {
|
|
1600
|
-
name: name
|
|
1601
|
-
}, function (_ref) {
|
|
1602
|
-
var input = _ref.input,
|
|
1603
|
-
meta = _ref.meta;
|
|
1604
|
-
return /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
|
|
1605
|
-
className: clsx('form-field_type_dropzone', 'form__item_type_dropzone', classNameGroupItem),
|
|
1606
|
-
fieldClassName: "form-dropzone",
|
|
1607
|
-
inputName: input.name,
|
|
1608
|
-
inputValue: input.value,
|
|
1609
|
-
isRequired: isRequired,
|
|
1610
|
-
label: label,
|
|
1611
|
-
labelTextColor: labelTextColor,
|
|
1612
|
-
metaActive: meta.active,
|
|
1613
|
-
metaError: meta.error,
|
|
1614
|
-
metaModifiedSinceLastSubmit: meta.modifiedSinceLastSubmit,
|
|
1615
|
-
metaSubmitError: meta.submitError,
|
|
1616
|
-
metaSubmitFailed: meta.submitFailed,
|
|
1617
|
-
metaTouched: meta.touched,
|
|
1618
|
-
metaValid: meta.valid,
|
|
1619
|
-
hideMessage: hideMessage
|
|
1620
|
-
}, fieldProps), /*#__PURE__*/React.createElement(FileInputDropzone, {
|
|
1621
|
-
dropzoneProps: dropzoneProps,
|
|
1622
|
-
hintDescription: hintDescription,
|
|
1623
|
-
hintTitle: hintTitle,
|
|
1624
|
-
borderWidth: borderWidth,
|
|
1625
|
-
borderColor: borderColor,
|
|
1626
|
-
borderColorHover: borderColorHover,
|
|
1627
|
-
borderType: borderType,
|
|
1628
|
-
thumbBorderWidth: thumbBorderWidth,
|
|
1629
|
-
thumbBorderColor: thumbBorderColor,
|
|
1630
|
-
thumbBorderColorHover: thumbBorderColorHover,
|
|
1631
|
-
thumbBorderType: thumbBorderType,
|
|
1632
|
-
fileErrorText: fileErrorText,
|
|
1633
|
-
fill: fill,
|
|
1634
|
-
size: size,
|
|
1635
|
-
maxFiles: maxFiles,
|
|
1636
|
-
maxSize: maxSize,
|
|
1637
|
-
removeThumbTextHoverColor: removeThumbTextHoverColor,
|
|
1638
|
-
fillHover: fillHover,
|
|
1639
|
-
className: className,
|
|
1640
|
-
thumbColumn: thumbColumn,
|
|
1641
|
-
thumbDirection: thumbDirection,
|
|
1642
|
-
inputName: input.name,
|
|
1643
|
-
inputValue: input.value,
|
|
1644
|
-
thumbNameTextSize: thumbNameTextSize,
|
|
1645
|
-
thumbNameTextColor: thumbNameTextColor,
|
|
1646
|
-
thumbNameTextWrap: thumbNameTextWrap,
|
|
1647
|
-
thumbNameTextWeight: thumbNameTextWeight,
|
|
1648
|
-
hintTitleTextSize: hintTitleTextSize,
|
|
1649
|
-
hintTitleTextColor: hintTitleTextColor,
|
|
1650
|
-
hintTitleTextWrap: hintTitleTextWrap,
|
|
1651
|
-
hintTitleTextWeight: hintTitleTextWeight,
|
|
1652
|
-
removeThumbTextSize: removeThumbTextSize,
|
|
1653
|
-
removeThumbTextColor: removeThumbTextColor,
|
|
1654
|
-
removeThumbTextWeight: removeThumbTextWeight,
|
|
1655
|
-
hintDescriptionTextSize: hintDescriptionTextSize,
|
|
1656
|
-
hintDescriptionTextColor: hintDescriptionTextColor,
|
|
1657
|
-
hintDescriptionTextWrap: hintDescriptionTextWrap,
|
|
1658
|
-
hintDescriptionTextWeight: hintDescriptionTextWeight,
|
|
1659
|
-
errorMessageTextSize: errorMessageTextSize,
|
|
1660
|
-
errorMessageWeight: errorMessageTextWeight,
|
|
1661
|
-
errorMessageTextColor: errorMessageTextColor,
|
|
1662
|
-
isPreviews: isPreviews,
|
|
1663
|
-
shape: shape,
|
|
1664
|
-
isShowFilename: isShowFilename,
|
|
1665
|
-
metaError: meta.error,
|
|
1666
|
-
metaTouched: meta.touched,
|
|
1667
|
-
removeThumbText: removeThumbText,
|
|
1668
|
-
onAddFiles: onAddFiles,
|
|
1669
|
-
onDeleteFile: onDeleteFile
|
|
1670
|
-
}));
|
|
1671
|
-
});
|
|
1672
|
-
});
|
|
1673
|
-
FileInput.defaultProps = {
|
|
1674
|
-
errorMessageTextSize: 's',
|
|
1675
|
-
errorMessageTextColor: 'errorTextPrimary',
|
|
1676
|
-
thumbColumn: 1,
|
|
1677
|
-
thumbDirection: 'vertical'
|
|
1678
|
-
};
|
|
1679
|
-
FileInput.propTypes = {
|
|
1680
|
-
name: PropTypes.string.isRequired,
|
|
1681
|
-
className: PropTypes.string,
|
|
1682
|
-
classNameGroupItem: PropTypes.string,
|
|
1683
|
-
classNameInput: PropTypes.string,
|
|
1684
|
-
classNameInputWrapper: PropTypes.string,
|
|
1685
|
-
dropzoneProps: PropTypes.object,
|
|
1686
|
-
hintDescription: PropTypes.string,
|
|
1687
|
-
hintTitle: PropTypes.string,
|
|
1688
|
-
inputClass: PropTypes.string,
|
|
1689
|
-
isPreviews: PropTypes.bool,
|
|
1690
|
-
isRequired: PropTypes.bool,
|
|
1691
|
-
isShowFilename: PropTypes.bool,
|
|
1692
|
-
label: PropTypes.any,
|
|
1693
|
-
removeThumbText: PropTypes.string,
|
|
1694
|
-
onAddFiles: PropTypes.func,
|
|
1695
|
-
onDeleteFile: PropTypes.func
|
|
1696
|
-
};
|
|
1697
|
-
|
|
1698
|
-
var Group = /*#__PURE__*/React.memo(function Group(props) {
|
|
1699
|
-
var after = props.after,
|
|
1700
|
-
before = props.before,
|
|
1701
|
-
className = props.className,
|
|
1702
|
-
label = props.label,
|
|
1703
|
-
labelTextColor = props.labelTextColor,
|
|
1704
|
-
labelTextSize = props.labelTextSize,
|
|
1705
|
-
labelTextWeight = props.labelTextWeight,
|
|
1706
|
-
message = props.message,
|
|
1707
|
-
errorMessageTextSize = props.errorMessageTextSize,
|
|
1708
|
-
errorMessageTextWeight = props.errorMessageTextWeight,
|
|
1709
|
-
errorMessageTextColor = props.errorMessageTextColor,
|
|
1710
|
-
messageTextSize = props.messageTextSize,
|
|
1711
|
-
messageTextWeight = props.messageTextWeight,
|
|
1712
|
-
messageTextColor = props.messageTextColor,
|
|
1713
|
-
children = props.children,
|
|
1714
|
-
dataTour = props.dataTour,
|
|
1715
|
-
hideMessage = props.hideMessage,
|
|
1716
|
-
name = props.name,
|
|
1717
|
-
showErrorsOnSubmit = props.showErrorsOnSubmit;
|
|
1718
|
-
return /*#__PURE__*/React.createElement(Field, {
|
|
1719
|
-
name: name
|
|
1720
|
-
}, function (_ref) {
|
|
1721
|
-
_ref.input;
|
|
1722
|
-
var meta = _ref.meta;
|
|
1723
|
-
var error = meta.error || !meta.modifiedSinceLastSubmit && meta.submitError || false;
|
|
1724
|
-
var showError = useMemo(function () {
|
|
1725
|
-
if (showErrorsOnSubmit) {
|
|
1726
|
-
return meta.submitFailed && meta.touched && error;
|
|
1727
|
-
} else {
|
|
1728
|
-
return meta.touched && error;
|
|
1729
|
-
}
|
|
1730
|
-
}, [showErrorsOnSubmit, meta.submitFailed, meta.touched, error]);
|
|
1731
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
1732
|
-
className: clsx('form__group', className),
|
|
1733
|
-
"data-tour": dataTour
|
|
1734
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
1735
|
-
className: "form__group-wrapper"
|
|
1736
|
-
}, before, /*#__PURE__*/React.createElement("div", {
|
|
1737
|
-
className: "form__group-label"
|
|
1738
|
-
}, /*#__PURE__*/React.createElement(Title, {
|
|
1739
|
-
textColor: labelTextColor,
|
|
1740
|
-
size: labelTextSize,
|
|
1741
|
-
textWeight: labelTextWeight
|
|
1742
|
-
}, label)), /*#__PURE__*/React.createElement("div", {
|
|
1743
|
-
className: "form__group-items"
|
|
1744
|
-
}, children), after), !hideMessage && /*#__PURE__*/React.createElement(React.Fragment, null, Boolean(showError) && /*#__PURE__*/React.createElement(Text, {
|
|
1745
|
-
className: "form__group-message form__group-message_type-error",
|
|
1746
|
-
size: errorMessageTextSize,
|
|
1747
|
-
textWeight: errorMessageTextWeight,
|
|
1748
|
-
textColor: errorMessageTextColor,
|
|
1749
|
-
id: name + "-error"
|
|
1750
|
-
}, error), Boolean(message) && !showError && /*#__PURE__*/React.createElement(Text, {
|
|
1751
|
-
className: "form__group-message",
|
|
1752
|
-
size: messageTextSize,
|
|
1753
|
-
textWeight: messageTextWeight,
|
|
1754
|
-
textColor: messageTextColor
|
|
1755
|
-
}, message), Boolean(!showError) && Boolean(!message) && /*#__PURE__*/React.createElement(Text, {
|
|
1756
|
-
className: "form__group-message",
|
|
1757
|
-
size: messageTextSize
|
|
1758
|
-
}, "\xA0")));
|
|
1759
|
-
});
|
|
1760
|
-
});
|
|
1761
|
-
Group.defaultProps = {
|
|
1762
|
-
inputProps: {},
|
|
1763
|
-
fieldProps: {},
|
|
1764
|
-
type: 'normal',
|
|
1765
|
-
errorMessageTextSize: 's',
|
|
1766
|
-
errorMessageTextColor: 'errorTextPrimary',
|
|
1767
|
-
messageTextSize: 's',
|
|
1768
|
-
messageTextColor: 'surfaceTextTertiary'
|
|
1769
|
-
};
|
|
1770
|
-
Group.propTypes = {
|
|
1771
|
-
name: PropTypes.string.isRequired,
|
|
1772
|
-
isRequired: PropTypes.bool,
|
|
1773
|
-
fieldProps: PropTypes.object,
|
|
1774
|
-
inputProps: PropTypes.object
|
|
1775
|
-
};
|
|
1776
|
-
|
|
1777
|
-
var InputField = /*#__PURE__*/React.memo(function InputField(props) {
|
|
1778
|
-
var isPassword = props.isPassword,
|
|
1779
|
-
isRequired = props.isRequired,
|
|
1780
|
-
fieldProps = props.fieldProps,
|
|
1781
|
-
inputProps = props.inputProps,
|
|
1782
|
-
isRevealable = props.isRevealable,
|
|
1783
|
-
name = props.name,
|
|
1784
|
-
parse = props.parse,
|
|
1785
|
-
iconSize = props.iconSize;
|
|
1786
|
-
props.iconBorder;
|
|
1787
|
-
props.iconBorderHover;
|
|
1788
|
-
var iconFill = props.iconFill,
|
|
1789
|
-
iconFillHover = props.iconFillHover,
|
|
1790
|
-
iconRevealableShow = props.iconRevealableShow,
|
|
1791
|
-
iconRevealableHide = props.iconRevealableHide,
|
|
1792
|
-
iconShape = props.iconShape,
|
|
1793
|
-
hideMessage = props.hideMessage,
|
|
1794
|
-
onChange = props.onChange,
|
|
1795
|
-
classNameGroupItem = props.classNameGroupItem;
|
|
1796
|
-
var _useState = useState(false),
|
|
1797
|
-
isRevealed = _useState[0],
|
|
1798
|
-
setIsRevealed = _useState[1];
|
|
1799
|
-
var inputType = useMemo(function () {
|
|
1800
|
-
if (isPassword) {
|
|
1801
|
-
return isRevealed ? 'text' : 'password';
|
|
1802
|
-
} else {
|
|
1803
|
-
return 'text';
|
|
1804
|
-
}
|
|
1805
|
-
}, [isRevealed, isPassword]);
|
|
1806
|
-
var revealeHandler = useCallback(function (e) {
|
|
1807
|
-
e.preventDefault();
|
|
1808
|
-
setIsRevealed(function (prev) {
|
|
1809
|
-
return !prev;
|
|
1810
|
-
});
|
|
1811
|
-
}, [setIsRevealed]);
|
|
1812
|
-
return /*#__PURE__*/React.createElement(Field, {
|
|
1813
|
-
name: name,
|
|
1814
|
-
parse: parse
|
|
1815
|
-
}, function (_ref) {
|
|
1816
|
-
var input = _ref.input,
|
|
1817
|
-
meta = _ref.meta;
|
|
1818
|
-
var onChangeField = useCallback(function (event) {
|
|
1819
|
-
input.onChange(event);
|
|
1820
|
-
if (onChange) {
|
|
1821
|
-
onChange(event.target.value, input.name);
|
|
1822
|
-
}
|
|
1823
|
-
}, [onChange]);
|
|
1824
|
-
return /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
|
|
1825
|
-
className: clsx('form-field_type_input', 'form__item_type_input', classNameGroupItem),
|
|
1826
|
-
fieldClassName: isRevealable ? 'form-password' : 'form-input',
|
|
1827
|
-
inputName: input.name,
|
|
1828
|
-
inputValue: input.value || '',
|
|
1829
|
-
isRequired: isRequired,
|
|
1830
|
-
metaActive: meta.active,
|
|
1831
|
-
metaError: meta.error,
|
|
1832
|
-
metaModifiedSinceLastSubmit: meta.modifiedSinceLastSubmit,
|
|
1833
|
-
metaSubmitError: meta.submitError,
|
|
1834
|
-
metaSubmitFailed: meta.submitFailed,
|
|
1835
|
-
metaTouched: meta.touched,
|
|
1836
|
-
metaValid: meta.valid,
|
|
1837
|
-
hideMessage: hideMessage
|
|
1838
|
-
}, fieldProps), /*#__PURE__*/React.createElement(Input, Object.assign({
|
|
1839
|
-
className: clsx(meta.active && 'input_state_focus', meta.error && meta.touched && 'input_state_error'),
|
|
1840
|
-
autoComplete: "nope",
|
|
1841
|
-
name: input.name,
|
|
1842
|
-
type: inputType,
|
|
1843
|
-
value: input.value || '',
|
|
1844
|
-
onBlur: input.onBlur,
|
|
1845
|
-
onChange: onChangeField,
|
|
1846
|
-
onFocus: input.onFocus
|
|
1847
|
-
}, inputProps)), isRevealable && /*#__PURE__*/React.createElement(Icon, {
|
|
1848
|
-
className: "form-field__icon",
|
|
1849
|
-
iconFill: iconFill,
|
|
1850
|
-
iconFillHover: iconFillHover,
|
|
1851
|
-
SvgImage: isRevealed ? iconRevealableHide : iconRevealableShow,
|
|
1852
|
-
imageSrc: isRevealed ? iconRevealableHide : iconRevealableShow,
|
|
1853
|
-
shape: iconShape,
|
|
1854
|
-
size: iconSize,
|
|
1855
|
-
onClick: revealeHandler
|
|
1856
|
-
}));
|
|
1857
|
-
});
|
|
1858
|
-
});
|
|
1859
|
-
InputField.defaultProps = {
|
|
1860
|
-
inputProps: {},
|
|
1861
|
-
fieldProps: {}
|
|
1862
|
-
};
|
|
1863
|
-
InputField.propTypes = {
|
|
1864
|
-
fieldProps: PropTypes.object,
|
|
1865
|
-
inputProps: PropTypes.object,
|
|
1866
|
-
isPassword: PropTypes.bool,
|
|
1867
|
-
isRequired: PropTypes.bool,
|
|
1868
|
-
isRevealable: PropTypes.bool,
|
|
1869
|
-
name: PropTypes.string.isRequired,
|
|
1870
|
-
onChange: PropTypes.func
|
|
1871
|
-
};
|
|
1872
|
-
|
|
1873
|
-
function RadioGroupItem(props) {
|
|
1874
|
-
var input = props.input,
|
|
1875
|
-
option = props.option,
|
|
1876
|
-
onChange = props.onChange,
|
|
1877
|
-
inputProps = props.inputProps;
|
|
1878
|
-
var onChangeField = useCallback(function (event) {
|
|
1879
|
-
if (event.target.checked) {
|
|
1880
|
-
onChange(option.value);
|
|
1881
|
-
}
|
|
1882
|
-
}, []);
|
|
1883
|
-
return /*#__PURE__*/React.createElement(RadioButton, Object.assign({
|
|
1884
|
-
className: "form-radio__item",
|
|
1885
|
-
checked: option.value === input.value,
|
|
1886
|
-
name: input.name,
|
|
1887
|
-
type: "radio",
|
|
1888
|
-
value: option.value,
|
|
1889
|
-
onBlur: input.onBlur,
|
|
1890
|
-
onChange: onChangeField,
|
|
1891
|
-
onFocus: input.onFocus,
|
|
1892
|
-
label: option.label
|
|
1893
|
-
}, inputProps));
|
|
1894
|
-
}
|
|
1895
|
-
RadioGroupItem.propTypes = {
|
|
1896
|
-
inputProps: PropTypes.object,
|
|
1897
|
-
onChange: PropTypes.func,
|
|
1898
|
-
option: PropTypes.shape({
|
|
1899
|
-
label: PropTypes.string,
|
|
1900
|
-
value: PropTypes.string
|
|
1901
|
-
}),
|
|
1902
|
-
input: PropTypes.shape({
|
|
1903
|
-
name: PropTypes.string,
|
|
1904
|
-
value: PropTypes.string,
|
|
1905
|
-
onBlur: PropTypes.func,
|
|
1906
|
-
onFocus: PropTypes.func,
|
|
1907
|
-
onChange: PropTypes.func
|
|
1908
|
-
})
|
|
1909
|
-
};
|
|
1910
|
-
|
|
1911
|
-
function RadioGroupInput(props) {
|
|
1912
|
-
var input = props.input,
|
|
1913
|
-
value = props.value,
|
|
1914
|
-
onChange = props.onChange;
|
|
1915
|
-
var onChangeField = useCallback(function (event) {
|
|
1916
|
-
return onChange(event.target.value);
|
|
1917
|
-
}, [onChange]);
|
|
1918
|
-
return /*#__PURE__*/React.createElement(Input, Object.assign({
|
|
1919
|
-
autoComplete: "nope",
|
|
1920
|
-
name: input.name,
|
|
1921
|
-
onBlur: input.onBlur,
|
|
1922
|
-
onChange: onChangeField,
|
|
1923
|
-
onFocus: input.onFocus,
|
|
1924
|
-
value: value
|
|
1925
|
-
}, props));
|
|
1926
|
-
}
|
|
1927
|
-
RadioGroupInput.propTypes = {
|
|
1928
|
-
input: PropTypes.string,
|
|
1929
|
-
value: PropTypes.string,
|
|
1930
|
-
editableProps: PropTypes.object,
|
|
1931
|
-
onChange: PropTypes.func
|
|
1932
|
-
};
|
|
1933
|
-
|
|
1934
|
-
function RadioGroupList(props) {
|
|
1935
|
-
var input = props.input,
|
|
1936
|
-
options = props.options,
|
|
1937
|
-
editableProps = props.editableProps,
|
|
1938
|
-
onChange = props.onChange,
|
|
1939
|
-
inputProps = props.inputProps;
|
|
1940
|
-
var _useState = useState(function () {
|
|
1941
|
-
var isRadioValue = options.find(function (option) {
|
|
1942
|
-
return option.value === input.value;
|
|
1943
|
-
});
|
|
1944
|
-
if (!isRadioValue) {
|
|
1945
|
-
return input.value;
|
|
1946
|
-
}
|
|
1947
|
-
return '';
|
|
1948
|
-
}),
|
|
1949
|
-
editableValue = _useState[0],
|
|
1950
|
-
setEditableValue = _useState[1];
|
|
1951
|
-
useEffect(function () {
|
|
1952
|
-
// When a new value from outside enters the form
|
|
1953
|
-
if (input.value) {
|
|
1954
|
-
// Check value for radio type
|
|
1955
|
-
var isRadioValue = options.find(function (option) {
|
|
1956
|
-
return option.value === input.value && !option.editable;
|
|
1957
|
-
});
|
|
1958
|
-
// If new value not in radio list - set to editable input
|
|
1959
|
-
setEditableValue(isRadioValue ? '' : input.value);
|
|
1960
|
-
} else {
|
|
1961
|
-
// If new value is empty - clear editable input
|
|
1962
|
-
setEditableValue('');
|
|
1963
|
-
}
|
|
1964
|
-
}, [input.value]);
|
|
1965
|
-
|
|
1966
|
-
// Callback for value changes
|
|
1967
|
-
var onChangeSomeInput = useCallback(function (value) {
|
|
1968
|
-
// Save to form values
|
|
1969
|
-
input.onChange(value);
|
|
1970
|
-
if (onChange) {
|
|
1971
|
-
// Pass to custom event
|
|
1972
|
-
onChange(value, input.name);
|
|
1973
|
-
}
|
|
1974
|
-
}, [input, onChange]);
|
|
1975
|
-
|
|
1976
|
-
// Handle for radio inputs
|
|
1977
|
-
var onChangeRadio = useCallback(function (value) {
|
|
1978
|
-
setEditableValue('');
|
|
1979
|
-
onChangeSomeInput(value);
|
|
1980
|
-
}, [onChangeSomeInput]);
|
|
1981
|
-
|
|
1982
|
-
// Handle for text input
|
|
1983
|
-
var onChangeEditable = useCallback(function (value) {
|
|
1984
|
-
setEditableValue(value);
|
|
1985
|
-
onChangeSomeInput(value);
|
|
1986
|
-
}, [onChangeSomeInput]);
|
|
1987
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, options.map(function (option) {
|
|
1988
|
-
return option.editable ? /*#__PURE__*/React.createElement(RadioGroupInput, {
|
|
1989
|
-
key: option.label,
|
|
1990
|
-
input: input,
|
|
1991
|
-
value: editableValue,
|
|
1992
|
-
option: option,
|
|
1993
|
-
onChange: onChangeEditable,
|
|
1994
|
-
editableProps: editableProps,
|
|
1995
|
-
inputProps: inputProps
|
|
1996
|
-
}) : /*#__PURE__*/React.createElement(RadioGroupItem, {
|
|
1997
|
-
key: option.value,
|
|
1998
|
-
input: input,
|
|
1999
|
-
option: option,
|
|
2000
|
-
onChange: onChangeRadio,
|
|
2001
|
-
inputProps: inputProps
|
|
2002
|
-
});
|
|
2003
|
-
}));
|
|
2004
|
-
}
|
|
2005
|
-
RadioGroupList.propTypes = {
|
|
2006
|
-
editableProps: PropTypes.object,
|
|
2007
|
-
input: PropTypes.object,
|
|
2008
|
-
inputProps: PropTypes.object,
|
|
2009
|
-
onChange: PropTypes.object,
|
|
2010
|
-
options: PropTypes.object
|
|
2011
|
-
};
|
|
2012
|
-
|
|
2013
|
-
var RadioGroup = /*#__PURE__*/React.memo(function RadioGroup(props) {
|
|
2014
|
-
var isRequired = props.isRequired,
|
|
2015
|
-
name = props.name,
|
|
2016
|
-
options = props.options,
|
|
2017
|
-
fieldProps = props.fieldProps,
|
|
2018
|
-
editableProps = props.editableProps,
|
|
2019
|
-
inputProps = props.inputProps,
|
|
2020
|
-
onChange = props.onChange,
|
|
2021
|
-
hideMessage = props.hideMessage;
|
|
2022
|
-
return /*#__PURE__*/React.createElement(Field, {
|
|
2023
|
-
name: name
|
|
2024
|
-
}, function (_ref) {
|
|
2025
|
-
var input = _ref.input,
|
|
2026
|
-
meta = _ref.meta;
|
|
2027
|
-
return /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
|
|
2028
|
-
className: "form__item_type_radio",
|
|
2029
|
-
fieldClassName: 'form-radio',
|
|
2030
|
-
inputName: input.name,
|
|
2031
|
-
inputValue: input.value || '',
|
|
2032
|
-
isRequired: isRequired,
|
|
2033
|
-
metaActive: meta.active,
|
|
2034
|
-
metaError: meta.error,
|
|
2035
|
-
metaModifiedSinceLastSubmit: meta.modifiedSinceLastSubmit,
|
|
2036
|
-
metaSubmitError: meta.submitError,
|
|
2037
|
-
metaSubmitFailed: meta.submitFailed,
|
|
2038
|
-
metaTouched: meta.touched,
|
|
2039
|
-
metaValid: meta.valid,
|
|
2040
|
-
hideMessage: hideMessage
|
|
2041
|
-
}, fieldProps), /*#__PURE__*/React.createElement(RadioGroupList, {
|
|
2042
|
-
input: input,
|
|
2043
|
-
options: options,
|
|
2044
|
-
onChange: onChange,
|
|
2045
|
-
editableProps: editableProps,
|
|
2046
|
-
inputProps: inputProps
|
|
2047
|
-
}));
|
|
2048
|
-
});
|
|
2049
|
-
});
|
|
2050
|
-
RadioGroup.defaultProps = {
|
|
2051
|
-
fieldProps: {},
|
|
2052
|
-
editableProps: {},
|
|
2053
|
-
inputProps: {},
|
|
2054
|
-
options: []
|
|
2055
|
-
};
|
|
2056
|
-
RadioGroup.propTypes = {
|
|
2057
|
-
name: PropTypes.string.isRequired,
|
|
2058
|
-
fieldProps: PropTypes.object,
|
|
2059
|
-
inputProps: PropTypes.object,
|
|
2060
|
-
editableProps: PropTypes.object,
|
|
2061
|
-
isRequired: PropTypes.bool,
|
|
2062
|
-
options: PropTypes.array,
|
|
2063
|
-
onChange: PropTypes.func
|
|
2064
|
-
};
|
|
2065
|
-
|
|
2066
|
-
// const SegmentedField = React.memo(
|
|
2067
|
-
function SegmentedField(props) {
|
|
2068
|
-
var options = props.options,
|
|
2069
|
-
isRequired = props.isRequired,
|
|
2070
|
-
name = props.name,
|
|
2071
|
-
fieldProps = props.fieldProps,
|
|
2072
|
-
inputProps = props.inputProps,
|
|
2073
|
-
hideMessage = props.hideMessage;
|
|
2074
|
-
var _useForm = useForm(),
|
|
2075
|
-
change = _useForm.change;
|
|
2076
|
-
return /*#__PURE__*/React.createElement(Field, {
|
|
2077
|
-
name: name
|
|
2078
|
-
}, function (_ref) {
|
|
2079
|
-
var input = _ref.input,
|
|
2080
|
-
meta = _ref.meta;
|
|
2081
|
-
var activeOption = useMemo(function () {
|
|
2082
|
-
var emptyOption = {
|
|
2083
|
-
value: null,
|
|
2084
|
-
label: null
|
|
2085
|
-
};
|
|
2086
|
-
if (input.value) {
|
|
2087
|
-
var currentOption = options.find(function (option) {
|
|
2088
|
-
return option.value === input.value;
|
|
2089
|
-
});
|
|
2090
|
-
return currentOption || emptyOption;
|
|
2091
|
-
}
|
|
2092
|
-
return emptyOption;
|
|
2093
|
-
}, [input.value]);
|
|
2094
|
-
var setActiveSegment = useCallback(function (option) {
|
|
2095
|
-
change(name, option.value);
|
|
2096
|
-
}, [change]);
|
|
2097
|
-
return /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
|
|
2098
|
-
className: clsx('form-field_type_segmented', 'form__item_type_segmented'),
|
|
2099
|
-
fieldClassName: "form-segmented",
|
|
2100
|
-
inputName: input.name,
|
|
2101
|
-
inputValue: input.value || [],
|
|
2102
|
-
isRequired: isRequired,
|
|
2103
|
-
metaActive: meta.active,
|
|
2104
|
-
metaError: meta.error,
|
|
2105
|
-
metaModifiedSinceLastSubmit: meta.modifiedSinceLastSubmit,
|
|
2106
|
-
metaSubmitError: meta.submitError,
|
|
2107
|
-
metaSubmitFailed: meta.submitFailed,
|
|
2108
|
-
metaTouched: meta.touched,
|
|
2109
|
-
metaValid: meta.valid,
|
|
2110
|
-
hideMessage: hideMessage
|
|
2111
|
-
}, fieldProps), /*#__PURE__*/React.createElement(Segmented, Object.assign({
|
|
2112
|
-
segments: options,
|
|
2113
|
-
setActiveSegment: setActiveSegment,
|
|
2114
|
-
activeSegment: activeOption
|
|
2115
|
-
}, inputProps)));
|
|
2116
|
-
});
|
|
2117
|
-
}
|
|
2118
|
-
// )
|
|
2119
|
-
|
|
2120
|
-
SegmentedField.propTypes = {
|
|
2121
|
-
options: PropTypes.array.isRequired,
|
|
2122
|
-
name: PropTypes.string.isRequired,
|
|
2123
|
-
className: PropTypes.string,
|
|
2124
|
-
inputClass: PropTypes.string,
|
|
2125
|
-
isRequired: PropTypes.bool,
|
|
2126
|
-
label: PropTypes.string,
|
|
2127
|
-
placeholder: PropTypes.string,
|
|
2128
|
-
fieldProps: PropTypes.object,
|
|
2129
|
-
inputProps: PropTypes.object
|
|
2130
|
-
};
|
|
2131
|
-
|
|
2132
|
-
function getDefaultValue(options, selectValue) {
|
|
2133
|
-
var selectValues = Array.isArray(selectValue) ? selectValue : [selectValue];
|
|
2134
|
-
var result = [];
|
|
2135
|
-
options.forEach(function (item) {
|
|
2136
|
-
var isValue = selectValues.includes(item.value);
|
|
2137
|
-
var isLabel = selectValues.includes(item.label);
|
|
2138
|
-
var childOptions = [];
|
|
2139
|
-
if (item.options) {
|
|
2140
|
-
childOptions = getDefaultValue(item.options, selectValue);
|
|
2141
|
-
}
|
|
2142
|
-
if (isValue || isLabel) {
|
|
2143
|
-
result.push(item);
|
|
2144
|
-
} else if (childOptions.length) {
|
|
2145
|
-
result = result.concat(childOptions);
|
|
2146
|
-
}
|
|
2147
|
-
});
|
|
2148
|
-
return result;
|
|
2149
|
-
}
|
|
2150
|
-
var SelectField = /*#__PURE__*/React.memo(function SelectField(props) {
|
|
2151
|
-
var isRequired = props.isRequired,
|
|
2152
|
-
key = props.key,
|
|
2153
|
-
name = props.name,
|
|
2154
|
-
options = props.options,
|
|
2155
|
-
fieldProps = props.fieldProps,
|
|
2156
|
-
selectProps = props.selectProps,
|
|
2157
|
-
selectRef = props.selectRef,
|
|
2158
|
-
onChange = props.onChange,
|
|
2159
|
-
classNameGroupItem = props.classNameGroupItem,
|
|
2160
|
-
hideMessage = props.hideMessage;
|
|
2161
|
-
return /*#__PURE__*/React.createElement(Field, {
|
|
2162
|
-
name: name
|
|
2163
|
-
}, function (_ref) {
|
|
2164
|
-
var input = _ref.input,
|
|
2165
|
-
meta = _ref.meta;
|
|
2166
|
-
var onChangeField = useCallback(function (value) {
|
|
2167
|
-
input.onChange(value);
|
|
2168
|
-
if (onChange) {
|
|
2169
|
-
onChange(value, input.name);
|
|
2170
|
-
}
|
|
2171
|
-
}, [onChange]);
|
|
2172
|
-
var _useState = useState(null),
|
|
2173
|
-
selectedOptions = _useState[0],
|
|
2174
|
-
setSelectedOptions = _useState[1];
|
|
2175
|
-
var defaultValue = useMemo(function () {
|
|
2176
|
-
var _input$value;
|
|
2177
|
-
var optionsValues = getDefaultValue(options, input.value);
|
|
2178
|
-
if (!optionsValues.length && (_input$value = input.value) != null && _input$value.length) {
|
|
2179
|
-
optionsValues.push({
|
|
2180
|
-
value: input.value,
|
|
2181
|
-
label: input.value
|
|
2182
|
-
});
|
|
2183
|
-
}
|
|
2184
|
-
return optionsValues;
|
|
2185
|
-
}, [input.value]);
|
|
2186
|
-
useEffect(function () {
|
|
2187
|
-
return setSelectedOptions(defaultValue);
|
|
2188
|
-
}, [defaultValue]);
|
|
2189
|
-
var onChangeValue = useCallback(function (option, actionMeta) {
|
|
2190
|
-
var value = Array.isArray(option) ? option.map(function (o) {
|
|
2191
|
-
return o.value;
|
|
2192
|
-
}) : (option == null ? void 0 : option.value) || null;
|
|
2193
|
-
setSelectedOptions(option);
|
|
2194
|
-
onChangeField(value);
|
|
2195
|
-
}, [onChangeField]);
|
|
2196
|
-
return /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
|
|
2197
|
-
className: clsx('form-field_type_select', 'form__item_type_select', classNameGroupItem),
|
|
2198
|
-
fieldClassName: 'form-select',
|
|
2199
|
-
inputName: input.name,
|
|
2200
|
-
inputValue: input.value,
|
|
2201
|
-
isRequired: isRequired,
|
|
2202
|
-
metaActive: meta.active,
|
|
2203
|
-
metaError: meta.error,
|
|
2204
|
-
metaModifiedSinceLastSubmit: meta.modifiedSinceLastSubmit,
|
|
2205
|
-
metaSubmitError: meta.submitError,
|
|
2206
|
-
metaSubmitFailed: meta.submitFailed,
|
|
2207
|
-
metaTouched: meta.touched,
|
|
2208
|
-
metaValid: meta.valid,
|
|
2209
|
-
hideMessage: hideMessage
|
|
2210
|
-
}, fieldProps), /*#__PURE__*/React.createElement(Select, Object.assign({
|
|
2211
|
-
className: "form-select-item",
|
|
2212
|
-
instanceId: "id_" + input.name,
|
|
2213
|
-
value: selectedOptions,
|
|
2214
|
-
onChange: onChangeValue,
|
|
2215
|
-
options: options,
|
|
2216
|
-
ref: selectRef,
|
|
2217
|
-
key: key
|
|
2218
|
-
}, selectProps)));
|
|
2219
|
-
});
|
|
2220
|
-
});
|
|
2221
|
-
SelectField.propTypes = {
|
|
2222
|
-
name: PropTypes.string.isRequired,
|
|
2223
|
-
selectProps: PropTypes.object,
|
|
2224
|
-
isRequired: PropTypes.bool,
|
|
2225
|
-
label: PropTypes.any,
|
|
2226
|
-
messageType: PropTypes.string,
|
|
2227
|
-
options: PropTypes.array,
|
|
2228
|
-
onChange: PropTypes.func
|
|
2229
|
-
};
|
|
2230
|
-
|
|
2231
|
-
var SwitchField = /*#__PURE__*/React.memo(function SwitchField(props) {
|
|
2232
|
-
var name = props.name,
|
|
2233
|
-
isRequired = props.isRequired,
|
|
2234
|
-
onChange = props.onChange,
|
|
2235
|
-
fieldProps = props.fieldProps,
|
|
2236
|
-
inputProps = props.inputProps,
|
|
2237
|
-
classNameGroupItem = props.classNameGroupItem,
|
|
2238
|
-
hideMessage = props.hideMessage;
|
|
2239
|
-
return /*#__PURE__*/React.createElement(Field, {
|
|
2240
|
-
name: name,
|
|
2241
|
-
type: "checkbox"
|
|
2242
|
-
}, function (_ref) {
|
|
2243
|
-
var input = _ref.input,
|
|
2244
|
-
meta = _ref.meta;
|
|
2245
|
-
var onChangeField = useCallback(function (event) {
|
|
2246
|
-
input.onChange(event);
|
|
2247
|
-
if (onChange) {
|
|
2248
|
-
onChange(event.target.checked, input.name);
|
|
2249
|
-
}
|
|
2250
|
-
}, [onChange]);
|
|
2251
|
-
return /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
|
|
2252
|
-
className: clsx('form-field_type_switch', 'form__item_type_switch', classNameGroupItem),
|
|
2253
|
-
fieldClassName: "form-switch",
|
|
2254
|
-
inputName: input.name,
|
|
2255
|
-
inputValue: input.checked,
|
|
2256
|
-
isRequired: isRequired,
|
|
2257
|
-
metaActive: meta.active,
|
|
2258
|
-
metaError: meta.error,
|
|
2259
|
-
metaModifiedSinceLastSubmit: meta.modifiedSinceLastSubmit,
|
|
2260
|
-
metaSubmitError: meta.submitError,
|
|
2261
|
-
metaSubmitFailed: meta.submitFailed,
|
|
2262
|
-
metaTouched: meta.touched,
|
|
2263
|
-
metaValid: meta.valid,
|
|
2264
|
-
hideMessage: hideMessage,
|
|
2265
|
-
tag: "label"
|
|
2266
|
-
}, fieldProps), /*#__PURE__*/React.createElement(Switch, Object.assign({
|
|
2267
|
-
autoComplete: "nope",
|
|
2268
|
-
checked: input.checked,
|
|
2269
|
-
name: input.name,
|
|
2270
|
-
type: "checkbox",
|
|
2271
|
-
onBlur: input.onBlur,
|
|
2272
|
-
onChange: onChangeField,
|
|
2273
|
-
onFocus: input.onFocus
|
|
2274
|
-
}, inputProps)));
|
|
2275
|
-
});
|
|
2276
|
-
});
|
|
2277
|
-
SwitchField.defaultProps = {
|
|
2278
|
-
inputProps: {},
|
|
2279
|
-
fieldProps: {}
|
|
2280
|
-
};
|
|
2281
|
-
SwitchField.propTypes = {
|
|
2282
|
-
fieldProps: PropTypes.object,
|
|
2283
|
-
inputProps: PropTypes.object,
|
|
2284
|
-
isRequired: PropTypes.bool,
|
|
2285
|
-
name: PropTypes.string,
|
|
2286
|
-
onChange: PropTypes.func
|
|
2287
|
-
};
|
|
2288
|
-
|
|
2289
|
-
var TextareaField = /*#__PURE__*/React.memo(function TextareaField(props) {
|
|
2290
|
-
var isRequired = props.isRequired,
|
|
2291
|
-
name = props.name,
|
|
2292
|
-
fieldProps = props.fieldProps,
|
|
2293
|
-
inputProps = props.inputProps,
|
|
2294
|
-
classNameGroupItem = props.classNameGroupItem,
|
|
2295
|
-
hideMessage = props.hideMessage;
|
|
2296
|
-
return /*#__PURE__*/React.createElement(Field, {
|
|
2297
|
-
name: name
|
|
2298
|
-
}, function (_ref) {
|
|
2299
|
-
var input = _ref.input,
|
|
2300
|
-
meta = _ref.meta;
|
|
2301
|
-
return /*#__PURE__*/React.createElement(FieldWrapper, Object.assign({
|
|
2302
|
-
className: clsx('form-field_type_textarea', 'form__item_type_textarea', classNameGroupItem),
|
|
2303
|
-
fieldClassName: 'form-textarea',
|
|
2304
|
-
inputName: input.name,
|
|
2305
|
-
inputValue: input.value,
|
|
2306
|
-
isRequired: isRequired,
|
|
2307
|
-
metaActive: meta.active,
|
|
2308
|
-
metaError: meta.error,
|
|
2309
|
-
metaModifiedSinceLastSubmit: meta.modifiedSinceLastSubmit,
|
|
2310
|
-
metaSubmitError: meta.submitError,
|
|
2311
|
-
metaSubmitFailed: meta.submitFailed,
|
|
2312
|
-
metaTouched: meta.touched,
|
|
2313
|
-
metaValid: meta.valid,
|
|
2314
|
-
hideMessage: hideMessage
|
|
2315
|
-
}, fieldProps), /*#__PURE__*/React.createElement(Textarea, Object.assign({
|
|
2316
|
-
autoComplete: "nope",
|
|
2317
|
-
name: input.name,
|
|
2318
|
-
value: input.value,
|
|
2319
|
-
onBlur: input.onBlur,
|
|
2320
|
-
onChange: input.onChange,
|
|
2321
|
-
onFocus: input.onFocus
|
|
2322
|
-
}, inputProps)));
|
|
2323
|
-
});
|
|
2324
|
-
});
|
|
2325
|
-
TextareaField.defaultProps = {
|
|
2326
|
-
inputProps: {},
|
|
2327
|
-
fieldProps: {}
|
|
2328
|
-
};
|
|
2329
|
-
TextareaField.propTypes = {
|
|
2330
|
-
name: PropTypes.string.isRequired,
|
|
2331
|
-
isRequired: PropTypes.bool,
|
|
2332
|
-
fieldProps: PropTypes.object,
|
|
2333
|
-
inputProps: PropTypes.object
|
|
2334
|
-
};
|
|
2335
|
-
|
|
2336
|
-
var focusOnError = function focusOnError(formElementsList, errors) {
|
|
2337
|
-
var selectsIds = Object.keys(errors).map(function (fieldName) {
|
|
2338
|
-
if (fieldName === FORM_ERROR) {
|
|
2339
|
-
// TODO: get from somewhere
|
|
2340
|
-
return 'notification__item_status_error';
|
|
2341
|
-
}
|
|
2342
|
-
return "react-select-id_" + fieldName + "-input";
|
|
2343
|
-
});
|
|
2344
|
-
var errorFieldElement = formElementsList.find(function (element) {
|
|
2345
|
-
if (element.name) {
|
|
2346
|
-
return getIn(errors, element.name);
|
|
2347
|
-
} else {
|
|
2348
|
-
return selectsIds.includes(element.id);
|
|
2349
|
-
}
|
|
2350
|
-
});
|
|
2351
|
-
var errorsList = Object.keys(errors);
|
|
2352
|
-
if (!errorFieldElement && errorsList.length) {
|
|
2353
|
-
var errorElement;
|
|
2354
|
-
try {
|
|
2355
|
-
var fieldName = errorsList[0];
|
|
2356
|
-
if (fieldName === FORM_ERROR) {
|
|
2357
|
-
errorElement = document.querySelector('notification__item_status_error');
|
|
2358
|
-
} else {
|
|
2359
|
-
errorElement = document.querySelector("#" + fieldName + "-error");
|
|
2360
|
-
if (!errorElement) {
|
|
2361
|
-
errorElement = document.querySelector("#id_" + fieldName);
|
|
2362
|
-
}
|
|
2363
|
-
}
|
|
2364
|
-
} catch (err) {
|
|
2365
|
-
console.warn(err);
|
|
2366
|
-
}
|
|
2367
|
-
if (errorElement) {
|
|
2368
|
-
errorElement.scrollIntoView({
|
|
2369
|
-
block: 'center'
|
|
2370
|
-
}); // , behavior: 'smooth'
|
|
2371
|
-
}
|
|
2372
|
-
}
|
|
2373
|
-
|
|
2374
|
-
// the field is covered by the header because header is "sticky",
|
|
2375
|
-
// that's we scroll manually so that the field falls into the center of the visible area
|
|
2376
|
-
if (errorFieldElement) {
|
|
2377
|
-
errorFieldElement.scrollIntoView({
|
|
2378
|
-
block: 'center'
|
|
2379
|
-
});
|
|
2380
|
-
}
|
|
2381
|
-
return null;
|
|
2382
|
-
};
|
|
2383
|
-
var focusOnErrorDecorator = createDecorator(null, focusOnError);
|
|
2384
|
-
var setErrorsMutator = function setErrorsMutator(args, state) {
|
|
2385
|
-
var fieldName = args[0],
|
|
2386
|
-
data = args[1];
|
|
2387
|
-
var submitError = data.submitError;
|
|
2388
|
-
var fieldError = data.error;
|
|
2389
|
-
if (fieldName === 'non_field_errors') {
|
|
2390
|
-
// state.formState.invalid = true
|
|
2391
|
-
// state.formState.valid = false
|
|
2392
|
-
state.formState.error = fieldError;
|
|
2393
|
-
state.formState.submitError = submitError;
|
|
2394
|
-
} else if (fieldName in state.fields) {
|
|
2395
|
-
if (fieldError) {
|
|
2396
|
-
var _Object$assign;
|
|
2397
|
-
var errorsState = Object.assign({}, state.formState.errors, (_Object$assign = {}, _Object$assign[fieldName] = fieldError, _Object$assign));
|
|
2398
|
-
state.fields[fieldName].touched = true;
|
|
2399
|
-
state.fields[fieldName].error = fieldError;
|
|
2400
|
-
state.formState.errors = errorsState;
|
|
2401
|
-
}
|
|
2402
|
-
if (submitError) {
|
|
2403
|
-
var _Object$assign2;
|
|
2404
|
-
var submitErrorsState = Object.assign({}, state.formState.submitErrors, (_Object$assign2 = {}, _Object$assign2[fieldName] = submitError, _Object$assign2));
|
|
2405
|
-
|
|
2406
|
-
// state.fields[fieldName].submitFailed = true
|
|
2407
|
-
// state.fields[fieldName].submitSucceeded = false
|
|
2408
|
-
state.fields[fieldName].submitError = submitError;
|
|
2409
|
-
state.formState.submitErrors = submitErrorsState;
|
|
2410
|
-
state.formState.submitFailed = true;
|
|
2411
|
-
state.formState.submitSucceeded = false;
|
|
2412
|
-
state.formState.lastSubmittedValues = state.formState.values;
|
|
2413
|
-
}
|
|
2414
|
-
}
|
|
2415
|
-
};
|
|
2416
|
-
var sendFormDataToServer = /*#__PURE__*/function () {
|
|
2417
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url, data) {
|
|
2418
|
-
var response, _error$response, _error$response2, formErrors;
|
|
2419
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
2420
|
-
while (1) switch (_context.prev = _context.next) {
|
|
2421
|
-
case 0:
|
|
2422
|
-
_context.prev = 0;
|
|
2423
|
-
_context.next = 3;
|
|
2424
|
-
return axios({
|
|
2425
|
-
url: url,
|
|
2426
|
-
method: 'POST',
|
|
2427
|
-
data: data
|
|
2428
|
-
});
|
|
2429
|
-
case 3:
|
|
2430
|
-
response = _context.sent;
|
|
2431
|
-
return _context.abrupt("return", {
|
|
2432
|
-
success: true,
|
|
2433
|
-
response: response
|
|
2434
|
-
});
|
|
2435
|
-
case 7:
|
|
2436
|
-
_context.prev = 7;
|
|
2437
|
-
_context.t0 = _context["catch"](0);
|
|
2438
|
-
formErrors = {};
|
|
2439
|
-
if (typeof ((_error$response = _context.t0.response) == null ? void 0 : _error$response.data) === 'string') {
|
|
2440
|
-
formErrors[FORM_ERROR] = 'Something went wrong';
|
|
2441
|
-
}
|
|
2442
|
-
if (typeof ((_error$response2 = _context.t0.response) == null ? void 0 : _error$response2.data) === 'object') {
|
|
2443
|
-
Object.entries(_context.t0.response.data).forEach(function (_ref2) {
|
|
2444
|
-
var fieldName = _ref2[0],
|
|
2445
|
-
errorsList = _ref2[1];
|
|
2446
|
-
formErrors[fieldName] = errorsList[0];
|
|
2447
|
-
});
|
|
2448
|
-
}
|
|
2449
|
-
return _context.abrupt("return", {
|
|
2450
|
-
success: false,
|
|
2451
|
-
formErrors: formErrors,
|
|
2452
|
-
error: _context.t0
|
|
2453
|
-
});
|
|
2454
|
-
case 13:
|
|
2455
|
-
case "end":
|
|
2456
|
-
return _context.stop();
|
|
2457
|
-
}
|
|
2458
|
-
}, _callee, null, [[0, 7]]);
|
|
2459
|
-
}));
|
|
2460
|
-
return function sendFormDataToServer(_x, _x2) {
|
|
2461
|
-
return _ref.apply(this, arguments);
|
|
2462
|
-
};
|
|
2463
|
-
}();
|
|
2464
|
-
|
|
2465
|
-
var formTypes = {
|
|
2466
|
-
checkbox: 'checkbox',
|
|
2467
|
-
custom: 'custom',
|
|
2468
|
-
choice: 'choice',
|
|
2469
|
-
code: 'code',
|
|
2470
|
-
datePicker: 'datePicker',
|
|
2471
|
-
dateRangePicker: 'dateRangePicker',
|
|
2472
|
-
fileInput: 'fileInput',
|
|
2473
|
-
group: 'group',
|
|
2474
|
-
radioGroup: 'radioGroup',
|
|
2475
|
-
segmented: 'segmented',
|
|
2476
|
-
select: 'select',
|
|
2477
|
-
"switch": 'switch',
|
|
2478
|
-
text: 'text',
|
|
2479
|
-
textarea: 'textarea'
|
|
2480
|
-
};
|
|
2481
|
-
function generateField(field, config, props) {
|
|
2482
|
-
switch (field.type) {
|
|
2483
|
-
case formTypes.checkbox:
|
|
2484
|
-
{
|
|
2485
|
-
return /*#__PURE__*/React.createElement(CheckboxField, Object.assign({
|
|
2486
|
-
key: config.key
|
|
2487
|
-
}, field, props));
|
|
2488
|
-
}
|
|
2489
|
-
case formTypes.choice:
|
|
2490
|
-
{
|
|
2491
|
-
return /*#__PURE__*/React.createElement(ChoiceField, Object.assign({
|
|
2492
|
-
key: config.key
|
|
2493
|
-
}, field, props));
|
|
2494
|
-
}
|
|
2495
|
-
case formTypes.code:
|
|
2496
|
-
{
|
|
2497
|
-
return /*#__PURE__*/React.createElement(CodeField, Object.assign({
|
|
2498
|
-
key: config.key
|
|
2499
|
-
}, field, props));
|
|
2500
|
-
}
|
|
2501
|
-
case formTypes["switch"]:
|
|
2502
|
-
{
|
|
2503
|
-
return /*#__PURE__*/React.createElement(SwitchField, Object.assign({
|
|
2504
|
-
key: config.key
|
|
2505
|
-
}, field, props));
|
|
2506
|
-
}
|
|
2507
|
-
case formTypes.segmented:
|
|
2508
|
-
{
|
|
2509
|
-
return /*#__PURE__*/React.createElement(SegmentedField, Object.assign({
|
|
2510
|
-
key: config.key
|
|
2511
|
-
}, field, props));
|
|
2512
|
-
}
|
|
2513
|
-
case formTypes.datePicker:
|
|
2514
|
-
{
|
|
2515
|
-
return /*#__PURE__*/React.createElement(DatePickerField, Object.assign({
|
|
2516
|
-
key: config.key
|
|
2517
|
-
}, field, props));
|
|
2518
|
-
}
|
|
2519
|
-
case formTypes.fileInput:
|
|
2520
|
-
{
|
|
2521
|
-
return /*#__PURE__*/React.createElement(FileInput, Object.assign({
|
|
2522
|
-
key: config.key
|
|
2523
|
-
}, field, props));
|
|
2524
|
-
}
|
|
2525
|
-
case formTypes.radioGroup:
|
|
2526
|
-
{
|
|
2527
|
-
return /*#__PURE__*/React.createElement(RadioGroup, Object.assign({
|
|
2528
|
-
key: config.key
|
|
2529
|
-
}, field, props));
|
|
2530
|
-
}
|
|
2531
|
-
case formTypes.select:
|
|
2532
|
-
{
|
|
2533
|
-
return /*#__PURE__*/React.createElement(SelectField, Object.assign({
|
|
2534
|
-
key: config.key
|
|
2535
|
-
}, field, props));
|
|
2536
|
-
}
|
|
2537
|
-
case formTypes.text:
|
|
2538
|
-
{
|
|
2539
|
-
return /*#__PURE__*/React.createElement(InputField, Object.assign({
|
|
2540
|
-
key: config.key
|
|
2541
|
-
}, field, props));
|
|
2542
|
-
}
|
|
2543
|
-
case formTypes.textarea:
|
|
2544
|
-
{
|
|
2545
|
-
return /*#__PURE__*/React.createElement(TextareaField, Object.assign({
|
|
2546
|
-
key: config.key
|
|
2547
|
-
}, field, props));
|
|
2548
|
-
}
|
|
2549
|
-
case formTypes.custom:
|
|
2550
|
-
{
|
|
2551
|
-
return /*#__PURE__*/React.createElement(CustomField, Object.assign({
|
|
2552
|
-
key: config.key
|
|
2553
|
-
}, field, props));
|
|
2554
|
-
}
|
|
2555
|
-
case formTypes.group:
|
|
2556
|
-
{
|
|
2557
|
-
return /*#__PURE__*/React.createElement(Group, Object.assign({
|
|
2558
|
-
key: config.key
|
|
2559
|
-
}, field, props), Object.entries(field.group).map(function (_ref) {
|
|
2560
|
-
var key = _ref[0],
|
|
2561
|
-
value = _ref[1];
|
|
2562
|
-
var groupProps = Object.assign({}, value, {
|
|
2563
|
-
hideMessage: field.hideMessage,
|
|
2564
|
-
classNameGroupItem: value.classNameGroupItem || 'form__group-item'
|
|
2565
|
-
});
|
|
2566
|
-
return generateField(groupProps, {
|
|
2567
|
-
key: key + '_form_group'
|
|
2568
|
-
}, props);
|
|
2569
|
-
}));
|
|
2570
|
-
}
|
|
2571
|
-
}
|
|
2572
|
-
}
|
|
2573
|
-
|
|
2574
|
-
var FinalForm = /*#__PURE__*/React.forwardRef(function FinalForm(props, ref) {
|
|
2575
|
-
var additionalProps = props.additionalProps,
|
|
2576
|
-
after = props.after,
|
|
2577
|
-
before = props.before,
|
|
2578
|
-
buttonDirection = props.buttonDirection,
|
|
2579
|
-
buttonGap = props.buttonGap,
|
|
2580
|
-
buttonPadding = props.buttonPadding,
|
|
2581
|
-
groupGap = props.groupGap,
|
|
2582
|
-
className = props.className,
|
|
2583
|
-
config = props.config,
|
|
2584
|
-
description = props.description,
|
|
2585
|
-
descriptionSize = props.descriptionSize,
|
|
2586
|
-
descriptionTextColor = props.descriptionTextColor,
|
|
2587
|
-
descriptionTextWeight = props.descriptionTextWeight,
|
|
2588
|
-
disableFieldsAutoComplete = props.disableFieldsAutoComplete,
|
|
2589
|
-
fieldsGap = props.fieldsGap,
|
|
2590
|
-
formName = props.formName,
|
|
2591
|
-
initialValues = props.initialValues,
|
|
2592
|
-
initialValuesEqual = props.initialValuesEqual,
|
|
2593
|
-
isLoading = props.isLoading,
|
|
2594
|
-
loader = props.loader,
|
|
2595
|
-
loaderSet = props.loaderSet,
|
|
2596
|
-
loaderFill = props.loaderFill,
|
|
2597
|
-
loaderItemFill = props.loaderItemFill,
|
|
2598
|
-
loaderText = props.loaderText,
|
|
2599
|
-
language = props.language,
|
|
2600
|
-
mutators = props.mutators,
|
|
2601
|
-
onChangeFormValues = props.onChangeFormValues,
|
|
2602
|
-
onClickSecondaryButton = props.onClickSecondaryButton,
|
|
2603
|
-
onClickTertiaryButton = props.onClickTertiaryButton,
|
|
2604
|
-
onSubmit = props.onSubmit,
|
|
2605
|
-
primaryButton = props.primaryButton,
|
|
2606
|
-
primaryButtonLabel = props.primaryButtonLabel,
|
|
2607
|
-
secondaryButton = props.secondaryButton,
|
|
2608
|
-
secondaryButtonLabel = props.secondaryButtonLabel,
|
|
2609
|
-
primaryButtonFill = props.primaryButtonFill,
|
|
2610
|
-
primaryButtonFillHover = props.primaryButtonFillHover,
|
|
2611
|
-
secondaryButtonFill = props.secondaryButtonFill,
|
|
2612
|
-
secondaryButtonFillHover = props.secondaryButtonFillHover,
|
|
2613
|
-
primaryButtonSize = props.primaryButtonSize,
|
|
2614
|
-
primaryButtonLabelTextColor = props.primaryButtonLabelTextColor,
|
|
2615
|
-
primaryButtonLabelSize = props.primaryButtonLabelSize,
|
|
2616
|
-
primaryButtonLabelTextWeight = props.primaryButtonLabelTextWeight,
|
|
2617
|
-
secondaryButtonSize = props.secondaryButtonSize,
|
|
2618
|
-
secondaryButtonLabelTextColor = props.secondaryButtonLabelTextColor,
|
|
2619
|
-
secondaryButtonLabelSize = props.secondaryButtonLabelSize,
|
|
2620
|
-
secondaryButtonLabelTextWeight = props.secondaryButtonLabelTextWeight,
|
|
2621
|
-
tertiaryButton = props.tertiaryButton,
|
|
2622
|
-
tertiaryButtonFill = props.tertiaryButtonFill,
|
|
2623
|
-
tertiaryButtonFillHover = props.tertiaryButtonFillHover,
|
|
2624
|
-
tertiaryButtonSize = props.tertiaryButtonSize,
|
|
2625
|
-
tertiaryButtonLabelTextColor = props.tertiaryButtonLabelTextColor,
|
|
2626
|
-
tertiaryButtonLabelSize = props.tertiaryButtonLabelSize,
|
|
2627
|
-
tertiaryButtonLabelTextWeight = props.tertiaryButtonLabelTextWeight,
|
|
2628
|
-
tertiaryButtonLabel = props.tertiaryButtonLabel,
|
|
2629
|
-
set = props.set,
|
|
2630
|
-
type = props.type,
|
|
2631
|
-
buttonJustifyContent = props.buttonJustifyContent,
|
|
2632
|
-
title = props.title,
|
|
2633
|
-
notificationType = props.notificationType,
|
|
2634
|
-
buttonFill = props.buttonFill,
|
|
2635
|
-
titleTextSize = props.titleTextSize,
|
|
2636
|
-
titleTextColor = props.titleTextColor,
|
|
2637
|
-
titleTextWeight = props.titleTextWeight,
|
|
2638
|
-
validationSchema = props.validationSchema,
|
|
2639
|
-
dataTour = props.dataTour,
|
|
2640
|
-
dataTourButtons = props.dataTourButtons,
|
|
2641
|
-
dataTourPrimaryButton = props.dataTourPrimaryButton,
|
|
2642
|
-
dataTourSecondaryButton = props.dataTourSecondaryButton,
|
|
2643
|
-
dataTourTertiaryButton = props.dataTourTertiaryButton;
|
|
2644
|
-
var validate = useYupValidationSchema(validationSchema, language);
|
|
2645
|
-
var onRefFormInstance = useCallback(function (formInstance) {
|
|
2646
|
-
if (ref) {
|
|
2647
|
-
ref.current = formInstance;
|
|
2648
|
-
}
|
|
2649
|
-
}, [ref]);
|
|
2650
|
-
var fillClass = useDeviceTargetClass(props, {
|
|
2651
|
-
prefix: 'fill_',
|
|
2652
|
-
propsKey: 'fill'
|
|
2653
|
-
});
|
|
2654
|
-
var directionClass = useDeviceTargetClass(props, {
|
|
2655
|
-
prefix: 'direction_',
|
|
2656
|
-
propsKey: 'direction'
|
|
2657
|
-
});
|
|
2658
|
-
var shapeClass = useDeviceTargetClass(props, {
|
|
2659
|
-
prefix: 'shape_',
|
|
2660
|
-
propsKey: 'shape'
|
|
2661
|
-
});
|
|
2662
|
-
var elevationClass = useDeviceTargetClass(props, {
|
|
2663
|
-
prefix: 'elevation_',
|
|
2664
|
-
propsKey: 'elevation'
|
|
2665
|
-
});
|
|
2666
|
-
var _useStyles = useStyles(props),
|
|
2667
|
-
formStyles = _useStyles.styles;
|
|
2668
|
-
return /*#__PURE__*/React.createElement(Form, {
|
|
2669
|
-
decorators: [focusOnErrorDecorator],
|
|
2670
|
-
initialValues: initialValues,
|
|
2671
|
-
initialValuesEqual: initialValuesEqual,
|
|
2672
|
-
mutators: mutators,
|
|
2673
|
-
render: function render(_ref) {
|
|
2674
|
-
var handleSubmit = _ref.handleSubmit,
|
|
2675
|
-
submitError = _ref.submitError,
|
|
2676
|
-
modifiedSinceLastSubmit = _ref.modifiedSinceLastSubmit,
|
|
2677
|
-
form = _ref.form;
|
|
2678
|
-
return /*#__PURE__*/React.createElement("form", {
|
|
2679
|
-
style: formStyles,
|
|
2680
|
-
className: clsx(className, 'form', set && "form_set_" + set, type && "form_type_" + type, directionClass, fillClass, shapeClass, elevationClass),
|
|
2681
|
-
name: formName,
|
|
2682
|
-
"data-tour": dataTour,
|
|
2683
|
-
ref: function ref() {
|
|
2684
|
-
return onRefFormInstance(form);
|
|
2685
|
-
},
|
|
2686
|
-
onSubmit: handleSubmit,
|
|
2687
|
-
autoComplete: disableFieldsAutoComplete ? 'off' : undefined,
|
|
2688
|
-
autoCorrect: disableFieldsAutoComplete ? 'off' : undefined,
|
|
2689
|
-
autoCapitalize: disableFieldsAutoComplete ? 'off' : undefined,
|
|
2690
|
-
spellCheck: disableFieldsAutoComplete ? 'false' : undefined
|
|
2691
|
-
}, before, title && /*#__PURE__*/React.createElement(Title, {
|
|
2692
|
-
className: "form__title",
|
|
2693
|
-
size: titleTextSize,
|
|
2694
|
-
textColor: titleTextColor,
|
|
2695
|
-
textWeight: titleTextWeight
|
|
2696
|
-
}, title), description && /*#__PURE__*/React.createElement(Text, {
|
|
2697
|
-
className: "form__description",
|
|
2698
|
-
size: descriptionSize,
|
|
2699
|
-
textColor: descriptionTextColor,
|
|
2700
|
-
textWeight: descriptionTextWeight
|
|
2701
|
-
}, description), submitError && !modifiedSinceLastSubmit && /*#__PURE__*/React.createElement("div", {
|
|
2702
|
-
className: clsx('notification', 'form-notification', notificationType ? "form-notification_type_" + notificationType : 'form-notification_type_global')
|
|
2703
|
-
}, /*#__PURE__*/React.createElement(NotificationItem, {
|
|
2704
|
-
className: "form-notification__item",
|
|
2705
|
-
titleTextSize: "h6",
|
|
2706
|
-
title: form.getState().submitError,
|
|
2707
|
-
set: "form",
|
|
2708
|
-
status: "error"
|
|
2709
|
-
})), onChangeFormValues && /*#__PURE__*/React.createElement(FormSpy, {
|
|
2710
|
-
subscription: {
|
|
2711
|
-
values: true
|
|
2712
|
-
},
|
|
2713
|
-
onChange: onChangeFormValues
|
|
2714
|
-
}), Boolean(Object.keys(config).length) && /*#__PURE__*/React.createElement(Group$1, {
|
|
2715
|
-
direction: "vertical",
|
|
2716
|
-
gap: fieldsGap || groupGap,
|
|
2717
|
-
className: "form__wrapper"
|
|
2718
|
-
}, Object.keys(config).map(function (key) {
|
|
2719
|
-
return generateField(config[key], {
|
|
2720
|
-
key: key
|
|
2721
|
-
}, additionalProps[config[key].name]);
|
|
2722
|
-
}), isLoading && (loader || /*#__PURE__*/React.createElement(Loader, {
|
|
2723
|
-
className: "form__loader",
|
|
2724
|
-
set: loaderSet,
|
|
2725
|
-
fill: loaderFill,
|
|
2726
|
-
itemFill: loaderItemFill,
|
|
2727
|
-
text: loaderText
|
|
2728
|
-
}))), (primaryButtonLabel || primaryButton || secondaryButtonLabel || secondaryButton || tertiaryButton || tertiaryButtonLabel) && /*#__PURE__*/React.createElement(Group$1, {
|
|
2729
|
-
fill: buttonFill,
|
|
2730
|
-
justifyContent: buttonJustifyContent,
|
|
2731
|
-
direction: buttonDirection,
|
|
2732
|
-
padding: buttonPadding,
|
|
2733
|
-
gap: buttonGap,
|
|
2734
|
-
className: "form__button",
|
|
2735
|
-
dataTour: dataTourButtons
|
|
2736
|
-
}, primaryButtonLabel ? /*#__PURE__*/React.createElement(Button, {
|
|
2737
|
-
width: "fill",
|
|
2738
|
-
className: "form__button-item",
|
|
2739
|
-
fill: primaryButtonFill,
|
|
2740
|
-
fillHover: primaryButtonFillHover,
|
|
2741
|
-
size: primaryButtonSize,
|
|
2742
|
-
labelTextColor: primaryButtonLabelTextColor,
|
|
2743
|
-
labelSize: primaryButtonLabelSize,
|
|
2744
|
-
labelTextWeight: primaryButtonLabelTextWeight,
|
|
2745
|
-
label: primaryButtonLabel,
|
|
2746
|
-
dataTour: dataTourPrimaryButton
|
|
2747
|
-
}) : primaryButton, secondaryButtonLabel ? /*#__PURE__*/React.createElement(Button, {
|
|
2748
|
-
width: "fill",
|
|
2749
|
-
className: "form__button-item",
|
|
2750
|
-
fill: secondaryButtonFill,
|
|
2751
|
-
fillHover: secondaryButtonFillHover,
|
|
2752
|
-
size: secondaryButtonSize,
|
|
2753
|
-
labelTextColor: secondaryButtonLabelTextColor,
|
|
2754
|
-
labelSize: secondaryButtonLabelSize,
|
|
2755
|
-
labelTextWeight: secondaryButtonLabelTextWeight,
|
|
2756
|
-
label: secondaryButtonLabel,
|
|
2757
|
-
onClick: onClickSecondaryButton,
|
|
2758
|
-
dataTour: dataTourSecondaryButton
|
|
2759
|
-
}) : secondaryButton, tertiaryButtonLabel ? /*#__PURE__*/React.createElement(Button, {
|
|
2760
|
-
width: "fill",
|
|
2761
|
-
className: "form__button-item",
|
|
2762
|
-
fill: tertiaryButtonFill,
|
|
2763
|
-
fillHover: tertiaryButtonFillHover,
|
|
2764
|
-
size: tertiaryButtonSize,
|
|
2765
|
-
labelTextColor: tertiaryButtonLabelTextColor,
|
|
2766
|
-
labelSize: tertiaryButtonLabelSize,
|
|
2767
|
-
labelTextWeight: tertiaryButtonLabelTextWeight,
|
|
2768
|
-
label: tertiaryButtonLabel,
|
|
2769
|
-
onClick: onClickTertiaryButton,
|
|
2770
|
-
dataTour: dataTourTertiaryButton
|
|
2771
|
-
}) : tertiaryButton), after);
|
|
2772
|
-
},
|
|
2773
|
-
subscription: {
|
|
2774
|
-
submitting: true,
|
|
2775
|
-
pristine: true,
|
|
2776
|
-
modifiedSinceLastSubmit: true,
|
|
2777
|
-
submitError: true
|
|
2778
|
-
},
|
|
2779
|
-
validate: validate,
|
|
2780
|
-
onSubmit: onSubmit
|
|
2781
|
-
});
|
|
2782
|
-
});
|
|
2783
|
-
FinalForm.propTypes = {
|
|
2784
|
-
additionalProps: PropTypes.object,
|
|
2785
|
-
after: PropTypes.any,
|
|
2786
|
-
before: PropTypes.any,
|
|
2787
|
-
buttonGap: PropTypes.string,
|
|
2788
|
-
className: PropTypes.string,
|
|
2789
|
-
config: PropTypes.object,
|
|
2790
|
-
description: PropTypes.string,
|
|
2791
|
-
descriptionSize: PropTypes.string,
|
|
2792
|
-
descriptionTextColor: PropTypes.string,
|
|
2793
|
-
descriptionTextWeight: PropTypes.string,
|
|
2794
|
-
disableFieldsAutoComplete: PropTypes.string,
|
|
2795
|
-
fieldsGap: PropTypes.string,
|
|
2796
|
-
formName: PropTypes.string,
|
|
2797
|
-
initialValues: PropTypes.any,
|
|
2798
|
-
initialValuesEqual: PropTypes.any,
|
|
2799
|
-
language: PropTypes.string,
|
|
2800
|
-
isLoading: PropTypes.bool,
|
|
2801
|
-
loaderText: PropTypes.string,
|
|
2802
|
-
mutators: PropTypes.any,
|
|
2803
|
-
onChangeFormValues: PropTypes.func,
|
|
2804
|
-
onClickSecondaryButton: PropTypes.func,
|
|
2805
|
-
onSubmit: PropTypes.func,
|
|
2806
|
-
primaryButton: PropTypes.string,
|
|
2807
|
-
primaryButtonFill: PropTypes.string,
|
|
2808
|
-
primaryButtonLabel: PropTypes.string,
|
|
2809
|
-
secondaryButton: PropTypes.string,
|
|
2810
|
-
secondaryButtonFill: PropTypes.string,
|
|
2811
|
-
secondaryButtonLabel: PropTypes.string,
|
|
2812
|
-
set: PropTypes.string,
|
|
2813
|
-
title: PropTypes.string,
|
|
2814
|
-
titleSize: PropTypes.string,
|
|
2815
|
-
titleTextColor: PropTypes.string,
|
|
2816
|
-
titleTextWeight: PropTypes.string,
|
|
2817
|
-
validationSchema: PropTypes.object
|
|
2818
|
-
};
|
|
2819
|
-
FinalForm.defaultProps = {
|
|
2820
|
-
additionalProps: {},
|
|
2821
|
-
isLoading: false,
|
|
2822
|
-
loaderSet: 'simple',
|
|
2823
|
-
loaderFill: 'surfacePrimary',
|
|
2824
|
-
loaderItemFill: 'surfaceItemAccent',
|
|
2825
|
-
language: 'en',
|
|
2826
|
-
titleSize: 'h1',
|
|
2827
|
-
buttonDirection: 'vertical',
|
|
2828
|
-
direction: 'vertical',
|
|
2829
|
-
disableFieldsAutoComplete: false
|
|
2830
|
-
};
|
|
2831
|
-
|
|
2832
|
-
export { CheckboxField as Checkbox, ChoiceField, CodeField, CustomField, DatePickerField, FieldWrapper, FieldWrapperBase, FileInput, FinalForm, Group, InputField, RadioGroup, SegmentedField, SelectField, SwitchField as Switch, TextareaField as Textarea, addRequiredFieldsParamToSchema, emailValidation, focusOnError, focusOnErrorDecorator, formTypes, generateField, phoneValidation, sendFormDataToServer, setErrorsMutator, useYupValidationSchema };
|
|
1
|
+
import{isPossiblePhoneNumber as e}from"libphonenumber-js";import t,{useMemo as r,useEffect as i,useCallback as o,useState as a}from"react";import{setIn as n,FORM_ERROR as s,getIn as l}from"final-form";import{useForm as m,Field as c,Form as u,FormSpy as d}from"react-final-form";export{Field,useForm,useFormState}from"react-final-form";import p from"prop-types";import f from"clsx";import{Checkbox as b}from"@itcase/ui/components/Checkbox";import{Divider as g}from"@itcase/ui/components/Divider";import{Text as h}from"@itcase/ui/components/Text";import{useDeviceTargetClass as _}from"@itcase/ui/hooks/useDeviceTargetClass";import{useStyles as x}from"@itcase/ui/hooks/useStyles";import{Choice as T}from"@itcase/ui/components/Choice";import{Code as y}from"@itcase/ui/components/Code";import{DatePickerInput as v}from"@itcase/ui/components/DatePicker";import S from"axios";import{useDropzone as E}from"react-dropzone";import{fromEvent as C}from"file-selector";import N from"lodash/castArray";import{createFileFromDataURL as z}from"@itcase/common";import{Loader as P}from"@itcase/ui/components/Loader";import{Title as F}from"@itcase/ui/components/Title";import{Input as j}from"@itcase/ui/components/Input";import{Icon as k}from"@itcase/ui/components/Icon";import{RadioButton as R}from"@itcase/ui/components/RadioButton";import{Segmented as B}from"@itcase/ui/components/Segmented";import{Select as W}from"@itcase/ui/components/Select";import{Switch as M}from"@itcase/ui/components/Switch";import{Textarea as w}from"@itcase/ui/components/Textarea";import{Button as L}from"@itcase/ui/components/Button";import{Group as q}from"@itcase/ui/components/Group";import{NotificationItem as O}from"@itcase/ui/components/Notification";import V from"final-form-focus";const D=(t,r)=>!t||e(t,"RU"),A=(e,t)=>{if(!e)return!0;return/^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]{2,}(?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/.test(String(e).toLowerCase())},I=e=>{const t=Object.entries(e.fields);return e.requiredFields=t.reduce(((e,[t,r])=>(r.exclusiveTests?.required&&e.push(t),e)),[]),e},$=(e,t)=>n(e,t.path,t.message),H=Object.create(null);function G(e,t){const i=r((()=>e&&(e=>async function(t){try{await e.validate(t,{abortEarly:!1})}catch(e){if(e.inner)return e.inner.reduce($,H);console.warn("itcase-forms schema.validate error: An error not related to the form occurred during validation. Validation ignored.")}})(e)),[e,t]);return i}function K(e){const{after:i,afterItem:o,before:a,beforeItem:n,children:s,className:l,desc:m,descTextSize:c,descTextColor:u,descTextWidth:d,divider:p,dividerDirection:b,dividerFill:T,dividerSize:y,dividerWidth:v,fieldClassName:S,id:E,inputName:C,inputValue:N,isRequired:z,label:P,labelTextSize:F,labelTextColor:j,labelTextWidth:k,errorMessageTextSize:R,errorMessageTextWeight:B,errorMessageTextColor:W,message:M,messageTextSize:w,messageTextColor:L,messageTextWeight:q,metaActive:O,metaError:V,metaModifiedSinceLastSubmit:D,metaSubmitError:A,metaSubmitFailed:I,metaTouched:$,metaValid:H,set:G,type:K,hideMessage:U,isHidden:J,tag:Q,dataTour:X,showErrorsOnSubmit:Y}=e,Z=V||!D&&A||!1,ee=r((()=>Y?I&&$&&Z:$&&Z),[Y,I,$,Z]),te=r((()=>(Array.isArray(N)?N.length:N)&&(H||!V&&A&&D)),[N,H,V,A,D]),re=r((()=>f(l,ee&&"form__item_state_error",te&&"form__item_state_success",z&&"form__item_state_required",O&&"form__item_state_focus",N&&"form__item_state_filled")),[l,ee,te,z,O,N]),ie=r((()=>f(S,ee&&`${S}_state_error`,te&&`${S}_state_success`,O&&`${S}_state_focus`,N&&`${S}_state_filled`)),[S,ee,te,O,N]),oe=_(e,{prefix:"form-field_size_",propsKey:"size"}),ae=_(e,{prefix:"fill_",propsKey:"fill"}),ne=_(e,{prefix:"fill_",propsKey:"inputFill"}),se=_(e,{prefix:"form-field_shape_",propsKey:"shape"}),le=_(e,{prefix:"form-field__item-value_shape_",propsKey:"inputShape"}),me=_(e,{prefix:"direction_",propsKey:"direction"}),ce=_(e,{prefix:"width_",propsKey:"width"}),{styles:ue}=x(e);return t.createElement(Q,{className:f(re,"form__item","form-field",K&&`form-field_type_${K}`,G&&`form-field_set_${G}`,oe,ae,se,J&&"form-field_state_hidden",me,ce),"data-tour":X,style:ue},a,P&&t.createElement("div",{htmlFor:E,className:"form-field__label"},t.createElement(h,{size:F,textWeight:k,textColor:j},P)),m&&t.createElement("div",{className:"form-field__desc"},t.createElement(h,{size:c,textWeight:d,textColor:u},m)),t.createElement("div",{className:f("form-field__content",ne,le)},t.createElement("div",{className:f("form-field__content-inner",ie)},n,s,o),p&&t.createElement(g,{className:"form-field__item-divider",width:v,direction:b,size:y,fill:T})),!U&&t.createElement("div",{className:"form-field__message"},Boolean(ee)&&t.createElement(h,{className:"form-field__message-item form-field__message-item_type-error",size:R,textWeight:B,textColor:W,id:`${C}-error`},Z),Boolean(M)&&!ee&&t.createElement(h,{className:"form-field__message-item form-field__message-item_type_message",size:w,textWeight:q,textColor:L},M),Boolean(!ee)&&Boolean(!M)&&t.createElement(h,{className:"form-field__message-item form-field__message-item_type_message",size:w}," ")),i)}function U(e){const{inputName:r}=e,{change:o}=m();return i((()=>()=>{o(r,void 0)}),[]),t.createElement(K,e)}K.defaultProps={tag:"div",type:"normal",errorMessageTextSize:"s",errorMessageTextColor:"errorTextSecondary"},K.propTypes={after:p.any,afterItem:p.any,autoComplete:p.string,before:p.any,beforeItem:p.any,children:p.any,className:p.string,desc:p.string,descTextSize:p.string,descTextColor:p.string,descTextWidth:p.string,dividerDirection:p.string,dividerFill:p.string,dividerSize:p.string,dividerWidth:p.string,fieldClassName:p.string,id:p.string,inputName:p.string,inputOnBlur:p.func,inputOnChange:p.func,inputOnFocus:p.func,inputValue:p.any,isRequired:p.bool,itemType:p.string,label:p.any,labelTextSize:p.string,labelTextColor:p.string,labelTextWidth:p.string,errorMessageTextSize:p.string,errorMessageTextWidth:p.string,errorMessageTextColor:p.string,message:p.string,messageSize:p.string,messageTextColor:p.string,messageTextWidth:p.string,metaActive:p.bool,metaError:p.string,metaModifiedSinceLastSubmit:p.bool,metaSubmitError:p.string,metaSubmitFailed:p.bool,metaTouched:p.bool,metaValid:p.bool,set:p.string,showErrorsOnSubmit:p.bool,type:p.string},U.propTypes={autoComplete:p.string,children:p.any,className:p.string,fieldClassName:p.string,hint:p.string,inputName:p.string,inputOnBlur:p.func,inputOnChange:p.func,inputOnFocus:p.func,inputValue:p.any,isRequired:p.bool,itemType:p.string,label:p.any,metaActive:p.bool,metaError:p.string,metaModifiedSinceLastSubmit:p.bool,metaSubmitError:p.string,metaSubmitFailed:p.bool,metaTouched:p.bool,metaValid:p.bool,showErrorsOnSubmit:p.bool};const J=t.memo((function(e){const{name:r,isRequired:i,onChange:a,fieldProps:n,inputProps:s,classNameGroupItem:l,hideMessage:m}=e;return t.createElement(c,{name:r,type:"checkbox"},(({input:e,meta:r})=>{const c=o((t=>{e.onChange(t),a&&a(t.target.checked,e.name)}),[a]);return t.createElement(U,Object.assign({className:f("form-field_type_checkbox","form__item_type_checkbox",l),fieldClassName:"form-checkbox",inputName:e.name,inputValue:e.checked,isRequired:i,metaActive:r.active,metaError:r.error,metaModifiedSinceLastSubmit:r.modifiedSinceLastSubmit,metaSubmitError:r.submitError,metaSubmitFailed:r.submitFailed,metaTouched:r.touched,metaValid:r.valid,tag:"label",hideMessage:m},n),t.createElement(b,Object.assign({autoComplete:"nope",checked:e.checked,name:e.name,type:"checkbox",onBlur:e.onBlur,onChange:c,onFocus:e.onFocus},s)))}))}));J.defaultProps={inputProps:{},fieldProps:{}},J.propTypes={fieldProps:p.object,inputProps:p.object,isRequired:p.bool,name:p.string,onChange:p.func};const Q=t.memo((function(e){const{options:i,classNameGroupItem:a,fieldProps:n,inputProps:s,isMultiple:l,isRequired:u,initialValue:d,label:p,name:b,messageType:g,hideMessage:h,placeholder:_}=e,{change:x}=m();return t.createElement(c,{name:b,initialValue:d},(({input:e,meta:m})=>{const c=r((()=>{const t={value:null,label:null};if(e.value){return i.find((t=>t.value===e.value))||t}return t}),[e.value]),d=o((e=>{x(b,e.value)}),[x]);return t.createElement(U,Object.assign({className:f("form-field_type_choice","form__item_type_choice",a),fieldClassName:"form-choice",inputName:e.name,inputValue:e.value||[],isRequired:u,label:p,messageType:g,metaActive:m.active,metaError:m.error,metaModifiedSinceLastSubmit:m.modifiedSinceLastSubmit,metaSubmitError:m.submitError,metaSubmitFailed:m.submitFailed,metaTouched:m.touched,metaValid:m.valid,hideMessage:h},n),t.createElement(T,Object.assign({className:f(m.active&&"form-choice_state_focus",m.error&&m.touched&&"form-choice_state_error"),options:i,inputName:e.name,inputValue:e.value||[],isMultiple:l,isRequired:u,placeholder:_,active:c,setActiveSegment:d},s)))}))}));Q.propTypes={options:p.array.isRequired,name:p.string.isRequired,className:p.string,inputClass:p.string,isMultiple:p.bool,isRequired:p.bool,label:p.string,placeholder:p.string};const X=t.memo((function(e){const{Component:r,isRequired:i,name:o,fieldProps:a,classNameGroupItem:n,hideMessage:s}=e;return t.createElement(c,{name:o},(({input:o,meta:l})=>t.createElement(U,Object.assign({className:f("form-field_type_custom","form__item_type_custom",n),fieldClassName:"form-custom",inputName:o.name,inputValue:o.value,isRequired:i,metaActive:l.active,metaError:l.error,metaModifiedSinceLastSubmit:l.modifiedSinceLastSubmit,metaSubmitError:l.submitError,metaSubmitFailed:l.submitFailed,metaTouched:l.touched,metaValid:l.valid,hideMessage:s},a),t.createElement(r,Object.assign({},e,{input:o,meta:l})))))}));X.defaultProps={inputProps:{},fieldProps:{}},X.propTypes={name:p.string.isRequired,isRequired:p.bool,fieldProps:p.object,inputProps:p.object};const Y=t.memo((function(e){const{isRequired:r,name:i,fieldProps:o,inputProps:a,classNameGroupItem:n,hideMessage:s}=e;return t.createElement(c,{name:i},(({input:e,meta:i})=>t.createElement(U,Object.assign({className:f("form-field_type_code","form__item_type_code",n),fieldClassName:"form-code",inputName:e.name,inputValue:e.value,isRequired:r,metaActive:i.active,metaError:i.error,metaModifiedSinceLastSubmit:i.modifiedSinceLastSubmit,metaSubmitError:i.submitError,metaSubmitFailed:i.submitFailed,metaTouched:i.touched,metaValid:i.valid,hideMessage:s},o),t.createElement(y,Object.assign({autoComplete:"nope",name:e.name,value:e.value,onBlur:e.onBlur,onChange:e.onChange,onFocus:e.onFocus},a)))))}));function Z(e){const{isRequired:r,fieldProps:i,inputProps:a,datePickerProps:n,name:s,iconSize:l,iconBorder:m,iconBorderHover:u,iconFill:d,iconFillHover:p,iconRevealableShow:b,iconRevealableHide:g,iconShape:h,hideMessage:_,onChange:x,classNameGroupItem:T}=e;return t.createElement(c,{name:s},(({input:e,meta:s})=>{const l=o((t=>{e.onChange(t),x&&x(t,e.name)}),[x]);return t.createElement(U,Object.assign({className:f("form-field_type_datepicker","form__item_type_datepicker",T),fieldClassName:"form-datepicker",inputName:e.name,inputValue:e.value||"",isRequired:r,metaActive:s.active,metaError:s.error,metaModifiedSinceLastSubmit:s.modifiedSinceLastSubmit,metaSubmitError:s.submitError,metaSubmitFailed:s.submitFailed,metaTouched:s.touched,metaValid:s.valid,hideMessage:_},i),t.createElement(v,{name:e.name,value:e.value||"",onBlur:e.onBlur,onChange:l,onFocus:e.onFocus,inputProps:a,datePickerProps:n}))}))}async function ee(e){try{const t=await S({url:`/api/${e}/`,responseType:"blob"}),r=t.data,i=t.headers["content-disposition"]?.split("filename=")[1];let o=i?.substring(1).slice(0,-1);if(!o){const e=r.type.split("/"),t=e[e.length-1];o=`${(new Date).getTime()}.${t}`}return new File([r],o,{type:r.type})}catch(e){return console.log("error: ",e),null}}function te(e,t){t=t||(()=>{});const r=new FileReader;r._readedFile=e,r.onabort=()=>t(),r.onerror=()=>t(),r.onload=e=>{e.target._readedFile.dataURL=r.result,t()},e instanceof File?r.readAsDataURL(e):t()}Y.defaultProps={inputProps:{},fieldProps:{}},Y.propTypes={name:p.string.isRequired,isRequired:p.bool,fieldProps:p.object,inputProps:p.object},Z.defaultProps={inputProps:{},fieldProps:{}},Z.propTypes={fieldProps:p.object,inputProps:p.object,isRequired:p.bool,name:p.string.isRequired,onChange:p.func};const re=t.memo((function(e){const{inputName:r,size:n,className:s,fileErrorText:l,hintTitleTextSize:c,removeThumbTextSize:u,removeThumbTextColor:d,removeThumbTextWeight:p,thumbNameTextSize:b,thumbNameTextColor:g,removeThumbTextHoverColor:x,thumbNameTextWrap:T,thumbNameTextWeight:y,hintTitleTextColor:v,hintTitleTextWrap:S,thumbColumn:F,hintTitleTextWeight:j,hintDescriptionTextSize:k,hintDescriptionTextColor:R,hintDescriptionTextWrap:B,hintDescriptionTextWeight:W,errorMessageTextSize:M,errorMessageTextWeight:w,errorMessageTextColor:L,inputValue:q,maxFiles:O,maxSize:V,removeThumbText:D,hintTitle:A,hintDescription:I,isShowFilename:$,isPreviews:H,loadingText:G,dropzoneProps:K={},onAddFiles:U,onDeleteFile:J}=e,[Q,X]=a(""),[Y,Z]=a(!1),[re,ie]=a(q?N(q):[]),{change:oe}=m(),ae=o((e=>{const t=1==K.maxFiles?e[0]:e;return oe(r,t),t}),[K,oe]),{getRootProps:ne,getInputProps:se}=E({maxSize:V||10485760,maxFiles:O||5,...K,getFilesFromEvent:async e=>{const t=(await C(e)).filter((e=>e instanceof File));return[...re,...t]},onDropAccepted:(e,t)=>{H&&e.forEach((e=>{e.error||(e.preview=URL.createObjectURL(e))})),ie(e),X("");const i=e.map((e=>new Promise((t=>te(e,t)))));Promise.all(i).then((()=>{const t=ae(e);U&&U(t,r)}))},onDropRejected:(e,t)=>{if(e.length){const t=e[0].errors[0]?.message;X(t||"Error on adding file")}else X("")}}),le=o(((e,t)=>{e.stopPropagation(),e.preventDefault();const i=[...re];i.splice(t,1),J&&J(re[t],r),ae(i)}),[re,ae,J]),me=o((async e=>{Z(!0);const t=await async function(e,t){const r=[];for await(const i of N(e)){let e=null;const o="string"==typeof i&&i.includes("/");(i.image||o)&&(e=await ee(i.image||i),e&&te(e)),i.dataURL&&(e=z(i.name||i.path,i.dataURL),e.dataURL=i.dataURL),e&&(e.id=i.id,t&&(e.preview=URL.createObjectURL(e)),r.push(e))}return r}(e,H);return Z(!1),ie(t),t}),[H]);i((()=>{me(q).then((e=>ae(e)))}),[]),i((()=>{q?me(q):ie([])}),[q]),i((()=>()=>re.forEach((e=>URL.revokeObjectURL(e?.preview)))),[]);const ce=_(e,{prefix:"fill_",propsKey:"fill"}),ue=_(e,{prefix:"fill_hover_",propsKey:"fillHover"}),de=_(e,{prefix:"border-width_",propsKey:"borderWidth"}),pe=_(e,{prefix:"border-color_",propsKey:"borderColor"}),fe=_(e,{prefix:"border-color_hover_",propsKey:"borderColorHover"}),be=_(e,{prefix:"border_type_",propsKey:"borderType"}),ge=_(e,{prefix:"form-dropzone_shape_",propsKey:"shape"}),he=_(e,{prefix:"border-width_",propsKey:"thumbBorderWidth"}),_e=_(e,{prefix:"form-dropzone__thumb_direction_",propsKey:"thumbDirection"}),xe=_(e,{prefix:"border-color_",propsKey:"thumbBorderColor"}),Te=_(e,{prefix:"border-color_hover_",propsKey:"thumbBorderColorHover"}),ye=_(e,{prefix:"border_type_",propsKey:"thumbBorderType"});return t.createElement(t.Fragment,null,t.createElement("div",ne({className:`form-dropzone__dropzone dropzone ${s} thumbColumn form-dropzone__dropzone_size_${n} ${ge}`}),t.createElement("input",Object.assign({},se(),{name:r})),t.createElement("div",{className:f("form-dropzone__dropzone-wrapper",F&&`form-dropzone__dropzone-wrapper_column_${F}`,ce,ue,de,pe,fe,be)},re.map(((e,r)=>t.createElement("aside",{className:f("form-dropzone__thumb",ce,_e,he,xe,Te,ye),key:`${e.id||`${e.name}_${r}`||"i"+r}`},H&&!e.error&&t.createElement("div",{className:"form-dropzone__thumb-image"},t.createElement("img",{className:"form-dropzone__thumb-image-inner",src:e.preview||e.image,onLoad:()=>{URL.revokeObjectURL(e.preview)}})),e.error&&t.createElement("div",null,t.createElement(h,{size:b,textColor:g,textWrap:T,textWeight:y},l||e.error)),$&&t.createElement("div",{className:"form-dropzone__thumb-name"},t.createElement(h,{size:b,textColor:g,textWrap:T,textWeight:y,className:"form-dropzone__thumb-name-inner"},e.name)),Y&&t.createElement("div",{className:"form-dropzone__thumb-loader"},t.createElement(P,{fill:"surfacePrimary",height:"fill",itemFill:"surfaceItemAccent",set:"simple",width:"fill"})),t.createElement("div",{className:"form-dropzone__thumb-remove",onClick:e=>le(e,r)},t.createElement(h,{size:u,textColor:d,textWeight:p,textColorHover:x,className:"form-dropzone__thumb-remove-text"},D||"Remove"))))),re.length?t.createElement("div",{className:"form-dropzone__hint form-dropzone__hint_type_add-more"},t.createElement(h,{size:c,textColor:v,textWrap:S,textWeight:j,className:"form-dropzone__hint-title"},A||"Select a file or drag in form"),t.createElement(h,{size:k,textColor:R,textWrap:B,textWeight:W,className:"form-dropzone__hint-text"},I)):t.createElement("div",{className:"form-dropzone__hint"},t.createElement(h,{size:c,textColor:v,textWrap:S,textWeight:j,className:"form-dropzone__hint-title"},A||"Select a file or drag in form"),t.createElement(h,{size:k,textColor:R,textWrap:B,textWeight:W,className:"form-dropzone__hint-text"},I)))),Q&&t.createElement("div",{className:"form-field__message"},t.createElement(h,{className:"form-field__message-item form-field__message-item_type_message",size:M,textWeight:w,textColor:L},Q)))}));re.propTypes={dropzoneProps:p.object,hintDescription:p.string,hintTitle:p.string,inputName:p.string,inputValue:p.any,isPreviews:p.bool,isShowFilename:p.bool,loadingText:p.string,metaError:p.string,metaTouched:p.bool,removeThumbText:p.string,onAddFiles:p.func,onDeleteFile:p.func};const ie=t.memo((function(e){const{name:r,shape:i,size:o,borderWidth:a,borderColor:n,borderColorHover:s,borderType:l,label:m,thumbBorderWidth:u,thumbBorderColor:d,thumbBorderColorHover:p,thumbBorderType:b,removeThumbTextHoverColor:g,labelTextColor:h,fill:_,fillHover:x,className:T,removeThumbText:y,thumbNameTextSize:v,thumbNameTextColor:S,thumbNameTextWrap:E,thumbNameTextWeight:C,removeThumbTextSize:N,removeThumbTextColor:z,removeThumbTextWeight:P,hintTitle:F,errorMessageTextSize:j,errorMessageTextWeight:k,errorMessageTextColor:R,fieldProps:B,hintTitleTextSize:W,hintTitleTextColor:M,hintTitleTextWrap:w,hintTitleTextWeight:L,hintDescriptionTextSize:q,hintDescriptionTextColor:O,hintDescriptionTextWrap:V,hintDescriptionTextWeight:D,hideMessage:A,thumbDirection:I,hintDescription:$,isShowFilename:H,fileErrorText:G,dropzoneProps:K,maxFiles:J,maxSize:Q,thumbColumn:X,isRequired:Y,isPreviews:Z,onAddFiles:ee,onDeleteFile:te,classNameGroupItem:ie}=e;return t.createElement(c,{name:r},(({input:e,meta:r})=>t.createElement(U,Object.assign({className:f("form-field_type_dropzone","form__item_type_dropzone",ie),fieldClassName:"form-dropzone",inputName:e.name,inputValue:e.value,isRequired:Y,label:m,labelTextColor:h,metaActive:r.active,metaError:r.error,metaModifiedSinceLastSubmit:r.modifiedSinceLastSubmit,metaSubmitError:r.submitError,metaSubmitFailed:r.submitFailed,metaTouched:r.touched,metaValid:r.valid,hideMessage:A},B),t.createElement(re,{dropzoneProps:K,hintDescription:$,hintTitle:F,borderWidth:a,borderColor:n,borderColorHover:s,borderType:l,thumbBorderWidth:u,thumbBorderColor:d,thumbBorderColorHover:p,thumbBorderType:b,fileErrorText:G,fill:_,size:o,maxFiles:J,maxSize:Q,removeThumbTextHoverColor:g,fillHover:x,className:T,thumbColumn:X,thumbDirection:I,inputName:e.name,inputValue:e.value,thumbNameTextSize:v,thumbNameTextColor:S,thumbNameTextWrap:E,thumbNameTextWeight:C,hintTitleTextSize:W,hintTitleTextColor:M,hintTitleTextWrap:w,hintTitleTextWeight:L,removeThumbTextSize:N,removeThumbTextColor:z,removeThumbTextWeight:P,hintDescriptionTextSize:q,hintDescriptionTextColor:O,hintDescriptionTextWrap:V,hintDescriptionTextWeight:D,errorMessageTextSize:j,errorMessageWeight:k,errorMessageTextColor:R,isPreviews:Z,shape:i,isShowFilename:H,metaError:r.error,metaTouched:r.touched,removeThumbText:y,onAddFiles:ee,onDeleteFile:te}))))}));ie.defaultProps={errorMessageTextSize:"s",errorMessageTextColor:"errorTextPrimary",thumbColumn:1,thumbDirection:"vertical"},ie.propTypes={name:p.string.isRequired,className:p.string,classNameGroupItem:p.string,classNameInput:p.string,classNameInputWrapper:p.string,dropzoneProps:p.object,hintDescription:p.string,hintTitle:p.string,inputClass:p.string,isPreviews:p.bool,isRequired:p.bool,isShowFilename:p.bool,label:p.any,removeThumbText:p.string,onAddFiles:p.func,onDeleteFile:p.func};const oe=t.memo((function(e){const{after:i,before:o,className:a,label:n,labelTextColor:s,labelTextSize:l,labelTextWeight:m,message:u,errorMessageTextSize:d,errorMessageTextWeight:p,errorMessageTextColor:b,messageTextSize:g,messageTextWeight:_,messageTextColor:x,children:T,dataTour:y,hideMessage:v,name:S,showErrorsOnSubmit:E}=e;return t.createElement(c,{name:S},(({input:e,meta:c})=>{const C=c.error||!c.modifiedSinceLastSubmit&&c.submitError||!1,N=r((()=>E?c.submitFailed&&c.touched&&C:c.touched&&C),[E,c.submitFailed,c.touched,C]);return t.createElement("div",{className:f("form__group",a),"data-tour":y},t.createElement("div",{className:"form__group-wrapper"},o,t.createElement("div",{className:"form__group-label"},t.createElement(F,{textColor:s,size:l,textWeight:m},n)),t.createElement("div",{className:"form__group-items"},T),i),!v&&t.createElement(t.Fragment,null,Boolean(N)&&t.createElement(h,{className:"form__group-message form__group-message_type-error",size:d,textWeight:p,textColor:b,id:`${S}-error`},C),Boolean(u)&&!N&&t.createElement(h,{className:"form__group-message",size:g,textWeight:_,textColor:x},u),Boolean(!N)&&Boolean(!u)&&t.createElement(h,{className:"form__group-message",size:g}," ")))}))}));oe.defaultProps={inputProps:{},fieldProps:{},type:"normal",errorMessageTextSize:"s",errorMessageTextColor:"errorTextPrimary",messageTextSize:"s",messageTextColor:"surfaceTextTertiary"},oe.propTypes={name:p.string.isRequired,isRequired:p.bool,fieldProps:p.object,inputProps:p.object};const ae=t.memo((function(e){const{isPassword:i,isRequired:n,fieldProps:s,inputProps:l,isRevealable:m,name:u,parse:d,iconSize:p,iconBorder:b,iconBorderHover:g,iconFill:h,iconFillHover:_,iconRevealableShow:x,iconRevealableHide:T,iconShape:y,hideMessage:v,onChange:S,classNameGroupItem:E}=e,[C,N]=a(!1),z=r((()=>i?C?"text":"password":"text"),[C,i]),P=o((e=>{e.preventDefault(),N((e=>!e))}),[N]);return t.createElement(c,{name:u,parse:d},(({input:e,meta:r})=>{const i=o((t=>{e.onChange(t),S&&S(t.target.value,e.name)}),[S]);return t.createElement(U,Object.assign({className:f("form-field_type_input","form__item_type_input",E),fieldClassName:m?"form-password":"form-input",inputName:e.name,inputValue:e.value||"",isRequired:n,metaActive:r.active,metaError:r.error,metaModifiedSinceLastSubmit:r.modifiedSinceLastSubmit,metaSubmitError:r.submitError,metaSubmitFailed:r.submitFailed,metaTouched:r.touched,metaValid:r.valid,hideMessage:v},s),t.createElement(j,Object.assign({className:f(r.active&&"input_state_focus",r.error&&r.touched&&"input_state_error"),autoComplete:"nope",name:e.name,type:z,value:e.value||"",onBlur:e.onBlur,onChange:i,onFocus:e.onFocus},l)),m&&t.createElement(k,{className:"form-field__icon",iconFill:h,iconFillHover:_,SvgImage:C?T:x,imageSrc:C?T:x,shape:y,size:p,onClick:P}))}))}));function ne(e){const{input:r,option:i,onChange:a,inputProps:n}=e,s=o((e=>{e.target.checked&&a(i.value)}),[]);return t.createElement(R,Object.assign({className:"form-radio__item",checked:i.value===r.value,name:r.name,type:"radio",value:i.value,onBlur:r.onBlur,onChange:s,onFocus:r.onFocus,label:i.label},n))}function se(e){const{input:r,value:i,onChange:a}=e,n=o((e=>a(e.target.value)),[a]);return t.createElement(j,Object.assign({autoComplete:"nope",name:r.name,onBlur:r.onBlur,onChange:n,onFocus:r.onFocus,value:i},e))}function le(e){const{input:r,options:n,editableProps:s,onChange:l,inputProps:m}=e,[c,u]=a((()=>n.find((e=>e.value===r.value))?"":r.value));i((()=>{if(r.value){const e=n.find((e=>e.value===r.value&&!e.editable));u(e?"":r.value)}else u("")}),[r.value]);const d=o((e=>{r.onChange(e),l&&l(e,r.name)}),[r,l]),p=o((e=>{u(""),d(e)}),[d]),f=o((e=>{u(e),d(e)}),[d]);return t.createElement(t.Fragment,null,n.map((e=>e.editable?t.createElement(se,{key:e.label,input:r,value:c,option:e,onChange:f,editableProps:s,inputProps:m}):t.createElement(ne,{key:e.value,input:r,option:e,onChange:p,inputProps:m}))))}ae.defaultProps={inputProps:{},fieldProps:{}},ae.propTypes={fieldProps:p.object,inputProps:p.object,isPassword:p.bool,isRequired:p.bool,isRevealable:p.bool,name:p.string.isRequired,onChange:p.func},ne.propTypes={inputProps:p.object,onChange:p.func,option:p.shape({label:p.string,value:p.string}),input:p.shape({name:p.string,value:p.string,onBlur:p.func,onFocus:p.func,onChange:p.func})},se.propTypes={input:p.string,value:p.string,editableProps:p.object,onChange:p.func},le.propTypes={editableProps:p.object,input:p.object,inputProps:p.object,onChange:p.object,options:p.object};const me=t.memo((function(e){const{isRequired:r,name:i,options:o,fieldProps:a,editableProps:n,inputProps:s,onChange:l,hideMessage:m}=e;return t.createElement(c,{name:i},(({input:e,meta:i})=>t.createElement(U,Object.assign({className:"form__item_type_radio",fieldClassName:"form-radio",inputName:e.name,inputValue:e.value||"",isRequired:r,metaActive:i.active,metaError:i.error,metaModifiedSinceLastSubmit:i.modifiedSinceLastSubmit,metaSubmitError:i.submitError,metaSubmitFailed:i.submitFailed,metaTouched:i.touched,metaValid:i.valid,hideMessage:m},a),t.createElement(le,{input:e,options:o,onChange:l,editableProps:n,inputProps:s}))))}));function ce(e){const{options:i,isRequired:a,name:n,fieldProps:s,inputProps:l,hideMessage:u}=e,{change:d}=m();return t.createElement(c,{name:n},(({input:e,meta:m})=>{const c=r((()=>{const t={value:null,label:null};if(e.value){return i.find((t=>t.value===e.value))||t}return t}),[e.value]),p=o((e=>{d(n,e.value)}),[d]);return t.createElement(U,Object.assign({className:f("form-field_type_segmented","form__item_type_segmented"),fieldClassName:"form-segmented",inputName:e.name,inputValue:e.value||[],isRequired:a,metaActive:m.active,metaError:m.error,metaModifiedSinceLastSubmit:m.modifiedSinceLastSubmit,metaSubmitError:m.submitError,metaSubmitFailed:m.submitFailed,metaTouched:m.touched,metaValid:m.valid,hideMessage:u},s),t.createElement(B,Object.assign({segments:i,setActiveSegment:p,activeSegment:c},l)))}))}function ue(e,t){const r=Array.isArray(t)?t:[t];let i=[];return e.forEach((e=>{const o=r.includes(e.value),a=r.includes(e.label);let n=[];e.options&&(n=ue(e.options,t)),o||a?i.push(e):n.length&&(i=i.concat(n))})),i}me.defaultProps={fieldProps:{},editableProps:{},inputProps:{},options:[]},me.propTypes={name:p.string.isRequired,fieldProps:p.object,inputProps:p.object,editableProps:p.object,isRequired:p.bool,options:p.array,onChange:p.func},ce.propTypes={options:p.array.isRequired,name:p.string.isRequired,className:p.string,inputClass:p.string,isRequired:p.bool,label:p.string,placeholder:p.string,fieldProps:p.object,inputProps:p.object};const de=t.memo((function(e){const{isRequired:n,key:s,name:l,options:m,fieldProps:u,selectProps:d,selectRef:p,onChange:b,classNameGroupItem:g,hideMessage:h}=e;return t.createElement(c,{name:l},(({input:e,meta:l})=>{const c=o((t=>{e.onChange(t),b&&b(t,e.name)}),[b]),[_,x]=a(null),T=r((()=>{const t=ue(m,e.value);return!t.length&&e.value?.length&&t.push({value:e.value,label:e.value}),t}),[e.value]);i((()=>x(T)),[T]);const y=o(((e,t)=>{const r=Array.isArray(e)?e.map((e=>e.value)):e?.value||null;x(e),c(r)}),[c]);return t.createElement(U,Object.assign({className:f("form-field_type_select","form__item_type_select",g),fieldClassName:"form-select",inputName:e.name,inputValue:e.value,isRequired:n,metaActive:l.active,metaError:l.error,metaModifiedSinceLastSubmit:l.modifiedSinceLastSubmit,metaSubmitError:l.submitError,metaSubmitFailed:l.submitFailed,metaTouched:l.touched,metaValid:l.valid,hideMessage:h},u),t.createElement(W,Object.assign({className:"form-select-item",instanceId:`id_${e.name}`,value:_,onChange:y,options:m,ref:p,key:s},d)))}))}));de.propTypes={name:p.string.isRequired,selectProps:p.object,isRequired:p.bool,label:p.any,messageType:p.string,options:p.array,onChange:p.func};const pe=t.memo((function(e){const{name:r,isRequired:i,onChange:a,fieldProps:n,inputProps:s,classNameGroupItem:l,hideMessage:m}=e;return t.createElement(c,{name:r,type:"checkbox"},(({input:e,meta:r})=>{const c=o((t=>{e.onChange(t),a&&a(t.target.checked,e.name)}),[a]);return t.createElement(U,Object.assign({className:f("form-field_type_switch","form__item_type_switch",l),fieldClassName:"form-switch",inputName:e.name,inputValue:e.checked,isRequired:i,metaActive:r.active,metaError:r.error,metaModifiedSinceLastSubmit:r.modifiedSinceLastSubmit,metaSubmitError:r.submitError,metaSubmitFailed:r.submitFailed,metaTouched:r.touched,metaValid:r.valid,hideMessage:m,tag:"label"},n),t.createElement(M,Object.assign({autoComplete:"nope",checked:e.checked,name:e.name,type:"checkbox",onBlur:e.onBlur,onChange:c,onFocus:e.onFocus},s)))}))}));pe.defaultProps={inputProps:{},fieldProps:{}},pe.propTypes={fieldProps:p.object,inputProps:p.object,isRequired:p.bool,name:p.string,onChange:p.func};const fe=t.memo((function(e){const{isRequired:r,name:i,fieldProps:o,inputProps:a,classNameGroupItem:n,hideMessage:s}=e;return t.createElement(c,{name:i},(({input:e,meta:i})=>t.createElement(U,Object.assign({className:f("form-field_type_textarea","form__item_type_textarea",n),fieldClassName:"form-textarea",inputName:e.name,inputValue:e.value,isRequired:r,metaActive:i.active,metaError:i.error,metaModifiedSinceLastSubmit:i.modifiedSinceLastSubmit,metaSubmitError:i.submitError,metaSubmitFailed:i.submitFailed,metaTouched:i.touched,metaValid:i.valid,hideMessage:s},o),t.createElement(w,Object.assign({autoComplete:"nope",name:e.name,value:e.value,onBlur:e.onBlur,onChange:e.onChange,onFocus:e.onFocus},a)))))}));fe.defaultProps={inputProps:{},fieldProps:{}},fe.propTypes={name:p.string.isRequired,isRequired:p.bool,fieldProps:p.object,inputProps:p.object};const be=(e,t)=>{const r=Object.keys(t).map((e=>e===s?"notification__item_status_error":`react-select-id_${e}-input`)),i=e.find((e=>e.name?l(t,e.name):r.includes(e.id))),o=Object.keys(t);if(!i&&o.length){let e;try{const t=o[0];t===s?e=document.querySelector("notification__item_status_error"):(e=document.querySelector(`#${t}-error`),e||(e=document.querySelector(`#id_${t}`)))}catch(e){console.warn(e)}e&&e.scrollIntoView({block:"center"})}return i&&i.scrollIntoView({block:"center"}),null},ge=V(null,be),he=(e,t)=>{const[r,i]=e,o=i.submitError,a=i.error;if("non_field_errors"===r)t.formState.error=a,t.formState.submitError=o;else if(r in t.fields){if(a){const e=Object.assign({},t.formState.errors,{[r]:a});t.fields[r].touched=!0,t.fields[r].error=a,t.formState.errors=e}if(o){const e=Object.assign({},t.formState.submitErrors,{[r]:o});t.fields[r].submitError=o,t.formState.submitErrors=e,t.formState.submitFailed=!0,t.formState.submitSucceeded=!1,t.formState.lastSubmittedValues=t.formState.values}}},_e=async(e,t)=>{try{return{success:!0,response:await S({url:e,method:"POST",data:t})}}catch(e){const t={};return"string"==typeof e.response?.data&&(t[s]="Something went wrong"),"object"==typeof e.response?.data&&Object.entries(e.response.data).forEach((([e,r])=>{t[e]=r[0]})),{success:!1,formErrors:t,error:e}}},xe={checkbox:"checkbox",custom:"custom",choice:"choice",code:"code",datePicker:"datePicker",dateRangePicker:"dateRangePicker",fileInput:"fileInput",group:"group",radioGroup:"radioGroup",segmented:"segmented",select:"select",switch:"switch",text:"text",textarea:"textarea"};function Te(e,r,i){switch(e.type){case xe.checkbox:return t.createElement(J,Object.assign({key:r.key},e,i));case xe.choice:return t.createElement(Q,Object.assign({key:r.key},e,i));case xe.code:return t.createElement(Y,Object.assign({key:r.key},e,i));case xe.switch:return t.createElement(pe,Object.assign({key:r.key},e,i));case xe.segmented:return t.createElement(ce,Object.assign({key:r.key},e,i));case xe.datePicker:return t.createElement(Z,Object.assign({key:r.key},e,i));case xe.fileInput:return t.createElement(ie,Object.assign({key:r.key},e,i));case xe.radioGroup:return t.createElement(me,Object.assign({key:r.key},e,i));case xe.select:return t.createElement(de,Object.assign({key:r.key},e,i));case xe.text:return t.createElement(ae,Object.assign({key:r.key},e,i));case xe.textarea:return t.createElement(fe,Object.assign({key:r.key},e,i));case xe.custom:return t.createElement(X,Object.assign({key:r.key},e,i));case xe.group:return t.createElement(oe,Object.assign({key:r.key},e,i),Object.entries(e.group).map((([t,r])=>Te({...r,hideMessage:e.hideMessage,classNameGroupItem:r.classNameGroupItem||"form__group-item"},{key:t+"_form_group"},i))))}}const ye=t.forwardRef((function(e,r){const{additionalProps:i,after:a,before:n,buttonDirection:s,buttonGap:l,buttonPadding:m,groupGap:c,className:p,config:b,description:g,descriptionSize:T,descriptionTextColor:y,descriptionTextWeight:v,disableFieldsAutoComplete:S,fieldsGap:E,formName:C,initialValues:N,initialValuesEqual:z,isLoading:j,loader:k,loaderSet:R,loaderFill:B,loaderItemFill:W,loaderText:M,language:w,mutators:V,onChangeFormValues:D,onClickSecondaryButton:A,onClickTertiaryButton:I,onSubmit:$,primaryButton:H,primaryButtonLabel:K,secondaryButton:U,secondaryButtonLabel:J,primaryButtonFill:Q,primaryButtonFillHover:X,secondaryButtonFill:Y,secondaryButtonFillHover:Z,primaryButtonSize:ee,primaryButtonLabelTextColor:te,primaryButtonLabelSize:re,primaryButtonLabelTextWeight:ie,secondaryButtonSize:oe,secondaryButtonLabelTextColor:ae,secondaryButtonLabelSize:ne,secondaryButtonLabelTextWeight:se,tertiaryButton:le,tertiaryButtonFill:me,tertiaryButtonFillHover:ce,tertiaryButtonSize:ue,tertiaryButtonLabelTextColor:de,tertiaryButtonLabelSize:pe,tertiaryButtonLabelTextWeight:fe,tertiaryButtonLabel:be,set:he,type:_e,buttonJustifyContent:xe,title:ye,notificationType:ve,buttonFill:Se,titleTextSize:Ee,titleTextColor:Ce,titleTextWeight:Ne,validationSchema:ze,dataTour:Pe,dataTourButtons:Fe,dataTourPrimaryButton:je,dataTourSecondaryButton:ke,dataTourTertiaryButton:Re}=e,Be=G(ze,w),We=o((e=>{r&&(r.current=e)}),[r]),Me=_(e,{prefix:"fill_",propsKey:"fill"}),we=_(e,{prefix:"direction_",propsKey:"direction"}),Le=_(e,{prefix:"shape_",propsKey:"shape"}),qe=_(e,{prefix:"elevation_",propsKey:"elevation"}),{styles:Oe}=x(e);return t.createElement(u,{decorators:[ge],initialValues:N,initialValuesEqual:z,mutators:V,render:({handleSubmit:e,submitError:r,modifiedSinceLastSubmit:o,form:u})=>t.createElement("form",{style:Oe,className:f(p,"form",he&&`form_set_${he}`,_e&&`form_type_${_e}`,we,Me,Le,qe),name:C,"data-tour":Pe,ref:()=>We(u),onSubmit:e,autoComplete:S?"off":void 0,autoCorrect:S?"off":void 0,autoCapitalize:S?"off":void 0,spellCheck:S?"false":void 0},n,ye&&t.createElement(F,{className:"form__title",size:Ee,textColor:Ce,textWeight:Ne},ye),g&&t.createElement(h,{className:"form__description",size:T,textColor:y,textWeight:v},g),r&&!o&&t.createElement("div",{className:f("notification","form-notification",ve?`form-notification_type_${ve}`:"form-notification_type_global")},t.createElement(O,{className:"form-notification__item",titleTextSize:"h6",title:u.getState().submitError,set:"form",status:"error"})),D&&t.createElement(d,{subscription:{values:!0},onChange:D}),Boolean(Object.keys(b).length)&&t.createElement(q,{direction:"vertical",gap:E||c,className:"form__wrapper"},Object.keys(b).map((e=>Te(b[e],{key:e},i[b[e].name]))),j&&(k||t.createElement(P,{className:"form__loader",set:R,fill:B,itemFill:W,text:M}))),(K||H||J||U||le||be)&&t.createElement(q,{fill:Se,justifyContent:xe,direction:s,padding:m,gap:l,className:"form__button",dataTour:Fe},K?t.createElement(L,{width:"fill",className:"form__button-item",fill:Q,fillHover:X,size:ee,labelTextColor:te,labelSize:re,labelTextWeight:ie,label:K,dataTour:je}):H,J?t.createElement(L,{width:"fill",className:"form__button-item",fill:Y,fillHover:Z,size:oe,labelTextColor:ae,labelSize:ne,labelTextWeight:se,label:J,onClick:A,dataTour:ke}):U,be?t.createElement(L,{width:"fill",className:"form__button-item",fill:me,fillHover:ce,size:ue,labelTextColor:de,labelSize:pe,labelTextWeight:fe,label:be,onClick:I,dataTour:Re}):le),a),subscription:{submitting:!0,pristine:!0,modifiedSinceLastSubmit:!0,submitError:!0},validate:Be,onSubmit:$})}));ye.propTypes={additionalProps:p.object,after:p.any,before:p.any,buttonGap:p.string,className:p.string,config:p.object,description:p.string,descriptionSize:p.string,descriptionTextColor:p.string,descriptionTextWeight:p.string,disableFieldsAutoComplete:p.string,fieldsGap:p.string,formName:p.string,initialValues:p.any,initialValuesEqual:p.any,language:p.string,isLoading:p.bool,loaderText:p.string,mutators:p.any,onChangeFormValues:p.func,onClickSecondaryButton:p.func,onSubmit:p.func,primaryButton:p.string,primaryButtonFill:p.string,primaryButtonLabel:p.string,secondaryButton:p.string,secondaryButtonFill:p.string,secondaryButtonLabel:p.string,set:p.string,title:p.string,titleSize:p.string,titleTextColor:p.string,titleTextWeight:p.string,validationSchema:p.object},ye.defaultProps={additionalProps:{},isLoading:!1,loaderSet:"simple",loaderFill:"surfacePrimary",loaderItemFill:"surfaceItemAccent",language:"en",titleSize:"h1",buttonDirection:"vertical",direction:"vertical",disableFieldsAutoComplete:!1};export{J as Checkbox,Q as ChoiceField,Y as CodeField,X as CustomField,Z as DatePickerField,U as FieldWrapper,K as FieldWrapperBase,ie as FileInput,ye as FinalForm,oe as Group,ae as InputField,me as RadioGroup,ce as SegmentedField,de as SelectField,pe as Switch,fe as Textarea,I as addRequiredFieldsParamToSchema,A as emailValidation,be as focusOnError,ge as focusOnErrorDecorator,xe as formTypes,Te as generateField,D as phoneValidation,_e as sendFormDataToServer,he as setErrorsMutator,G as useYupValidationSchema};
|