@arquimedes.co/eureka-forms 2.0.53 → 2.0.55

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.
Files changed (59) hide show
  1. package/dist/@Types/Condition.d.ts +54 -2
  2. package/dist/@Types/Draft/Draft.d.ts +12 -0
  3. package/dist/@Types/Draft/Draft.js +1 -0
  4. package/dist/@Types/Draft/DraftEntityData.d.ts +50 -0
  5. package/dist/@Types/Draft/DraftEntityData.js +1 -0
  6. package/dist/@Types/Entity.d.ts +33 -0
  7. package/dist/@Types/Entity.js +1 -0
  8. package/dist/@Types/Form.d.ts +7 -0
  9. package/dist/@Types/FormStep.d.ts +7 -0
  10. package/dist/App/App.css +14 -0
  11. package/dist/App/AppFunctions.d.ts +2 -2
  12. package/dist/App/AppFunctions.js +167 -156
  13. package/dist/App/AppHooks.js +12 -8
  14. package/dist/Contexts/FormContext.d.ts +2 -0
  15. package/dist/Contexts/FormContext.js +49 -0
  16. package/dist/Form/ConfirmationDialog/ConfirmationDialog.js +30 -5
  17. package/dist/Form/ConfirmationDialog/ConfirmationDialog.module.css +2 -0
  18. package/dist/Form/Form.js +1 -1
  19. package/dist/Form/FormFunctions.js +15 -12
  20. package/dist/Form/FormTypes/StepperForm/StepperForm.js +10 -7
  21. package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValueDialog/MaterialEntityValueDialog.d.ts +12 -0
  22. package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValueDialog/MaterialEntityValueDialog.js +49 -0
  23. package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValueDialog/MaterialEntityValueDialog.module.css +60 -0
  24. package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValuePickerStep.js +103 -49
  25. package/dist/FormSteps/MapperStep/MaterialMapperStep/Element/MapperElementComponent.d.ts +3 -0
  26. package/dist/FormSteps/MapperStep/MaterialMapperStep/Element/MapperElementComponent.js +3 -0
  27. package/dist/FormSteps/MapperStep/MaterialMapperStep/Element/PagedMapperElement/PagedMapperElement.d.ts +5 -0
  28. package/dist/FormSteps/MapperStep/MaterialMapperStep/Element/PagedMapperElement/PagedMapperElement.js +204 -0
  29. package/dist/FormSteps/MapperStep/MaterialMapperStep/Element/PagedMapperElement/PagedMapperElement.module.css +75 -0
  30. package/dist/FormSteps/MapperStep/MaterialMapperStep/MaterialMapperStep.d.ts +6 -2
  31. package/dist/FormSteps/MapperStep/MaterialMapperStep/MaterialMapperStep.js +44 -14
  32. package/dist/FormSteps/StepFunctions.d.ts +11 -1
  33. package/dist/FormSteps/StepFunctions.js +146 -1
  34. package/dist/FormSteps/StepHooks.js +12 -4
  35. package/dist/FormSteps/TextAreaStep/MaterialTextAreaStep/MaterialTextAreaEditorStep.js +0 -2
  36. package/dist/Shared/CustomBtn/CustomBtn.d.ts +7 -2
  37. package/dist/Shared/CustomBtn/CustomBtn.js +14 -5
  38. package/dist/Shared/CustomBtn/CustomBtn.module.css +0 -2
  39. package/dist/States/GlobalSlice.d.ts +9 -0
  40. package/dist/States/GlobalSlice.js +5 -0
  41. package/dist/States/SiteSlice.d.ts +32 -3
  42. package/dist/States/SiteSlice.js +50 -5
  43. package/dist/Utils/DraftFunctions.d.ts +21 -0
  44. package/dist/Utils/DraftFunctions.js +239 -0
  45. package/dist/constants/ConditionTypes.d.ts +6 -1
  46. package/dist/constants/ConditionTypes.js +5 -0
  47. package/dist/constants/Draft/DraftEntityDataTypes.d.ts +10 -0
  48. package/dist/constants/Draft/DraftEntityDataTypes.js +12 -0
  49. package/dist/constants/Draft/DraftEntityTypes.d.ts +3 -0
  50. package/dist/constants/Draft/DraftEntityTypes.js +4 -0
  51. package/dist/constants/Draft/DraftStyleTypes.d.ts +7 -0
  52. package/dist/constants/Draft/DraftStyleTypes.js +8 -0
  53. package/dist/constants/EntityPropertyTypes.d.ts +9 -0
  54. package/dist/constants/EntityPropertyTypes.js +10 -0
  55. package/dist/constants/FormStepTypes.d.ts +1 -0
  56. package/dist/constants/FormStepTypes.js +1 -0
  57. package/dist/constants/TicketPropertyTypes.d.ts +3 -0
  58. package/dist/constants/TicketPropertyTypes.js +4 -0
  59. package/package.json +2 -2
@@ -67,6 +67,7 @@ import InternalFormStyle from '../constants/InternalFormStyle';
67
67
  import { calcDependencies } from '../Form/FormFunctions';
68
68
  import { iterateNestedSteps } from '../FormSteps/StepFunctions';
69
69
  import { createNextState } from '@reduxjs/toolkit';
70
+ import { BaseConfirmationMessage } from '../Contexts/FormContext';
70
71
  export var useSetupApp = function (isEmbedded, _a) {
71
72
  var preview = _a.preview, internal = _a.internal, postview = _a.postview, partial = _a.partial, editable = _a.editable, handleConfirmed = _a.handleConfirmed, customSteps = _a.customSteps, valuesData = _a.valuesData, apiKey = _a.apiKey, formData = _a.formData, classifiers = _a.classifiers, others = __rest(_a, ["preview", "internal", "postview", "partial", "editable", "handleConfirmed", "customSteps", "valuesData", "apiKey", "formData", "classifiers"]);
72
73
  var _b = useState(undefined), form = _b[0], setForm = _b[1];
@@ -114,9 +115,9 @@ export var useSetupApp = function (isEmbedded, _a) {
114
115
  var loadData = function () { return __awaiter(void 0, void 0, void 0, function () {
115
116
  var idOrganization, organization, form, match, dependencies, values;
116
117
  var _a;
117
- var _b;
118
- return __generator(this, function (_c) {
119
- switch (_c.label) {
118
+ var _b, _c, _d;
119
+ return __generator(this, function (_e) {
120
+ switch (_e.label) {
120
121
  case 0:
121
122
  idOrganization = others.idOrganization;
122
123
  organization = null;
@@ -124,7 +125,7 @@ export var useSetupApp = function (isEmbedded, _a) {
124
125
  if (!(form && preview && form.isStandAlone)) return [3 /*break*/, 2];
125
126
  return [4 /*yield*/, loadOrg()];
126
127
  case 1:
127
- organization = _c.sent();
128
+ organization = _e.sent();
128
129
  return [3 /*break*/, 4];
129
130
  case 2:
130
131
  if (!(!form && apiKey)) return [3 /*break*/, 4];
@@ -134,8 +135,8 @@ export var useSetupApp = function (isEmbedded, _a) {
134
135
  ])];
135
136
  case 3:
136
137
  //Is iframe or widget
137
- _a = _c.sent(), organization = _a[0], form = _a[1];
138
- _c.label = 4;
138
+ _a = _e.sent(), organization = _a[0], form = _a[1];
139
+ _e.label = 4;
139
140
  case 4:
140
141
  if (organization && !idOrganization)
141
142
  idOrganization = organization.idOrganization;
@@ -179,10 +180,13 @@ export var useSetupApp = function (isEmbedded, _a) {
179
180
  dependencies = {};
180
181
  return [4 /*yield*/, calcValuesStore(idOrganization, form, valuesData, postview, customSteps)];
181
182
  case 5:
182
- values = _c.sent();
183
+ values = _e.sent();
183
184
  dispatch(reset(__assign(__assign({ formStyle: internal
184
185
  ? InternalFormStyle
185
- : __assign(__assign({}, InternalFormStyle), ((_b = form === null || form === void 0 ? void 0 : form.style) !== null && _b !== void 0 ? _b : {})), internal: !!internal, idOrganization: idOrganization, preview: !!preview, partial: !!partial, postview: !!postview, editable: !!(editable !== null && editable !== void 0 ? editable : true), values: values }, calcInitialSections(form)), { dependencies: calcDependencies(form.steps, customSteps, form.steps, dependencies, values) })));
186
+ : __assign(__assign({}, InternalFormStyle), ((_b = form === null || form === void 0 ? void 0 : form.style) !== null && _b !== void 0 ? _b : {})), confirmation: {
187
+ confirmationMessage: (_c = form.confirmationMessage) !== null && _c !== void 0 ? _c : BaseConfirmationMessage,
188
+ showLink: (_d = form.showLink) !== null && _d !== void 0 ? _d : false,
189
+ }, internal: !!internal, idOrganization: idOrganization, preview: !!preview, partial: !!partial, postview: !!postview, editable: !!(editable !== null && editable !== void 0 ? editable : true), values: values }, calcInitialSections(form)), { dependencies: calcDependencies(form.steps, customSteps, form.steps, dependencies, values) })));
186
190
  return [2 /*return*/];
187
191
  }
188
192
  });
@@ -1,4 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { Form } from '../@Types';
3
+ import { EurekaDraft } from '../@Types/Draft/Draft';
4
+ export declare const BaseConfirmationMessage: EurekaDraft;
3
5
  declare const FormContext: import("react").Context<Form>;
4
6
  export default FormContext;
@@ -1,4 +1,51 @@
1
1
  import { createContext } from 'react';
2
+ import { DraftEntityTypes } from '../constants/Draft/DraftEntityTypes';
3
+ import { DraftEntityDataTypes } from '../constants/Draft/DraftEntityDataTypes';
4
+ import { TicketPropertyTypes } from '../constants/TicketPropertyTypes';
5
+ export var BaseConfirmationMessage = {
6
+ blocks: [
7
+ {
8
+ depth: 0,
9
+ data: {},
10
+ inlineStyleRanges: [
11
+ {
12
+ offset: 15,
13
+ length: 6,
14
+ style: 'BOLD',
15
+ },
16
+ ],
17
+ text: 'Tu caso número ABC123 ha sido registrado!',
18
+ type: 'unstyled',
19
+ key: '5l788',
20
+ entityRanges: [
21
+ {
22
+ offset: 15,
23
+ length: 6,
24
+ key: 0,
25
+ },
26
+ ],
27
+ },
28
+ {
29
+ depth: 0,
30
+ data: {},
31
+ inlineStyleRanges: [],
32
+ text: 'Pronto te estaremos dando respuesta.',
33
+ type: 'unstyled',
34
+ key: 'aco4l',
35
+ entityRanges: [],
36
+ },
37
+ ],
38
+ entityMap: {
39
+ '0': {
40
+ type: DraftEntityTypes.EUREKA,
41
+ data: {
42
+ type: DraftEntityDataTypes.TICKET,
43
+ property: TicketPropertyTypes.CASENUMBER,
44
+ },
45
+ mutability: 'IMMUTABLE',
46
+ },
47
+ },
48
+ };
2
49
  var FormContext = createContext({
3
50
  firstSection: 'FIRST',
4
51
  sections: {
@@ -10,6 +57,8 @@ var FormContext = createContext({
10
57
  },
11
58
  },
12
59
  steps: {},
60
+ confirmationMessage: BaseConfirmationMessage,
61
+ showLink: true,
13
62
  size: {
14
63
  blockSize: 0,
15
64
  blockNum: 4,
@@ -9,15 +9,40 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
13
24
  import CheckCircleOutlineRoundedIcon from '@material-ui/icons/CheckCircleOutlineRounded';
14
25
  import styles from './ConfirmationDialog.module.css';
15
26
  import Dialog from '@material-ui/core/Dialog';
16
27
  import CloseRoundedIcon from '@material-ui/icons/CloseRounded';
17
28
  import { useAppSelector } from '../../hooks';
29
+ import { EditorState, convertFromRaw } from 'draft-js';
30
+ import { Editor } from 'react-draft-wysiwyg';
31
+ import { useContext, useMemo } from 'react';
32
+ import { mapDraftEntities } from '../../Utils/DraftFunctions';
33
+ import FormContext from '../../Contexts/FormContext';
18
34
  function ConfirmationDialog(_a) {
19
35
  var confirmation = _a.confirmation, onClose = _a.onClose;
20
- var formStyle = useAppSelector(function (state) { return state.global; }).formStyle;
36
+ var _b = useAppSelector(function (state) { return state.global; }), formStyle = _b.formStyle, global = __rest(_b, ["formStyle"]);
37
+ var form = useContext(FormContext);
38
+ var dependencies = useAppSelector(function (state) { return state.site.dependencies; });
39
+ var editorState = useMemo(function () {
40
+ return EditorState.createWithContent(convertFromRaw(mapDraftEntities({
41
+ dependencies: dependencies,
42
+ ticket: { caseNumber: confirmation.case },
43
+ }, JSON.parse(JSON.stringify(global.confirmation.confirmationMessage)))));
44
+ }, [global.confirmation, dependencies, form]);
45
+ var hasText = editorState.getCurrentContent().hasText();
21
46
  return (_jsx(Dialog, __assign({ PaperProps: {
22
47
  style: {
23
48
  borderRadius: '20px',
@@ -26,8 +51,8 @@ function ConfirmationDialog(_a) {
26
51
  },
27
52
  }, open: true }, { children: _jsxs("div", __assign({ className: styles.confirmationContainer, style: { color: '#293241' } }, { children: [_jsx("div", __assign({ className: styles.closeIcon, onClick: function () {
28
53
  onClose();
29
- } }, { children: _jsx(CloseRoundedIcon, { fontSize: "inherit" }) })), _jsxs("div", __assign({ className: styles.container }, { children: [_jsx("div", __assign({ className: styles.checkContainer, style: { color: formStyle.primaryColor } }, { children: _jsx(CheckCircleOutlineRoundedIcon, { fontSize: "inherit", style: { fontSize: '160px' } }) })), _jsxs("div", __assign({ className: styles.messageContainer }, { children: ["Tu caso n\u00FAmero", ' ', _jsx("span", __assign({ style: { fontWeight: 'bold' } }, { children: confirmation.case })), ' ', "ha sido registrado!"] })), _jsx("div", __assign({ className: styles.messageContainer }, { children: "Pronto te estaremos dando respuesta." })), _jsxs("div", __assign({ className: styles.linkContainer }, { children: ["Puedes consultar el estado aqui:", ' '] })), _jsx("a", __assign({ className: styles.url, "data-testid": "ResUrl", target: "_blank", href: confirmation.url, style: {
30
- color: '#293241',
31
- } }, { children: confirmation.url }))] }))] })) })));
54
+ } }, { children: _jsx(CloseRoundedIcon, { fontSize: "inherit" }) })), _jsxs("div", __assign({ className: styles.container }, { children: [_jsx("div", __assign({ className: styles.checkContainer, style: { color: formStyle.primaryColor } }, { children: _jsx(CheckCircleOutlineRoundedIcon, { fontSize: "inherit", style: { fontSize: '160px' } }) })), hasText && (_jsx("div", __assign({ className: styles.messageContainer }, { children: _jsx(Editor, { editorClassName: 'Erk-Forms-Confirmation', editorState: editorState, readOnly: true, toolbarHidden: true }) }))), global.confirmation.showLink && (_jsxs(_Fragment, { children: [_jsxs("div", __assign({ className: styles.linkContainer }, { children: ["Puedes consultar el estado aqui:", ' '] })), _jsx("a", __assign({ className: styles.url, "data-testid": "ResUrl", target: "_blank", href: confirmation.url, style: {
55
+ color: '#293241',
56
+ } }, { children: confirmation.url }))] }))] }))] })) })));
32
57
  }
33
58
  export default ConfirmationDialog;
@@ -37,6 +37,8 @@
37
37
  margin-right: 20px;
38
38
  font-size: 1.2rem;
39
39
  text-align: center;
40
+ margin-left: auto;
41
+ margin-right: auto;
40
42
  }
41
43
 
42
44
  .linkContainer {
package/dist/Form/Form.js CHANGED
@@ -170,7 +170,7 @@ function FormComponent(_a) {
170
170
  return (_jsxs(React.Fragment, { children: [showConfirmation !== undefined && (_jsx(ConfirmationDialog, { confirmation: showConfirmation, onClose: function () {
171
171
  reload();
172
172
  setShowConfirmation(undefined);
173
- } })), form.hasCaptcha && !internal && (_jsx(ReCAPTCHA, { ref: recaptchaRef, sitekey: "6LcL22kkAAAAAEotDeAFbRATob-u5vbibbCyWL2p", size: 'invisible', badge: 'bottomright' })), _jsx(FormProvider, __assign({}, formMethods, { children: _jsx(FormContext.Provider, __assign({ value: form }, { children: _jsx(FormTypeComponent, { onSubmit: onSubmit, scrollToTop: scrollToTop, customSubmitBtns: customSubmitBtns }) })) }))] }));
173
+ } })), form.hasCaptcha && !internal && !postview && (_jsx(ReCAPTCHA, { ref: recaptchaRef, sitekey: "6LcL22kkAAAAAEotDeAFbRATob-u5vbibbCyWL2p", size: 'invisible', badge: 'bottomright' })), _jsx(FormProvider, __assign({}, formMethods, { children: _jsx(FormContext.Provider, __assign({ value: form }, { children: _jsx(FormTypeComponent, { onSubmit: onSubmit, scrollToTop: scrollToTop, customSubmitBtns: customSubmitBtns }) })) }))] }));
174
174
  };
175
175
  if (!idOrganization)
176
176
  return _jsx(_Fragment, {});
@@ -26,7 +26,7 @@ import { calcStepDeps } from '../FormSteps/StepHooks';
26
26
  * Function that cals the value of a step to output on submit
27
27
  */
28
28
  export var calcValue = function (idStep, steps, values, customSteps, deleteIds, value) {
29
- var _a, _b;
29
+ var _a, _b, _c;
30
30
  if (value === void 0) { value = values[idStep]; }
31
31
  var step = steps[idStep];
32
32
  if (!step)
@@ -63,29 +63,29 @@ export var calcValue = function (idStep, steps, values, customSteps, deleteIds,
63
63
  return value.value;
64
64
  }
65
65
  case StepTypes.MAPPER: {
66
- var elements = value === null || value === void 0 ? void 0 : value.filter(function (element) { return element.deleted !== true; });
66
+ var elements = (_c = value === null || value === void 0 ? void 0 : value.elements) === null || _c === void 0 ? void 0 : _c.filter(function (element) { return element.deleted !== true; });
67
67
  var mappedValues = [];
68
68
  for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) {
69
69
  var element = elements_1[_i];
70
70
  var newValue = {
71
71
  id: element.id,
72
72
  };
73
- for (var _c = 0, _d = Object.keys(element.originalValues); _c < _d.length; _c++) {
74
- var key = _d[_c];
73
+ for (var _d = 0, _e = Object.keys(element.originalValues); _d < _e.length; _d++) {
74
+ var key = _e[_d];
75
75
  newValue[key] = element.originalValues[key];
76
76
  }
77
77
  if (element.value)
78
78
  newValue.value = element.value;
79
79
  var nestedDeleteIds = [];
80
- for (var _e = 0, _f = Object.keys(step.steps); _e < _f.length; _e++) {
81
- var idStep_1 = _f[_e];
80
+ for (var _f = 0, _g = Object.keys(step.steps); _f < _g.length; _f++) {
81
+ var idStep_1 = _g[_f];
82
82
  var mappedId = element.ids[idStep_1];
83
83
  if (values[mappedId] !== undefined) {
84
84
  newValue[idStep_1] = calcValue(idStep_1, step.steps, values, customSteps, nestedDeleteIds, values[mappedId]);
85
85
  }
86
86
  }
87
- for (var _g = 0, nestedDeleteIds_1 = nestedDeleteIds; _g < nestedDeleteIds_1.length; _g++) {
88
- var idStep_2 = nestedDeleteIds_1[_g];
87
+ for (var _h = 0, nestedDeleteIds_1 = nestedDeleteIds; _h < nestedDeleteIds_1.length; _h++) {
88
+ var idStep_2 = nestedDeleteIds_1[_h];
89
89
  delete newValue[idStep_2];
90
90
  }
91
91
  deleteIds.push.apply(deleteIds, nestedDeleteIds);
@@ -165,7 +165,7 @@ export function calcDependencies(steps, customSteps, allSteps, dependencies, val
165
165
  }
166
166
  }
167
167
  if (step.type === StepTypes.MAPPER) {
168
- var subSteps = calcMapperSubSteps(step, (_b = values.sections[step.idSection]) === null || _b === void 0 ? void 0 : _b[step.id], customSteps);
168
+ var subSteps = calcMapperSubSteps(step, (_b = values.sections[step.idSection]) === null || _b === void 0 ? void 0 : _b[step.id].elements, customSteps);
169
169
  var hasSubSteps = Object.keys(subSteps).length > 0;
170
170
  calcDependencies(hasSubSteps ? subSteps : step.steps, customSteps, __assign(__assign({}, allSteps), subSteps), dependencies, values, hasSubSteps);
171
171
  }
@@ -196,7 +196,7 @@ export var calcMapperSubSteps = function (step, elements, customSteps) {
196
196
  return newSteps;
197
197
  };
198
198
  function calcStepDependency(idStep, steps, values, customSteps) {
199
- var _a;
199
+ var _a, _b;
200
200
  var depStep = steps[idStep];
201
201
  if (!depStep) {
202
202
  var originalValue_1 = values.global[idStep];
@@ -208,7 +208,7 @@ function calcStepDependency(idStep, steps, values, customSteps) {
208
208
  dependents: [],
209
209
  };
210
210
  }
211
- var originalValue = (_a = values.sections[depStep.idSection]) === null || _a === void 0 ? void 0 : _a[depStep.id];
211
+ var originalValue = (_b = (_a = values.sections[depStep.idSection]) === null || _a === void 0 ? void 0 : _a[depStep.id]) !== null && _b !== void 0 ? _b : values.global[depStep.id];
212
212
  return {
213
213
  type: depStep.type,
214
214
  value: calcStepDependencyValue(depStep, originalValue, customSteps),
@@ -234,7 +234,10 @@ function calcStepDependencyValue(depStep, originalValue, customSteps) {
234
234
  }
235
235
  case StepTypes.MAPPER: {
236
236
  //TODO: Esto aun no se usa
237
- return ((_a = originalValue === null || originalValue === void 0 ? void 0 : originalValue.map(function (mapperValue) { var _a; return (_a = mapperValue.value) !== null && _a !== void 0 ? _a : mapperValue; })) !== null && _a !== void 0 ? _a : null);
237
+ return ((_a = {
238
+ elements: originalValue === null || originalValue === void 0 ? void 0 : originalValue.map(function (mapperValue) { var _a; return (_a = mapperValue.value) !== null && _a !== void 0 ? _a : mapperValue; }),
239
+ page: 0,
240
+ }) !== null && _a !== void 0 ? _a : null);
238
241
  }
239
242
  default:
240
243
  return originalValue !== null && originalValue !== void 0 ? originalValue : null;
@@ -57,13 +57,16 @@ import * as SiteReducer from '../../../States/SiteSlice';
57
57
  import { getAppState } from '../../../Utils/store';
58
58
  import { IdFormContext } from '../../../App/App';
59
59
  import CustomBtn from '../../../Shared/CustomBtn/CustomBtn';
60
+ import FormContext from '../../../Contexts/FormContext';
60
61
  function StepperForm(_a) {
61
62
  var _this = this;
63
+ var _b, _c;
62
64
  var onSubmit = _a.onSubmit, scrollToTop = _a.scrollToTop;
63
- var _b = useState(undefined), loading = _b[0], setLoading = _b[1];
64
- var _c = useAppSelector(function (state) { return state.global; }), postview = _c.postview, editable = _c.editable, formStyle = _c.formStyle;
65
- var _d = useFormContext(), trigger = _d.trigger, getValues = _d.getValues, handleSubmit = _d.handleSubmit;
65
+ var _d = useState(undefined), loading = _d[0], setLoading = _d[1];
66
+ var _e = useAppSelector(function (state) { return state.global; }), postview = _e.postview, editable = _e.editable, formStyle = _e.formStyle;
67
+ var _f = useFormContext(), trigger = _f.trigger, getValues = _f.getValues, handleSubmit = _f.handleSubmit;
66
68
  var sendLabel = useContext(CustomContext).sendLabel;
69
+ var form = useContext(FormContext);
67
70
  var dispatch = useAppDispatch();
68
71
  var previous = useAppSelector(function (state) { return state.site.previousSections; });
69
72
  var idCurrent = useAppSelector(function (state) { return state.site.idCurrentSection; });
@@ -75,7 +78,7 @@ function StepperForm(_a) {
75
78
  });
76
79
  var handlePrevious = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
77
80
  return __generator(this, function (_a) {
78
- dispatch(SiteReducer.handlePrevious(getValues()));
81
+ dispatch(SiteReducer.handlePrevious({ values: getValues(), form: form }));
79
82
  scrollToTop === null || scrollToTop === void 0 ? void 0 : scrollToTop();
80
83
  return [2 /*return*/];
81
84
  });
@@ -95,7 +98,7 @@ function StepperForm(_a) {
95
98
  return [2 /*return*/, setLoading(undefined)];
96
99
  }
97
100
  if (next.length > 0) {
98
- dispatch(SiteReducer.handleNext(getValues()));
101
+ dispatch(SiteReducer.handleNext({ values: getValues(), form: form }));
99
102
  scrollToTop === null || scrollToTop === void 0 ? void 0 : scrollToTop();
100
103
  return [2 /*return*/, setLoading(undefined)];
101
104
  }
@@ -115,8 +118,8 @@ function StepperForm(_a) {
115
118
  }); }, [next]);
116
119
  if (!idCurrent)
117
120
  return _jsx(_Fragment, {});
118
- return (_jsxs("div", __assign({ className: styles.container, style: { color: formStyle.textColor } }, { children: [loading && _jsx("div", { className: styles.curtain }), _jsx(Section, { idSection: idCurrent }, idCurrent), next.length === 0 && _jsx(Terms, {}), _jsxs("div", __assign({ className: styles.btnsContainer }, { children: [previous.length > 0 && (_jsx(CustomBtn, { label: "Volver", "data-testid": "form__back", onClick: handlePrevious, backgroundColor: formStyle.primaryColor, color: formStyle.primaryContrastColor, disabled: !!loading, loading: loading === 'BACK' })), (next.length > 0 || (!postview && editable)) && (_jsx(CustomBtn, { label: next.length > 0
119
- ? 'Siguiente'
121
+ return (_jsxs("div", __assign({ className: styles.container, style: { color: formStyle.textColor } }, { children: [loading && _jsx("div", { className: styles.curtain }), _jsx(Section, { idSection: idCurrent }, idCurrent), next.length === 0 && _jsx(Terms, {}), _jsxs("div", __assign({ className: styles.btnsContainer }, { children: [previous.length > 0 && (_jsx(CustomBtn, { label: (_b = form.prevSectionLabel) !== null && _b !== void 0 ? _b : 'Volver', "data-testid": "form__back", onClick: handlePrevious, backgroundColor: formStyle.primaryColor, color: formStyle.primaryContrastColor, disabled: !!loading, loading: loading === 'BACK' })), (next.length > 0 || (!postview && editable)) && (_jsx(CustomBtn, { label: next.length > 0
122
+ ? (_c = form.nextSectionLabel) !== null && _c !== void 0 ? _c : 'Siguiente'
120
123
  : sendLabel !== null && sendLabel !== void 0 ? sendLabel : 'Enviar', "data-testid": "form__submit", onClick: handleNext, backgroundColor: formStyle.primaryColor, color: formStyle.primaryContrastColor, disabled: !!loading, loading: loading === 'NEXT' }))] }))] })));
121
124
  }
122
125
  export default StepperForm;
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { EurekaDraft } from '../../../../@Types/Draft/Draft';
3
+ import { Entity } from '../../../../@Types/Entity';
4
+ interface EntityValueDialogProps {
5
+ type: 'WARNING' | 'INFO';
6
+ message: EurekaDraft;
7
+ entityValue: any;
8
+ entity: Entity;
9
+ handleClose: () => void;
10
+ }
11
+ declare function MaterialEntityValueDialog({ type, entity, message, entityValue, handleClose, }: EntityValueDialogProps): JSX.Element;
12
+ export default MaterialEntityValueDialog;
@@ -0,0 +1,49 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { Dialog } from '@material-ui/core';
14
+ import CloseRoundedIcon from '@material-ui/icons/CloseRounded';
15
+ import WarningRoundedIcon from '@material-ui/icons/WarningRounded';
16
+ import InfoRoundedIcon from '@material-ui/icons/InfoRounded';
17
+ import styles from './MaterialEntityValueDialog.module.css';
18
+ import RoundedButton from '../../../../Shared/RoundedButton/RoundedButton';
19
+ import { useAppSelector } from '../../../../hooks';
20
+ import { EditorState, convertFromRaw } from 'draft-js';
21
+ import { useMemo } from 'react';
22
+ import { mapDraftEntities } from '../../../../Utils/DraftFunctions';
23
+ import { Editor } from 'react-draft-wysiwyg';
24
+ function MaterialEntityValueDialog(_a) {
25
+ var type = _a.type, entity = _a.entity, message = _a.message, entityValue = _a.entityValue, handleClose = _a.handleClose;
26
+ var formStyle = useAppSelector(function (state) { return state.global.formStyle; });
27
+ var dependencies = useAppSelector(function (state) { return state.site.dependencies; });
28
+ var editorState = useMemo(function () {
29
+ return EditorState.createWithContent(convertFromRaw(mapDraftEntities({
30
+ dependencies: dependencies,
31
+ entity: entity,
32
+ entityValue: entityValue,
33
+ }, JSON.parse(JSON.stringify(message)))));
34
+ }, [message, dependencies]);
35
+ return (_jsx(Dialog, __assign({ PaperProps: {
36
+ style: {
37
+ borderRadius: '20px',
38
+ maxWidth: '100vw',
39
+ boxSizing: 'content-box',
40
+ },
41
+ }, open: true }, { children: _jsxs("div", __assign({ className: styles.confirmationContainer, style: { color: formStyle.textColor } }, { children: [_jsx("div", __assign({ className: styles.closeIcon, onClick: function () { return handleClose(); } }, { children: _jsx(CloseRoundedIcon, { fontSize: "inherit" }) })), _jsxs("div", __assign({ className: styles.container }, { children: [_jsxs("div", __assign({ className: styles.contentContainer }, { children: [_jsx("div", __assign({ className: styles.warningContainer, style: {
42
+ color: type === 'INFO'
43
+ ? formStyle.primaryColor
44
+ : formStyle.errorColor,
45
+ } }, { children: type === 'INFO' ? (_jsx(InfoRoundedIcon, { fontSize: "inherit", style: { fontSize: '160px' } })) : (_jsx(WarningRoundedIcon, { fontSize: "inherit", style: { fontSize: '160px' } })) })), _jsx("div", __assign({ className: styles.messageContainer }, { children: _jsx(Editor, { editorClassName: 'Erk-Forms-Dialog', editorState: editorState, readOnly: true, toolbarHidden: true }) }))] })), _jsx("div", __assign({ className: styles.btnContainer }, { children: _jsx(RoundedButton, { text: 'Continuar', color: formStyle.primaryContrastColor, backgroundColor: type === 'INFO'
46
+ ? formStyle.primaryColor
47
+ : formStyle.errorColor, fontSize: '1.2rem', height: undefined, padding: '16px 20px', onClick: function () { return handleClose(); } }) }))] }))] })) })));
48
+ }
49
+ export default MaterialEntityValueDialog;
@@ -0,0 +1,60 @@
1
+ .confirmationContainer {
2
+ display: flex;
3
+ flex-direction: column;
4
+ width: fit-content;
5
+ max-height: 80vh;
6
+ max-width: 80vw;
7
+ position: relative;
8
+ }
9
+
10
+ .container {
11
+ max-height: 100%;
12
+ display: flex;
13
+ flex-direction: column;
14
+ overflow: hidden;
15
+ overflow-y: auto;
16
+ }
17
+ .contentContainer {
18
+ padding: 0px 20px;
19
+ padding-top: 20px;
20
+ display: flex;
21
+ flex-direction: row;
22
+ align-items: center;
23
+ justify-content: center;
24
+ }
25
+ .confirmationContainer,
26
+ .confirmationContainer *,
27
+ .confirmationContainer *::after,
28
+ .confirmationContainer *::before {
29
+ -webkit-box-sizing: content-box;
30
+ -moz-box-sizing: content-box;
31
+ box-sizing: content-box;
32
+ }
33
+
34
+ .warningContainer {
35
+ margin-left: auto;
36
+ margin-right: auto;
37
+ height: fit-content;
38
+ }
39
+
40
+ .messageContainer {
41
+ margin-top: 5px;
42
+ margin-left: 20px;
43
+ margin-right: 20px;
44
+ font-size: 1.2rem;
45
+ text-align: center;
46
+ }
47
+
48
+ .btnContainer {
49
+ margin-left: auto;
50
+ margin-right: auto;
51
+ margin-bottom: 30px;
52
+ }
53
+
54
+ .closeIcon {
55
+ right: 15px;
56
+ top: 10px;
57
+ font-size: 26px;
58
+ position: absolute;
59
+ cursor: pointer;
60
+ }
@@ -54,8 +54,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
54
54
  }
55
55
  return to.concat(ar || Array.prototype.slice.call(from));
56
56
  };
57
- import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
58
- import React, { useContext } from 'react';
57
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
58
+ import React, { useCallback, useContext, useMemo, useState } from 'react';
59
59
  import FormStepTypes, { EntityValueDataTypes, EntityValueOptionTypes, } from '../../../constants/FormStepTypes';
60
60
  import StepComponent from '../../Step';
61
61
  import SmartSelect from '../../SmartSelectStep/MaterialSmartSelectStep/MaterialSmartSelectStep';
@@ -64,57 +64,111 @@ import InputIcon from '../../../Shared/InputIcon/InputIcon';
64
64
  import FormContext from '../../../Contexts/FormContext';
65
65
  import StepFillerContainer from '../../Utils/@StepFiller/StepFiller';
66
66
  import { evaluateCondition } from '../../StepFunctions';
67
- import { recursivelyCalcConditionSteps } from '../../StepHooks';
67
+ import { recursivelyCalcConditionSteps, selectDependencies, } from '../../StepHooks';
68
+ import { useAppSelector } from '../../../hooks';
69
+ import MaterialEntityValueDialog from './MaterialEntityValueDialog/MaterialEntityValueDialog';
68
70
  function EntityValuePickerStep(_a) {
71
+ var _b, _c;
69
72
  var step = _a.step, editable = _a.editable;
70
73
  var form = useContext(FormContext);
71
- return (_jsx(StepFillerContainer, __assign({ step: step }, { children: _jsx(SmartSelect, { editable: editable, step: step, icon: step.icon ? _jsx(InputIcon, { icon: step.icon }) : undefined, getOptions: getEntityValueOptions, getOptionSelected: function (option, value) {
72
- return option._id === value._id;
73
- }, calcDepError: function (steps) {
74
- for (var _i = 0, steps_1 = steps; _i < steps_1.length; _i++) {
75
- var step_1 = steps_1[_i];
76
- if (step_1.type === FormStepTypes.ENTITYVALUEPICKER) {
77
- return 'Selecciona un ' + step_1.label;
78
- }
79
- }
80
- return undefined;
81
- }, filterOptions: function (options, dependencies) {
82
- var filteredOptions = [];
83
- for (var _i = 0, options_1 = options; _i < options_1.length; _i++) {
84
- var value = options_1[_i];
85
- var option = step.options[value._id];
86
- if ((option === null || option === void 0 ? void 0 : option.type) === EntityValueOptionTypes.HIDE)
87
- continue;
88
- if (!option ||
89
- !option.condition ||
90
- evaluateCondition(option.condition, dependencies))
91
- filteredOptions.push(value);
92
- }
93
- return filteredOptions;
94
- }, getOptionsConditionsIdSteps: function () {
95
- var _a;
96
- var dependencies = __spreadArray([], ((_a = step.dependencies) !== null && _a !== void 0 ? _a : []), true);
97
- for (var _i = 0, _b = Object.values(step.options); _i < _b.length; _i++) {
98
- var option = _b[_i];
99
- if (option.type !== EntityValueOptionTypes.HIDE &&
100
- option.condition) {
101
- dependencies.push.apply(dependencies, recursivelyCalcConditionSteps(option.condition));
102
- }
103
- }
104
- return dependencies;
105
- }, getValueString: function (value) { return value === null || value === void 0 ? void 0 : value._id; }, renderNestedSteps: function (value) {
106
- if (!value)
107
- return _jsx(_Fragment, {});
108
- var currentOption = step.options[value._id];
109
- if ((currentOption === null || currentOption === void 0 ? void 0 : currentOption.type) === EntityValueOptionTypes.NESTED) {
110
- return (_jsx(React.Fragment, { children: currentOption.steps.map(function (idStep) {
111
- var subStep = form.steps[idStep];
112
- return (_jsx(StepComponent, { editable: editable, step: subStep }, idStep));
113
- }) }));
74
+ var _d = useState(), dialogs = _d[0], setDialogs = _d[1];
75
+ var dialogsIdStepDeps = useMemo(function () {
76
+ var ids = [];
77
+ if (!step.dialogs)
78
+ return ids;
79
+ for (var _i = 0, _a = step.dialogs; _i < _a.length; _i++) {
80
+ var dialog = _a[_i];
81
+ ids.push.apply(ids, recursivelyCalcConditionSteps(dialog.condition));
82
+ }
83
+ return ids;
84
+ }, []);
85
+ var dialogDeps = useAppSelector(function (state) {
86
+ return selectDependencies(state, dialogsIdStepDeps);
87
+ });
88
+ var handleCloseDialog = useCallback(function () {
89
+ setDialogs(function (dialogs) {
90
+ return dialogs && (dialogs === null || dialogs === void 0 ? void 0 : dialogs.pending.length) > 0
91
+ ? {
92
+ current: dialogs.pending[0],
93
+ pending: dialogs.pending.slice(1),
94
+ value: dialogs.value,
114
95
  }
115
- else
116
- return _jsx(_Fragment, {});
117
- } }) })));
96
+ : undefined;
97
+ });
98
+ }, []);
99
+ return (_jsxs(React.Fragment, { children: [dialogs !== undefined && ((_b = form.entities) === null || _b === void 0 ? void 0 : _b[step.idEntity]) && (_jsx(MaterialEntityValueDialog, { type: dialogs.current.type, entity: (_c = form.entities) === null || _c === void 0 ? void 0 : _c[step.idEntity], entityValue: dialogs.value, message: dialogs.current.message, handleClose: handleCloseDialog })), _jsx(StepFillerContainer, __assign({ step: step }, { children: _jsx(SmartSelect, { editable: editable, step: step, icon: step.icon ? _jsx(InputIcon, { icon: step.icon }) : undefined, getOptions: getEntityValueOptions, getOptionSelected: function (option, value) {
100
+ return option._id === value._id;
101
+ }, calcDepError: function (steps) {
102
+ for (var _i = 0, steps_1 = steps; _i < steps_1.length; _i++) {
103
+ var step_1 = steps_1[_i];
104
+ if (step_1.type === FormStepTypes.ENTITYVALUEPICKER) {
105
+ return 'Selecciona un ' + step_1.label;
106
+ }
107
+ }
108
+ return undefined;
109
+ }, changeListener: function (value) {
110
+ var _a, _b;
111
+ if (!value)
112
+ return;
113
+ var dialogsToDisplay = [];
114
+ for (var _i = 0, _c = (_a = step.dialogs) !== null && _a !== void 0 ? _a : []; _i < _c.length; _i++) {
115
+ var dialog = _c[_i];
116
+ if (!dialog.condition) {
117
+ dialogsToDisplay.push(dialog);
118
+ continue;
119
+ }
120
+ if (evaluateCondition(dialog.condition, dialogDeps, {
121
+ entity: (_b = form.entities) === null || _b === void 0 ? void 0 : _b[step.idEntity],
122
+ entityValue: value,
123
+ })) {
124
+ dialogsToDisplay.push(dialog);
125
+ }
126
+ }
127
+ if (dialogsToDisplay.length > 0) {
128
+ setDialogs({
129
+ value: value,
130
+ current: dialogsToDisplay[0],
131
+ pending: dialogsToDisplay.slice(1),
132
+ });
133
+ }
134
+ }, filterOptions: function (options, dependencies) {
135
+ var filteredOptions = [];
136
+ for (var _i = 0, options_1 = options; _i < options_1.length; _i++) {
137
+ var value = options_1[_i];
138
+ var option = step.options[value._id];
139
+ if ((option === null || option === void 0 ? void 0 : option.type) === EntityValueOptionTypes.HIDE)
140
+ continue;
141
+ if (!option ||
142
+ !option.condition ||
143
+ evaluateCondition(option.condition, dependencies))
144
+ filteredOptions.push(value);
145
+ }
146
+ return filteredOptions;
147
+ }, getOptionsConditionsIdSteps: function () {
148
+ var _a;
149
+ var dependencies = __spreadArray([], ((_a = step.dependencies) !== null && _a !== void 0 ? _a : []), true);
150
+ for (var _i = 0, _b = Object.values(step.options); _i < _b.length; _i++) {
151
+ var option = _b[_i];
152
+ if (option.type !== EntityValueOptionTypes.HIDE &&
153
+ option.condition) {
154
+ dependencies.push.apply(dependencies, recursivelyCalcConditionSteps(option.condition));
155
+ }
156
+ }
157
+ return dependencies;
158
+ }, getValueString: function (value) { return value === null || value === void 0 ? void 0 : value._id; }, renderNestedSteps: function (value) {
159
+ if (!value)
160
+ return _jsx(_Fragment, {});
161
+ var currentOption = step.options[value._id];
162
+ if ((currentOption === null || currentOption === void 0 ? void 0 : currentOption.type) ===
163
+ EntityValueOptionTypes.NESTED) {
164
+ return (_jsx(React.Fragment, { children: currentOption.steps.map(function (idStep) {
165
+ var subStep = form.steps[idStep];
166
+ return (_jsx(StepComponent, { editable: editable, step: subStep }, idStep));
167
+ }) }));
168
+ }
169
+ else
170
+ return _jsx(_Fragment, {});
171
+ } }) }))] }));
118
172
  }
119
173
  export default EntityValuePickerStep;
120
174
  var getEntityValueOptions = function (idOrganization, step, dependencyStore) { return __awaiter(void 0, void 0, void 0, function () {