@arquimedes.co/eureka-forms 1.4.3-test → 1.4.6-test

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/App.js CHANGED
@@ -68,10 +68,18 @@ import widgetInstance from './AxiosWidget';
68
68
  function App(_a) {
69
69
  var _this = this;
70
70
  var _b, _c, _d, _e;
71
- var apiKey = _a.apiKey, domain = _a.domain, preview = _a.preview, formData = _a.formData, postview = _a.postview, isWidget = _a.isWidget, internal = _a.internal, valuesData = _a.valuesData, customSend = _a.customSend, customSteps = _a.customSteps, handleConfirmed = _a.handleConfirmed, others = __rest(_a, ["apiKey", "domain", "preview", "formData", "postview", "isWidget", "internal", "valuesData", "customSend", "customSteps", "handleConfirmed"]);
72
- var _f = useState(undefined), form = _f[0], setForm = _f[1];
73
- var _g = useState({}), originalValues = _g[0], setOriginalValues = _g[1];
74
- var _h = useState(undefined), organizationInfo = _h[0], setOrganizationInfo = _h[1];
71
+ var apiKey = _a.apiKey, domain = _a.domain, preview = _a.preview, formData = _a.formData, postview = _a.postview, isWidget = _a.isWidget, internal = _a.internal, valuesData = _a.valuesData, _f = _a.customSend, customSend = _f === void 0 ? function (a, b) { return __awaiter(_this, void 0, void 0, function () {
72
+ return __generator(this, function (_a) {
73
+ // eslint-disable-next-line no-console
74
+ console.log('HOLA', a, b);
75
+ return [2 /*return*/];
76
+ });
77
+ }); } : _f, customSteps = _a.customSteps, handleConfirmed = _a.handleConfirmed, others = __rest(_a, ["apiKey", "domain", "preview", "formData", "postview", "isWidget", "internal", "valuesData", "customSend", "customSteps", "handleConfirmed"]);
78
+ // eslint-disable-next-line no-console
79
+ console.log(formData, valuesData, customSend);
80
+ var _g = useState(undefined), form = _g[0], setForm = _g[1];
81
+ var _h = useState({}), originalValues = _h[0], setOriginalValues = _h[1];
82
+ var _j = useState(undefined), organizationInfo = _j[0], setOrganizationInfo = _j[1];
75
83
  function fetchPreview(formData) {
76
84
  return __awaiter(this, void 0, void 0, function () {
77
85
  var response;
@@ -284,6 +284,5 @@ function calcDependencies(steps, originalValues) {
284
284
  }
285
285
  }
286
286
  }
287
- dependencies['CBR_PROYECTO'] = null; //REMOVE
288
287
  return dependencies;
289
288
  }
@@ -1,8 +1,7 @@
1
1
  /// <reference types="react" />
2
- import { SmartSelectStepProps } from '../../SmartSelectStep/SmartSelectStep';
3
2
  import { StepProps } from '../../Step';
4
3
  import { CBRElementStep } from '../../../../@Types/CBRFormStep';
5
- declare function CBRLocativasStep(props: SmartSelectStepProps): JSX.Element;
4
+ declare function CBRLocativasStep(props: LocativasSubStepRendererProps): JSX.Element;
6
5
  export default CBRLocativasStep;
7
6
  export interface LocativasSubStepRendererProps extends Omit<StepProps, 'step'> {
8
7
  step: CBRElementStep;
@@ -57,6 +57,8 @@ function CBRLocativasStep(props) {
57
57
  marginTop: 2,
58
58
  } }, void 0), getOptions: getLocativasOptions, getOptionSelected: function (option, value) {
59
59
  return option.id === value.id;
60
+ }, calcDepError: calcDepError, calcInvalidDeps: calcInvaidDependencies, valueOverwrite: function (value) {
61
+ return __assign(__assign({}, value), { subStep: props.step.subStep });
60
62
  }, iconComponent: LeakIconComponent }, { children: _jsx(LocativasSubStepRenderer, {}, void 0) }), void 0));
61
63
  }
62
64
  export default CBRLocativasStep;
@@ -75,7 +77,7 @@ function LocativasSubStepRenderer(_a) {
75
77
  height: 23,
76
78
  width: 23,
77
79
  marginTop: 2,
78
- } }, void 0), getOptions: getLocativasOptions, getOptionSelected: function (option, value) {
80
+ } }, void 0), calcInvalidDeps: calcInvaidDependencies, getOptions: getLocativasOptions, calcDepError: calcDepError, getOptionSelected: function (option, value) {
79
81
  return option.id === value.id;
80
82
  }, iconComponent: LeakIconComponent }, { children: _jsx(LocativasSubStepRenderer, {}, void 0) }), void 0));
81
83
  }
@@ -119,4 +121,29 @@ var getLocativasOptions = function (step, dependencyStore) { return __awaiter(vo
119
121
  return [2 /*return*/];
120
122
  });
121
123
  }); };
124
+ var calcInvaidDependencies = function (step, dependencyStore) {
125
+ var _a;
126
+ var deps = [];
127
+ if (step.dependencies) {
128
+ for (var _i = 0, _b = step.dependencies; _i < _b.length; _i++) {
129
+ var idDep = _b[_i];
130
+ if (((_a = dependencyStore[idDep]) === null || _a === void 0 ? void 0 : _a.id) === undefined) {
131
+ deps.push(idDep);
132
+ }
133
+ }
134
+ }
135
+ return deps;
136
+ };
137
+ var calcDepError = function (types) {
138
+ for (var _i = 0, _a = types; _i < _a.length; _i++) {
139
+ var type = _a[_i];
140
+ if (type === CBRFormStepTypes.CBR_PROYECTO) {
141
+ return 'Selecciona un proyecto';
142
+ }
143
+ if (type === CBRFormStepTypes.CBR_LOCATIVAS) {
144
+ return 'Selecciona un padre';
145
+ }
146
+ }
147
+ return undefined;
148
+ };
122
149
  var Leak = function (props) { return (_jsxs("svg", __assign({ fill: props.fill, className: props.class, style: props.style, height: "512pt", viewBox: "0 -86 512.00056 512", width: "512pt", xmlns: "http://www.w3.org/2000/svg" }, { children: [_jsx("path", { d: "m203.484375 196.359375c2.402344 0 4.753906-.867187 6.601563-2.492187l26.621093-23.394532c3.03125-2.664062 4.164063-6.890625 2.871094-10.714844l-9.21875-27.257812 21.613281-18.996094c3.03125-2.664062 4.164063-6.890625 2.871094-10.714844l-11.359375-33.570312c-1.070313-3.167969-3.652344-5.589844-6.882813-6.457031l-57.925781-15.519531c-5.335937-1.433594-10.816406 1.734374-12.246093 7.070312-1.429688 5.335938 1.734374 10.820312 7.070312 12.25l52.753906 14.132812 7.507813 22.1875-21.613281 18.996094c-3.03125 2.664063-4.164063 6.890625-2.871094 10.714844l9.21875 27.257812-17.59375 15.460938-130.027344-34.839844 30.992188-115.667968c.6875-2.5625.328124-5.292969-.996094-7.589844-1.328125-2.296875-3.511719-3.972656-6.074219-4.660156l-45.574219-12.210938c-5.332031-1.429688-10.816406 1.734375-12.246094 7.070312l-36.636718 136.722657c-.6875 2.5625-.324219 5.292969 1 7.589843 1.324218 2.292969 3.511718 3.972657 6.070312 4.65625l45.574219 12.210938c.867187.234375 1.738281.34375 2.597656.34375 4.414063 0 8.453125-2.945312 9.652344-7.414062l.464844-1.734376 135.199219 36.226563c.851562.230469 1.722656.34375 2.585937.34375zm-181.238281-56.703125 31.460937-117.40625 26.253907 7.035156-31.457032 117.40625zm0 0" }, void 0), _jsx("path", { d: "m511.660156 144.136719-36.636718-136.722657c-1.429688-5.332031-6.910157-8.5-12.246094-7.070312l-45.574219 12.210938c-2.5625.6875-4.746094 2.363281-6.070313 4.660156-1.328124 2.296875-1.6875 5.023437-1 7.585937l.464844 1.734375-135.199218 36.226563c-3.28125.878906-5.894532 3.367187-6.933594 6.605469-1.039063 3.238281-.363282 6.777343 1.796875 9.40625l19.121093 23.265624-5.867187 25.070313c-.796875 3.40625.242187 6.980469 2.738281 9.425781l19.386719 18.988282-6.847656 28.496093c-.824219 3.429688.21875 7.039063 2.742187 9.5 1.894532 1.84375 4.40625 2.839844 6.980469 2.839844.863281 0 1.730469-.113281 2.585937-.34375l57.925782-15.519531c5.335937-1.429688 8.5-6.914063 7.070312-12.25-1.429687-5.332032-6.914062-8.5-12.246094-7.070313l-41.683593 11.171875 4.246093-17.664062c.820313-3.421875-.214843-7.023438-2.726562-9.484375l-19.417969-19.015625 5.714844-24.398438c.710937-3.035156-.035156-6.222656-2.011719-8.628906l-12.40625-15.09375 120.207032-32.207031 30.992187 115.667969c1.199219 4.46875 5.238281 7.414062 9.65625 7.414062.855469 0 1.726563-.109375 2.59375-.339844l45.574219-12.210937c2.5625-.6875 4.746094-2.363281 6.070312-4.660157 1.328125-2.296874 1.6875-5.027343 1-7.589843zm-48.160156 2.554687-30.996094-115.667968s0 0 0-.003907v-.003906l-.464844-1.730469 26.257813-7.035156 31.457031 117.40625zm0 0" }, void 0), _jsx("path", { d: "m263.386719 203.265625c-1.894531-2.078125-4.574219-3.261719-7.386719-3.261719-2.808594 0-5.492188 1.183594-7.386719 3.261719-.78125.855469-1.640625 1.789063-2.570312 2.792969-14.488281 15.730468-44.640625 48.457031-44.640625 79.34375 0 30.105468 24.492187 54.601562 54.597656 54.601562s54.597656-24.496094 54.597656-54.601562c0-30.886719-30.148437-63.613282-44.640625-79.339844-.925781-1.007812-1.789062-1.941406-2.570312-2.796875zm-7.386719 116.738281c-19.078125 0-34.597656-15.523437-34.597656-34.601562 0-20.492188 20.960937-45.539063 34.597656-60.601563 13.636719 15.0625 34.597656 40.109375 34.597656 60.601563 0 19.078125-15.519531 34.601562-34.597656 34.601562zm0 0" }, void 0), _jsx("path", { d: "m129.878906 54.871094c.917969.261718 1.839844.386718 2.75.386718 4.351563 0 8.355469-2.863281 9.609375-7.253906 1.519531-5.3125-1.554687-10.847656-6.867187-12.363281h-.007813c-5.308593-1.519531-10.839843 1.554687-12.359375 6.867187-1.515625 5.308594 1.5625 10.847657 6.875 12.363282zm0 0" }, void 0), _jsx("path", { d: "m407.335938 149.527344-.007813.003906c-5.335937 1.421875-8.507813 6.898438-7.082031 12.238281 1.191406 4.472657 5.238281 7.421875 9.65625 7.421875.855468 0 1.722656-.109375 2.585937-.339844 5.335938-1.421874 8.507813-6.902343 7.085938-12.238281-1.425781-5.335937-6.90625-8.511719-12.238281-7.085937zm0 0" }, void 0)] }), void 0)); };
@@ -66,18 +66,23 @@ import React from 'react';
66
66
  function SmartSelect(_a) {
67
67
  var _this = this;
68
68
  var _b, _c, _d;
69
- var icon = _a.icon, step = _a.step, form = _a.form, value = _a.value, onBlur = _a.onBlur, errors = _a.errors, trigger = _a.trigger, children = _a.children, onChange = _a.onChange, inputRef = _a.inputRef, postview = _a.postview, formStyle = _a.formStyle, getOptions = _a.getOptions, widthStats = _a.widthStats, calcDepError = _a.calcDepError, iconComponent = _a.iconComponent, dependencyStore = _a.dependencyStore, getOptionSelected = _a.getOptionSelected, setDependencyStore = _a.setDependencyStore, others = __rest(_a, ["icon", "step", "form", "value", "onBlur", "errors", "trigger", "children", "onChange", "inputRef", "postview", "formStyle", "getOptions", "widthStats", "calcDepError", "iconComponent", "dependencyStore", "getOptionSelected", "setDependencyStore"]);
70
- var _e = useState(), options = _e[0], setOptions = _e[1];
71
- var _f = useState(), depError = _f[0], setDepError = _f[1];
69
+ var icon = _a.icon, step = _a.step, form = _a.form, value = _a.value, onBlur = _a.onBlur, errors = _a.errors, trigger = _a.trigger, children = _a.children, onChange = _a.onChange, inputRef = _a.inputRef, postview = _a.postview, formStyle = _a.formStyle, getOptions = _a.getOptions, widthStats = _a.widthStats, calcDepError = _a.calcDepError, iconComponent = _a.iconComponent, valueOverwrite = _a.valueOverwrite, dependencyStore = _a.dependencyStore, calcInvalidDeps = _a.calcInvalidDeps, getOptionSelected = _a.getOptionSelected, setDependencyStore = _a.setDependencyStore, others = __rest(_a, ["icon", "step", "form", "value", "onBlur", "errors", "trigger", "children", "onChange", "inputRef", "postview", "formStyle", "getOptions", "widthStats", "calcDepError", "iconComponent", "valueOverwrite", "dependencyStore", "calcInvalidDeps", "getOptionSelected", "setDependencyStore"]);
70
+ var _e = useState(true), first = _e[0], setFirst = _e[1];
71
+ var _f = useState(), options = _f[0], setOptions = _f[1];
72
+ var _g = useState(), depError = _g[0], setDepError = _g[1];
72
73
  var calcOptions = function () { return __awaiter(_this, void 0, void 0, function () {
73
- var resp;
74
- return __generator(this, function (_a) {
75
- switch (_a.label) {
74
+ var resp, invalidDeps;
75
+ var _a;
76
+ return __generator(this, function (_b) {
77
+ switch (_b.label) {
76
78
  case 0: return [4 /*yield*/, (getOptions === null || getOptions === void 0 ? void 0 : getOptions(step, dependencyStore))];
77
79
  case 1:
78
- resp = _a.sent();
80
+ resp = _b.sent();
79
81
  if (resp !== null) {
80
- setDepError(undefined);
82
+ invalidDeps = (_a = calcInvalidDeps === null || calcInvalidDeps === void 0 ? void 0 : calcInvalidDeps(step, dependencyStore)) !== null && _a !== void 0 ? _a : [];
83
+ if (invalidDeps.length === 0) {
84
+ setDepError(undefined);
85
+ }
81
86
  }
82
87
  setOptions(resp);
83
88
  return [2 /*return*/];
@@ -85,7 +90,15 @@ function SmartSelect(_a) {
85
90
  });
86
91
  }); };
87
92
  useEffect(function () {
88
- if (value) {
93
+ var _a;
94
+ if (first) {
95
+ setFirst(false);
96
+ var invalidDeps = (_a = calcInvalidDeps === null || calcInvalidDeps === void 0 ? void 0 : calcInvalidDeps(step, dependencyStore)) !== null && _a !== void 0 ? _a : [];
97
+ if (invalidDeps.length > 0) {
98
+ setDepError(calcDepError === null || calcDepError === void 0 ? void 0 : calcDepError(invalidDeps.map(function (idDep) { var _a; return (_a = form.steps[idDep]) === null || _a === void 0 ? void 0 : _a.type; })));
99
+ }
100
+ }
101
+ else if (value) {
89
102
  onChange(null);
90
103
  }
91
104
  calcOptions();
@@ -123,7 +136,9 @@ function SmartSelect(_a) {
123
136
  if (dependencyStore[step.id] !== undefined) {
124
137
  setDependencyStore(__assign(__assign({}, dependencyStore), (_a = {}, _a[step.id] = value, _a)));
125
138
  }
126
- onChange(value);
139
+ valueOverwrite
140
+ ? onChange(valueOverwrite(value))
141
+ : onChange(value);
127
142
  }, getOptionSelected: getOptionSelected, helperText: depError !== null && depError !== void 0 ? depError : (errors[step.id]
128
143
  ? errors[step.id].message
129
144
  : step.description), error: depError !== undefined || !!errors[step.id] }, void 0) }), void 0), children &&
@@ -133,7 +148,8 @@ function SmartSelect(_a) {
133
148
  })] }, void 0));
134
149
  }
135
150
  function SmartSelectStep(props) {
136
- return (_jsx(Controller, { name: props.step.id, control: props.control, defaultValue: null, rules: {
151
+ var _a;
152
+ return (_jsx(Controller, { name: props.step.id, control: props.control, defaultValue: (_a = props.originalValues[props.step.id]) !== null && _a !== void 0 ? _a : null, rules: {
137
153
  required: props.step.required
138
154
  ? 'Este campo es obligatorio'
139
155
  : undefined,
@@ -15,8 +15,12 @@ export interface SmartSelectStepProps extends Omit<StepProps, 'step'> {
15
15
  getOptionSelected?: (option: any, value: any) => boolean;
16
16
  /** Function that returns the error message based on the types of the missing Dependencies, undefined if no error msg */
17
17
  calcDepError?: (types: Types[]) => string | undefined;
18
+ /** Function that returns the missing dependencies based on the current value */
19
+ calcInvalidDeps?: (step: GSmartSelect, dependencyStore: Record<string, any>) => string[];
18
20
  /** children to render */
19
21
  children?: React.ReactElement<any, string>;
22
+ /** Function that overwrites the value before setting it */
23
+ valueOverwrite?: (value: any) => any;
20
24
  }
21
25
  declare function SmartSelectStep(props: SmartSelectStepProps): JSX.Element;
22
26
  export default SmartSelectStep;
@@ -143,7 +143,7 @@ export default function RoundedSmartSelect(_a) {
143
143
  if (typeof option === 'string') {
144
144
  return option;
145
145
  }
146
- else if (option.inputValue) {
146
+ else if (option === null || option === void 0 ? void 0 : option.inputValue) {
147
147
  return option.inputValue;
148
148
  }
149
149
  else {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@arquimedes.co/eureka-forms",
3
3
  "repository": "git://github.com/Arquimede5/Eureka-Forms.git",
4
- "version":"1.4.3-test",
4
+ "version":"1.4.6-test",
5
5
  "scripts": {
6
6
  "start": "react-scripts start",
7
7
  "build": "react-scripts build",