@arquimedes.co/eureka-forms 2.0.24 → 2.0.25
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/@Types/Form.d.ts +1 -1
- package/dist/@Types/FormStep.d.ts +0 -1
- package/dist/App/App.d.ts +2 -0
- package/dist/App/App.js +1 -1
- package/dist/App/AppFunctions.js +2 -3
- package/dist/Form/Form.d.ts +3 -1
- package/dist/Form/Form.js +3 -3
- package/dist/Form/FormFunctions.d.ts +3 -0
- package/dist/Form/FormFunctions.js +19 -17
- package/dist/Form/FormTypes/StepperForm/StepperForm.d.ts +1 -1
- package/dist/Form/FormTypes/StepperForm/StepperForm.js +3 -1
- package/dist/FormSteps/MapperStep/MaterialMapperStep/MaterialMapperStep.d.ts +8 -4
- package/dist/FormSteps/MapperStep/MaterialMapperStep/MaterialMapperStep.js +50 -79
- package/dist/FormSteps/StepFunctions.d.ts +2 -2
- package/dist/FormSteps/StepFunctions.js +1 -1
- package/dist/Shared/Navbar/Navbar.stories.d.ts +13 -0
- package/dist/Shared/Navbar/Navbar.stories.js +13 -0
- package/dist/Shared/Rating/Rating.stories.d.ts +15 -0
- package/dist/Shared/Rating/Rating.stories.js +59 -0
- package/dist/Shared/RoundedButton/RoundedButton.stories.d.ts +23 -0
- package/dist/Shared/RoundedButton/RoundedButton.stories.js +36 -0
- package/dist/Shared/RoundedCheckBox/RoundedCheckBox.stories.d.ts +21 -0
- package/dist/Shared/RoundedCheckBox/RoundedCheckBox.stories.js +50 -0
- package/dist/Shared/RoundedDatePicker/RoundedDatePicker.d.ts +3 -2
- package/dist/Shared/RoundedDatePicker/RoundedDatePicker.js +3 -3
- package/dist/Shared/RoundedDatePicker/RoundedDatePicker.stories.d.ts +36 -0
- package/dist/Shared/RoundedDatePicker/RoundedDatePicker.stories.js +223 -0
- package/dist/Shared/RoundedSelect/RoundedSelect.stories.d.ts +28 -0
- package/dist/Shared/RoundedSelect/RoundedSelect.stories.js +91 -0
- package/dist/Shared/RoundedSmartSelect/RoundedSmartSelect.d.ts +0 -2
- package/dist/Shared/RoundedSmartSelect/RoundedSmartSelect.js +3 -3
- package/dist/Shared/RoundedSmartSelect/RoundedSmartSelect.stories.d.ts +36 -0
- package/dist/Shared/RoundedSmartSelect/RoundedSmartSelect.stories.js +318 -0
- package/dist/Shared/RoundedTextField/RoundedTextField.js +2 -2
- package/dist/Shared/RoundedTextField/RoundedTextField.stories.d.ts +13 -0
- package/dist/Shared/RoundedTextField/RoundedTextField.stories.js +200 -1
- package/dist/Utils/TestUtils.d.ts +77 -0
- package/dist/Utils/TestUtils.js +65 -0
- package/dist/Utils/store.d.ts +2 -0
- package/dist/Utils/store.js +1 -1
- package/dist/__mocks__/axios.d.ts +2 -0
- package/dist/__mocks__/axios.js +2 -0
- package/dist/index.js +5 -1
- package/package.json +15 -1
- /package/dist/Form/{Hooks.d.ts → FormHooks.d.ts} +0 -0
- /package/dist/Form/{Hooks.js → FormHooks.js} +0 -0
package/dist/@Types/Form.d.ts
CHANGED
package/dist/App/App.d.ts
CHANGED
|
@@ -39,6 +39,8 @@ export interface AppProps {
|
|
|
39
39
|
fetchDownloadUrl?: (S3Key: string, fileName: string) => Promise<string>;
|
|
40
40
|
/** Function to call after the confimation dialog has been closed */
|
|
41
41
|
handleConfirmed?: () => void;
|
|
42
|
+
/** Function called to scroll to the top */
|
|
43
|
+
scrollToTop?: () => void;
|
|
42
44
|
}
|
|
43
45
|
export declare const IdFormContext: React.Context<string>;
|
|
44
46
|
declare function AppComponent({ formData, valuesData, ...props }: AppProps): JSX.Element;
|
package/dist/App/App.js
CHANGED
|
@@ -74,6 +74,6 @@ function App(_a) {
|
|
|
74
74
|
sendLabel: props.sendLabel,
|
|
75
75
|
fetchDownloadUrl: props.fetchDownloadUrl,
|
|
76
76
|
customStepProps: (_g = props.customStepProps) !== null && _g !== void 0 ? _g : {},
|
|
77
|
-
} }, { children: _jsx("div", __assign({ className: styles.container }, { children: _jsx(FormComponent, { form: form, reload: reload, branding: branding, apiKey: props.apiKey, isWidget: !!isWidget, customSteps: customSteps, containerRef: containerRef, customSubmit: props.customSubmit, customSubmitBtns: props.customSubmitBtns }) })) })));
|
|
77
|
+
} }, { children: _jsx("div", __assign({ className: styles.container }, { children: _jsx(FormComponent, { form: form, reload: reload, branding: branding, apiKey: props.apiKey, isWidget: !!isWidget, customSteps: customSteps, containerRef: containerRef, customSubmit: props.customSubmit, scrollToTop: props.scrollToTop, customSubmitBtns: props.customSubmitBtns }) })) })));
|
|
78
78
|
}
|
|
79
79
|
}
|
package/dist/App/AppFunctions.js
CHANGED
|
@@ -173,10 +173,9 @@ export var mapOriginalValue = function (step, value, values, form) {
|
|
|
173
173
|
}
|
|
174
174
|
case StepTypes.CLASSIFIER_SELECTOR: {
|
|
175
175
|
var stepClassifier = (_d = form === null || form === void 0 ? void 0 : form.classifiers) === null || _d === void 0 ? void 0 : _d[(_e = step.idClassifier) !== null && _e !== void 0 ? _e : ''];
|
|
176
|
-
if (stepClassifier) {
|
|
176
|
+
if (stepClassifier && !value.value) {
|
|
177
177
|
var classifier = (_f = form.classifiers) === null || _f === void 0 ? void 0 : _f[value];
|
|
178
|
-
|
|
179
|
-
return { value: value, label: classifier === null || classifier === void 0 ? void 0 : classifier.name };
|
|
178
|
+
return { value: value, label: classifier === null || classifier === void 0 ? void 0 : classifier.name };
|
|
180
179
|
}
|
|
181
180
|
break;
|
|
182
181
|
}
|
package/dist/Form/Form.d.ts
CHANGED
|
@@ -29,10 +29,12 @@ export interface BaseFormProps extends CustomAppProps {
|
|
|
29
29
|
apiKey: string | undefined;
|
|
30
30
|
customSubmit: AppProps['customSubmit'];
|
|
31
31
|
containerRef: React.RefObject<HTMLDivElement>;
|
|
32
|
+
scrollToTop?: () => void;
|
|
32
33
|
}
|
|
33
34
|
export interface FormComponentProps extends CustomAppProps {
|
|
34
35
|
/** Function called when users clicks submit */
|
|
35
36
|
onSubmit: (values: FieldValues) => Promise<any>;
|
|
37
|
+
scrollToTop?: () => void;
|
|
36
38
|
}
|
|
37
|
-
declare function FormComponent({ form, apiKey, reload, isWidget, branding, customSteps, containerRef, customSubmit, customSubmitBtns, }: BaseFormProps): JSX.Element;
|
|
39
|
+
declare function FormComponent({ form, apiKey, reload, isWidget, branding, scrollToTop, customSteps, containerRef, customSubmit, customSubmitBtns, }: BaseFormProps): JSX.Element;
|
|
38
40
|
export default FormComponent;
|
package/dist/Form/Form.js
CHANGED
|
@@ -62,7 +62,7 @@ import axiosInstance from '../Utils/AxiosAPI';
|
|
|
62
62
|
import ReCAPTCHA from 'react-google-recaptcha';
|
|
63
63
|
import ConfirmationDialog from './ConfirmationDialog/ConfirmationDialog';
|
|
64
64
|
import MaterialProviders from '../Utils/MaterialProviders';
|
|
65
|
-
import { useWidthStats } from './
|
|
65
|
+
import { useWidthStats } from './FormHooks';
|
|
66
66
|
import { IdFormContext } from '../App/App';
|
|
67
67
|
import { useAppDispatch, useAppSelector } from '../hooks';
|
|
68
68
|
import FormContext from '../Contexts/FormContext';
|
|
@@ -84,7 +84,7 @@ export var getLocale = function () {
|
|
|
84
84
|
function FormComponent(_a) {
|
|
85
85
|
var _this = this;
|
|
86
86
|
var _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
87
|
-
var form = _a.form, apiKey = _a.apiKey, reload = _a.reload, isWidget = _a.isWidget, branding = _a.branding, customSteps = _a.customSteps, containerRef = _a.containerRef, customSubmit = _a.customSubmit, customSubmitBtns = _a.customSubmitBtns;
|
|
87
|
+
var form = _a.form, apiKey = _a.apiKey, reload = _a.reload, isWidget = _a.isWidget, branding = _a.branding, scrollToTop = _a.scrollToTop, customSteps = _a.customSteps, containerRef = _a.containerRef, customSubmit = _a.customSubmit, customSubmitBtns = _a.customSubmitBtns;
|
|
88
88
|
var _l = useAppSelector(function (state) { return state.global; }), idOrganization = _l.idOrganization, internal = _l.internal, postview = _l.postview;
|
|
89
89
|
var formMethods = useForm({
|
|
90
90
|
mode: 'onTouched',
|
|
@@ -168,7 +168,7 @@ function FormComponent(_a) {
|
|
|
168
168
|
return (_jsxs(React.Fragment, { children: [showConfirmation !== undefined && (_jsx(ConfirmationDialog, { confirmation: showConfirmation, onClose: function () {
|
|
169
169
|
reload();
|
|
170
170
|
setShowConfirmation(undefined);
|
|
171
|
-
} })), 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, customSubmitBtns: customSubmitBtns }) })) }))] }));
|
|
171
|
+
} })), 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 }) })) }))] }));
|
|
172
172
|
};
|
|
173
173
|
if (!idOrganization)
|
|
174
174
|
return _jsx(_Fragment, {});
|
|
@@ -4,6 +4,9 @@ import { CustomStep } from '../FormSteps/CustomStep';
|
|
|
4
4
|
import { CBRFormStep } from '../@Types/CBRFormStep';
|
|
5
5
|
import { MapperElement } from '../@Types/MapperElement';
|
|
6
6
|
import { ValuesStore } from '../States/SiteSlice';
|
|
7
|
+
/**
|
|
8
|
+
* Function that cals the value of a step to output on submit
|
|
9
|
+
*/
|
|
7
10
|
export declare const calcValue: (idStep: string, steps: Record<string, FormStep>, values: Record<string, any>, customSteps: Record<string, CustomStep> | undefined, deleteIds: string[], value?: any) => any;
|
|
8
11
|
export declare function calcDependencies(steps: Record<string, FormStep | CBRFormStep>, customSteps?: Record<string, CustomStep>, allSteps?: Record<string, FormStep | CBRFormStep>, dependencies?: DependencyStore, values?: ValuesStore, addDependents?: boolean): DependencyStore;
|
|
9
12
|
export declare const calcMapperSubSteps: (step: Mapper, elements: MapperElement<any>[] | undefined, customSteps: Record<string, CustomStep>) => Record<string, FormStep>;
|
|
@@ -18,9 +18,12 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
18
18
|
}
|
|
19
19
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
20
|
};
|
|
21
|
-
import { convertToRaw } from 'draft-js';
|
|
21
|
+
import { convertFromRaw, convertToRaw } from 'draft-js';
|
|
22
22
|
import StepTypes, { EntityValueDataTypes } from '../constants/FormStepTypes';
|
|
23
23
|
import { calcRecursiveData } from '../App/AppFunctions';
|
|
24
|
+
/**
|
|
25
|
+
* Function that cals the value of a step to output on submit
|
|
26
|
+
*/
|
|
24
27
|
export var calcValue = function (idStep, steps, values, customSteps, deleteIds, value) {
|
|
25
28
|
var _a, _b;
|
|
26
29
|
if (value === void 0) { value = values[idStep]; }
|
|
@@ -32,7 +35,7 @@ export var calcValue = function (idStep, steps, values, customSteps, deleteIds,
|
|
|
32
35
|
return (_b = (_a = custom.calcValue) === null || _a === void 0 ? void 0 : _a.call(custom, step, value)) !== null && _b !== void 0 ? _b : value;
|
|
33
36
|
}
|
|
34
37
|
else {
|
|
35
|
-
switch (step
|
|
38
|
+
switch (step.type) {
|
|
36
39
|
case StepTypes.TEXTAREA: {
|
|
37
40
|
if (step.hasTextEditor) {
|
|
38
41
|
var currentContent = value.getCurrentContent();
|
|
@@ -58,9 +61,6 @@ export var calcValue = function (idStep, steps, values, customSteps, deleteIds,
|
|
|
58
61
|
case StepTypes.CLASSIFIER_SELECTOR: {
|
|
59
62
|
return value.value;
|
|
60
63
|
}
|
|
61
|
-
case StepTypes.COLLAPSIBLE: {
|
|
62
|
-
return !!value;
|
|
63
|
-
}
|
|
64
64
|
case StepTypes.MAPPER: {
|
|
65
65
|
var elements = value === null || value === void 0 ? void 0 : value.filter(function (element) { return element.deleted !== true; });
|
|
66
66
|
var mappedValues = [];
|
|
@@ -88,6 +88,7 @@ export var calcValue = function (idStep, steps, values, customSteps, deleteIds,
|
|
|
88
88
|
return mappedValues;
|
|
89
89
|
}
|
|
90
90
|
case StepTypes.TITLE:
|
|
91
|
+
case StepTypes.COLLAPSIBLE:
|
|
91
92
|
deleteIds.push(idStep);
|
|
92
93
|
return;
|
|
93
94
|
default:
|
|
@@ -128,7 +129,6 @@ export function calcDependencies(steps, customSteps, allSteps, dependencies, val
|
|
|
128
129
|
if (addDependents === void 0) { addDependents = true; }
|
|
129
130
|
for (var _i = 0, _c = Object.values(steps); _i < _c.length; _i++) {
|
|
130
131
|
var step = _c[_i];
|
|
131
|
-
var originalValue = (_a = values.sections[step.idSection]) === null || _a === void 0 ? void 0 : _a[step.id];
|
|
132
132
|
if (step.dependencies) {
|
|
133
133
|
for (var _d = 0, _e = step.dependencies; _d < _e.length; _d++) {
|
|
134
134
|
var idDep = _e[_d];
|
|
@@ -144,7 +144,7 @@ export function calcDependencies(steps, customSteps, allSteps, dependencies, val
|
|
|
144
144
|
var dep = _g[_f];
|
|
145
145
|
if (dep.type !== EntityValueDataTypes.STEP)
|
|
146
146
|
continue;
|
|
147
|
-
if ((
|
|
147
|
+
if ((_a = step.dependencies) === null || _a === void 0 ? void 0 : _a.includes(dep.idStep))
|
|
148
148
|
continue;
|
|
149
149
|
if (dependencies[dep.idStep] === undefined &&
|
|
150
150
|
(addDependents || allSteps[dep.idStep])) {
|
|
@@ -155,7 +155,7 @@ export function calcDependencies(steps, customSteps, allSteps, dependencies, val
|
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
if (step.type === StepTypes.MAPPER) {
|
|
158
|
-
var subSteps = calcMapperSubSteps(step,
|
|
158
|
+
var subSteps = calcMapperSubSteps(step, (_b = values.sections[step.idSection]) === null || _b === void 0 ? void 0 : _b[step.id], customSteps);
|
|
159
159
|
var hasSubSteps = Object.keys(subSteps).length > 0;
|
|
160
160
|
calcDependencies(hasSubSteps ? subSteps : step.steps, customSteps, __assign(__assign({}, allSteps), subSteps), dependencies, values, hasSubSteps);
|
|
161
161
|
}
|
|
@@ -182,22 +182,21 @@ export var calcMapperSubSteps = function (step, elements, customSteps) {
|
|
|
182
182
|
return newSteps;
|
|
183
183
|
};
|
|
184
184
|
function calcStepDependency(idStep, steps, values, customSteps) {
|
|
185
|
-
var _a
|
|
185
|
+
var _a;
|
|
186
186
|
var depStep = steps[idStep];
|
|
187
187
|
if (!depStep) {
|
|
188
188
|
console.error('Missing Step Dependency:', idStep);
|
|
189
|
+
var originalValue_1 = values.global[idStep];
|
|
189
190
|
return {
|
|
190
|
-
type: 'MISSING',
|
|
191
|
-
value: null,
|
|
191
|
+
type: originalValue_1 ? 'ORIGINAL' : 'MISSING',
|
|
192
|
+
value: originalValue_1 !== null && originalValue_1 !== void 0 ? originalValue_1 : null,
|
|
192
193
|
dependents: [],
|
|
193
194
|
};
|
|
194
195
|
}
|
|
195
196
|
var originalValue = (_a = values.sections[depStep.idSection]) === null || _a === void 0 ? void 0 : _a[depStep.id];
|
|
196
197
|
return {
|
|
197
|
-
type:
|
|
198
|
-
value: depStep
|
|
199
|
-
? calcStepDependencyValue(depStep, originalValue, customSteps)
|
|
200
|
-
: originalValue !== null && originalValue !== void 0 ? originalValue : null,
|
|
198
|
+
type: depStep.type,
|
|
199
|
+
value: calcStepDependencyValue(depStep, originalValue, customSteps),
|
|
201
200
|
dependents: [],
|
|
202
201
|
};
|
|
203
202
|
}
|
|
@@ -210,13 +209,16 @@ function calcStepDependencyValue(depStep, originalValue, customSteps) {
|
|
|
210
209
|
switch (depStep.type) {
|
|
211
210
|
case StepTypes.TEXTAREA: {
|
|
212
211
|
if (depStep.hasTextEditor) {
|
|
213
|
-
return
|
|
212
|
+
return originalValue
|
|
213
|
+
? convertFromRaw(originalValue).getPlainText()
|
|
214
|
+
: null;
|
|
214
215
|
}
|
|
215
216
|
else {
|
|
216
|
-
return originalValue
|
|
217
|
+
return originalValue !== null && originalValue !== void 0 ? originalValue : null;
|
|
217
218
|
}
|
|
218
219
|
}
|
|
219
220
|
case StepTypes.MAPPER: {
|
|
221
|
+
//TODO: Esto aun no se usa
|
|
220
222
|
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);
|
|
221
223
|
}
|
|
222
224
|
default:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { FormComponentProps } from '../../Form';
|
|
3
|
-
declare function StepperForm({ onSubmit }: FormComponentProps): JSX.Element;
|
|
3
|
+
declare function StepperForm({ onSubmit, scrollToTop, }: FormComponentProps): JSX.Element;
|
|
4
4
|
export default StepperForm;
|
|
@@ -59,7 +59,7 @@ import { getAppState } from '../../../Utils/store';
|
|
|
59
59
|
import { IdFormContext } from '../../../App/App';
|
|
60
60
|
function StepperForm(_a) {
|
|
61
61
|
var _this = this;
|
|
62
|
-
var onSubmit = _a.onSubmit;
|
|
62
|
+
var onSubmit = _a.onSubmit, scrollToTop = _a.scrollToTop;
|
|
63
63
|
var _b = useState(undefined), loading = _b[0], setLoading = _b[1];
|
|
64
64
|
var _c = useAppSelector(function (state) { return state.global; }), postview = _c.postview, editable = _c.editable, formStyle = _c.formStyle;
|
|
65
65
|
var _d = useFormContext(), trigger = _d.trigger, getValues = _d.getValues, handleSubmit = _d.handleSubmit;
|
|
@@ -75,6 +75,7 @@ function StepperForm(_a) {
|
|
|
75
75
|
});
|
|
76
76
|
var handlePrevious = useCallback(function () {
|
|
77
77
|
dispatch(SiteReducer.handlePrevious(getValues()));
|
|
78
|
+
scrollToTop === null || scrollToTop === void 0 ? void 0 : scrollToTop();
|
|
78
79
|
}, []);
|
|
79
80
|
var handleNext = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
80
81
|
var valid, state, values, response;
|
|
@@ -92,6 +93,7 @@ function StepperForm(_a) {
|
|
|
92
93
|
}
|
|
93
94
|
if (next.length > 0) {
|
|
94
95
|
dispatch(SiteReducer.handleNext(getValues()));
|
|
96
|
+
scrollToTop === null || scrollToTop === void 0 ? void 0 : scrollToTop();
|
|
95
97
|
return [2 /*return*/, setLoading(undefined)];
|
|
96
98
|
}
|
|
97
99
|
return [4 /*yield*/, dispatch(getAppState({ idForm: idForm })).unwrap()];
|
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
import { MapperStepProps } from '../MapperStep';
|
|
3
3
|
import { FieldError } from 'react-hook-form';
|
|
4
4
|
import { MapperElement } from '../../../@Types/MapperElement';
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
5
|
+
import { Form } from '../../../@Types';
|
|
6
|
+
export interface MapperComponentProps<Type> extends MapperStepProps<Type> {
|
|
7
|
+
form: Form;
|
|
8
|
+
loading?: boolean;
|
|
8
9
|
error: FieldError | undefined;
|
|
9
10
|
onChange: (elements: MapperElement<Type>[]) => void;
|
|
11
|
+
handleAddElement: (elementValue?: Type) => void;
|
|
10
12
|
elements: MapperElement<Type>[];
|
|
11
13
|
inputRef: any;
|
|
12
|
-
}
|
|
14
|
+
}
|
|
15
|
+
declare function MapperStep<Type>(props: MapperStepProps<Type>): JSX.Element;
|
|
16
|
+
export declare function CustomMapperStep<Type>(props: Omit<MapperComponentProps<Type>, 'form' | 'handleAddElement'>): JSX.Element;
|
|
13
17
|
export default MapperStep;
|
|
@@ -44,14 +44,52 @@ import CustomContext from '../../../Contexts/CustomContext';
|
|
|
44
44
|
import { useFormStep } from '../../StepHooks';
|
|
45
45
|
import { addMapperStep } from '../../../App/AppFunctions';
|
|
46
46
|
import { calcMapperSubSteps } from '../../../Form/FormFunctions';
|
|
47
|
-
function
|
|
48
|
-
var step = _a.step, editable = _a.editable, customAdd = _a.customAdd, others = __rest(_a, ["step", "editable", "customAdd"]);
|
|
49
|
-
var
|
|
47
|
+
function MapperComponent(_a) {
|
|
48
|
+
var form = _a.form, step = _a.step, error = _a.error, loading = _a.loading, inputRef = _a.inputRef, editable = _a.editable, customAdd = _a.customAdd, elements = _a.elements, onChange = _a.onChange, handleAddElement = _a.handleAddElement, others = __rest(_a, ["form", "step", "error", "loading", "inputRef", "editable", "customAdd", "elements", "onChange", "handleAddElement"]);
|
|
49
|
+
var handleDeleteElement = useCallback(function (index) { return function () {
|
|
50
|
+
var tempElements = __spreadArray([], elements, true);
|
|
51
|
+
tempElements[index] = __assign(__assign({}, tempElements[index]), { deleted: true });
|
|
52
|
+
onChange(tempElements);
|
|
53
|
+
}; }, [elements, onChange]);
|
|
54
|
+
var inputValue = useMemo(function () { return JSON.stringify(elements); }, [elements]);
|
|
50
55
|
var _b = useAppSelector(function (state) { return state.global; }), formStyle = _b.formStyle, postview = _b.postview;
|
|
56
|
+
var container = useMemo(function () {
|
|
57
|
+
var _a;
|
|
58
|
+
switch ((_a = step.style) === null || _a === void 0 ? void 0 : _a.type) {
|
|
59
|
+
case MapperStyleTypes.LIST:
|
|
60
|
+
return { container: styles.listContainer };
|
|
61
|
+
case MapperStyleTypes.PILL:
|
|
62
|
+
default:
|
|
63
|
+
return { container: styles.pillContainer };
|
|
64
|
+
}
|
|
65
|
+
}, [step]).container;
|
|
66
|
+
var mapElements = function () {
|
|
67
|
+
return (_jsx(FormContext.Provider, __assign({ value: form }, { children: elements.map(function (element, index) { return (_createElement(MapperElementComponent, __assign({}, others, { key: element.id, num: index, element: element, step: step, editable: editable, loading: loading, handleDelete: handleDeleteElement(index) }))); }) })));
|
|
68
|
+
};
|
|
69
|
+
if (step.style.type === MapperStyleTypes.INLINE)
|
|
70
|
+
return _jsx(React.Fragment, { children: mapElements() });
|
|
71
|
+
return (_jsxs("div", __assign({ className: container, style: { color: formStyle.textColor }, "data-testid": step.id }, { children: [step.label && _jsx("div", __assign({ className: styles.titleLbl }, { children: step.label })), step.description && (_jsx("p", __assign({ className: styles.descriptionPar, style: {
|
|
72
|
+
margin: step.description
|
|
73
|
+
? '10px 0px'
|
|
74
|
+
: '0px 0px 5px 0px',
|
|
75
|
+
} }, { children: step.description }))), mapElements(), _jsx("input", { id: step.id, ref: inputRef, className: 'hidden-input', readOnly: true, value: inputValue }), step.creatable !== false &&
|
|
76
|
+
(!step.max ||
|
|
77
|
+
elements.filter(function (elem) { return !elem.deleted; }).length < step.max) && (_jsxs("div", __assign({ className: styles.btnContainer }, { children: [!customAdd && (_jsx(RoundedButton, { disabled: !editable || postview, text: step.addBtnLabel +
|
|
78
|
+
(step.required ? ' *' : ''), color: formStyle.primaryContrastColor, backgroundColor: formStyle.primaryColor, fontSize: '1rem', padding: '5px 15px 5px 15px', onClick: function () {
|
|
79
|
+
if (editable && !postview) {
|
|
80
|
+
handleAddElement();
|
|
81
|
+
}
|
|
82
|
+
} })), customAdd === null || customAdd === void 0 ? void 0 : customAdd(inputRef, !editable || postview, handleAddElement)] }))), !!error &&
|
|
83
|
+
elements.filter(function (elem) { return !elem.deleted; }).length === 0 && (_jsx("div", __assign({ className: styles.errorMsg, style: { color: formStyle.errorColor } }, { children: "Este campo es obligatorio" })))] })));
|
|
84
|
+
}
|
|
85
|
+
function MapperStep(props) {
|
|
86
|
+
var step = props.step, editable = props.editable, customAdd = props.customAdd;
|
|
87
|
+
var form = useContext(FormContext);
|
|
88
|
+
var postview = useAppSelector(function (state) { return state.global; }).postview;
|
|
51
89
|
var customSteps = useContext(CustomContext).customSteps;
|
|
52
90
|
var dispatch = useAppDispatch();
|
|
53
91
|
var setValue = useFormContext().setValue;
|
|
54
|
-
var
|
|
92
|
+
var _a = useFormStep(step, {
|
|
55
93
|
defaultValue: [],
|
|
56
94
|
rules: {
|
|
57
95
|
validate: function (array) {
|
|
@@ -60,9 +98,9 @@ function MapperStep(_a) {
|
|
|
60
98
|
array.filter(function (elem) { return !elem.deleted; }).length > 0);
|
|
61
99
|
},
|
|
62
100
|
},
|
|
63
|
-
}), ref =
|
|
64
|
-
var
|
|
65
|
-
//Por alguna razón si se saca del componente no se ejecuta
|
|
101
|
+
}), ref = _a.ref, value = _a.value, onChange = _a.onChange, error = _a.error;
|
|
102
|
+
var _b = useState(calcMapperSubSteps(step, value, customSteps)), localSteps = _b[0], setLocalSteps = _b[1];
|
|
103
|
+
//Por alguna razón si se saca esto del componente no se ejecuta el agregar inicial
|
|
66
104
|
useEffect(function () {
|
|
67
105
|
if (value.length === 0 && !postview && editable && step.creatable) {
|
|
68
106
|
if (!customAdd)
|
|
@@ -86,50 +124,16 @@ function MapperStep(_a) {
|
|
|
86
124
|
allSteps: __assign(__assign({}, form.steps), steps),
|
|
87
125
|
}));
|
|
88
126
|
}, [step, form, customSteps, value, onChange]);
|
|
89
|
-
var handleDeleteElement = useCallback(function (index) { return function () {
|
|
90
|
-
var tempElements = __spreadArray([], value, true);
|
|
91
|
-
tempElements[index] = __assign(__assign({}, tempElements[index]), { deleted: true });
|
|
92
|
-
onChange(tempElements);
|
|
93
|
-
}; }, [value, onChange]);
|
|
94
127
|
var subForm = useMemo(function () { return (__assign(__assign({}, form), { steps: __assign(__assign({}, form.steps), localSteps) })); }, [localSteps]);
|
|
95
|
-
|
|
96
|
-
var container = useMemo(function () {
|
|
97
|
-
var _a;
|
|
98
|
-
switch ((_a = step.style) === null || _a === void 0 ? void 0 : _a.type) {
|
|
99
|
-
case MapperStyleTypes.LIST:
|
|
100
|
-
return { container: styles.listContainer };
|
|
101
|
-
case MapperStyleTypes.PILL:
|
|
102
|
-
default:
|
|
103
|
-
return { container: styles.pillContainer };
|
|
104
|
-
}
|
|
105
|
-
}, [step]).container;
|
|
106
|
-
var mapElements = function () {
|
|
107
|
-
return (_jsx(FormContext.Provider, __assign({ value: subForm }, { children: value.map(function (element, index) { return (_createElement(MapperElementComponent, __assign({}, others, { key: element.id, num: index, element: element, step: step, editable: editable, handleDelete: handleDeleteElement(index) }))); }) })));
|
|
108
|
-
};
|
|
109
|
-
if (step.style.type === MapperStyleTypes.INLINE)
|
|
110
|
-
return _jsx(React.Fragment, { children: mapElements() });
|
|
111
|
-
return (_jsxs("div", __assign({ className: container, style: { color: formStyle.textColor }, "data-testid": step.id }, { children: [step.label && _jsx("div", __assign({ className: styles.titleLbl }, { children: step.label })), step.description && (_jsx("p", __assign({ className: styles.descriptionPar, style: {
|
|
112
|
-
margin: step.description
|
|
113
|
-
? '10px 0px'
|
|
114
|
-
: '0px 0px 5px 0px',
|
|
115
|
-
} }, { children: step.description }))), mapElements(), _jsx("input", { id: step.id, ref: ref, className: 'hidden-input', readOnly: true, value: inputValue }), step.creatable !== false &&
|
|
116
|
-
(!step.max ||
|
|
117
|
-
value.filter(function (elem) { return !elem.deleted; })
|
|
118
|
-
.length < step.max) && (_jsxs("div", __assign({ className: styles.btnContainer }, { children: [!customAdd && (_jsx(RoundedButton, { disabled: !editable || postview, text: step.addBtnLabel +
|
|
119
|
-
(step.required ? ' *' : ''), color: formStyle.primaryContrastColor, backgroundColor: formStyle.primaryColor, fontSize: '1rem', padding: '5px 15px 5px 15px', onClick: function () {
|
|
120
|
-
if (editable && !postview) {
|
|
121
|
-
handleAddElement();
|
|
122
|
-
}
|
|
123
|
-
} })), customAdd === null || customAdd === void 0 ? void 0 : customAdd(ref, !editable || postview, handleAddElement)] }))), !!error && value.filter(function (elem) { return !elem.deleted; }).length === 0 && (_jsx("div", __assign({ className: styles.errorMsg, style: { color: formStyle.errorColor } }, { children: "Este campo es obligatorio" })))] })));
|
|
128
|
+
return (_jsx(MapperComponent, __assign({}, props, { error: error, inputRef: ref, onChange: onChange, handleAddElement: handleAddElement, form: subForm, elements: value })));
|
|
124
129
|
}
|
|
125
|
-
export function CustomMapperStep(
|
|
126
|
-
var step =
|
|
130
|
+
export function CustomMapperStep(props) {
|
|
131
|
+
var step = props.step, elements = props.elements, onChange = props.onChange;
|
|
127
132
|
var form = useContext(FormContext);
|
|
128
|
-
var _c = useAppSelector(function (state) { return state.global; }), formStyle = _c.formStyle, postview = _c.postview;
|
|
129
133
|
var customSteps = useContext(CustomContext).customSteps;
|
|
130
134
|
var dispatch = useAppDispatch();
|
|
131
135
|
var setValue = useFormContext().setValue;
|
|
132
|
-
var
|
|
136
|
+
var _a = useState(calcMapperSubSteps(step, elements, customSteps)), localSteps = _a[0], setLocalSteps = _a[1];
|
|
133
137
|
var handleAddElement = useCallback(function (elementValue) {
|
|
134
138
|
var _a = addMapperStep(step, customSteps), element = _a.element, steps = _a.steps, mappers = _a.mappers;
|
|
135
139
|
if (elementValue)
|
|
@@ -147,40 +151,7 @@ export function CustomMapperStep(_a) {
|
|
|
147
151
|
allSteps: __assign(__assign({}, form.steps), steps),
|
|
148
152
|
}));
|
|
149
153
|
}, [step, form, customSteps, elements, onChange]);
|
|
150
|
-
var handleDeleteElement = useCallback(function (index) { return function () {
|
|
151
|
-
var tempElements = __spreadArray([], elements, true);
|
|
152
|
-
tempElements[index] = __assign(__assign({}, tempElements[index]), { deleted: true });
|
|
153
|
-
onChange(tempElements);
|
|
154
|
-
}; }, [elements, onChange]);
|
|
155
154
|
var subForm = useMemo(function () { return (__assign(__assign({}, form), { steps: __assign(__assign({}, form.steps), localSteps) })); }, [localSteps]);
|
|
156
|
-
|
|
157
|
-
var container = useMemo(function () {
|
|
158
|
-
var _a;
|
|
159
|
-
switch ((_a = step.style) === null || _a === void 0 ? void 0 : _a.type) {
|
|
160
|
-
case MapperStyleTypes.LIST:
|
|
161
|
-
return { container: styles.listContainer };
|
|
162
|
-
case MapperStyleTypes.PILL:
|
|
163
|
-
default:
|
|
164
|
-
return { container: styles.pillContainer };
|
|
165
|
-
}
|
|
166
|
-
}, [step]).container;
|
|
167
|
-
var mapElements = function () {
|
|
168
|
-
return (_jsx(FormContext.Provider, __assign({ value: subForm }, { children: elements.map(function (element, index) { return (_createElement(MapperElementComponent, __assign({}, others, { key: element.id, num: index, loading: loading, element: element, step: step, editable: editable, handleDelete: handleDeleteElement(index) }))); }) })));
|
|
169
|
-
};
|
|
170
|
-
if (step.style.type === MapperStyleTypes.INLINE)
|
|
171
|
-
return _jsx(React.Fragment, { children: mapElements() });
|
|
172
|
-
return (_jsxs("div", __assign({ className: container, style: { color: formStyle.textColor }, "data-testid": step.id }, { children: [step.label && _jsx("div", __assign({ className: styles.titleLbl }, { children: step.label })), step.description && (_jsx("p", __assign({ className: styles.descriptionPar, style: {
|
|
173
|
-
margin: step.description
|
|
174
|
-
? '10px 0px'
|
|
175
|
-
: '0px 0px 5px 0px',
|
|
176
|
-
} }, { children: step.description }))), mapElements(), _jsx("input", { id: step.id, ref: inputRef, className: 'hidden-input', readOnly: true, value: inputValue }), step.creatable !== false &&
|
|
177
|
-
(!step.max ||
|
|
178
|
-
elements.filter(function (elem) { return !elem.deleted; }).length < step.max) && (_jsxs("div", __assign({ className: styles.btnContainer }, { children: [!customAdd && (_jsx(RoundedButton, { disabled: !editable || postview, text: step.addBtnLabel +
|
|
179
|
-
(step.required ? ' *' : ''), color: formStyle.primaryContrastColor, backgroundColor: formStyle.primaryColor, fontSize: '1rem', padding: '5px 15px 5px 15px', onClick: function () {
|
|
180
|
-
if (editable && !postview) {
|
|
181
|
-
handleAddElement();
|
|
182
|
-
}
|
|
183
|
-
} })), customAdd === null || customAdd === void 0 ? void 0 : customAdd(inputRef, !editable || postview, handleAddElement)] }))), !!error &&
|
|
184
|
-
elements.filter(function (elem) { return !elem.deleted; }).length === 0 && (_jsx("div", __assign({ className: styles.errorMsg, style: { color: formStyle.errorColor } }, { children: "Este campo es obligatorio" })))] })));
|
|
155
|
+
return (_jsx(MapperComponent, __assign({}, props, { form: subForm, elements: elements, onChange: onChange, handleAddElement: handleAddElement })));
|
|
185
156
|
}
|
|
186
157
|
export default MapperStep;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { FormSize } from '../@Types/Form';
|
|
2
2
|
import { ApiSelector, CheckBox, ClassifierSelector, EntityValuePicker, FormSelector, FormStep } from '../@Types/FormStep';
|
|
3
|
+
import { AYFFormStep } from '../@Types/AYFFormStep';
|
|
3
4
|
import { CBRFormStep } from '../@Types/CBRFormStep';
|
|
4
5
|
export type FillerSteps = FormSelector | ClassifierSelector | EntityValuePicker | ApiSelector | CheckBox;
|
|
5
6
|
export declare function calcFillerSize(step: FillerSteps, steps: Record<string, FormStep>, values: Record<string, unknown>, size: FormSize): number;
|
|
6
|
-
export declare function recursivelyCheckOpenSize(idStep: string, steps: Record<string, FormStep>, values: Record<string, any>): number;
|
|
7
7
|
export declare const calcStepWidth: (stepSize: 1 | 2 | 3 | 4, size: FormSize) => number;
|
|
8
8
|
export declare const calcDefaultValue: (step: FormStep | CBRFormStep) => any;
|
|
9
9
|
export declare const iterateNestedSteps: (idStep: string, steps: Record<string, FormStep>, iteration: (step: FormStep) => void) => void;
|
|
@@ -13,4 +13,4 @@ export declare const iterateNestedSteps: (idStep: string, steps: Record<string,
|
|
|
13
13
|
* @param idModifier optional modifier for the ids of the substeps and all other properties
|
|
14
14
|
* @returns list of the ids of the direct substeps of the step, if modifier returns modified steps
|
|
15
15
|
*/
|
|
16
|
-
export declare const calcSubSteps: (step: FormStep, idModifier?: ((idSubStep: string) => string) | undefined) => string[];
|
|
16
|
+
export declare const calcSubSteps: (step: FormStep | CBRFormStep | AYFFormStep, idModifier?: ((idSubStep: string) => string) | undefined) => string[];
|
|
@@ -14,7 +14,7 @@ export function calcFillerSize(step, steps, values, size) {
|
|
|
14
14
|
return 0;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
function recursivelyCheckOpenSize(idStep, steps, values) {
|
|
18
18
|
var step = steps[idStep];
|
|
19
19
|
var value = values[idStep];
|
|
20
20
|
switch (step.type) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { StoryObj } from '@storybook/react';
|
|
2
|
+
import Navbar from './Navbar';
|
|
3
|
+
declare const meta: {
|
|
4
|
+
component: typeof Navbar;
|
|
5
|
+
tags: string[];
|
|
6
|
+
args: {
|
|
7
|
+
logo: string;
|
|
8
|
+
color: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export default meta;
|
|
12
|
+
type Story = StoryObj<typeof meta>;
|
|
13
|
+
export declare const Default: Story;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { StoryObj } from '@storybook/react';
|
|
2
|
+
import Rating from './Rating';
|
|
3
|
+
declare const meta: {
|
|
4
|
+
component: typeof Rating;
|
|
5
|
+
tags: string[];
|
|
6
|
+
args: {};
|
|
7
|
+
};
|
|
8
|
+
export default meta;
|
|
9
|
+
type Story = StoryObj<typeof meta>;
|
|
10
|
+
export declare const ScaleRating: Story;
|
|
11
|
+
export declare const ScaleRatingWidthValue: Story;
|
|
12
|
+
export declare const LikeRating: Story;
|
|
13
|
+
export declare const LikeRatingWithValue: Story;
|
|
14
|
+
export declare const SatisfactionRating: Story;
|
|
15
|
+
export declare const SatisfactionRatingWidthValue: Story;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import Rating from './Rating';
|
|
2
|
+
import { RatingTypes } from '../../constants/FormStepTypes';
|
|
3
|
+
var meta = {
|
|
4
|
+
component: Rating,
|
|
5
|
+
tags: ['autodocs'],
|
|
6
|
+
args: {},
|
|
7
|
+
};
|
|
8
|
+
export default meta;
|
|
9
|
+
export var ScaleRating = {
|
|
10
|
+
args: {
|
|
11
|
+
type: RatingTypes.SCALE,
|
|
12
|
+
name: 'Rating',
|
|
13
|
+
focusColor: '#3d5a7f',
|
|
14
|
+
unSelectedColor: '#d8d8d8',
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
export var ScaleRatingWidthValue = {
|
|
18
|
+
args: {
|
|
19
|
+
type: RatingTypes.SCALE,
|
|
20
|
+
name: 'Rating',
|
|
21
|
+
focusColor: '#3d5a7f',
|
|
22
|
+
unSelectedColor: '#d8d8d8',
|
|
23
|
+
value: 4,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
export var LikeRating = {
|
|
27
|
+
args: {
|
|
28
|
+
type: RatingTypes.LIKE,
|
|
29
|
+
name: 'Rating',
|
|
30
|
+
focusColor: '#3d5a7f',
|
|
31
|
+
unSelectedColor: '#d8d8d8',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
export var LikeRatingWithValue = {
|
|
35
|
+
args: {
|
|
36
|
+
type: RatingTypes.LIKE,
|
|
37
|
+
name: 'Rating',
|
|
38
|
+
focusColor: '#3d5a7f',
|
|
39
|
+
unSelectedColor: '#d8d8d8',
|
|
40
|
+
value: 1,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
export var SatisfactionRating = {
|
|
44
|
+
args: {
|
|
45
|
+
type: RatingTypes.SATISFACTION,
|
|
46
|
+
name: 'Rating',
|
|
47
|
+
focusColor: '#3d5a7f',
|
|
48
|
+
unSelectedColor: '#d8d8d8',
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
export var SatisfactionRatingWidthValue = {
|
|
52
|
+
args: {
|
|
53
|
+
type: RatingTypes.SATISFACTION,
|
|
54
|
+
name: 'Rating',
|
|
55
|
+
focusColor: '#3d5a7f',
|
|
56
|
+
unSelectedColor: '#d8d8d8',
|
|
57
|
+
value: 3,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { StoryObj } from '@storybook/react';
|
|
2
|
+
import RoundedButton from './RoundedButton';
|
|
3
|
+
declare const meta: {
|
|
4
|
+
component: typeof RoundedButton;
|
|
5
|
+
tags: string[];
|
|
6
|
+
args: {
|
|
7
|
+
text: string;
|
|
8
|
+
backgroundColor: string;
|
|
9
|
+
color: string;
|
|
10
|
+
disabled: false;
|
|
11
|
+
fontSize: string;
|
|
12
|
+
padding: string;
|
|
13
|
+
borderRadius: number;
|
|
14
|
+
height: number;
|
|
15
|
+
bold: false;
|
|
16
|
+
width: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export default meta;
|
|
20
|
+
type Story = StoryObj<typeof meta>;
|
|
21
|
+
export declare const Default: Story;
|
|
22
|
+
export declare const Disabled: Story;
|
|
23
|
+
export declare const DifferentColors: Story;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import RoundedButton from './RoundedButton';
|
|
2
|
+
var meta = {
|
|
3
|
+
component: RoundedButton,
|
|
4
|
+
tags: ['autodocs'],
|
|
5
|
+
args: {
|
|
6
|
+
text: 'Label',
|
|
7
|
+
backgroundColor: '#3d5a7f',
|
|
8
|
+
color: '#ffffff',
|
|
9
|
+
disabled: false,
|
|
10
|
+
fontSize: '1rem',
|
|
11
|
+
padding: '0 13px 0 13px',
|
|
12
|
+
borderRadius: 10,
|
|
13
|
+
height: 28,
|
|
14
|
+
bold: false,
|
|
15
|
+
width: 'fit-content',
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
export default meta;
|
|
19
|
+
export var Default = {
|
|
20
|
+
args: {
|
|
21
|
+
text: 'Label',
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
export var Disabled = {
|
|
25
|
+
args: {
|
|
26
|
+
text: 'Label',
|
|
27
|
+
disabled: true,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
export var DifferentColors = {
|
|
31
|
+
args: {
|
|
32
|
+
text: 'Label',
|
|
33
|
+
backgroundColor: 'red',
|
|
34
|
+
color: 'blue',
|
|
35
|
+
},
|
|
36
|
+
};
|