@washingtonpost/subs-de-inputs 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,792 @@
1
+ import React, { useState, useEffect } from 'react';
2
+ import { Icon, theme, Select, styled } from '@washingtonpost/wpds-ui-kit';
3
+ import { useWindowSize } from '@washingtonpost/subs-hooks';
4
+ import { ChevronDown } from '@washingtonpost/wpds-assets';
5
+ import { getCookie, WPGeo, ENDPOINTS, ResponseStatus } from '@washingtonpost/subs-sdk';
6
+
7
+ function _regeneratorRuntime() {
8
+ _regeneratorRuntime = function () {
9
+ return exports;
10
+ };
11
+ var exports = {},
12
+ Op = Object.prototype,
13
+ hasOwn = Op.hasOwnProperty,
14
+ defineProperty = Object.defineProperty || function (obj, key, desc) {
15
+ obj[key] = desc.value;
16
+ },
17
+ $Symbol = "function" == typeof Symbol ? Symbol : {},
18
+ iteratorSymbol = $Symbol.iterator || "@@iterator",
19
+ asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
20
+ toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
21
+ function define(obj, key, value) {
22
+ return Object.defineProperty(obj, key, {
23
+ value: value,
24
+ enumerable: !0,
25
+ configurable: !0,
26
+ writable: !0
27
+ }), obj[key];
28
+ }
29
+ try {
30
+ define({}, "");
31
+ } catch (err) {
32
+ define = function (obj, key, value) {
33
+ return obj[key] = value;
34
+ };
35
+ }
36
+ function wrap(innerFn, outerFn, self, tryLocsList) {
37
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
38
+ generator = Object.create(protoGenerator.prototype),
39
+ context = new Context(tryLocsList || []);
40
+ return defineProperty(generator, "_invoke", {
41
+ value: makeInvokeMethod(innerFn, self, context)
42
+ }), generator;
43
+ }
44
+ function tryCatch(fn, obj, arg) {
45
+ try {
46
+ return {
47
+ type: "normal",
48
+ arg: fn.call(obj, arg)
49
+ };
50
+ } catch (err) {
51
+ return {
52
+ type: "throw",
53
+ arg: err
54
+ };
55
+ }
56
+ }
57
+ exports.wrap = wrap;
58
+ var ContinueSentinel = {};
59
+ function Generator() {}
60
+ function GeneratorFunction() {}
61
+ function GeneratorFunctionPrototype() {}
62
+ var IteratorPrototype = {};
63
+ define(IteratorPrototype, iteratorSymbol, function () {
64
+ return this;
65
+ });
66
+ var getProto = Object.getPrototypeOf,
67
+ NativeIteratorPrototype = getProto && getProto(getProto(values([])));
68
+ NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
69
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
70
+ function defineIteratorMethods(prototype) {
71
+ ["next", "throw", "return"].forEach(function (method) {
72
+ define(prototype, method, function (arg) {
73
+ return this._invoke(method, arg);
74
+ });
75
+ });
76
+ }
77
+ function AsyncIterator(generator, PromiseImpl) {
78
+ function invoke(method, arg, resolve, reject) {
79
+ var record = tryCatch(generator[method], generator, arg);
80
+ if ("throw" !== record.type) {
81
+ var result = record.arg,
82
+ value = result.value;
83
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
84
+ invoke("next", value, resolve, reject);
85
+ }, function (err) {
86
+ invoke("throw", err, resolve, reject);
87
+ }) : PromiseImpl.resolve(value).then(function (unwrapped) {
88
+ result.value = unwrapped, resolve(result);
89
+ }, function (error) {
90
+ return invoke("throw", error, resolve, reject);
91
+ });
92
+ }
93
+ reject(record.arg);
94
+ }
95
+ var previousPromise;
96
+ defineProperty(this, "_invoke", {
97
+ value: function (method, arg) {
98
+ function callInvokeWithMethodAndArg() {
99
+ return new PromiseImpl(function (resolve, reject) {
100
+ invoke(method, arg, resolve, reject);
101
+ });
102
+ }
103
+ return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
104
+ }
105
+ });
106
+ }
107
+ function makeInvokeMethod(innerFn, self, context) {
108
+ var state = "suspendedStart";
109
+ return function (method, arg) {
110
+ if ("executing" === state) throw new Error("Generator is already running");
111
+ if ("completed" === state) {
112
+ if ("throw" === method) throw arg;
113
+ return doneResult();
114
+ }
115
+ for (context.method = method, context.arg = arg;;) {
116
+ var delegate = context.delegate;
117
+ if (delegate) {
118
+ var delegateResult = maybeInvokeDelegate(delegate, context);
119
+ if (delegateResult) {
120
+ if (delegateResult === ContinueSentinel) continue;
121
+ return delegateResult;
122
+ }
123
+ }
124
+ if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
125
+ if ("suspendedStart" === state) throw state = "completed", context.arg;
126
+ context.dispatchException(context.arg);
127
+ } else "return" === context.method && context.abrupt("return", context.arg);
128
+ state = "executing";
129
+ var record = tryCatch(innerFn, self, context);
130
+ if ("normal" === record.type) {
131
+ if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
132
+ return {
133
+ value: record.arg,
134
+ done: context.done
135
+ };
136
+ }
137
+ "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
138
+ }
139
+ };
140
+ }
141
+ function maybeInvokeDelegate(delegate, context) {
142
+ var methodName = context.method,
143
+ method = delegate.iterator[methodName];
144
+ if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
145
+ var record = tryCatch(method, delegate.iterator, context.arg);
146
+ if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
147
+ var info = record.arg;
148
+ return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
149
+ }
150
+ function pushTryEntry(locs) {
151
+ var entry = {
152
+ tryLoc: locs[0]
153
+ };
154
+ 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
155
+ }
156
+ function resetTryEntry(entry) {
157
+ var record = entry.completion || {};
158
+ record.type = "normal", delete record.arg, entry.completion = record;
159
+ }
160
+ function Context(tryLocsList) {
161
+ this.tryEntries = [{
162
+ tryLoc: "root"
163
+ }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
164
+ }
165
+ function values(iterable) {
166
+ if (iterable) {
167
+ var iteratorMethod = iterable[iteratorSymbol];
168
+ if (iteratorMethod) return iteratorMethod.call(iterable);
169
+ if ("function" == typeof iterable.next) return iterable;
170
+ if (!isNaN(iterable.length)) {
171
+ var i = -1,
172
+ next = function next() {
173
+ for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
174
+ return next.value = undefined, next.done = !0, next;
175
+ };
176
+ return next.next = next;
177
+ }
178
+ }
179
+ return {
180
+ next: doneResult
181
+ };
182
+ }
183
+ function doneResult() {
184
+ return {
185
+ value: undefined,
186
+ done: !0
187
+ };
188
+ }
189
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
190
+ value: GeneratorFunctionPrototype,
191
+ configurable: !0
192
+ }), defineProperty(GeneratorFunctionPrototype, "constructor", {
193
+ value: GeneratorFunction,
194
+ configurable: !0
195
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
196
+ var ctor = "function" == typeof genFun && genFun.constructor;
197
+ return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
198
+ }, exports.mark = function (genFun) {
199
+ return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
200
+ }, exports.awrap = function (arg) {
201
+ return {
202
+ __await: arg
203
+ };
204
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
205
+ return this;
206
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
207
+ void 0 === PromiseImpl && (PromiseImpl = Promise);
208
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
209
+ return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
210
+ return result.done ? result.value : iter.next();
211
+ });
212
+ }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
213
+ return this;
214
+ }), define(Gp, "toString", function () {
215
+ return "[object Generator]";
216
+ }), exports.keys = function (val) {
217
+ var object = Object(val),
218
+ keys = [];
219
+ for (var key in object) keys.push(key);
220
+ return keys.reverse(), function next() {
221
+ for (; keys.length;) {
222
+ var key = keys.pop();
223
+ if (key in object) return next.value = key, next.done = !1, next;
224
+ }
225
+ return next.done = !0, next;
226
+ };
227
+ }, exports.values = values, Context.prototype = {
228
+ constructor: Context,
229
+ reset: function (skipTempReset) {
230
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
231
+ },
232
+ stop: function () {
233
+ this.done = !0;
234
+ var rootRecord = this.tryEntries[0].completion;
235
+ if ("throw" === rootRecord.type) throw rootRecord.arg;
236
+ return this.rval;
237
+ },
238
+ dispatchException: function (exception) {
239
+ if (this.done) throw exception;
240
+ var context = this;
241
+ function handle(loc, caught) {
242
+ return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
243
+ }
244
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
245
+ var entry = this.tryEntries[i],
246
+ record = entry.completion;
247
+ if ("root" === entry.tryLoc) return handle("end");
248
+ if (entry.tryLoc <= this.prev) {
249
+ var hasCatch = hasOwn.call(entry, "catchLoc"),
250
+ hasFinally = hasOwn.call(entry, "finallyLoc");
251
+ if (hasCatch && hasFinally) {
252
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
253
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
254
+ } else if (hasCatch) {
255
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
256
+ } else {
257
+ if (!hasFinally) throw new Error("try statement without catch or finally");
258
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
259
+ }
260
+ }
261
+ }
262
+ },
263
+ abrupt: function (type, arg) {
264
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
265
+ var entry = this.tryEntries[i];
266
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
267
+ var finallyEntry = entry;
268
+ break;
269
+ }
270
+ }
271
+ finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
272
+ var record = finallyEntry ? finallyEntry.completion : {};
273
+ return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
274
+ },
275
+ complete: function (record, afterLoc) {
276
+ if ("throw" === record.type) throw record.arg;
277
+ return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
278
+ },
279
+ finish: function (finallyLoc) {
280
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
281
+ var entry = this.tryEntries[i];
282
+ if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
283
+ }
284
+ },
285
+ catch: function (tryLoc) {
286
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
287
+ var entry = this.tryEntries[i];
288
+ if (entry.tryLoc === tryLoc) {
289
+ var record = entry.completion;
290
+ if ("throw" === record.type) {
291
+ var thrown = record.arg;
292
+ resetTryEntry(entry);
293
+ }
294
+ return thrown;
295
+ }
296
+ }
297
+ throw new Error("illegal catch attempt");
298
+ },
299
+ delegateYield: function (iterable, resultName, nextLoc) {
300
+ return this.delegate = {
301
+ iterator: values(iterable),
302
+ resultName: resultName,
303
+ nextLoc: nextLoc
304
+ }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
305
+ }
306
+ }, exports;
307
+ }
308
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
309
+ try {
310
+ var info = gen[key](arg);
311
+ var value = info.value;
312
+ } catch (error) {
313
+ reject(error);
314
+ return;
315
+ }
316
+ if (info.done) {
317
+ resolve(value);
318
+ } else {
319
+ Promise.resolve(value).then(_next, _throw);
320
+ }
321
+ }
322
+ function _asyncToGenerator(fn) {
323
+ return function () {
324
+ var self = this,
325
+ args = arguments;
326
+ return new Promise(function (resolve, reject) {
327
+ var gen = fn.apply(self, args);
328
+ function _next(value) {
329
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
330
+ }
331
+ function _throw(err) {
332
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
333
+ }
334
+ _next(undefined);
335
+ });
336
+ };
337
+ }
338
+ function _extends() {
339
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
340
+ for (var i = 1; i < arguments.length; i++) {
341
+ var source = arguments[i];
342
+ for (var key in source) {
343
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
344
+ target[key] = source[key];
345
+ }
346
+ }
347
+ }
348
+ return target;
349
+ };
350
+ return _extends.apply(this, arguments);
351
+ }
352
+
353
+ var I1pDataInputTypes;
354
+ (function (I1pDataInputTypes) {
355
+ I1pDataInputTypes["DROPDOWN"] = "dropdown";
356
+ })(I1pDataInputTypes || (I1pDataInputTypes = {}));
357
+ var I1pIngestDataTypes;
358
+ (function (I1pIngestDataTypes) {
359
+ I1pIngestDataTypes["JOB_LEVEL"] = "profile_job_level";
360
+ I1pIngestDataTypes["JOB_INDUSTRY"] = "profile_job_industry";
361
+ I1pIngestDataTypes["NY_PERSONAL_GOALS"] = "new_year_personal_goals";
362
+ I1pIngestDataTypes["NY_HOBBIES"] = "new_year_hobbies";
363
+ I1pIngestDataTypes["NY_PROFESSIONAL_GOALS"] = "new_year_professional_goals";
364
+ I1pIngestDataTypes["NY_INDUSTRY"] = "new_year_industry";
365
+ I1pIngestDataTypes["NY_NEWS_LOCATION"] = "new_year_news_location";
366
+ })(I1pIngestDataTypes || (I1pIngestDataTypes = {}));
367
+ var I1pDataIngestTypes;
368
+ (function (I1pDataIngestTypes) {
369
+ I1pDataIngestTypes["EXPLICIT"] = "explicit";
370
+ I1pDataIngestTypes["IMPLICIT"] = "implicit";
371
+ })(I1pDataIngestTypes || (I1pDataIngestTypes = {}));
372
+ var IngestResponseState;
373
+ (function (IngestResponseState) {
374
+ IngestResponseState["SUCCESS"] = "100";
375
+ IngestResponseState["SYSTEM_ERROR"] = "101";
376
+ IngestResponseState["INVALID_TYPE"] = "102";
377
+ IngestResponseState["INVALID_IDENTIFIER"] = "103";
378
+ IngestResponseState["INVALID_DATA"] = "104";
379
+ IngestResponseState["INVALID_ATTRIBUTE_DEFINITION"] = "105";
380
+ IngestResponseState["INVALID_META_DEFINITION"] = "106";
381
+ })(IngestResponseState || (IngestResponseState = {}));
382
+
383
+ var StyledMobileSelect = /*#__PURE__*/styled('select', {
384
+ padding: '12px 16px 12px 6px',
385
+ display: 'flex',
386
+ justifyContent: 'space-between',
387
+ width: '100%',
388
+ backgroundColor: '$secondary',
389
+ color: '$primary',
390
+ fontFamily: '$meta',
391
+ fontSize: '$100',
392
+ fontWeight: '$light',
393
+ lineHeight: '$125',
394
+ paddingBlockRight: '$125',
395
+ textOverflow: 'ellipsis',
396
+ position: 'relative',
397
+ borderColor: 'transparent',
398
+ borderRightWidth: '10px',
399
+ borderRightColor: 'transparent',
400
+ appearance: 'none',
401
+ '-webkit-appearance': 'none',
402
+ '&:disabled': {
403
+ backgroundColor: theme.colors.disabled,
404
+ borderColor: theme.colors.disabled,
405
+ color: theme.colors.onDisabled,
406
+ cursor: 'not-allowed'
407
+ }
408
+ });
409
+ var StyledSelectWrapper = /*#__PURE__*/styled('div', {
410
+ width: '100%',
411
+ maxWidth: '380px',
412
+ borderRadius: '$012',
413
+ borderColor: '$subtle',
414
+ borderStyle: 'solid',
415
+ borderWidth: '1px',
416
+ backgroundColor: '$secondary',
417
+ position: 'relative'
418
+ });
419
+ var StyledMobileOption = /*#__PURE__*/styled('option', {
420
+ fontFamily: 'inherit',
421
+ fontSize: 'inherit',
422
+ color: 'inherit'
423
+ });
424
+ var Dropdown = function Dropdown(_ref) {
425
+ var id = _ref.id,
426
+ label = _ref.label,
427
+ values = _ref.values,
428
+ _ref$required = _ref.required,
429
+ required = _ref$required === void 0 ? false : _ref$required,
430
+ defaultValue = _ref.defaultValue,
431
+ _ref$onChange = _ref.onChange,
432
+ onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
433
+ _ref$disabled = _ref.disabled,
434
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled;
435
+ var _useState = useState(),
436
+ answer = _useState[0],
437
+ setAnswer = _useState[1];
438
+ var _useWindowSize = useWindowSize(),
439
+ isMobileSize = _useWindowSize.isMobileSize;
440
+ useEffect(function () {
441
+ if (answer) onChange(answer);
442
+ }, [answer]);
443
+ var defaultValueProp = defaultValue ? {
444
+ defaultValue: defaultValue
445
+ } : {};
446
+ var disabledProp = disabled ? {
447
+ disabled: true
448
+ } : {};
449
+ var defaultValuePropMobile = function defaultValuePropMobile(value) {
450
+ return value === defaultValue ? {
451
+ selected: true
452
+ } : {};
453
+ };
454
+ return isMobileSize ? React.createElement(StyledSelectWrapper, null, React.createElement(StyledMobileSelect, _extends({
455
+ id: "",
456
+ required: required,
457
+ onChange: function onChange(e) {
458
+ return setAnswer(e.target.value);
459
+ },
460
+ placeholder: label
461
+ }, disabledProp), React.createElement("label", null, label), React.createElement(StyledMobileOption, {
462
+ value: "",
463
+ disabled: true,
464
+ selected: true,
465
+ style: {
466
+ color: '#666666'
467
+ }
468
+ }, label), values.map(function (value) {
469
+ return React.createElement(StyledMobileOption, _extends({
470
+ value: value,
471
+ key: value
472
+ }, defaultValuePropMobile(value)), value);
473
+ })), React.createElement(Icon, {
474
+ label: "",
475
+ size: "100",
476
+ fill: theme.colors['gray80'],
477
+ style: {
478
+ pointerEvents: 'none',
479
+ position: 'absolute',
480
+ right: '10px',
481
+ top: '50%',
482
+ transform: 'translateY(-50%)'
483
+ }
484
+ }, React.createElement(ChevronDown, {
485
+ style: {
486
+ position: 'absolute',
487
+ right: '10px'
488
+ }
489
+ }))) : React.createElement(Select.Root, _extends({
490
+ onValueChange: function onValueChange(e) {
491
+ return setAnswer(e);
492
+ },
493
+ required: required
494
+ }, defaultValueProp, disabledProp), React.createElement(Select.Trigger, {
495
+ "data-test-id": id + "-dropdown-label"
496
+ }, React.createElement(Select.Label, null, label), React.createElement(Select.Value, null)), React.createElement(Select.Content, {
497
+ css: {
498
+ zIndex: 8
499
+ },
500
+ "data-test-id": id + "-dropdown-input"
501
+ }, values.map(function (value) {
502
+ return React.createElement(Select.Item, {
503
+ value: value,
504
+ key: value
505
+ }, value);
506
+ })));
507
+ };
508
+
509
+ var hasRequiredPrivacyCookies = function hasRequiredPrivacyCookies() {
510
+ var _WPGeo;
511
+ if (typeof window === 'undefined') {
512
+ return false;
513
+ }
514
+ var wp_usp = getCookie('wp_usp');
515
+ var countryCode = (_WPGeo = WPGeo()) == null ? void 0 : _WPGeo.country_code;
516
+ return !!(wp_usp && countryCode === 'US');
517
+ };
518
+
519
+ var base = ENDPOINTS.base + "/de/v1";
520
+ var JSONHeaders = {
521
+ Accept: 'application/json',
522
+ 'Content-Type': 'application/json'
523
+ };
524
+ var ingest = /*#__PURE__*/function () {
525
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(submitData, metadata) {
526
+ var url, wapo_login_id, jucid, ga, payload, response, json;
527
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
528
+ while (1) switch (_context.prev = _context.next) {
529
+ case 0:
530
+ url = base + "/ingest";
531
+ wapo_login_id = getCookie('wapo_login_id');
532
+ if (hasRequiredPrivacyCookies()) {
533
+ _context.next = 4;
534
+ break;
535
+ }
536
+ throw new Error('does not satisfy cookie check');
537
+ case 4:
538
+ jucid = localStorage.getItem('uuid');
539
+ ga = getCookie('_ga');
540
+ payload = {
541
+ jucid: jucid,
542
+ ga: ga,
543
+ type: I1pDataIngestTypes.EXPLICIT,
544
+ wapo_login_id: wapo_login_id,
545
+ data: submitData,
546
+ metadata: metadata
547
+ };
548
+ _context.prev = 7;
549
+ _context.next = 10;
550
+ return fetch(url, {
551
+ method: 'POST',
552
+ credentials: 'include',
553
+ headers: JSONHeaders,
554
+ body: JSON.stringify(payload)
555
+ });
556
+ case 10:
557
+ response = _context.sent;
558
+ _context.next = 13;
559
+ return response.json();
560
+ case 13:
561
+ json = _context.sent;
562
+ return _context.abrupt("return", json);
563
+ case 17:
564
+ _context.prev = 17;
565
+ _context.t0 = _context["catch"](7);
566
+ console.debug(_context.t0);
567
+ return _context.abrupt("return", null);
568
+ case 21:
569
+ case "end":
570
+ return _context.stop();
571
+ }
572
+ }, _callee, null, [[7, 17]]);
573
+ }));
574
+ return function ingest(_x, _x2) {
575
+ return _ref.apply(this, arguments);
576
+ };
577
+ }();
578
+
579
+ var sendGAEvent = function sendGAEvent(props) {
580
+ if (typeof window === 'undefined') {
581
+ if (process.env.NODE_ENV !== "production") console.warn('NO WINDOW');
582
+ return;
583
+ }
584
+ // Initialize dataLayer if needed
585
+ window.dataLayer = window.dataLayer || [];
586
+ var eventData = _extends({}, props);
587
+ window.dataLayer.push(eventData);
588
+ };
589
+ var sendToGA = /*#__PURE__*/function () {
590
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(submitData, metadata) {
591
+ var keysToSubmit;
592
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
593
+ while (1) switch (_context.prev = _context.next) {
594
+ case 0:
595
+ if (hasRequiredPrivacyCookies()) {
596
+ _context.next = 2;
597
+ break;
598
+ }
599
+ throw new Error('does not satisfy cookie check');
600
+ case 2:
601
+ keysToSubmit = Object.keys(submitData);
602
+ keysToSubmit.forEach(function (key) {
603
+ if (Object.values(I1pIngestDataTypes).includes(key)) {
604
+ var _sendGAEvent;
605
+ sendGAEvent((_sendGAEvent = {
606
+ event: 'site-onpage-click',
607
+ action: 'site-onpage-click',
608
+ category: 'profile',
609
+ label: key,
610
+ 'de-label': key
611
+ }, _sendGAEvent[key] = submitData[key], _sendGAEvent.section = 'profile', _sendGAEvent.subsection = metadata.source, _sendGAEvent));
612
+ }
613
+ });
614
+ return _context.abrupt("return", true);
615
+ case 5:
616
+ case "end":
617
+ return _context.stop();
618
+ }
619
+ }, _callee);
620
+ }));
621
+ return function sendToGA(_x, _x2) {
622
+ return _ref.apply(this, arguments);
623
+ };
624
+ }();
625
+
626
+ var getDefaultSubmitData = function getDefaultSubmitData(formOptions) {
627
+ var defaultSubmitData = {};
628
+ formOptions.forEach(function (formOption) {
629
+ if (formOption.default_value) {
630
+ if (formOption.input_type === I1pDataInputTypes.DROPDOWN && formOption.values) {
631
+ var values = formOption.values.filter(function (value) {
632
+ return value.archived !== true;
633
+ }).map(function (value) {
634
+ return value.name;
635
+ });
636
+ if (values.includes(formOption.default_value)) {
637
+ defaultSubmitData[formOption.id] = [formOption.default_value];
638
+ }
639
+ } else {
640
+ defaultSubmitData[formOption.id] = [formOption.default_value];
641
+ }
642
+ }
643
+ });
644
+ return defaultSubmitData;
645
+ };
646
+
647
+ var DataEnrichmentForm = function DataEnrichmentForm(_ref) {
648
+ var submit = _ref.submit,
649
+ source = _ref.source,
650
+ ingestType = _ref.ingestType,
651
+ _ref$formOptions = _ref.formOptions,
652
+ formOptions = _ref$formOptions === void 0 ? [] : _ref$formOptions,
653
+ _ref$onChange = _ref.onChange,
654
+ onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
655
+ _ref$onFinished = _ref.onFinished,
656
+ onFinished = _ref$onFinished === void 0 ? function () {} : _ref$onFinished,
657
+ _ref$handleSubmit = _ref.handleSubmit,
658
+ handleSubmit = _ref$handleSubmit === void 0 ? function () {} : _ref$handleSubmit,
659
+ _ref$disabled = _ref.disabled,
660
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled;
661
+ var _useState = useState(false),
662
+ render = _useState[0],
663
+ setRender = _useState[1];
664
+ var _useState2 = useState(getDefaultSubmitData(formOptions)),
665
+ submitData = _useState2[0],
666
+ setSubmitData = _useState2[1];
667
+ var _useState3 = useState(true),
668
+ missingRequiredFields = _useState3[0],
669
+ setMissingRequiredFields = _useState3[1];
670
+ useEffect(function () {
671
+ if (hasRequiredPrivacyCookies()) {
672
+ setRender(true);
673
+ } else {
674
+ console.error('does not satisfy cookie check');
675
+ onFinished(true, true);
676
+ }
677
+ }, []);
678
+ useEffect(function () {
679
+ // check for required fields that haven't been completed yet
680
+ var missingRequiredFields = formOptions.filter(function (option) {
681
+ if (option.required && option.input_type === I1pDataInputTypes.DROPDOWN && !submitData[option.id]) {
682
+ return true;
683
+ }
684
+ return false;
685
+ });
686
+ setMissingRequiredFields(missingRequiredFields.length > 0);
687
+ onChange(submitData, missingRequiredFields.length === 0);
688
+ }, [JSON.stringify(submitData)]);
689
+ useEffect(function () {
690
+ _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
691
+ var result, isError, _result;
692
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
693
+ while (1) switch (_context.prev = _context.next) {
694
+ case 0:
695
+ if (!submit) {
696
+ _context.next = 17;
697
+ break;
698
+ }
699
+ if (!(Object.keys(submitData).length >= 1)) {
700
+ _context.next = 16;
701
+ break;
702
+ }
703
+ if (!(ingestType === I1pDataIngestTypes.EXPLICIT)) {
704
+ _context.next = 10;
705
+ break;
706
+ }
707
+ _context.next = 5;
708
+ return ingest(submitData, {
709
+ source: source
710
+ });
711
+ case 5:
712
+ result = _context.sent;
713
+ isError = result && result.status !== ResponseStatus.SUCCESS;
714
+ onFinished(true, isError);
715
+ _context.next = 14;
716
+ break;
717
+ case 10:
718
+ _context.next = 12;
719
+ return sendToGA(submitData, {
720
+ source: source
721
+ });
722
+ case 12:
723
+ _result = _context.sent;
724
+ onFinished(true, _result);
725
+ case 14:
726
+ _context.next = 17;
727
+ break;
728
+ case 16:
729
+ onFinished(true, false);
730
+ case 17:
731
+ case "end":
732
+ return _context.stop();
733
+ }
734
+ }, _callee);
735
+ }))();
736
+ }, [submit]);
737
+ if (!render) return React.createElement(React.Fragment, null);
738
+ return React.createElement("form", {
739
+ method: "post",
740
+ onSubmit: function onSubmit(e) {
741
+ e.preventDefault();
742
+ handleSubmit(e);
743
+ }
744
+ }, formOptions.map(function (formOption) {
745
+ if (formOption.input_type === I1pDataInputTypes.DROPDOWN && formOption.values) {
746
+ // sort and filter out archived values
747
+ var values = formOption.values.sort(function (a, b) {
748
+ return a.order - b.order;
749
+ }).filter(function (value) {
750
+ return value.archived !== true;
751
+ });
752
+ return React.createElement(OptionWrapper, {
753
+ "data-private": true,
754
+ key: formOption.id
755
+ }, React.createElement(Dropdown, {
756
+ id: formOption.id,
757
+ label: formOption.input_label,
758
+ values: values.map(function (value) {
759
+ return value.name;
760
+ }),
761
+ required: formOption.required,
762
+ defaultValue: formOption.default_value,
763
+ onChange: function onChange(value) {
764
+ var _extends2;
765
+ setSubmitData(_extends({}, submitData, (_extends2 = {}, _extends2[formOption.id] = [value], _extends2)));
766
+ },
767
+ disabled: disabled
768
+ }));
769
+ }
770
+ return null;
771
+ }), React.createElement("input", {
772
+ type: "submit",
773
+ hidden: true,
774
+ disabled: missingRequiredFields || disabled,
775
+ "data-qa": "1p-data-inputs-submit"
776
+ }));
777
+ };
778
+ var OptionWrapper = /*#__PURE__*/styled('div', {
779
+ boxSizing: 'border-box',
780
+ display: 'flex',
781
+ marginBottom: '$100',
782
+ flexDirection: 'column',
783
+ '& button': {
784
+ padding: '1px 6px'
785
+ },
786
+ '& *': {
787
+ boxSizing: 'border-box'
788
+ }
789
+ });
790
+
791
+ export { DataEnrichmentForm, I1pDataIngestTypes, I1pDataInputTypes, I1pIngestDataTypes, IngestResponseState, hasRequiredPrivacyCookies, ingest, sendToGA };
792
+ //# sourceMappingURL=subs-de-inputs.esm.js.map