@reachfive/identity-ui 1.21.0 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7327,12 +7327,6 @@ function isValued(v) {
7327
7327
  var unwrap = isObject(v) ? v[rawProperty] : v;
7328
7328
  return unwrap !== null && unwrap !== undefined && unwrap !== '' && !Number.isNaN(unwrap) && (Array.isArray(unwrap) ? unwrap.length > 0 : true);
7329
7329
  }
7330
- function formatISO8601Date(year, month, day) {
7331
- if (isValued(year) && isValued(month) && isValued(day)) {
7332
- return "".concat(year, "-").concat(month.toString().padStart(2, '0'), "-").concat(day.toString().padStart(2, '0'));
7333
- }
7334
- return null;
7335
- }
7336
7330
  function specializeIdentifierData(data) {
7337
7331
  return data.identifier ? _objectSpread2(_objectSpread2(_objectSpread2({}, data), {}, {
7338
7332
  identifier: undefined
@@ -8408,6 +8402,9 @@ var Check = withTheme(styled__default(function (_ref4) {
8408
8402
  checked: checked,
8409
8403
  name: name,
8410
8404
  onChange: onSelect,
8405
+ style: radio && {
8406
+ appearance: "radio"
8407
+ },
8411
8408
  required: required,
8412
8409
  value: value
8413
8410
  }), label);
@@ -9624,275 +9621,248 @@ function selectField(_ref) {
9624
9621
  }));
9625
9622
  }
9626
9623
 
9627
- var formatDate = function formatDate(formValue) {
9628
- if (formValue && formValue.length) {
9629
- var _formValue$split = formValue.split('/'),
9630
- _formValue$split2 = _slicedToArray(_formValue$split, 3),
9631
- month = _formValue$split2[0],
9632
- day = _formValue$split2[1],
9633
- year = _formValue$split2[2];
9634
- if (year && year.length && month && month.length && day && day.length) {
9635
- return formatISO8601Date(year, month, day);
9636
- }
9637
- }
9638
- return null;
9624
+ var useDebounce = function useDebounce(value, milliSeconds) {
9625
+ var _useState = React.useState(value),
9626
+ _useState2 = _slicedToArray(_useState, 2),
9627
+ debouncedValue = _useState2[0],
9628
+ setDebouncedValue = _useState2[1];
9629
+ React.useEffect(function () {
9630
+ var handler = setTimeout(function () {
9631
+ setDebouncedValue(value);
9632
+ }, milliSeconds);
9633
+ return function () {
9634
+ clearTimeout(handler);
9635
+ };
9636
+ }, [value, milliSeconds]);
9637
+ return debouncedValue;
9639
9638
  };
9640
- function dateField(config) {
9641
- return simpleField(_objectSpread2(_objectSpread2({
9642
- placeholder: 'mm/dd/yyyy'
9643
- }, config), {}, {
9644
- type: 'text',
9645
- format: {
9646
- bind: function bind(modelValue) {
9647
- if (modelValue && modelValue.length) {
9648
- var _modelValue$split = modelValue.split('-'),
9649
- _modelValue$split2 = _slicedToArray(_modelValue$split, 3),
9650
- _modelValue$split2$ = _modelValue$split2[0],
9651
- year = _modelValue$split2$ === void 0 ? '' : _modelValue$split2$,
9652
- _modelValue$split2$2 = _modelValue$split2[1],
9653
- month = _modelValue$split2$2 === void 0 ? '' : _modelValue$split2$2,
9654
- _modelValue$split2$3 = _modelValue$split2[2],
9655
- day = _modelValue$split2$3 === void 0 ? '' : _modelValue$split2$3;
9656
- return "".concat(month, "/").concat(day, "/").concat(year);
9657
- }
9658
- },
9659
- unbind: formatDate
9660
- },
9661
- validator: new Validator({
9662
- rule: function rule(value) {
9663
- var date = formatDate(value);
9664
- return !date || validator.isISO8601(date);
9665
- },
9666
- hint: 'date'
9667
- })
9668
- }));
9669
- }
9670
9639
 
9671
- var _excluded$6 = ["state"];
9672
9640
  var _templateObject$a, _templateObject2$5;
9673
- var BIRTHDAY_PATH = 'birthdate';
9674
- var months = function months(i18n) {
9675
- return ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].map(function (m, i) {
9676
- return {
9677
- value: i + 1,
9678
- label: i18n(m)
9679
- };
9680
- });
9681
- };
9682
9641
  var inputRowGutter = 10;
9683
- var InputRow = styled__default.div(_templateObject$a || (_templateObject$a = _taggedTemplateLiteral(["\n margin-right: ", "px;\n margin-left: ", "px;\n ", "\n"])), -inputRowGutter / 2, -inputRowGutter / 2, polished.clearFix());
9684
- var InputCol = styled__default.div(_templateObject2$5 || (_templateObject2$5 = _taggedTemplateLiteral(["\n float: left;\n padding-right: ", "px;\n padding-left: ", "px;\n width: ", "%;\n box-sizing: border-box;\n"])), inputRowGutter / 2, inputRowGutter / 2, function (props) {
9642
+ var InputRow = styled__default.div(_templateObject$a || (_templateObject$a = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: row;\n justify-content: space-between;\n gap: ", "px;\n"])), inputRowGutter);
9643
+ var InputCol = styled__default.div(_templateObject2$5 || (_templateObject2$5 = _taggedTemplateLiteral(["\n flex-basis: ", "%;\n"])), function (props) {
9685
9644
  return props.width;
9686
9645
  });
9687
- var BirthdateField = function BirthdateField(props) {
9688
- var day = props.day,
9689
- month = props.month,
9690
- year = props.year,
9691
- _props$validation = props.validation,
9692
- validation = _props$validation === void 0 ? {} : _props$validation,
9693
- onChange = props.onChange,
9694
- showLabel = props.showLabel,
9695
- inputId = props.inputId,
9696
- label = props.label,
9697
- _props$required = props.required,
9698
- required = _props$required === void 0 ? true : _props$required,
9699
- months = props.months,
9700
- i18n = props.i18n;
9701
- var handleFieldChange = function handleFieldChange(field) {
9702
- return function (e) {
9703
- var value = e.target.value;
9704
- onChange(function (state) {
9705
- return _defineProperty({}, field, _objectSpread2(_objectSpread2({}, state[field]), {}, {
9706
- value: value
9707
- }));
9708
- });
9709
- };
9646
+ var DateField = function DateField(_ref) {
9647
+ var i18n = _ref.i18n,
9648
+ inputId = _ref.inputId,
9649
+ label = _ref.label,
9650
+ locale = _ref.locale,
9651
+ onChange = _ref.onChange,
9652
+ path = _ref.path,
9653
+ required = _ref.required,
9654
+ showLabel = _ref.showLabel,
9655
+ validation = _ref.validation,
9656
+ value = _ref.value;
9657
+ var _useState = React.useState(isValued(value) ? value.raw.day : undefined),
9658
+ _useState2 = _slicedToArray(_useState, 2),
9659
+ day = _useState2[0],
9660
+ setDay = _useState2[1];
9661
+ var _useState3 = React.useState(isValued(value) ? value.raw.month : undefined),
9662
+ _useState4 = _slicedToArray(_useState3, 2),
9663
+ month = _useState4[0],
9664
+ setMonth = _useState4[1];
9665
+ var _useState5 = React.useState(isValued(value) ? value.raw.year : undefined),
9666
+ _useState6 = _slicedToArray(_useState5, 2),
9667
+ year = _useState6[0],
9668
+ setYear = _useState6[1];
9669
+
9670
+ // debounce year value to delay value update when user is currently editing it
9671
+ var debouncedYear = useDebounce(year, 1000);
9672
+ var setDatePart = function setDatePart(setter, value) {
9673
+ if (Number.isNaN(Number(value))) return; // only accept number value
9674
+ setter(Number(value));
9710
9675
  };
9711
- var handleFieldBlur = function handleFieldBlur(field) {
9712
- return function () {
9713
- return onChange(function (state) {
9714
- return _defineProperty({}, field, _objectSpread2(_objectSpread2({}, state[field]), {}, {
9676
+ var handleDayChange = function handleDayChange(event) {
9677
+ return setDatePart(setDay, event.target.value);
9678
+ };
9679
+ var handleMonthChange = function handleMonthChange(event) {
9680
+ return setDatePart(setMonth, event.target.value);
9681
+ };
9682
+ var handleYearChange = function handleYearChange(event) {
9683
+ return setDatePart(setYear, event.target.value);
9684
+ };
9685
+ React.useEffect(function () {
9686
+ if (day && month && debouncedYear) {
9687
+ onChange(function () {
9688
+ return {
9689
+ value: {
9690
+ raw: luxon.DateTime.fromObject({
9691
+ year: debouncedYear,
9692
+ month: month,
9693
+ day: day
9694
+ })
9695
+ },
9715
9696
  isDirty: true
9716
- }));
9697
+ };
9717
9698
  });
9718
- };
9699
+ }
9700
+ }, [debouncedYear, month, day]); // eslint-disable-line react-hooks/exhaustive-deps
9701
+
9702
+ var months = React.useMemo(function () {
9703
+ return luxon.Info.months("long", {
9704
+ locale: locale
9705
+ });
9706
+ }, [locale]);
9707
+ var daysInMonth = React.useMemo(function () {
9708
+ return Array.from({
9709
+ length: luxon.DateTime.fromObject({
9710
+ year: debouncedYear,
9711
+ month: month
9712
+ }).daysInMonth
9713
+ }, function (_value, index) {
9714
+ return index + 1;
9715
+ });
9716
+ }, [debouncedYear, month]);
9717
+
9718
+ // reset day if current value is out of range
9719
+ if (day && !daysInMonth.includes(day)) {
9720
+ setDay(undefined);
9721
+ }
9722
+ var parts = React.useMemo(function () {
9723
+ return luxon.DateTime.now().setLocale(locale).toLocaleParts().map(function (part) {
9724
+ return part.type;
9725
+ }).filter(function (type) {
9726
+ return type !== 'literal';
9727
+ });
9728
+ }, [locale]);
9729
+ var error = _typeof(validation) === 'object' && 'error' in validation ? validation.error : null;
9730
+ var fields = {
9731
+ day: /*#__PURE__*/React__default.createElement(InputCol, {
9732
+ key: "day",
9733
+ width: 20
9734
+ }, /*#__PURE__*/React__default.createElement(Select, {
9735
+ name: "".concat(path, ".day"),
9736
+ value: day || '',
9737
+ hasError: error,
9738
+ required: required,
9739
+ onChange: handleDayChange,
9740
+ placeholder: i18n('day'),
9741
+ options: daysInMonth.map(function (day) {
9742
+ return {
9743
+ value: day,
9744
+ label: day
9745
+ };
9746
+ }),
9747
+ "data-testid": "".concat(path, ".day"),
9748
+ "aria-label": i18n('day')
9749
+ })),
9750
+ month: /*#__PURE__*/React__default.createElement(InputCol, {
9751
+ key: "month",
9752
+ width: 50
9753
+ }, /*#__PURE__*/React__default.createElement(Select, {
9754
+ name: "".concat(path, ".month"),
9755
+ value: month || '',
9756
+ hasError: error,
9757
+ required: required,
9758
+ onChange: handleMonthChange,
9759
+ placeholder: i18n('month'),
9760
+ options: months.map(function (month, index) {
9761
+ return {
9762
+ value: index + 1,
9763
+ label: month
9764
+ };
9765
+ }),
9766
+ "data-testid": "".concat(path, ".month"),
9767
+ "aria-label": i18n('month')
9768
+ })),
9769
+ year: /*#__PURE__*/React__default.createElement(InputCol, {
9770
+ key: "year",
9771
+ width: 30
9772
+ }, /*#__PURE__*/React__default.createElement(Input, {
9773
+ type: "number",
9774
+ maxlength: "4",
9775
+ inputmode: "numeric",
9776
+ name: "".concat(path, ".year"),
9777
+ value: year || '',
9778
+ hasError: error,
9779
+ required: required,
9780
+ onChange: handleYearChange,
9781
+ placeholder: i18n('year'),
9782
+ "data-testid": "".concat(path, ".year"),
9783
+ "aria-label": i18n('year')
9784
+ }))
9719
9785
  };
9720
- return /*#__PURE__*/React__default.createElement(FormGroup, _extends({
9786
+ return /*#__PURE__*/React__default.createElement(FormGroup, {
9721
9787
  inputId: inputId,
9722
- labelText: label
9723
- }, pick(validation, 'error'), {
9788
+ labelText: label,
9789
+ error: error,
9724
9790
  showLabel: showLabel
9725
- }), /*#__PURE__*/React__default.createElement(InputRow, null, /*#__PURE__*/React__default.createElement(InputCol, {
9726
- width: 20
9727
- }, /*#__PURE__*/React__default.createElement(Input, {
9728
- type: "text",
9729
- id: inputId,
9730
- name: "".concat(BIRTHDAY_PATH, ".day"),
9731
- maxlength: "2",
9732
- inputmode: "numeric",
9733
- value: day.value,
9734
- hasError: !!validation.day,
9735
- required: required,
9736
- placeholder: i18n('day'),
9737
- onChange: handleFieldChange('day'),
9738
- onBlur: handleFieldBlur('day'),
9739
- "data-testid": "".concat(BIRTHDAY_PATH, ".day")
9740
- })), /*#__PURE__*/React__default.createElement(InputCol, {
9741
- width: 50
9742
- }, /*#__PURE__*/React__default.createElement(Select, {
9743
- name: "".concat(BIRTHDAY_PATH, ".month"),
9744
- value: month.value || '',
9745
- hasError: !!validation.month,
9746
- required: required,
9747
- onChange: handleFieldChange('month'),
9748
- onBlur: handleFieldBlur('month'),
9749
- placeholder: i18n('month'),
9750
- options: months,
9751
- "data-testid": "".concat(BIRTHDAY_PATH, ".month")
9752
- })), /*#__PURE__*/React__default.createElement(InputCol, {
9753
- width: 30
9754
- }, /*#__PURE__*/React__default.createElement(Input, {
9755
- type: "text",
9756
- name: "".concat(BIRTHDAY_PATH, ".year"),
9757
- maxlength: "4",
9758
- inputmode: "numeric",
9759
- value: year.value,
9760
- hasError: !!validation.year,
9761
- required: required,
9762
- placeholder: i18n('year'),
9763
- onChange: handleFieldChange('year'),
9764
- onBlur: handleFieldBlur('year'),
9765
- "data-testid": "".concat(BIRTHDAY_PATH, ".year")
9766
- }))));
9791
+ }, /*#__PURE__*/React__default.createElement(InputRow, null, parts.map(function (part) {
9792
+ return fields[part];
9793
+ })));
9767
9794
  };
9768
- var validateLimitAge = function validateLimitAge(day, month, year) {
9769
- var yearNbr = parseInt(year, 10);
9770
- var dayNbr = parseInt(day, 10);
9771
- var monthNbr = parseInt(month, 10);
9772
- var age = luxon.DateTime.now().diff(luxon.DateTime.local(yearNbr, monthNbr, dayNbr), "years").years;
9773
- if (age < 6 || age > 129) {
9774
- return 'birthdate.yearLimit';
9775
- }
9776
- return false;
9795
+ var dateFormat = function dateFormat(locale) {
9796
+ return luxon.DateTime.now().setLocale(locale).toLocaleParts().map(function (part) {
9797
+ switch (part.type) {
9798
+ case 'day':
9799
+ return 'dd';
9800
+ case 'month':
9801
+ return 'mm';
9802
+ case 'year':
9803
+ return 'yyyy';
9804
+ case 'literal':
9805
+ return part.value;
9806
+ }
9807
+ }).join('');
9777
9808
  };
9778
- var format = function format(_ref3) {
9779
- var day = _ref3.day,
9780
- month = _ref3.month,
9781
- year = _ref3.year;
9782
- return formatISO8601Date(year.value, month.value, day.value);
9809
+ var datetimeValidator = function datetimeValidator(locale) {
9810
+ return new Validator({
9811
+ rule: function rule(value) {
9812
+ return isValued(value) && value.raw.isValid;
9813
+ },
9814
+ hint: 'date',
9815
+ parameters: {
9816
+ format: dateFormat(locale)
9817
+ }
9818
+ });
9783
9819
  };
9784
- function birthdateField(_ref4) {
9785
- var label = _ref4.label,
9786
- _ref4$required = _ref4.required,
9787
- required = _ref4$required === void 0 ? true : _ref4$required,
9788
- defaultValue = _ref4.defaultValue;
9789
- return {
9790
- path: BIRTHDAY_PATH,
9791
- create: function create(_ref5) {
9792
- var i18n = _ref5.i18n,
9793
- showLabel = _ref5.showLabel;
9794
- var staticProps = {
9795
- inputId: generateId(),
9796
- label: label || i18n(BIRTHDAY_PATH),
9797
- months: months(i18n),
9798
- required: required,
9799
- i18n: i18n,
9800
- showLabel: showLabel
9801
- };
9802
- return {
9803
- key: BIRTHDAY_PATH,
9804
- modelPath: BIRTHDAY_PATH,
9805
- render: function render(_ref6) {
9806
- var state = _ref6.state,
9807
- props = _objectWithoutProperties(_ref6, _excluded$6);
9808
- return /*#__PURE__*/React__default.createElement(BirthdateField, _extends({
9809
- key: BIRTHDAY_PATH
9810
- }, state, props, staticProps));
9811
- },
9812
- initialize: function initialize(model) {
9813
- var modelValue = model.birthdate || defaultValue;
9814
- var _ref7 = modelValue ? modelValue.split('-') : [],
9815
- _ref8 = _slicedToArray(_ref7, 3),
9816
- _ref8$ = _ref8[0],
9817
- year = _ref8$ === void 0 ? '' : _ref8$,
9818
- _ref8$2 = _ref8[1],
9819
- month = _ref8$2 === void 0 ? '' : _ref8$2,
9820
- _ref8$3 = _ref8[2],
9821
- day = _ref8$3 === void 0 ? '' : _ref8$3;
9822
- return {
9823
- day: {
9824
- value: day,
9825
- isDirty: false
9826
- },
9827
- month: {
9828
- value: parseInt(month),
9829
- isDirty: false
9830
- },
9831
- year: {
9832
- value: year,
9833
- isDirty: false
9834
- }
9835
- };
9836
- },
9837
- unbind: function unbind(model, state) {
9838
- return _objectSpread2(_objectSpread2({}, model), {}, {
9839
- birthdate: format(state)
9840
- });
9841
- },
9842
- validate: function validate(state, _ref9) {
9843
- var isSubmitted = _ref9.isSubmitted;
9844
- var required = staticProps.required;
9845
- var day = state.day,
9846
- month = state.month,
9847
- year = state.year;
9848
- var missingFields = ['day', 'month', 'year'].filter(function (field) {
9849
- return (isSubmitted || state[field].isDirty) && !isValued(state[field].value);
9850
- });
9851
- if (missingFields.length) {
9852
- return required || missingFields.length < 3 ? _objectSpread2({
9853
- error: i18n('validation.required')
9854
- }, missingFields.reduce(function (acc, field) {
9855
- return _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, field, true));
9856
- }, {})) : {};
9857
- }
9858
- if (isSubmitted || day.isDirty || month.isDirty || year.isDirty) {
9859
- if (!validator.isNumeric(year.value.toString()) || !luxon.DateTime.fromObject({
9860
- year: parseInt(year.value, 10)
9861
- }).isValid) {
9862
- return {
9863
- error: i18n("validation.birthdate.year"),
9864
- year: true
9865
- };
9866
- }
9867
- var birthdate = format(state);
9868
- if (!birthdate || !validator.isISO8601(birthdate)) {
9869
- return {
9870
- error: i18n('validation.birthdate.dayOfMonth'),
9871
- day: true
9872
- };
9873
- }
9874
- if (!(validator.isNumeric(month.value.toString()) && validator.isNumeric(day.value.toString())) || !luxon.DateTime.fromObject({
9875
- year: year.value,
9876
- month: month.value,
9877
- day: day.value
9878
- }).isValid) {
9879
- return {
9880
- error: i18n("validation.birthdate.dayOfMonth"),
9881
- day: true
9882
- };
9883
- }
9884
- var limitAge = validateLimitAge(day.value, month.value, year.value);
9885
- if (limitAge) {
9886
- return {
9887
- error: i18n("validation.".concat(limitAge))
9888
- };
9889
- }
9890
- }
9891
- return {};
9892
- }
9893
- };
9820
+ function dateField(props, config) {
9821
+ return createField(_objectSpread2(_objectSpread2({}, props), {}, {
9822
+ format: {
9823
+ bind: function bind(value) {
9824
+ var dt = value ? luxon.DateTime.fromISO(value) : luxon.DateTime.invalid('empty value');
9825
+ return dt.isValid ? {
9826
+ raw: dt
9827
+ } : undefined;
9828
+ },
9829
+ unbind: function unbind(value) {
9830
+ return value.raw.toISODate();
9831
+ }
9832
+ },
9833
+ validator: props.validator ? datetimeValidator(config.language).and(props.validator) : datetimeValidator(config.language),
9834
+ component: DateField,
9835
+ extendedParams: {
9836
+ locale: config.language
9894
9837
  }
9895
- };
9838
+ }));
9839
+ }
9840
+
9841
+ var _excluded$6 = ["min", "max", "label"];
9842
+ var ageLimitValidator = function ageLimitValidator() {
9843
+ var min = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 6;
9844
+ var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 129;
9845
+ return new Validator({
9846
+ rule: function rule(value) {
9847
+ var age = luxon.DateTime.now().diff(value.raw, 'years').years;
9848
+ return min < age && age < max;
9849
+ },
9850
+ hint: 'birthdate.yearLimit',
9851
+ parameters: {
9852
+ min: min,
9853
+ max: max
9854
+ }
9855
+ });
9856
+ };
9857
+ function birthdateField(_ref, config) {
9858
+ var min = _ref.min,
9859
+ max = _ref.max,
9860
+ label = _ref.label,
9861
+ props = _objectWithoutProperties(_ref, _excluded$6);
9862
+ return dateField(_objectSpread2(_objectSpread2({}, props), {}, {
9863
+ label: label || 'birthdate',
9864
+ validator: ageLimitValidator(min, max)
9865
+ }), config);
9896
9866
  }
9897
9867
 
9898
9868
  var PhoneNumberField = /*#__PURE__*/function (_React$Component) {
@@ -10513,7 +10483,7 @@ var predefinedFields = {
10513
10483
  }, cfg));
10514
10484
  }
10515
10485
  };
10516
- function customFieldComponent(customField, cfg) {
10486
+ function customFieldComponent(customField, cfg, config) {
10517
10487
  var baseConfig = _objectSpread2(_objectSpread2({
10518
10488
  label: customField.name
10519
10489
  }, cfg), {}, {
@@ -10525,7 +10495,7 @@ function customFieldComponent(customField, cfg) {
10525
10495
  }) : _objectSpread2({}, baseConfig);
10526
10496
  return checkboxField(checkboxConfig);
10527
10497
  } else if (customField.dataType === 'date') {
10528
- return dateField(baseConfig);
10498
+ return dateField(baseConfig, config);
10529
10499
  } else if (customField.dataType === 'integer') {
10530
10500
  return simpleField(_objectSpread2(_objectSpread2({}, baseConfig), {}, {
10531
10501
  type: 'number',
@@ -10620,7 +10590,7 @@ var resolveField = function resolveField(fieldConfig, config) {
10620
10590
  }
10621
10591
  var customField = findCustomField(config, camelPath);
10622
10592
  if (customField) {
10623
- return customFieldComponent(customField, fieldConfig);
10593
+ return customFieldComponent(customField, fieldConfig, config);
10624
10594
  }
10625
10595
  var camelPathSplit = camelPath.split('.v'); // TODO What if consent start with a `v`?
10626
10596
  var consentField = findConsentField(config, camelPathSplit[0]);
@@ -11149,66 +11119,89 @@ var StartPasswordlessForm = createForm({
11149
11119
  })];
11150
11120
  }
11151
11121
  });
11152
- var MfaStepUpView = /*#__PURE__*/function (_React$Component) {
11153
- _inherits(MfaStepUpView, _React$Component);
11154
- var _super = _createSuper(MfaStepUpView);
11155
- function MfaStepUpView() {
11122
+ var MainView = /*#__PURE__*/function (_React$Component) {
11123
+ _inherits(MainView, _React$Component);
11124
+ var _super = _createSuper(MainView);
11125
+ function MainView(props) {
11156
11126
  var _this;
11157
- _classCallCheck(this, MfaStepUpView);
11158
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
11159
- args[_key] = arguments[_key];
11160
- }
11161
- _this = _super.call.apply(_super, [this].concat(args));
11127
+ _classCallCheck(this, MainView);
11128
+ _this = _super.call(this, props);
11162
11129
  _defineProperty(_assertThisInitialized(_this), "onGetStepUpToken", function () {
11163
11130
  return _this.props.apiClient.getMfaStepUpToken({
11164
11131
  options: _this.props.auth,
11165
11132
  accessToken: _this.props.accessToken
11133
+ }).then(function (res) {
11134
+ return _this.setState({
11135
+ response: res
11136
+ });
11166
11137
  });
11167
11138
  });
11139
+ _this.state = {
11140
+ response: undefined
11141
+ };
11168
11142
  return _this;
11169
11143
  }
11170
- _createClass(MfaStepUpView, [{
11144
+ _createClass(MainView, [{
11145
+ key: "componentDidMount",
11146
+ value: function componentDidMount() {
11147
+ this.onGetStepUpToken();
11148
+ }
11149
+ }, {
11171
11150
  key: "render",
11172
11151
  value: function render() {
11173
11152
  var _this2 = this;
11174
- return /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(StartStepUpMfaButton, {
11153
+ var _this$props = this.props,
11154
+ showStepUpStart = _this$props.showStepUpStart,
11155
+ goTo = _this$props.goTo;
11156
+ return this.state.response === undefined ? null : /*#__PURE__*/React__default.createElement("div", null, showStepUpStart ? /*#__PURE__*/React__default.createElement(StartStepUpMfaButton, {
11175
11157
  handler: this.onGetStepUpToken,
11176
- onSuccess: function onSuccess(data) {
11177
- return _this2.props.goTo('fa-selection', _objectSpread2({}, data));
11158
+ onSuccess: function onSuccess(_) {
11159
+ return goTo('fa-selection', _this2.state.response);
11178
11160
  }
11179
- }));
11161
+ }) : /*#__PURE__*/React__default.createElement(FaSelectionView, _extends({}, this.state.response, this.props)));
11180
11162
  }
11181
11163
  }]);
11182
- return MfaStepUpView;
11164
+ return MainView;
11183
11165
  }(React__default.Component);
11184
11166
  var FaSelectionView = /*#__PURE__*/function (_React$Component2) {
11185
11167
  _inherits(FaSelectionView, _React$Component2);
11186
11168
  var _super2 = _createSuper(FaSelectionView);
11187
- function FaSelectionView() {
11169
+ function FaSelectionView(props) {
11188
11170
  var _this3;
11189
11171
  _classCallCheck(this, FaSelectionView);
11190
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
11191
- args[_key2] = arguments[_key2];
11192
- }
11193
- _this3 = _super2.call.apply(_super2, [this].concat(args));
11172
+ _this3 = _super2.call(this, props);
11194
11173
  _defineProperty(_assertThisInitialized(_this3), "onChooseFa", function (factor) {
11195
11174
  return _this3.props.apiClient.startPasswordless(_objectSpread2(_objectSpread2({}, factor), {}, {
11196
11175
  stepUp: _this3.props.token
11197
- })).then(function (resp) {
11198
- return _objectSpread2(_objectSpread2({}, resp), factor);
11176
+ })).then(function (res) {
11177
+ return _this3.setState({
11178
+ response: _objectSpread2(_objectSpread2({}, res), factor)
11179
+ });
11199
11180
  });
11200
11181
  });
11182
+ _this3.state = {
11183
+ response: undefined
11184
+ };
11201
11185
  return _this3;
11202
11186
  }
11203
11187
  _createClass(FaSelectionView, [{
11188
+ key: "componentDidMount",
11189
+ value: function componentDidMount() {
11190
+ if (this.props.amr.length == 1) this.onChooseFa({
11191
+ authType: this.props.amr[0]
11192
+ });else this.setState({
11193
+ response: {}
11194
+ });
11195
+ }
11196
+ }, {
11204
11197
  key: "render",
11205
11198
  value: function render() {
11206
11199
  var _this4 = this;
11207
- var _this$props = this.props,
11208
- amr = _this$props.amr,
11209
- showIntro = _this$props.showIntro,
11210
- i18n = _this$props.i18n;
11211
- return /*#__PURE__*/React__default.createElement("div", null, showIntro && /*#__PURE__*/React__default.createElement(Intro, null, i18n('mfa.select.factor')), /*#__PURE__*/React__default.createElement(StartPasswordlessForm, {
11200
+ var _this$props2 = this.props,
11201
+ amr = _this$props2.amr,
11202
+ showIntro = _this$props2.showIntro,
11203
+ i18n = _this$props2.i18n;
11204
+ return this.state.response === undefined ? null : amr.length == 1 ? /*#__PURE__*/React__default.createElement(VerificationCodeView, _extends({}, this.state.response, this.props)) : /*#__PURE__*/React__default.createElement("div", null, showIntro && /*#__PURE__*/React__default.createElement(Intro, null, i18n('mfa.select.factor')), /*#__PURE__*/React__default.createElement(StartPasswordlessForm, {
11212
11205
  options: amr.map(function (factor) {
11213
11206
  return {
11214
11207
  key: factor,
@@ -11220,7 +11213,7 @@ var FaSelectionView = /*#__PURE__*/function (_React$Component2) {
11220
11213
  onSuccess: function onSuccess(data) {
11221
11214
  return _this4.props.goTo('verification-code', _objectSpread2(_objectSpread2({}, data), {}, {
11222
11215
  amr: amr
11223
- }));
11216
+ }, _this4.state.response));
11224
11217
  }
11225
11218
  }));
11226
11219
  }
@@ -11233,20 +11226,18 @@ var VerificationCodeView = /*#__PURE__*/function (_React$Component3) {
11233
11226
  function VerificationCodeView() {
11234
11227
  var _this5;
11235
11228
  _classCallCheck(this, VerificationCodeView);
11236
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
11237
- args[_key3] = arguments[_key3];
11229
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
11230
+ args[_key] = arguments[_key];
11238
11231
  }
11239
11232
  _this5 = _super3.call.apply(_super3, [this].concat(args));
11240
11233
  _defineProperty(_assertThisInitialized(_this5), "handleSubmit", function (data) {
11241
11234
  var _this5$props = _this5.props,
11242
11235
  apiClient = _this5$props.apiClient,
11243
11236
  auth = _this5$props.auth,
11244
- challengeId = _this5$props.challengeId,
11245
- accessToken = _this5$props.accessToken;
11237
+ challengeId = _this5$props.challengeId;
11246
11238
  return apiClient.verifyMfaPasswordless({
11247
11239
  challengeId: challengeId,
11248
- verificationCode: data.verificationCode,
11249
- accessToken: accessToken
11240
+ verificationCode: data.verificationCode
11250
11241
  }).then(function (resp) {
11251
11242
  return window.location.replace(auth.redirectUri + "?" + toQueryString(resp));
11252
11243
  });
@@ -11264,15 +11255,16 @@ var VerificationCodeView = /*#__PURE__*/function (_React$Component3) {
11264
11255
  return VerificationCodeView;
11265
11256
  }(React__default.Component);
11266
11257
  var mfaStepUpWidget = createMultiViewWidget({
11267
- initialView: 'mfa-step-up',
11258
+ initialView: 'main',
11268
11259
  views: {
11269
- 'mfa-step-up': MfaStepUpView,
11260
+ 'main': MainView,
11270
11261
  'fa-selection': FaSelectionView,
11271
11262
  'verification-code': VerificationCodeView
11272
11263
  },
11273
11264
  prepare: function prepare(options) {
11274
11265
  return deepDefaults({}, options, {
11275
- showIntro: true
11266
+ showIntro: true,
11267
+ showStepUpStart: true
11276
11268
  });
11277
11269
  }
11278
11270
  });
@@ -11336,7 +11328,7 @@ var EmailEditorForm = createForm({
11336
11328
  validator: email
11337
11329
  })]
11338
11330
  });
11339
- var MainView = /*#__PURE__*/function (_React$Component) {
11331
+ var MainView$1 = /*#__PURE__*/function (_React$Component) {
11340
11332
  _inherits(MainView, _React$Component);
11341
11333
  var _super = _createSuper(MainView);
11342
11334
  function MainView() {
@@ -11388,7 +11380,7 @@ var SuccessView = function SuccessView(_ref) {
11388
11380
  var emailEditorWidget = createMultiViewWidget({
11389
11381
  initialView: 'main',
11390
11382
  views: {
11391
- main: MainView,
11383
+ main: MainView$1,
11392
11384
  success: SuccessView
11393
11385
  }
11394
11386
  });
@@ -11525,7 +11517,7 @@ var VerificationCodeInputForm$1 = createForm({
11525
11517
  type: 'text'
11526
11518
  })]
11527
11519
  });
11528
- var MainView$1 = /*#__PURE__*/function (_React$Component) {
11520
+ var MainView$2 = /*#__PURE__*/function (_React$Component) {
11529
11521
  _inherits(MainView, _React$Component);
11530
11522
  var _super = _createSuper(MainView);
11531
11523
  function MainView() {
@@ -11607,12 +11599,12 @@ _defineProperty(VerificationCodeView$1, "defaultProps", {
11607
11599
  var phoneNumberEditorWidget = createMultiViewWidget({
11608
11600
  initialView: 'main',
11609
11601
  views: {
11610
- main: MainView$1,
11602
+ main: MainView$2,
11611
11603
  verificationCode: VerificationCodeView$1
11612
11604
  }
11613
11605
  });
11614
11606
 
11615
- var MainView$2 = /*#__PURE__*/function (_React$Component) {
11607
+ var MainView$3 = /*#__PURE__*/function (_React$Component) {
11616
11608
  _inherits(MainView, _React$Component);
11617
11609
  var _super = _createSuper(MainView);
11618
11610
  function MainView() {
@@ -11646,7 +11638,7 @@ var MainView$2 = /*#__PURE__*/function (_React$Component) {
11646
11638
  }]);
11647
11639
  return MainView;
11648
11640
  }(React__default.Component);
11649
- _defineProperty(MainView$2, "defaultProps", {
11641
+ _defineProperty(MainView$3, "defaultProps", {
11650
11642
  onSuccess: function onSuccess() {},
11651
11643
  onError: function onError() {}
11652
11644
  });
@@ -11666,7 +11658,7 @@ var resolveCode = function resolveCode() {
11666
11658
  var passwordResetWidget = createMultiViewWidget({
11667
11659
  initialView: 'main',
11668
11660
  views: {
11669
- main: MainView$2,
11661
+ main: MainView$3,
11670
11662
  success: SuccessView$1
11671
11663
  },
11672
11664
  prepare: function prepare(options) {
@@ -11699,7 +11691,7 @@ var VerificationCodeInputForm$2 = createForm({
11699
11691
  type: 'text'
11700
11692
  })]
11701
11693
  });
11702
- var MainView$3 = /*#__PURE__*/function (_React$Component) {
11694
+ var MainView$4 = /*#__PURE__*/function (_React$Component) {
11703
11695
  _inherits(MainView, _React$Component);
11704
11696
  var _super = _createSuper(MainView);
11705
11697
  function MainView() {
@@ -11797,7 +11789,7 @@ var EmailSentView = function EmailSentView(_ref) {
11797
11789
  var passwordlessWidget = createMultiViewWidget({
11798
11790
  initialView: 'main',
11799
11791
  views: {
11800
- main: MainView$3,
11792
+ main: MainView$4,
11801
11793
  emailSent: EmailSentView,
11802
11794
  verificationCode: VerificationCodeView$2
11803
11795
  },
@@ -12332,7 +12324,7 @@ var PhoneNumberRegisteringCredentialForm = function PhoneNumberRegisteringCreden
12332
12324
  var DivCredentialBlock = withTheme(styled__default.div(_templateObject$h || (_templateObject$h = _taggedTemplateLiteral(["\n margin-left: ", "px;\n margin-bottom: 5em;\n"])), function (props) {
12333
12325
  return props.theme.get('_blockInnerHeight');
12334
12326
  }));
12335
- var MainView$4 = /*#__PURE__*/function (_React$Component) {
12327
+ var MainView$5 = /*#__PURE__*/function (_React$Component) {
12336
12328
  _inherits(MainView, _React$Component);
12337
12329
  var _super = _createSuper(MainView);
12338
12330
  function MainView() {
@@ -12374,7 +12366,8 @@ var MainView$4 = /*#__PURE__*/function (_React$Component) {
12374
12366
  showIntro = _this$props.showIntro,
12375
12367
  config = _this$props.config,
12376
12368
  showRemoveMfaCredentials = _this$props.showRemoveMfaCredentials,
12377
- credentials = _this$props.credentials;
12369
+ credentials = _this$props.credentials,
12370
+ requireMfaRegistration = _this$props.requireMfaRegistration;
12378
12371
  var PhoneNumberInputForm = PhoneNumberRegisteringCredentialForm(config);
12379
12372
  var phoneNumberCredentialRegistered = credentials.find(function (credential) {
12380
12373
  return credential.type === 'sms';
@@ -12382,7 +12375,9 @@ var MainView$4 = /*#__PURE__*/function (_React$Component) {
12382
12375
  var isEmailCredentialRegistered = credentials.some(function (credential) {
12383
12376
  return credential.type === 'email';
12384
12377
  });
12385
- return /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(DivCredentialBlock, null, config.mfaEmailEnabled && /*#__PURE__*/React__default.createElement("div", null, showIntro && /*#__PURE__*/React__default.createElement(Intro, null, i18n('mfa.email.explain')), /*#__PURE__*/React__default.createElement(EmailRegisteringCredentialForm, {
12378
+ return /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(DivCredentialBlock, null, config.mfaEmailEnabled && !credentials.map(function (credential) {
12379
+ return credential.type;
12380
+ }).includes('email') && /*#__PURE__*/React__default.createElement("div", null, showIntro && /*#__PURE__*/React__default.createElement(Intro, null, requireMfaRegistration ? i18n('mfa.email.explain.required') : i18n('mfa.email.explain')), /*#__PURE__*/React__default.createElement(EmailRegisteringCredentialForm, {
12386
12381
  handler: this.onEmailRegistering,
12387
12382
  onSuccess: function onSuccess(data) {
12388
12383
  return _this2.props.goTo('verification-code', _objectSpread2(_objectSpread2({}, data), {}, {
@@ -12483,7 +12478,7 @@ var CredentialRemovedView = function CredentialRemovedView(_ref2) {
12483
12478
  var mfaCredentialsWidget = createMultiViewWidget({
12484
12479
  initialView: 'main',
12485
12480
  views: {
12486
- 'main': MainView$4,
12481
+ 'main': MainView$5,
12487
12482
  'credential-registered': CredentialRegisteredView,
12488
12483
  'verification-code': VerificationCodeView$3,
12489
12484
  'credential-removed': CredentialRemovedView
@@ -12495,6 +12490,7 @@ var mfaCredentialsWidget = createMultiViewWidget({
12495
12490
  }).then(function (credentials) {
12496
12491
  return deepDefaults(_objectSpread2(_objectSpread2({
12497
12492
  showIntro: true,
12493
+ requireMfaRegistration: false,
12498
12494
  showRemoveMfaCredentials: true
12499
12495
  }, options), credentials));
12500
12496
  });
@@ -12549,7 +12545,7 @@ var Credential = withTheme(styled__default(Card)(_templateObject3$6 || (_templat
12549
12545
  var CardContent = withTheme(styled__default.div(_templateObject4$4 || (_templateObject4$4 = _taggedTemplateLiteral(["\n margin-left: ", "px;\n white-space: initial;\n"])), function (props) {
12550
12546
  return props.theme.get('_blockInnerHeight');
12551
12547
  }));
12552
- var dateFormat = function dateFormat(dateString, locales) {
12548
+ var dateFormat$1 = function dateFormat(dateString, locales) {
12553
12549
  return new Date(dateString).toLocaleDateString(locales, {
12554
12550
  timeZone: 'UTC'
12555
12551
  });
@@ -12572,7 +12568,7 @@ var MfaList = compose(withI18n, withConfig)(function (_ref) {
12572
12568
  }
12573
12569
  }, friendlyName), /*#__PURE__*/React__default.createElement("div", null, email || phoneNumber), /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("span", null, i18n('mfaList.createdAt'), "\xA0: "), /*#__PURE__*/React__default.createElement("time", {
12574
12570
  dateTime: createdAt
12575
- }, dateFormat(createdAt, config.language)))));
12571
+ }, dateFormat$1(createdAt, config.language)))));
12576
12572
  }));
12577
12573
  });
12578
12574
  var mfaListWidget = createWidget({