@arquimedes.co/eureka-forms 3.0.34-test → 3.0.35-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/AppHooks.js +3 -0
- package/dist/Form/Form.d.ts +1 -1
- package/dist/Form/Form.js +5 -2
- package/dist/Form/FormHooks.d.ts +1 -1
- package/dist/Form/FormHooks.js +1 -0
- package/dist/Form/FormTypes/ColumnForm/ColumnForm.js +2 -0
- package/dist/Form/FormTypes/StepperForm/StepperForm.js +2 -0
- package/dist/Form/Terms/Terms.js +7 -3
- package/dist/FormSteps/@Construction/CBRIncidentsStep/MaterialCBRIncidentsStep/MaterialCBRIncidentsStep.js +23 -29
- package/dist/FormSteps/@Construction/CBRIncidentsStep/MaterialCBRIncidentsStep/addRecursiveElementStep.d.ts +2 -0
- package/dist/FormSteps/@Construction/CBRIncidentsStep/MaterialCBRIncidentsStep/addRecursiveElementStep.js +22 -0
- package/dist/FormSteps/@Construction/CBRPropertyStep/CBRPropertyStep.js +2 -2
- package/dist/FormSteps/ClassifierSelectorStep/MaterialClassifierSelectorStep/MaterialClassifierSelectorStep.js +6 -1
- package/dist/FormSteps/CollapsibleStep/MaterialTitleStep/MaterialCollapsibleStep.js +8 -9
- package/dist/FormSteps/DatePickerRangeStep/MaterialDatePickerRangeStep/MaterialDatePickerRangeStep.js +3 -3
- package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValuePickerStep.js +1 -0
- package/dist/FormSteps/FileUploadStep/MaterialFileUploadStep/MaterialFileUploadStep.js +44 -42
- package/dist/FormSteps/MapperStep/MaterialMapperStep/Element/MapperElementComponent.js +4 -4
- package/dist/FormSteps/MapperStep/MaterialMapperStep/Element/PagedMapperElement/PagedMapperElement.js +5 -1
- package/dist/FormSteps/MapperStep/MaterialMapperStep/MaterialMapperStep.js +10 -4
- package/dist/FormSteps/SelectorStep/MaterialSelectorStep/MaterialSelectorStep.js +7 -1
- package/dist/FormSteps/SmartSelectStep/MaterialSmartSelectStep/MaterialSmartSelectStep.js +9 -2
- package/dist/FormSteps/StepHooks.js +11 -4
- package/dist/FormSteps/TextAreaStep/MaterialTextAreaStep/MaterialTextAreaEditorStep.js +3 -1
- package/dist/FormSteps/Utils/@StepFiller/StepFiller.js +1 -0
- package/dist/Shared/CustomBtn/CustomBtn.js +1 -0
- package/dist/Shared/{ErkDatePickerRange/ErkDatePickerRange.d.ts → ErkDateRangePicker/ErkDateRangePicker.d.ts} +3 -3
- package/dist/Shared/{ErkDatePickerRange/ErkDatePickerRange.js → ErkDateRangePicker/ErkDateRangePicker.js} +2 -2
- package/dist/Shared/{ErkDatePickerRange/ErkDatePickerRange.stories.d.ts → ErkDateRangePicker/ErkDateRangePicker.stories.d.ts} +2 -2
- package/dist/Shared/{ErkDatePickerRange/ErkDatePickerRange.stories.js → ErkDateRangePicker/ErkDateRangePicker.stories.js} +23 -23
- package/dist/Shared/ErkMenuItem.d.ts +1 -3
- package/dist/Shared/ErkSelect/ErkSelect.d.ts +2 -6
- package/dist/Shared/ErkSelect/ErkSelect.js +1 -0
- package/dist/Shared/ErkSmartSelect/ErkSmartSelect.js +1 -1
- package/dist/Shared/ErkTextField/ErkTextField.js +13 -10
- package/dist/Shared/ErkTimePicker/ErkTimePicker.js +4 -4
- package/dist/Widget.js +3 -3
- package/package.json +73 -66
package/dist/App/AppHooks.js
CHANGED
|
@@ -125,6 +125,7 @@ export const useSetupApp = (isEmbedded, props) => {
|
|
|
125
125
|
// Use stringified keys for stable comparison - only changes when content changes
|
|
126
126
|
// Other object/function props (classifiers) are still
|
|
127
127
|
// intentionally excluded to prevent re-renders when parent re-creates these objects
|
|
128
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
128
129
|
}, [
|
|
129
130
|
apiKey,
|
|
130
131
|
partial,
|
|
@@ -149,6 +150,7 @@ export const useSetupApp = (isEmbedded, props) => {
|
|
|
149
150
|
if (handleConfirmed) {
|
|
150
151
|
handleConfirmed();
|
|
151
152
|
}
|
|
153
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
152
154
|
}, [form]);
|
|
153
155
|
return {
|
|
154
156
|
form,
|
|
@@ -174,5 +176,6 @@ export const useLogRocket = (organization, form, { apiKey, internal, postview, p
|
|
|
174
176
|
};
|
|
175
177
|
useEffect(() => {
|
|
176
178
|
void loadLogRocket();
|
|
179
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
177
180
|
}, [organization, form]);
|
|
178
181
|
};
|
package/dist/Form/Form.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface BaseFormProps extends CustomAppProps {
|
|
|
29
29
|
isWidget: boolean;
|
|
30
30
|
apiKey: string | undefined;
|
|
31
31
|
customSubmit: AppProps['customSubmit'];
|
|
32
|
-
containerRef: React.RefObject<HTMLDivElement>;
|
|
32
|
+
containerRef: React.RefObject<HTMLDivElement | null>;
|
|
33
33
|
scrollToTop?: () => void;
|
|
34
34
|
}
|
|
35
35
|
export interface FormComponentProps extends CustomAppProps {
|
package/dist/Form/Form.js
CHANGED
|
@@ -25,7 +25,7 @@ function FormComponent({ form, apiKey, reload, isWidget, branding, setSubmit, sc
|
|
|
25
25
|
shouldFocusError: true,
|
|
26
26
|
});
|
|
27
27
|
const idForm = useContext(IdFormContext);
|
|
28
|
-
const recaptchaRef = useRef();
|
|
28
|
+
const recaptchaRef = useRef(null);
|
|
29
29
|
const dispatch = useAppDispatch();
|
|
30
30
|
const [showConfirmation, setShowConfirmation] = useState();
|
|
31
31
|
const idFocusStep = useAppSelector((state) => state.site.focusStep);
|
|
@@ -34,6 +34,7 @@ function FormComponent({ form, apiKey, reload, isWidget, branding, setSubmit, sc
|
|
|
34
34
|
formMethods.setFocus(idFocusStep);
|
|
35
35
|
dispatch(focusStep(undefined));
|
|
36
36
|
}
|
|
37
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
37
38
|
}, [idFocusStep]);
|
|
38
39
|
const onSubmit = useCallback(async (values) => {
|
|
39
40
|
let token = null;
|
|
@@ -76,7 +77,9 @@ function FormComponent({ form, apiKey, reload, isWidget, branding, setSubmit, sc
|
|
|
76
77
|
catch (error) {
|
|
77
78
|
console.error(error);
|
|
78
79
|
}
|
|
79
|
-
},
|
|
80
|
+
},
|
|
81
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
82
|
+
[customSteps, internal, customSubmit, idOrganization, idForm]);
|
|
80
83
|
useWidthStats(containerRef, form, postview, internal);
|
|
81
84
|
const isResponsive = useAppSelector((state) => state.widthStats.isResponsive);
|
|
82
85
|
const renderForm = () => {
|
package/dist/Form/FormHooks.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Form } from '../@Types';
|
|
2
|
-
export declare function useWidthStats(containerRef: React.RefObject<HTMLDivElement>, form: Form, postview: boolean, internal: boolean): void;
|
|
2
|
+
export declare function useWidthStats(containerRef: React.RefObject<HTMLDivElement | null>, form: Form, postview: boolean, internal: boolean): void;
|
package/dist/Form/FormHooks.js
CHANGED
|
@@ -25,6 +25,7 @@ function ColumnForm({ onSubmit, customSubmitBtns, ...props }) {
|
|
|
25
25
|
useEffect(() => {
|
|
26
26
|
if (props.setSubmit)
|
|
27
27
|
props.setSubmit(submit);
|
|
28
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
28
29
|
}, [props.setSubmit]);
|
|
29
30
|
/** Esto se usa para no tener que escuchar todo el tiempo los errores del formulario */
|
|
30
31
|
const handleErrors = handleSubmit(() => { }, (errors) => {
|
|
@@ -46,6 +47,7 @@ function ColumnForm({ onSubmit, customSubmitBtns, ...props }) {
|
|
|
46
47
|
values = await onSubmit(values);
|
|
47
48
|
setLoading(false);
|
|
48
49
|
return values;
|
|
50
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
49
51
|
}, [form]);
|
|
50
52
|
return (_jsxs("div", { className: styles.container, style: { color: formStyle.textColor }, children: [loading && _jsx("div", { className: styles.curtain }), previous.map((idSection) => (_jsx(Section, { idSection: idSection }, idSection))), next.map((idSection) => (_jsx(Section, { idSection: idSection }, idSection))), _jsx(Terms, {}), !postview && editable && (_jsxs(React.Fragment, { children: [customSubmitBtns === undefined && (_jsx("div", { className: styles.submitBtnContainer, children: _jsx(CustomBtn, { onClick: () => void submit(), width: "calc(100% - 70px)", label: sendLabel ?? 'Enviar', backgroundColor: formStyle.primaryColor, color: formStyle.primaryContrastColor, loading: loading, "data-testid": "form__submit" }) })), customSubmitBtns?.(submit, loading)] }))] }));
|
|
51
53
|
}
|
|
@@ -29,6 +29,7 @@ function StepperForm({ onSubmit, scrollToTop }) {
|
|
|
29
29
|
const handlePrevious = useCallback(() => {
|
|
30
30
|
dispatch(SiteReducer.handlePrevious({ values: getValues(), form }));
|
|
31
31
|
scrollToTop?.();
|
|
32
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
32
33
|
}, []);
|
|
33
34
|
const handleNext = useCallback(async () => {
|
|
34
35
|
setLoading('NEXT');
|
|
@@ -57,6 +58,7 @@ function StepperForm({ onSubmit, scrollToTop }) {
|
|
|
57
58
|
const response = await onSubmit(values);
|
|
58
59
|
setLoading(undefined);
|
|
59
60
|
return response;
|
|
61
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
60
62
|
}, [next]);
|
|
61
63
|
if (!idCurrent)
|
|
62
64
|
return _jsx(_Fragment, {});
|
package/dist/Form/Terms/Terms.js
CHANGED
|
@@ -14,10 +14,14 @@ function Terms() {
|
|
|
14
14
|
useEffect(() => {
|
|
15
15
|
if (!isSubmitting)
|
|
16
16
|
return;
|
|
17
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
17
18
|
setTempError(true);
|
|
18
|
-
setTimeout(() => {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const timer = setTimeout(() => {
|
|
20
|
+
setTimeout(() => {
|
|
21
|
+
setTempError(false);
|
|
22
|
+
}, 500);
|
|
23
|
+
}, 0);
|
|
24
|
+
return () => clearTimeout(timer);
|
|
21
25
|
}, [isSubmitting]);
|
|
22
26
|
if (form.terms && (!internal || (internal && postview)) && !isInteralAgent) {
|
|
23
27
|
return (_jsx("div", { className: styles.termsContainer, style: {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useContext, useEffect, useState } from 'react';
|
|
2
|
+
import { useCallback, useContext, useEffect, useLayoutEffect, useState } from 'react';
|
|
3
3
|
import CBRFormStepTypes from '../../../../constants/CBRFormStepTypes';
|
|
4
4
|
import IncidentComponent from './Incident/Incident';
|
|
5
5
|
import styles from './MaterialCBRIncidentsStep.module.css';
|
|
6
6
|
import { nanoid } from 'nanoid';
|
|
7
|
+
import { addRecursiveElementStep } from './addRecursiveElementStep';
|
|
7
8
|
import ErkButton from '../../../../Shared/ErkButton/ErkButton';
|
|
8
9
|
import FormContext from '../../../../Contexts/FormContext';
|
|
9
10
|
import { addStepsDependencies } from '../../../../States/SiteSlice';
|
|
@@ -27,15 +28,10 @@ function CBRIncidentsStep({ step, editable, ...others }) {
|
|
|
27
28
|
steps: { ...form.steps },
|
|
28
29
|
});
|
|
29
30
|
const [firstRender, setFirstRender] = useState(false);
|
|
30
|
-
|
|
31
|
+
useLayoutEffect(() => {
|
|
31
32
|
setFirstRender(true);
|
|
32
|
-
}, []);
|
|
33
|
-
|
|
34
|
-
if (firstRender && value.length === 0 && !postview && editable) {
|
|
35
|
-
handleAddIncident();
|
|
36
|
-
}
|
|
37
|
-
}, [firstRender]);
|
|
38
|
-
const handleAddIncident = () => {
|
|
33
|
+
}, [setFirstRender]);
|
|
34
|
+
const handleAddIncident = useCallback(() => {
|
|
39
35
|
const current = value.filter((incident) => !incident.deleted);
|
|
40
36
|
const newIncident = {
|
|
41
37
|
idSpaceStep: CBRFormStepTypes.CBR_TIPO_ESPACIO + '-' + nanoid(),
|
|
@@ -65,27 +61,25 @@ function CBRIncidentsStep({ step, editable, ...others }) {
|
|
|
65
61
|
customSteps,
|
|
66
62
|
allSteps: { ...form.steps, ...localForm.steps, ...newSteps },
|
|
67
63
|
}));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
steps[idStep] = newStep;
|
|
85
|
-
if (newSubStep) {
|
|
86
|
-
addRecursiveElementStep(idSubStep, newSubStep, idStep, steps, idProjectDep);
|
|
64
|
+
}, [
|
|
65
|
+
customSteps,
|
|
66
|
+
dispatch,
|
|
67
|
+
form.steps,
|
|
68
|
+
localForm,
|
|
69
|
+
onChange,
|
|
70
|
+
step.commentStep,
|
|
71
|
+
step.dependencies,
|
|
72
|
+
step.elementStep,
|
|
73
|
+
step.spaceStep,
|
|
74
|
+
value,
|
|
75
|
+
]);
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (firstRender && value.length === 0 && !postview && editable) {
|
|
78
|
+
const timer = setTimeout(() => handleAddIncident(), 0);
|
|
79
|
+
return () => clearTimeout(timer);
|
|
87
80
|
}
|
|
88
|
-
|
|
81
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
82
|
+
}, [firstRender]);
|
|
89
83
|
return (_jsxs("div", { className: styles.container, style: { color: formStyle.textColor }, children: [_jsx("div", { className: styles.titleLbl, children: step.label }), step.description && (_jsx("p", { className: styles.descriptionPar, style: {
|
|
90
84
|
margin: step.description ? '10px 0px' : '0px 0px 5px 0px',
|
|
91
85
|
}, children: step.description })), _jsx(FormContext.Provider, { value: localForm, children: value.map((incident, index) => (_jsx(IncidentComponent, { incident: incident, step: step, editable: editable, handleDelete: () => {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { nanoid } from 'nanoid';
|
|
2
|
+
import CBRFormStepTypes from '../../../../constants/CBRFormStepTypes';
|
|
3
|
+
export const addRecursiveElementStep = (idStep, step, idParent, steps, idProjectDep) => {
|
|
4
|
+
const idSubStep = CBRFormStepTypes.CBR_LOCATIVAS + '-' + nanoid();
|
|
5
|
+
const newSubStep = step.subStep ? { ...step.subStep } : undefined;
|
|
6
|
+
const newStep = {
|
|
7
|
+
...step,
|
|
8
|
+
id: idStep,
|
|
9
|
+
type: CBRFormStepTypes.CBR_LOCATIVAS,
|
|
10
|
+
dependencies: [idProjectDep],
|
|
11
|
+
subStep: null,
|
|
12
|
+
};
|
|
13
|
+
if (idParent)
|
|
14
|
+
newStep.dependencies.push(idParent);
|
|
15
|
+
if (newSubStep) {
|
|
16
|
+
newStep.subStep = idSubStep;
|
|
17
|
+
}
|
|
18
|
+
steps[idStep] = newStep;
|
|
19
|
+
if (newSubStep) {
|
|
20
|
+
addRecursiveElementStep(idSubStep, newSubStep, idStep, steps, idProjectDep);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -43,7 +43,7 @@ function CBRPropertyStepComponent(props) {
|
|
|
43
43
|
return undefined;
|
|
44
44
|
}, getValueString: (value) => value?.id, getValueWarning: props.step.validation
|
|
45
45
|
? (value) => {
|
|
46
|
-
if (value
|
|
46
|
+
if (value?.entrega !== undefined && props.step.validation) {
|
|
47
47
|
const date = new Date(value.entrega);
|
|
48
48
|
const today = new Date();
|
|
49
49
|
const time = today.getTime() - date.getTime();
|
|
@@ -56,7 +56,7 @@ function CBRPropertyStepComponent(props) {
|
|
|
56
56
|
}
|
|
57
57
|
: undefined, changeListener: props.step.validation
|
|
58
58
|
? (value) => {
|
|
59
|
-
if (value
|
|
59
|
+
if (value?.entrega !== undefined && props.step.validation) {
|
|
60
60
|
const date = new Date(value.entrega);
|
|
61
61
|
const today = new Date();
|
|
62
62
|
const time = today.getTime() - date.getTime();
|
|
@@ -25,8 +25,10 @@ function ClassifierSelectorStep({ step, editable }) {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
return dependencies;
|
|
28
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
28
29
|
}, []);
|
|
29
30
|
const dependencies = useAppSelector((state) => selectDependencies(state, idDependencies));
|
|
31
|
+
const dependenciesValues = useMemo(() => idDependencies.map((id) => dependencies[id].value), [dependencies, idDependencies]);
|
|
30
32
|
const { postview, preview } = useAppSelector((state) => state.global);
|
|
31
33
|
const form = useContext(FormContext);
|
|
32
34
|
const classifier = form.classifiers?.[step.idClassifier ?? ''];
|
|
@@ -46,11 +48,14 @@ function ClassifierSelectorStep({ step, editable }) {
|
|
|
46
48
|
label: classifier?.clientName?.trim?.() && preview ? classifier?.clientName : classifier?.name,
|
|
47
49
|
};
|
|
48
50
|
});
|
|
49
|
-
},
|
|
51
|
+
},
|
|
52
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
53
|
+
[dependenciesValues]);
|
|
50
54
|
useEffect(() => {
|
|
51
55
|
if (value && !options?.find((option) => option.value === value?.value)) {
|
|
52
56
|
onChange('');
|
|
53
57
|
}
|
|
58
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
54
59
|
}, [options]);
|
|
55
60
|
if (!step.idClassifier || !classifier)
|
|
56
61
|
return _jsx(_Fragment, {});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createElement as _createElement } from "react";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import React, { useContext, useEffect, useState } from 'react';
|
|
3
|
+
import React, { useContext, useEffect, useMemo, useState } from 'react';
|
|
4
4
|
import styles from './MaterialCollapsibleStep.module.css';
|
|
5
5
|
import { Controller, useFormContext } from 'react-hook-form';
|
|
6
6
|
import StepComponent from '../../Step';
|
|
@@ -14,11 +14,14 @@ function Collapsible({ step, open, setOpen, ...others }) {
|
|
|
14
14
|
const form = useContext(FormContext);
|
|
15
15
|
const { formState: { errors }, } = useFormContext();
|
|
16
16
|
const contentRef = React.useRef(null);
|
|
17
|
+
const depsErrors = useMemo(() => step.dependencies?.map((dep) => errors[dep]) ?? [], [step.dependencies, errors]);
|
|
17
18
|
useEffect(() => {
|
|
18
|
-
|
|
19
|
+
//TODO: review this
|
|
20
|
+
if (!open && depsErrors.find((dep) => !!dep)) {
|
|
19
21
|
setOpen(true);
|
|
20
22
|
}
|
|
21
|
-
|
|
23
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
24
|
+
}, [depsErrors]);
|
|
22
25
|
return (_jsxs("div", { style: { maxWidth: '100%' }, children: [_jsxs("div", { className: styles.container, style: {
|
|
23
26
|
color: formStyle.textColor,
|
|
24
27
|
borderColor: formStyle.primaryColor,
|
|
@@ -31,14 +34,10 @@ function Collapsible({ step, open, setOpen, ...others }) {
|
|
|
31
34
|
setFirstTime(false);
|
|
32
35
|
setOpen(!open);
|
|
33
36
|
}, children: _jsx("div", { className: styles.expandIcon, children: open ? (_jsx(ExpandLessIcon, { style: { fontSize: 'inherit' } })) : (_jsx(ExpandMoreIcon, { style: { fontSize: 'inherit' } })) }) })] }), _jsx("div", { className: styles.content, style: {
|
|
34
|
-
height: open
|
|
35
|
-
? firstTime
|
|
36
|
-
? 'auto'
|
|
37
|
-
: contentRef.current?.offsetHeight
|
|
38
|
-
: 0,
|
|
37
|
+
height: open ? (firstTime ? 'auto' : contentRef.current?.offsetHeight) : 0,
|
|
39
38
|
}, children: _jsx("div", { className: styles.contentContainer, ref: contentRef, children: step.steps.map((idSubStep) => {
|
|
40
39
|
const subStep = form.steps[idSubStep];
|
|
41
|
-
return
|
|
40
|
+
return _createElement(StepComponent, { ...others, step: subStep, key: idSubStep });
|
|
42
41
|
}) }) }), _jsx("div", { className: styles.separator, style: {
|
|
43
42
|
backgroundColor: formStyle.primaryColor,
|
|
44
43
|
} })] }));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback } from 'react';
|
|
3
|
-
import
|
|
3
|
+
import ErkDateRangePicker from '../../../Shared/ErkDateRangePicker/ErkDateRangePicker';
|
|
4
4
|
import { useAppSelector } from '../../../hooks';
|
|
5
5
|
import { useFormStep } from '../../StepHooks';
|
|
6
6
|
import MaterialInputContainer from '../../Utils/MaterialInputContainer/MaterialInputContainer';
|
|
@@ -28,7 +28,7 @@ function MaterialDatePickerRangeStep({ step, editable, defaultValue }) {
|
|
|
28
28
|
}
|
|
29
29
|
}, [onChange]);
|
|
30
30
|
const [minDate, maxDate] = [safeDate(step.minDate), safeDate(step.maxDate)];
|
|
31
|
-
const dateRangeValue = value
|
|
32
|
-
return (_jsx(MaterialInputContainer, { step: step, editable: editable, children: _jsx(
|
|
31
|
+
const dateRangeValue = value?.length === 2 ? [safeDate(value[0]) ?? null, safeDate(value[1]) ?? null] : [null, null];
|
|
32
|
+
return (_jsx(MaterialInputContainer, { step: step, editable: editable, children: _jsx(ErkDateRangePicker, { ...field, value: dateRangeValue, inputRef: ref, error: !!error, minDate: minDate, maxDate: maxDate, labelMargin: 0, onChange: handleChange, required: step.required, readOnly: !editable || postview, helperText: error?.message ?? step.description }) }));
|
|
33
33
|
}
|
|
34
34
|
export default MaterialDatePickerRangeStep;
|
|
@@ -22,6 +22,7 @@ function EntityValuePickerStep({ step, editable }) {
|
|
|
22
22
|
ids.push(...recursivelyCalcConditionSteps(dialog.condition));
|
|
23
23
|
}
|
|
24
24
|
return ids;
|
|
25
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
25
26
|
}, []);
|
|
26
27
|
const dialogDeps = useAppSelector((state) => selectDependencies(state, dialogsIdStepDeps));
|
|
27
28
|
const handleCloseDialog = useCallback(() => {
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import styles from './MaterialFileUploadStep.module.css';
|
|
3
3
|
import { useFormContext } from 'react-hook-form';
|
|
4
4
|
import ErkButton from '../../../Shared/ErkButton/ErkButton';
|
|
5
|
-
import { useContext, useEffect, useRef, useState } from 'react';
|
|
5
|
+
import { useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
6
6
|
import { getAcceptedExtensions } from '../../../constants/Files/FileExtensions';
|
|
7
7
|
import { getUploadUrls, postFile } from '../../../Services/FileService';
|
|
8
8
|
import FileComponent from './FileComponent/FileComponent';
|
|
@@ -23,7 +23,47 @@ function FileUploadStep({ step, editable }) {
|
|
|
23
23
|
const { clearErrors } = useFormContext();
|
|
24
24
|
const [error, setError] = useState(undefined);
|
|
25
25
|
const [fileChange, setFileChange] = useState([]);
|
|
26
|
-
const inputRef = useRef();
|
|
26
|
+
const inputRef = useRef(null);
|
|
27
|
+
const getLinks = useCallback(async (pFiles) => {
|
|
28
|
+
try {
|
|
29
|
+
const fileLinks = await getUploadUrls(pFiles.map((file) => file.file), idOrganization);
|
|
30
|
+
const errorsExt = [];
|
|
31
|
+
setFileChange(pFiles.map((file, index) => {
|
|
32
|
+
if (fileLinks[index] === 'ERROR:INVALIDEXTENSION') {
|
|
33
|
+
errorsExt.push(file.file.name.split('.').pop() ?? '');
|
|
34
|
+
return { ...file, state: 'ERROR' };
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return {
|
|
38
|
+
...file,
|
|
39
|
+
state: 'UPLOADING',
|
|
40
|
+
postInfo: fileLinks[index],
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}));
|
|
44
|
+
if (errorsExt.length === 1) {
|
|
45
|
+
setError('La extención .' + errorsExt[0] + ' no es válida');
|
|
46
|
+
}
|
|
47
|
+
else if (errorsExt.length > 1) {
|
|
48
|
+
setError('Las extenciónes .' + errorsExt.join(',.') + ' no son válidas');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
console.error(error);
|
|
53
|
+
}
|
|
54
|
+
}, [idOrganization]);
|
|
55
|
+
const uploadFile = useCallback(async (pFile) => {
|
|
56
|
+
try {
|
|
57
|
+
const resp = await Promise.all([
|
|
58
|
+
postFile(pFile.file, pFile.postInfo),
|
|
59
|
+
new Promise((resolve) => setTimeout(resolve, 1000)),
|
|
60
|
+
]);
|
|
61
|
+
setFileChange([{ ...pFile, state: 'DONE', ...resp[0] }]);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.error(error);
|
|
65
|
+
}
|
|
66
|
+
}, []);
|
|
27
67
|
useEffect(() => {
|
|
28
68
|
const filesToFetchLink = [];
|
|
29
69
|
const filesChanged = [];
|
|
@@ -32,6 +72,7 @@ function FileUploadStep({ step, editable }) {
|
|
|
32
72
|
filesToFetchLink.push(file);
|
|
33
73
|
}
|
|
34
74
|
if (file.state === 'UPLOADING') {
|
|
75
|
+
// eslint-disable-next-line
|
|
35
76
|
void uploadFile(file);
|
|
36
77
|
filesChanged.push(file);
|
|
37
78
|
}
|
|
@@ -64,47 +105,8 @@ function FileUploadStep({ step, editable }) {
|
|
|
64
105
|
void getLinks(filesToFetchLink);
|
|
65
106
|
onChange([...value, ...filesToFetchLink]);
|
|
66
107
|
}
|
|
108
|
+
// eslint-disable-next-line
|
|
67
109
|
}, [fileChange]);
|
|
68
|
-
async function getLinks(pFiles) {
|
|
69
|
-
try {
|
|
70
|
-
const fileLinks = await getUploadUrls(pFiles.map((file) => file.file), idOrganization);
|
|
71
|
-
const errorsExt = [];
|
|
72
|
-
setFileChange(pFiles.map((file, index) => {
|
|
73
|
-
if (fileLinks[index] === 'ERROR:INVALIDEXTENSION') {
|
|
74
|
-
errorsExt.push(file.file.name.split('.').pop() ?? '');
|
|
75
|
-
return { ...file, state: 'ERROR' };
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
return {
|
|
79
|
-
...file,
|
|
80
|
-
state: 'UPLOADING',
|
|
81
|
-
postInfo: fileLinks[index],
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
}));
|
|
85
|
-
if (errorsExt.length === 1) {
|
|
86
|
-
setError('La extención .' + errorsExt[0] + ' no es válida');
|
|
87
|
-
}
|
|
88
|
-
else if (errorsExt.length > 1) {
|
|
89
|
-
setError('Las extenciónes .' + errorsExt.join(',.') + ' no son válidas');
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
console.error(error);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
async function uploadFile(pFile) {
|
|
97
|
-
try {
|
|
98
|
-
const resp = await Promise.all([
|
|
99
|
-
postFile(pFile.file, pFile.postInfo),
|
|
100
|
-
new Promise((resolve) => setTimeout(resolve, 1000)),
|
|
101
|
-
]);
|
|
102
|
-
setFileChange([{ ...pFile, state: 'DONE', ...resp[0] }]);
|
|
103
|
-
}
|
|
104
|
-
catch (error) {
|
|
105
|
-
console.error(error);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
110
|
const calcErrorMsg = () => {
|
|
109
111
|
if (fieldError) {
|
|
110
112
|
const errNum = value.filter((val) => val.state === 'ERROR').length;
|
|
@@ -9,17 +9,17 @@ import FormContext from '../../../../Contexts/FormContext';
|
|
|
9
9
|
import CustomContext from '../../../../Contexts/CustomContext';
|
|
10
10
|
import PagedMapperElement from './PagedMapperElement/PagedMapperElement';
|
|
11
11
|
function MapperElementComponent(props) {
|
|
12
|
-
const { step, element, editable } = props;
|
|
12
|
+
const { step, element, editable, calcCustomStepProps } = props;
|
|
13
13
|
const customContext = useContext(CustomContext);
|
|
14
14
|
const form = useContext(FormContext);
|
|
15
15
|
const nestedCustomContext = useMemo(() => {
|
|
16
|
-
if (!
|
|
16
|
+
if (!calcCustomStepProps)
|
|
17
17
|
return customContext;
|
|
18
18
|
return {
|
|
19
19
|
...customContext,
|
|
20
|
-
customStepProps:
|
|
20
|
+
customStepProps: calcCustomStepProps(element, customContext.customStepProps),
|
|
21
21
|
};
|
|
22
|
-
}, [element, customContext]);
|
|
22
|
+
}, [element, customContext, calcCustomStepProps]);
|
|
23
23
|
if (element.deleted)
|
|
24
24
|
return _jsx(_Fragment, {});
|
|
25
25
|
const mapSubSteps = () => {
|
|
@@ -29,6 +29,7 @@ function PagedMapperElement({ step, num, loading, element, children, editable, o
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
return null;
|
|
32
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
32
33
|
}, [value]);
|
|
33
34
|
const prevIndex = useMemo(() => {
|
|
34
35
|
for (let i = page - 1; i >= 0; i--) {
|
|
@@ -38,6 +39,7 @@ function PagedMapperElement({ step, num, loading, element, children, editable, o
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
return null;
|
|
42
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
41
43
|
}, [value]);
|
|
42
44
|
/** Esto se usa para no tener que escuchar todo el tiempo los errores del formulario */
|
|
43
45
|
const handleErrors = handleSubmit(() => { }, (errors) => {
|
|
@@ -68,7 +70,9 @@ function PagedMapperElement({ step, num, loading, element, children, editable, o
|
|
|
68
70
|
page: index,
|
|
69
71
|
});
|
|
70
72
|
return;
|
|
71
|
-
},
|
|
73
|
+
},
|
|
74
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
75
|
+
[elements]);
|
|
72
76
|
const widthStats = useAppSelector((state) => state.widthStats);
|
|
73
77
|
const { calcName } = customElementModifiers ?? {};
|
|
74
78
|
const name = calcName ? calcName(element) : step.unitLabel ? step.unitLabel + ' ' + (num + 1) : '';
|
|
@@ -33,7 +33,9 @@ function MapperComponent({ form, step, error, value, loading, inputRef, editable
|
|
|
33
33
|
elements: tempElements,
|
|
34
34
|
page: page === index ? newPage : page,
|
|
35
35
|
});
|
|
36
|
-
},
|
|
36
|
+
},
|
|
37
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
38
|
+
[elements, onChange]);
|
|
37
39
|
const inputValue = useMemo(() => JSON.stringify(elements), [elements]);
|
|
38
40
|
const { formStyle, postview } = useAppSelector((state) => state.global);
|
|
39
41
|
const { container } = useMemo(() => {
|
|
@@ -87,6 +89,7 @@ function MapperStep(props) {
|
|
|
87
89
|
if (!customAdd)
|
|
88
90
|
handleAddElement();
|
|
89
91
|
}
|
|
92
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
90
93
|
}, []);
|
|
91
94
|
const handleAddElement = useCallback((elementValue) => {
|
|
92
95
|
const { element, steps, mappers } = addMapperStep(step, customSteps);
|
|
@@ -106,7 +109,10 @@ function MapperStep(props) {
|
|
|
106
109
|
customSteps,
|
|
107
110
|
allSteps: { ...form.steps, ...steps },
|
|
108
111
|
}));
|
|
109
|
-
},
|
|
112
|
+
},
|
|
113
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
114
|
+
[step, form, customSteps, value, onChange]);
|
|
115
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
110
116
|
const subForm = useMemo(() => ({ ...form, steps: { ...form.steps, ...localSteps } }), [localSteps]);
|
|
111
117
|
return (_jsx(MapperComponent, { ...props, error: error, inputRef: ref, onChange: onChange, value: value, handleAddElement: handleAddElement, form: subForm }));
|
|
112
118
|
}
|
|
@@ -136,8 +142,8 @@ export function CustomMapperStep(props) {
|
|
|
136
142
|
customSteps,
|
|
137
143
|
allSteps: { ...form.steps, ...steps },
|
|
138
144
|
}));
|
|
139
|
-
}, [step, form, customSteps, elements, onChange]);
|
|
140
|
-
const subForm = useMemo(() => ({ ...form, steps: { ...form.steps, ...localSteps } }), [localSteps]);
|
|
145
|
+
}, [step, form, customSteps, elements, onChange, dispatch, setValue]);
|
|
146
|
+
const subForm = useMemo(() => ({ ...form, steps: { ...form.steps, ...localSteps } }), [localSteps, form]);
|
|
141
147
|
return _jsx(MapperComponent, { ...props, form: subForm, onChange: onChange, handleAddElement: handleAddElement });
|
|
142
148
|
}
|
|
143
149
|
export default MapperStep;
|
|
@@ -27,6 +27,7 @@ function SelectorStep({ step, editable }) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
return dependencies;
|
|
30
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
31
|
}, []);
|
|
31
32
|
const dependencies = useAppSelector((state) => selectDependencies(state, idDependencies));
|
|
32
33
|
const mapNestedOption = () => {
|
|
@@ -47,17 +48,22 @@ function SelectorStep({ step, editable }) {
|
|
|
47
48
|
}
|
|
48
49
|
return null;
|
|
49
50
|
};
|
|
51
|
+
const dependenciesValues = useMemo(() => {
|
|
52
|
+
return idDependencies.map((id) => dependencies[id].value);
|
|
53
|
+
}, [dependencies, idDependencies]);
|
|
50
54
|
const filteredOptions = useMemo(() => {
|
|
51
55
|
return step.options.filter((option) => {
|
|
52
56
|
if (!option.condition || evaluateCondition(option.condition, dependencies))
|
|
53
57
|
return true;
|
|
54
58
|
return false;
|
|
55
59
|
});
|
|
56
|
-
|
|
60
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
61
|
+
}, [dependenciesValues]);
|
|
57
62
|
useEffect(() => {
|
|
58
63
|
if (value && !filteredOptions.find((option) => option.value === value?.value)) {
|
|
59
64
|
onChange('');
|
|
60
65
|
}
|
|
66
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
61
67
|
}, [filteredOptions]);
|
|
62
68
|
return (_jsxs(React.Fragment, { children: [_jsx(MaterialInputContainer, { step: step, editable: editable, children: _jsx(ErkSmartSelect, { ...field, value: value, inputRef: ref, error: !!error, label: step.label, onChange: onChange, required: step.required, options: filteredOptions, searchable: step.searchable, readOnly: !editable || postview, helperText: error?.message?.toString() ?? step.description, getOptionSelected: (option, value) => option?.value === value?.value }) }), value && mapNestedOption()] }));
|
|
63
69
|
}
|
|
@@ -31,8 +31,11 @@ function SmartSelectStep({ step, editable, getOptions, calcDepError, defaultValu
|
|
|
31
31
|
const allDeps = useMemo(() => [...(step.dependencies ?? []), ...getOptionalDependencies(step)], [getOptionalDependencies, step]);
|
|
32
32
|
const idDependencies = useMemo(() => getOptionsConditionsIdSteps(step), [getOptionsConditionsIdSteps, step]);
|
|
33
33
|
const dependencies = useAppSelector((state) => selectDependencies(state, allDeps));
|
|
34
|
+
const allDepsValues = useMemo(() => allDeps.map((dep) => dependencies[dep]?.value), [dependencies, allDeps]);
|
|
34
35
|
const deps = useAppSelector((state) => selectDependencies(state, idDependencies));
|
|
35
|
-
const
|
|
36
|
+
const dependenciesValues = useMemo(() => idDependencies.map((id) => deps[id]?.value), [deps, idDependencies]);
|
|
37
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
38
|
+
const conditionDependencies = useMemo(() => deps, [dependenciesValues]);
|
|
36
39
|
const { emptyDep, invalids } = useAppSelector((state) => selectStepDependencies(state, step, form));
|
|
37
40
|
const { getValues, setFocus } = useFormContext();
|
|
38
41
|
const isEmpty = useAppSelector((state) => state.site.dependencies[step.id]?.empty);
|
|
@@ -45,7 +48,8 @@ function SmartSelectStep({ step, editable, getOptions, calcDepError, defaultValu
|
|
|
45
48
|
else if (value && !step.searchable) {
|
|
46
49
|
setOptions([value]);
|
|
47
50
|
}
|
|
48
|
-
|
|
51
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
52
|
+
}, [allDepsValues]);
|
|
49
53
|
const calcOptions = async (firstTime) => {
|
|
50
54
|
if (!firstTime)
|
|
51
55
|
setOptions(undefined);
|
|
@@ -110,11 +114,13 @@ function SmartSelectStep({ step, editable, getOptions, calcDepError, defaultValu
|
|
|
110
114
|
}
|
|
111
115
|
if (!touched)
|
|
112
116
|
setTouched(true);
|
|
117
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
113
118
|
}, [options, emptyDep, postview, editable, invalids, touched]);
|
|
114
119
|
const filteredOptions = useMemo(() => {
|
|
115
120
|
if (!options || !filterOptions)
|
|
116
121
|
return options;
|
|
117
122
|
return filterOptions(options, conditionDependencies);
|
|
123
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
118
124
|
}, [options, conditionDependencies]);
|
|
119
125
|
const errorMsg = useMemo(() => {
|
|
120
126
|
if (postview || loading)
|
|
@@ -132,6 +138,7 @@ function SmartSelectStep({ step, editable, getOptions, calcDepError, defaultValu
|
|
|
132
138
|
return 'Error al cargar las opciones';
|
|
133
139
|
}
|
|
134
140
|
return undefined;
|
|
141
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
135
142
|
}, [invalids, touched, value, filteredOptions]);
|
|
136
143
|
return (_jsxs(React.Fragment, { children: [_jsx(MaterialInputContainer, { step: step, onClick: onFocus, editable: editable, children: _jsx(ErkSmartSelect, { ...field, value: value, inputRef: ref, onFocus: onFocus, loading: loading, label: step.label, onChange: onChange, required: step.required, searchable: step.searchable, getValueString: getValueString, disabled: emptyDep, getOptionSelected: getOptionSelected, options: filteredOptions ?? undefined, IconComponent: step.showIcon ? IconComponent : undefined, error: !!errorMsg || !!warning || !!error, readOnly: !editable || postview || emptyDep || filteredOptions === null, helperText: errorMsg ?? warning ?? error?.message?.toString() ?? step.description ?? undefined }) }), renderNestedSteps?.(value)] }));
|
|
137
144
|
}
|