@arquimedes.co/eureka-forms 3.0.19-refactor → 3.0.21-refactor

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 (57) hide show
  1. package/dist/@Types/FormStep.d.ts +7 -3
  2. package/dist/@Types/GenericFormSteps.d.ts +1 -0
  3. package/dist/App/App.css +11 -0
  4. package/dist/App/App.d.ts +6 -0
  5. package/dist/App/App.js +3 -1
  6. package/dist/App/AppFunctions.d.ts +4 -4
  7. package/dist/App/AppFunctions.test.js +70 -0
  8. package/dist/App/AppHooks.d.ts +1 -1
  9. package/dist/App/AppHooks.js +11 -2
  10. package/dist/Contexts/CustomContext.d.ts +3 -0
  11. package/dist/Form/ConfirmationDialog/ConfirmationDialog.d.ts +2 -1
  12. package/dist/Form/ConfirmationDialog/ConfirmationDialog.js +4 -10
  13. package/dist/Form/Form.d.ts +2 -0
  14. package/dist/Form/FormFunctions.js +4 -0
  15. package/dist/Form/FormFunctions.test.js +4 -0
  16. package/dist/FormSteps/@Construction/CBRElementStep/CBRElementStep.js +1 -1
  17. package/dist/FormSteps/@Construction/CBRPropertyStep/CBRPropertyStep.js +1 -1
  18. package/dist/FormSteps/AYFStepMapper.js +1 -1
  19. package/dist/FormSteps/ApiSelectorStep/MaterialApiSelectorStep/MaterialApiSelectorStep.js +1 -1
  20. package/dist/FormSteps/CBRStepMapper.js +5 -5
  21. package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValuePickerStep.js +9 -5
  22. package/dist/FormSteps/SmartSelectStep/MaterialSmartSelectStep/MaterialSmartSelectStep.js +6 -3
  23. package/dist/FormSteps/SmartSelectStep/SmartSelectStep.d.ts +7 -4
  24. package/dist/FormSteps/StepFunctions.d.ts +1 -1
  25. package/dist/FormSteps/StepFunctions.js +7 -4
  26. package/dist/FormSteps/StepFunctions.test.js +2 -2
  27. package/dist/FormSteps/TitleStep/MaterialTitleStep/MaterialTitleStep.js +27 -16
  28. package/dist/Services/DraftService.d.ts +23 -0
  29. package/dist/Services/DraftService.js +30 -0
  30. package/dist/Shared/ErkDatePicker/ErkDatePicker.d.ts +2 -2
  31. package/dist/Shared/ErkSelect/ErkSelect.js +1 -1
  32. package/dist/Shared/ErkTimePicker/ErkTimePicker.js +1 -1
  33. package/dist/Shared/SmartDraftRenderer/DraftLoadingContext.d.ts +1 -0
  34. package/dist/Shared/SmartDraftRenderer/DraftLoadingContext.js +2 -0
  35. package/dist/Shared/SmartDraftRenderer/FormDecorator.d.ts +12 -0
  36. package/dist/Shared/SmartDraftRenderer/FormDecorator.js +20 -0
  37. package/dist/Shared/SmartDraftRenderer/FormDecorator.module.css +30 -0
  38. package/dist/Shared/SmartDraftRenderer/SmartDraftRenderer.d.ts +11 -0
  39. package/dist/Shared/SmartDraftRenderer/SmartDraftRenderer.js +58 -0
  40. package/dist/States/GlobalSlice.d.ts +4 -0
  41. package/dist/Utils/AxiosAPI.d.ts +10 -0
  42. package/dist/Utils/AxiosAPI.js +22 -0
  43. package/dist/Utils/MaterialProviders.d.ts +1 -1
  44. package/dist/Utils/MaterialProviders.js +1 -1
  45. package/dist/Utils/StoreContext.d.ts +2 -0
  46. package/dist/Utils/StoreContext.js +2 -0
  47. package/dist/Utils/TestUtils.d.ts +8 -2
  48. package/dist/Utils/TestUtils.js +11 -4
  49. package/dist/Utils/_api.d.ts +8 -0
  50. package/dist/Utils/_api.js +15 -0
  51. package/dist/Utils/store.d.ts +9 -3
  52. package/dist/Utils/store.js +7 -1
  53. package/dist/constants/FormStepTypes.d.ts +2 -1
  54. package/dist/constants/FormStepTypes.js +1 -0
  55. package/dist/hooks.d.ts +0 -2
  56. package/dist/hooks.js +1 -2
  57. package/package.json +17 -17
@@ -1,16 +1,16 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React, { useCallback, useContext, useMemo, useState } from 'react';
3
3
  import FormStepTypes, { EntityValueDataTypes, EntityValueOptionTypes } from '../../../constants/FormStepTypes';
4
- import StepComponent from '../../Step';
5
4
  import SmartSelect from '../../SmartSelectStep/MaterialSmartSelectStep/MaterialSmartSelectStep';
6
5
  import widgetInstance from '../../../Utils/AxiosWidget';
7
- import InputIcon from '../../../Shared/InputIcon/InputIcon';
8
6
  import FormContext from '../../../Contexts/FormContext';
9
7
  import StepFillerContainer from '../../Utils/@StepFiller/StepFiller';
10
- import { evaluateCondition } from '../../StepFunctions';
11
8
  import { recursivelyCalcConditionSteps, selectDependencies } from '../../StepHooks';
12
9
  import { useAppSelector } from '../../../hooks';
13
10
  import MaterialEntityValueDialog from './MaterialEntityValueDialog/MaterialEntityValueDialog';
11
+ import InputIcon from '../../../Shared/InputIcon/InputIcon';
12
+ import { evaluateCondition } from '../../StepFunctions';
13
+ import StepComponent from '../../Step';
14
14
  function EntityValuePickerStep({ step, editable }) {
15
15
  const form = useContext(FormContext);
16
16
  const [dialogs, setDialogs] = useState();
@@ -34,7 +34,7 @@ function EntityValuePickerStep({ step, editable }) {
34
34
  }
35
35
  : undefined);
36
36
  }, []);
37
- return (_jsxs(React.Fragment, { children: [dialogs !== undefined && form.entities?.[step.idEntity] && (_jsx(MaterialEntityValueDialog, { type: dialogs.current.type, entity: form.entities?.[step.idEntity], entityValue: dialogs.value, message: dialogs.current.message, handleClose: handleCloseDialog })), _jsx(StepFillerContainer, { step: step, children: _jsx(SmartSelect, { step: step, editable: editable, getOptionalDependencies: getOptionalDependencies, IconComponent: () => (step.icon ? _jsx(InputIcon, { icon: step.icon }) : undefined), getOptions: getEntityValueOptions, getOptionSelected: (option, value) => option._id === value._id, calcDepError: (steps) => {
37
+ return (_jsxs(React.Fragment, { children: [dialogs !== undefined && form.entities?.[step.idEntity] && (_jsx(MaterialEntityValueDialog, { type: dialogs.current.type, entity: form.entities?.[step.idEntity], entityValue: dialogs.value, message: dialogs.current.message, handleClose: handleCloseDialog })), _jsx(StepFillerContainer, { step: step, children: _jsx(SmartSelect, { step: step, editable: editable, getOptions: getEntityValueOptions, getOptionalDependencies: getOptionalDependencies, IconComponent: () => (step.icon ? _jsx(InputIcon, { icon: step.icon }) : undefined), getOptionSelected: (option, value) => option._id === value._id, calcDepError: (steps) => {
38
38
  for (const step of steps) {
39
39
  if (step.type === FormStepTypes.ENTITYVALUEPICKER) {
40
40
  return 'Selecciona un ' + step.label;
@@ -97,7 +97,7 @@ function EntityValuePickerStep({ step, editable }) {
97
97
  } }) })] }));
98
98
  }
99
99
  export default EntityValuePickerStep;
100
- const getEntityValueOptions = async (idOrganization, step, dependencyStore) => {
100
+ const getEntityValueOptions = async (step, dependencyStore, { idOrganization, idCurrentAgent, }) => {
101
101
  if (!idOrganization)
102
102
  return null;
103
103
  let urlPath = '';
@@ -137,6 +137,10 @@ const getEntityValueOptions = async (idOrganization, step, dependencyStore) => {
137
137
  }
138
138
  break;
139
139
  }
140
+ case EntityValueDataTypes.CURRENT_AGENT:
141
+ if (idCurrentAgent)
142
+ params.set(filter.idProperty, idCurrentAgent);
143
+ break;
140
144
  case EntityValueDataTypes.VALUE:
141
145
  default:
142
146
  params.set(filter.idProperty, filter.value);
@@ -21,7 +21,7 @@ function SmartSelectStep({ step, editable, getOptions, calcDepError, defaultValu
21
21
  changeListener?.(value);
22
22
  handleChange(valueOverwrite ? valueOverwrite(value) : value);
23
23
  }, [handleChange, valueOverwrite, changeListener]);
24
- const { postview, idOrganization } = useAppSelector((state) => state.global);
24
+ const { postview, idOrganization, idCurrentAgent } = useAppSelector((state) => state.global);
25
25
  const form = useContext(FormContext);
26
26
  const [options, setOptions] = useState();
27
27
  const [loading, setLoading] = useState(false);
@@ -49,14 +49,17 @@ function SmartSelectStep({ step, editable, getOptions, calcDepError, defaultValu
49
49
  }
50
50
  },
51
51
  // eslint-disable-next-line react-hooks/exhaustive-deps
52
- step.dependencies?.map((dep) => dependencies[dep]?.value) ?? []);
52
+ allDeps.map((dep) => dependencies[dep]?.value) ?? []);
53
53
  const calcOptions = async (firstTime) => {
54
54
  if (!firstTime)
55
55
  setOptions(undefined);
56
56
  if (value && !firstTime)
57
57
  setLoading(true);
58
58
  try {
59
- const resp = await getOptions?.(idOrganization, step, dependencies);
59
+ const resp = await getOptions?.(step, dependencies, {
60
+ idOrganization,
61
+ idCurrentAgent: postview ? undefined : idCurrentAgent,
62
+ });
60
63
  if (value) {
61
64
  /** If the value is still valid select it */
62
65
  if (resp && getValueString(value) !== undefined) {
@@ -3,13 +3,16 @@ import { GSmartSelect } from '../../@Types/GenericFormSteps';
3
3
  import { FormStep } from '../../@Types/FormStep';
4
4
  import { DependencyStore } from '../../Form/Form';
5
5
  import React from 'react';
6
- export interface SmartSelectStepProps<StepType extends GSmartSelect = GSmartSelect> extends Omit<StepProps, 'step'> {
6
+ export interface SmartSelectStepProps<StepType extends GSmartSelect> extends Omit<StepProps, 'step'> {
7
7
  /** The SmartSelectStep to display */
8
8
  step: StepType;
9
9
  /** The icon to display */
10
10
  IconComponent?: React.ElementType;
11
11
  /** Function to call to get the options of the selector, return null if dependency is not met */
12
- getOptions: (idOrganization: string | undefined, step: StepType, dependencyStore: DependencyStore) => Promise<any[] | null>;
12
+ getOptions: (step: StepType, dependencyStore: DependencyStore, options: {
13
+ idOrganization?: string;
14
+ idCurrentAgent?: string;
15
+ }) => Promise<any[] | null>;
13
16
  /** Function to call to filter the options of the selector */
14
17
  filterOptions?: (options: any[], dependencyStore: DependencyStore) => any[];
15
18
  /** Function to determine the currently selected option */
@@ -17,7 +20,7 @@ export interface SmartSelectStepProps<StepType extends GSmartSelect = GSmartSele
17
20
  /** Function to determine the current value in string format */
18
21
  getValueString: (value: any) => string;
19
22
  /** Function to if currently selected option has warning */
20
- getValueWarning?: (value: any) => string | null;
23
+ getValueWarning?: (value: undefined | any) => string | null;
21
24
  /** Function called to get the idSteps of the optional dependencies */
22
25
  getOptionalDependencies?: (step: StepType) => string[];
23
26
  /** Function called to get the idSteps of the step's conditions for better refreshing */
@@ -33,5 +36,5 @@ export interface SmartSelectStepProps<StepType extends GSmartSelect = GSmartSele
33
36
  /** function called to render nested elements when selected */
34
37
  renderNestedSteps?: (value: any) => JSX.Element;
35
38
  }
36
- declare function SmartSelectStep(props: SmartSelectStepProps): JSX.Element;
39
+ declare function SmartSelectStep<StepType extends GSmartSelect = GSmartSelect>(props: SmartSelectStepProps<StepType>): JSX.Element;
37
40
  export default SmartSelectStep;
@@ -9,7 +9,7 @@ export type FillerSteps = FormSelector | ClassifierSelector | EntityValuePicker
9
9
  export declare function calcFillerSize(step: FillerSteps, steps: Record<string, FormStep>, values: Record<string, unknown>, size: FormSize): number;
10
10
  export declare const calcStepWidth: (stepSize: 1 | 2 | 3 | 4, size: FormSize) => number;
11
11
  export declare const calcDefaultValue: (step: FormStep | CBRFormStep) => any;
12
- export declare const iterateNestedSteps: (idStep: string, steps: Record<string, FormStep>, iteration: (step: FormStep) => void) => void;
12
+ export declare const iterateNestedSteps: (idStep: string, steps: Record<string, FormStep>, iteration: (step: FormStep, path: string[]) => void, path?: string[]) => void;
13
13
  /**
14
14
  * Utility function to calc the substeps of a step
15
15
  * @param step step to calc the substeps
@@ -134,21 +134,24 @@ export const calcDefaultValue = (step) => {
134
134
  return undefined;
135
135
  }
136
136
  };
137
- export const iterateNestedSteps = (idStep, steps, iteration) => {
137
+ export const iterateNestedSteps = (idStep, steps, iteration, path = [idStep]) => {
138
138
  const step = steps[idStep];
139
139
  if (!step) {
140
140
  console.error('Missing Step:', idStep);
141
141
  return;
142
142
  }
143
- iteration(step);
143
+ iteration(step, path);
144
144
  if (step.type === FormStepTypes.MAPPER) {
145
145
  for (const idStep of step.rootSteps) {
146
- iterateNestedSteps(idStep, step.steps, iteration);
146
+ iterateNestedSteps(idStep, step.steps, iteration, [
147
+ ...path,
148
+ step.id,
149
+ ]);
147
150
  }
148
151
  }
149
152
  else {
150
153
  for (const idSubStep of calcSubSteps(step.id, steps)) {
151
- iterateNestedSteps(idSubStep, steps, iteration);
154
+ iterateNestedSteps(idSubStep, steps, iteration, [...path, step.id]);
152
155
  }
153
156
  }
154
157
  };
@@ -3,6 +3,7 @@ import CBRFormStepTypes from '../constants/CBRFormStepTypes';
3
3
  import FormStepTypes, { ApiSelectorOptionTypes, ClassifierOptionTypes, EntityValueOptionTypes, OptionTypes, } from '../constants/FormStepTypes';
4
4
  import { describe, expect, test, vi } from 'vitest';
5
5
  import { calcDefaultValue, calcFillerSize, calcStepWidth, calcSubSteps, iterateNestedSteps } from './StepFunctions';
6
+ import { stringToDraft } from '../Utils/DraftFunctions';
6
7
  describe('StepFunctions', function () {
7
8
  describe('calcFillerSize', function () {
8
9
  test('No maxSize', async () => {
@@ -428,8 +429,7 @@ describe('StepFunctions', function () {
428
429
  test('Title step type', async () => {
429
430
  const step = {
430
431
  type: FormStepTypes.TITLE,
431
- title: 'Title',
432
- description: 'Description',
432
+ title: stringToDraft('Title'),
433
433
  };
434
434
  const defaultValue = calcDefaultValue(step);
435
435
  expect(defaultValue).toEqual(undefined);
@@ -3,30 +3,41 @@ import { calcStepWidth } from '../../StepFunctions';
3
3
  import styles from './MaterialTitleStep.module.css';
4
4
  import { useAppSelector } from '../../../hooks';
5
5
  import FormContext from '../../../Contexts/FormContext';
6
- import { useContext } from 'react';
7
- import { useFormStep } from '../../StepHooks';
6
+ import { useContext, useMemo } from 'react';
7
+ import { selectDependencies, useFormStep } from '../../StepHooks';
8
+ import { stringToDraft } from '../../../Utils/DraftFunctions';
9
+ import SmartDraftRenderer from '../../../Shared/SmartDraftRenderer/SmartDraftRenderer';
10
+ //**Pendientes a mejorar, esperar antes de enviar, en local (actividades), usar el value envez de el draft en actividades, esperar a que dejen de escribir, optimizar para que use lo que tiene en local y si necesita ahi si pregunte. */
8
11
  function TitleStep({ step }) {
9
- const { value } = useFormStep(step, {
12
+ const { value, onChange } = useFormStep(step, {
10
13
  defaultValue: undefined,
11
14
  });
12
- const title = value?.title ?? step.title;
13
- const description = value?.description ?? step.description;
14
15
  const { formStyle } = useAppSelector((state) => state.global);
15
16
  const form = useContext(FormContext);
16
17
  const widthStats = useAppSelector((state) => state.widthStats);
17
18
  const size = step.size ?? form.size.blockNum;
19
+ const title = useMemo(() => calcBaseDraft(value?.title ?? step.title), //Usa por defecto lo que venga en el value, pero no escucha cambios
20
+ [step.title, value?.title]);
21
+ const description = useMemo(() => calcBaseDraft(value?.description ?? step.description), //Usa por defecto lo que venga en el value, pero no escucha cambios
22
+ [step.description, value?.description]);
23
+ const dependencies = useAppSelector((state) => selectDependencies(state, step.dependencies));
24
+ const values = useMemo(() => {
25
+ const values = {};
26
+ for (const { idOriginal, value } of Object.values(dependencies)) {
27
+ values[idOriginal] = value;
28
+ }
29
+ return values;
30
+ }, [dependencies]);
18
31
  return (_jsxs("div", { className: styles.container, style: {
19
32
  color: formStyle.textColor,
20
- width: widthStats.currentBreakPoint <= size
21
- ? '100%'
22
- : calcStepWidth(size, form.size),
23
- }, children: [title && (_jsx("div", { className: styles.titleLbl, style: {
24
- textAlign: widthStats.isMobile &&
25
- widthStats.currentBreakPoint <= size
26
- ? 'center'
27
- : 'start',
28
- }, children: title })), description && (_jsx("p", { className: styles.descriptionPar, style: {
29
- margin: title ? '10px 0px' : '0px 0px 5px 0px',
30
- }, children: description }))] }));
33
+ width: widthStats.currentBreakPoint <= size ? '100%' : calcStepWidth(size, form.size),
34
+ }, children: [_jsx("div", { className: styles.titleLbl, style: {
35
+ textAlign: widthStats.isMobile && widthStats.currentBreakPoint <= size ? 'center' : 'start',
36
+ }, children: _jsx(SmartDraftRenderer, { draft: title, dependencies: values, property: `${step.stepPath.join('.')}.title`, onChange: (title) => onChange({ ...value, title }) }) }), _jsx("div", { className: styles.descriptionPar, children: _jsx(SmartDraftRenderer, { draft: description, dependencies: values, margin: title ? '10px 0px' : '0px 0px 5px 0px', property: `${step.stepPath.join('.')}.description`, onChange: (description) => onChange({ ...value, description }) }) })] }));
31
37
  }
32
38
  export default TitleStep;
39
+ function calcBaseDraft(value) {
40
+ return typeof value === 'string'
41
+ ? stringToDraft(value)
42
+ : (value ?? stringToDraft(''));
43
+ }
@@ -0,0 +1,23 @@
1
+ import { EurekaDraft } from '../@Types/Draft/Draft';
2
+ export declare const DraftApi: import("@reduxjs/toolkit/query").Api<import("@reduxjs/toolkit/query").BaseQueryFn<{
3
+ url: string;
4
+ timeout?: import("axios").AxiosRequestConfig["timeout"];
5
+ method?: import("axios").AxiosRequestConfig["method"];
6
+ body?: import("axios").AxiosRequestConfig["data"];
7
+ params?: import("axios").AxiosRequestConfig["params"];
8
+ headers?: Record<string, any>;
9
+ }, unknown, unknown>, {
10
+ mapDraft: import("@reduxjs/toolkit/query").QueryDefinition<{
11
+ idForm: string;
12
+ property: string;
13
+ dependencies: Record<string, any>;
14
+ mapDraftEntities?: (property: string, dependencies: Record<string, any>) => Promise<EurekaDraft>;
15
+ }, import("@reduxjs/toolkit/query").BaseQueryFn<{
16
+ url: string;
17
+ timeout?: import("axios").AxiosRequestConfig["timeout"];
18
+ method?: import("axios").AxiosRequestConfig["method"];
19
+ body?: import("axios").AxiosRequestConfig["data"];
20
+ params?: import("axios").AxiosRequestConfig["params"];
21
+ headers?: Record<string, any>;
22
+ }, unknown, unknown>, never, EurekaDraft | undefined, "api", unknown>;
23
+ }, "api", never, typeof import("@reduxjs/toolkit/query").coreModuleName | typeof import("@reduxjs/toolkit/query/react").reactHooksModuleName>;
@@ -0,0 +1,30 @@
1
+ import { RootApi } from '../Utils/_api';
2
+ import axiosInstance from '../Utils/AxiosAPI';
3
+ import widgetInstance from '../Utils/AxiosWidget';
4
+ export const DraftApi = RootApi.injectEndpoints({
5
+ endpoints: (build) => ({
6
+ mapDraft: build.query({
7
+ queryFn: async ({ idForm, dependencies, property, mapDraftEntities }, { getState }) => {
8
+ const idOrganization = getState()[idForm].global.idOrganization;
9
+ if (mapDraftEntities)
10
+ return {
11
+ data: await mapDraftEntities(property, dependencies),
12
+ };
13
+ const apiKey = getState()[idForm].global.apiKey;
14
+ if (!apiKey)
15
+ return { data: undefined };
16
+ let response;
17
+ if (idOrganization) {
18
+ response = await widgetInstance.post(`/form/draft/${apiKey}?idOrganization=${idOrganization}`, {
19
+ property,
20
+ dependencies,
21
+ });
22
+ }
23
+ else {
24
+ response = await axiosInstance.post(`/form/draft/${apiKey}`, dependencies);
25
+ }
26
+ return { data: response.data };
27
+ },
28
+ }),
29
+ }),
30
+ });
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
- import { MobileDatePickerProps as MuiDatePickerProps, PickerValidDate } from '@mui/x-date-pickers';
2
+ import { MobileDatePickerProps as MuiDatePickerProps } from '@mui/x-date-pickers';
3
3
  import { ErkTextFieldProps } from '../ErkTextField/ErkTextField';
4
- interface ErkDatePickerProps extends Omit<MuiDatePickerProps<PickerValidDate>, 'ref' | 'onChange'>, Pick<ErkTextFieldProps, 'error' | 'required' | 'helperText' | 'size'> {
4
+ interface ErkDatePickerProps extends Omit<MuiDatePickerProps, 'ref' | 'onChange'>, Pick<ErkTextFieldProps, 'error' | 'required' | 'helperText' | 'size'> {
5
5
  onChange?: (date: Date | null) => void;
6
6
  /** If it should display the timePicker */
7
7
  pickTime?: boolean;
@@ -95,7 +95,7 @@ export const StyledHelperText = styled(MuiFormHelperText)(({ theme, ...props })
95
95
  function CustomSelect({ label, error, value, loading, onChange, children, required, inputRef, MenuProps, helperText, IconComponent, size = 'small', labelMargin = 5, multiple = false, readOnly = false, disabled = false, clearable = true, fullWidth = true, clearLabel = 'Sin Seleccionar', ...others }) {
96
96
  const [open, setOpen] = useState(false);
97
97
  const handleChange = useCallback((event) => onChange?.(event.target.value), [onChange]);
98
- return (_jsxs(FormControl, { size: size, error: error, variant: "outlined", required: required, fullWidth: fullWidth, style: { marginTop: label ? labelMargin : undefined, maxWidth: '100%' }, children: [label && (_jsx(StyledInputLabel, { disabled: disabled, open: open, size: size === 'small' ? 'small' : 'normal', children: label })), _jsxs(StyledSelect, { ...others, size: size, autoWidth: false, open: others.open ?? open, label: label, inputRef: inputRef, readOnly: readOnly, disabled: disabled, multiple: multiple, onChange: handleChange, value: value ?? (multiple ? [] : ''), IconComponent: IconComponent ? () => _jsx(_Fragment, {}) : undefined, endAdornment: IconComponent ? (_jsx(InputAdornment, { position: "end", onClick: (e) => {
98
+ return (_jsxs(FormControl, { size: size, error: error, variant: "outlined", required: required, fullWidth: fullWidth, style: { marginTop: label ? labelMargin : undefined, maxWidth: '100%' }, children: [label && (_jsx(StyledInputLabel, { disabled: disabled, open: open, size: size === 'small' ? 'small' : undefined, children: label })), _jsxs(StyledSelect, { ...others, size: size, autoWidth: false, open: others.open ?? open, label: label, inputRef: inputRef, readOnly: readOnly, disabled: disabled, multiple: multiple, onChange: handleChange, value: value ?? (multiple ? [] : ''), IconComponent: IconComponent ? () => _jsx(_Fragment, {}) : undefined, endAdornment: IconComponent ? (_jsx(InputAdornment, { position: "end", onClick: (e) => {
99
99
  e.stopPropagation();
100
100
  if (!readOnly && !disabled) {
101
101
  if (others.open !== undefined) {
@@ -53,7 +53,7 @@ function CustomSelect({ value, onChange, label, error, required, pickDays, helpe
53
53
  ...value,
54
54
  working,
55
55
  });
56
- } })] }))] }) }) })), _jsxs(FormControl, { fullWidth: true, size: size, error: error, variant: "outlined", required: required, style: { marginTop: label ? labelMargin : undefined, maxWidth: '100%' }, children: [label && (_jsx(StyledInputLabel, { disabled: disabled, open: open, size: size === 'small' ? 'small' : 'normal', children: label })), _jsx(StyledSelect, { ...others, ref: ref, open: open, size: size, readOnly: readOnly, disabled: disabled, onBlur: () => {
56
+ } })] }))] }) }) })), _jsxs(FormControl, { fullWidth: true, size: size, error: error, variant: "outlined", required: required, style: { marginTop: label ? labelMargin : undefined, maxWidth: '100%' }, children: [label && (_jsx(StyledInputLabel, { disabled: disabled, open: open, size: size === 'small' ? 'small' : undefined, children: label })), _jsx(StyledSelect, { ...others, ref: ref, open: open, size: size, readOnly: readOnly, disabled: disabled, onBlur: () => {
57
57
  if (!readOnly && !disabled)
58
58
  setOpen(false);
59
59
  }, label: label ? calcLabel() : undefined, value: value ? 0 : '', title: calcTimeString(value), IconComponent: () => _jsx(_Fragment, {}), MenuProps: { sx: { visibility: 'hidden' } }, endAdornment: _jsx(InputAdornment, { position: "end", onClick: (e) => {
@@ -0,0 +1 @@
1
+ export declare const DraftLoadingContext: import("react").Context<boolean>;
@@ -0,0 +1,2 @@
1
+ import { createContext } from 'react';
2
+ export const DraftLoadingContext = createContext(true);
@@ -0,0 +1,12 @@
1
+ import { ContentState } from 'draft-js';
2
+ export interface DecoratorComponentProps {
3
+ children: JSX.Element;
4
+ contentState: ContentState;
5
+ entityKey: string;
6
+ blockKey: string;
7
+ start: number;
8
+ end: number;
9
+ editable?: boolean;
10
+ }
11
+ export declare function FormDecorator({ children, entityKey }: DecoratorComponentProps): JSX.Element;
12
+ export declare function FormDecoratorsStrategy(contentBlock: any, callback: any, contentState: any): void;
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useContext } from 'react';
3
+ import { DraftEntityTypes } from '../../constants/Draft/DraftEntityTypes';
4
+ import styles from './FormDecorator.module.css';
5
+ import { DraftLoadingContext } from './DraftLoadingContext';
6
+ export function FormDecorator({ children, entityKey }) {
7
+ const loading = useContext(DraftLoadingContext);
8
+ return (_jsx("span", { id: entityKey, className: loading ? styles.loadingDecorator : styles.decorator, style: {
9
+ overflow: 'hidden',
10
+ position: 'relative',
11
+ padding: '0px 3px',
12
+ borderRadius: 12,
13
+ }, children: children }));
14
+ }
15
+ export function FormDecoratorsStrategy(contentBlock, callback, contentState) {
16
+ contentBlock.findEntityRanges((character) => {
17
+ const entityKey = character.getEntity();
18
+ return entityKey !== null && contentState.getEntity(entityKey).getType() === DraftEntityTypes.EUREKA;
19
+ }, callback);
20
+ }
@@ -0,0 +1,30 @@
1
+ .loadingDecorator {
2
+ position: absolute;
3
+ animation-duration: 3s;
4
+ animation-fill-mode: forwards;
5
+ animation-iteration-count: infinite;
6
+ animation-name: loading;
7
+ animation-timing-function: linear;
8
+ background: linear-gradient(
9
+ to right,
10
+ #d6d6d6 2%,
11
+ rgba(255, 255, 255, 0.3) 20%,
12
+ #d6d6d6 50%
13
+ );
14
+ background-size: 800px 100px;
15
+ height: 100%;
16
+ width: 100%;
17
+ }
18
+
19
+ .decorator {
20
+ background-color: #d6d6d6;
21
+ }
22
+
23
+ @keyframes loading {
24
+ 0% {
25
+ background-position: -800px 0;
26
+ }
27
+ 100% {
28
+ background-position: 800px 0;
29
+ }
30
+ }
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { EurekaDraft } from '../../@Types/Draft/Draft';
3
+ interface SmartDraftRendererProps {
4
+ property: string;
5
+ draft: EurekaDraft;
6
+ margin?: React.CSSProperties['margin'];
7
+ dependencies: Record<string, any>;
8
+ onChange?: (value: EurekaDraft) => void;
9
+ }
10
+ declare function SmartDraftRenderer({ draft, margin, onChange, property, dependencies }: SmartDraftRendererProps): JSX.Element;
11
+ export default SmartDraftRenderer;
@@ -0,0 +1,58 @@
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import { useContext, useEffect, useMemo } from 'react';
3
+ import { DraftApi } from '../../Services/DraftService';
4
+ import { convertFromRaw, EditorState } from 'draft-js';
5
+ import { Editor } from 'react-draft-wysiwyg';
6
+ import { produce } from 'immer';
7
+ import CustomContext from '../../Contexts/CustomContext';
8
+ import { FormDecoratorsStrategy, FormDecorator } from './FormDecorator';
9
+ import { skipToken } from '@reduxjs/toolkit/query';
10
+ import { useAppSelector } from '../../hooks';
11
+ import { IdFormContext } from '../../Contexts/FormContext';
12
+ import { DraftLoadingContext } from './DraftLoadingContext';
13
+ function SmartDraftRenderer({ draft, margin, onChange, property, dependencies }) {
14
+ const idForm = useContext(IdFormContext);
15
+ const mapDraftEntities = useContext(CustomContext).mapDraftEntities;
16
+ const postview = useAppSelector((state) => state.global.postview);
17
+ const hasEntities = useMemo(() => Object.keys(draft.entityMap).length > 0, [draft]);
18
+ const { data: mapped, isFetching } = DraftApi.useMapDraftQuery(!hasEntities || postview
19
+ ? skipToken
20
+ : {
21
+ idForm,
22
+ property,
23
+ dependencies,
24
+ mapDraftEntities,
25
+ });
26
+ useEffect(() => {
27
+ if (mapped && !postview)
28
+ onChange?.(mapped);
29
+ }, [mapped, onChange, postview]);
30
+ const { editorState, isEmpty } = useMemo(() => {
31
+ const content = convertFromRaw(cleanUpDraftParams(isFetching ? draft : (mapped ?? draft)));
32
+ return {
33
+ editorState: EditorState.createWithContent(content),
34
+ isEmpty: !content.hasText(),
35
+ };
36
+ }, [mapped, draft, isFetching]);
37
+ if (isEmpty)
38
+ return _jsx(_Fragment, {});
39
+ return (_jsx("div", { style: { margin }, children: _jsx(DraftLoadingContext.Provider, { value: !postview && isFetching, children: _jsx(Editor, { readOnly: true, toolbarHidden: true, editorState: editorState, editorClassName: 'Erk-Forms-Draft', customDecorators: customDecorators }) }) }));
40
+ }
41
+ export default SmartDraftRenderer;
42
+ function cleanUpDraftParams(draft) {
43
+ return produce(draft, (draft) => {
44
+ for (const block of draft.blocks) {
45
+ for (const entity of block.entityRanges) {
46
+ const { offset, length } = entity;
47
+ //Change text into spaces
48
+ block.text = block.text.replace(block.text.substring(offset, offset + length), ' '.repeat(length));
49
+ }
50
+ }
51
+ });
52
+ }
53
+ const customDecorators = [
54
+ {
55
+ strategy: FormDecoratorsStrategy,
56
+ component: FormDecorator,
57
+ },
58
+ ];
@@ -4,7 +4,9 @@ import { SiteState } from './SiteSlice';
4
4
  import { EurekaDraft } from '../@Types/Draft/Draft';
5
5
  import { CountryCode } from 'libphonenumber-js';
6
6
  export interface GlobalState {
7
+ apiKey?: string;
7
8
  idOrganization: string;
9
+ idCurrentAgent?: string;
8
10
  countryCode: CountryCode;
9
11
  formStyle: FormStyle;
10
12
  confirmation: {
@@ -28,6 +30,8 @@ export declare const GlobalSlice: import("@reduxjs/toolkit").Slice<GlobalState,
28
30
  postview: boolean;
29
31
  preview: boolean;
30
32
  idOrganization: string;
33
+ idCurrentAgent?: string;
34
+ apiKey?: string;
31
35
  countryCode: CountryCode;
32
36
  confirmation: {
33
37
  confirmationMessage: EurekaDraft;
@@ -1,2 +1,12 @@
1
+ import { BaseQueryFn } from '@reduxjs/toolkit/query';
2
+ import { AxiosRequestConfig } from 'axios';
1
3
  declare const axiosInstance: import("axios").AxiosInstance;
2
4
  export default axiosInstance;
5
+ export declare const axiosBaseQuery: () => BaseQueryFn<{
6
+ url: string;
7
+ timeout?: AxiosRequestConfig["timeout"];
8
+ method?: AxiosRequestConfig["method"];
9
+ body?: AxiosRequestConfig["data"];
10
+ params?: AxiosRequestConfig["params"];
11
+ headers?: Record<string, any>;
12
+ }, unknown, unknown>;
@@ -6,3 +6,25 @@ const axiosInstance = axios.create({
6
6
  headers,
7
7
  });
8
8
  export default axiosInstance;
9
+ export const axiosBaseQuery = () => async ({ url, method, body, params, timeout, headers, }) => {
10
+ try {
11
+ const result = await axiosInstance({
12
+ url,
13
+ method,
14
+ data: body,
15
+ params,
16
+ headers,
17
+ timeout,
18
+ });
19
+ return { data: result.data };
20
+ }
21
+ catch (axiosError) {
22
+ const err = axiosError;
23
+ return {
24
+ error: {
25
+ status: err.response?.status,
26
+ data: err.response?.data || err.message,
27
+ },
28
+ };
29
+ }
30
+ };
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { FormStyle } from '../@Types/Form';
3
- import { Palette, PaletteColor } from '@mui/material/styles/createPalette';
3
+ import { Palette, PaletteColor } from '@mui/material/styles';
4
4
  declare module '@mui/material/styles' {
5
5
  interface Palette {
6
6
  outline: Palette['primary'];
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { esES as DatePickersEs } from '@mui/x-date-pickers/locales';
3
3
  import { createTheme, ThemeProvider } from '@mui/material';
4
- import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFnsV3';
4
+ import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
5
5
  import { LocalizationProvider } from '@mui/x-date-pickers';
6
6
  import { getLocale } from './LocaleUtils';
7
7
  // stepBackgroundColor: string;
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const StoreContext: React.Context<any>;
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export const StoreContext = React.createContext({});
@@ -59,8 +59,14 @@ export declare function renderWithProviders(ui: React.ReactElement, { store, ...
59
59
  queryAllByTestId: (id: import("@testing-library/dom").Matcher, options?: import("@testing-library/dom").MatcherOptions | undefined) => HTMLElement[];
60
60
  findByTestId: (id: import("@testing-library/dom").Matcher, options?: import("@testing-library/dom").MatcherOptions | undefined, waitForElementOptions?: import("@testing-library/dom").waitForOptions | undefined) => Promise<HTMLElement>;
61
61
  findAllByTestId: (id: import("@testing-library/dom").Matcher, options?: import("@testing-library/dom").MatcherOptions | undefined, waitForElementOptions?: import("@testing-library/dom").waitForOptions | undefined) => Promise<HTMLElement[]>;
62
- store: import("@reduxjs/toolkit").EnhancedStore<import("./store").EurekaFormsState, import("redux").AnyAction, import("@reduxjs/toolkit").Tuple<[import("redux").StoreEnhancer<{
63
- dispatch: import("redux-thunk").ThunkDispatch<import("./store").EurekaFormsState, undefined, import("redux").UnknownAction>;
62
+ store: import("@reduxjs/toolkit").EnhancedStore<{
63
+ forms: import("./store").EurekaFormsState;
64
+ api: import("@reduxjs/toolkit/query").CombinedState<{}, never, "api">;
65
+ }, import("redux").UnknownAction | import("redux").AnyAction, import("@reduxjs/toolkit").Tuple<[import("redux").StoreEnhancer<{
66
+ dispatch: import("redux-thunk").ThunkDispatch<{
67
+ forms: import("./store").EurekaFormsState;
68
+ api: import("@reduxjs/toolkit/query").CombinedState<{}, never, "api">;
69
+ }, undefined, import("redux").UnknownAction>;
64
70
  }>, import("redux").StoreEnhancer]>>;
65
71
  };
66
72
  interface ExtendedRenderHookOptions<TProps> extends Omit<RenderHookOptions<TProps>, 'wrapper'> {
@@ -1,17 +1,21 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import React from 'react';
3
3
  import { render, renderHook } from '@testing-library/react';
4
- import { configureStore, nanoid } from '@reduxjs/toolkit';
4
+ import { combineReducers, configureStore, nanoid } from '@reduxjs/toolkit';
5
5
  import { Provider } from 'react-redux';
6
6
  // As a basic setup, import your same slice reducers
7
7
  import { EurekaFormsReducer } from './store';
8
- import { StoreContext } from '../hooks';
9
8
  import { IdFormContext } from '../Contexts/FormContext';
9
+ import { RootApi } from './_api';
10
+ import { StoreContext } from './StoreContext';
10
11
  // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
11
12
  export function renderWithProviders(ui, {
12
13
  // Automatically create a store instance if no store was passed in
13
14
  store = configureStore({
14
- reducer: EurekaFormsReducer,
15
+ reducer: combineReducers({
16
+ forms: EurekaFormsReducer,
17
+ api: RootApi.reducer,
18
+ }),
15
19
  }), ...renderOptions } = {}) {
16
20
  function Wrapper({ children }) {
17
21
  return _jsx(Provider, { store: store, children: children });
@@ -20,7 +24,10 @@ store = configureStore({
20
24
  return { store, ...render(ui, { wrapper: Wrapper, ...renderOptions }) };
21
25
  }
22
26
  export function renderHookWithProviders(callback, { store = configureStore({
23
- reducer: EurekaFormsReducer,
27
+ reducer: combineReducers({
28
+ forms: EurekaFormsReducer,
29
+ api: RootApi.reducer,
30
+ }),
24
31
  }), ...renderHookOptions } = {}) {
25
32
  function Wrapper({ children }) {
26
33
  const [idForm] = React.useState(nanoid(6));
@@ -0,0 +1,8 @@
1
+ export declare const RootApi: import("@reduxjs/toolkit/query").Api<import("@reduxjs/toolkit/query").BaseQueryFn<{
2
+ url: string;
3
+ timeout?: import("axios").AxiosRequestConfig["timeout"];
4
+ method?: import("axios").AxiosRequestConfig["method"];
5
+ body?: import("axios").AxiosRequestConfig["data"];
6
+ params?: import("axios").AxiosRequestConfig["params"];
7
+ headers?: Record<string, any>;
8
+ }, unknown, unknown>, {}, "api", never, typeof import("@reduxjs/toolkit/query").coreModuleName | typeof import("@reduxjs/toolkit/query/react").reactHooksModuleName>;