@arquimedes.co/eureka-forms 3.0.70 → 3.0.71-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.
Files changed (146) hide show
  1. package/README +1 -33
  2. package/dist/@Types/FormStep.d.ts +2 -7
  3. package/dist/@Types/FormStep.js +1 -2
  4. package/dist/App/App.stories.d.ts +0 -10
  5. package/dist/App/App.stories.js +0 -189
  6. package/dist/App/AppHooks.js +0 -8
  7. package/dist/App/AppHooks.test.js +0 -8
  8. package/dist/Form/Form.js +6 -7
  9. package/dist/Form/FormFunctions.d.ts +0 -17
  10. package/dist/Form/FormFunctions.js +0 -22
  11. package/dist/Form/FormFunctions.test.js +1 -28
  12. package/dist/FormSteps/AYFStepMapper.js +2 -24
  13. package/dist/FormSteps/CheckBoxStep/CheckBoxStep.mobileLabel.test.js +12 -20
  14. package/dist/FormSteps/CheckBoxStep/MaterialCheckBoxStep/MaterialCheckBoxStep.js +13 -6
  15. package/dist/FormSteps/CheckBoxStep/MaterialCheckBoxStep/MaterialCheckBoxStep.module.css +13 -2
  16. package/dist/FormSteps/ClassifierSelectorStep/MaterialClassifierSelectorStep/MaterialClassifierSelectorStep.js +1 -3
  17. package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValuePickerStep.js +26 -26
  18. package/dist/FormSteps/SmartSelectStep/MaterialSmartSelectStep/MaterialSmartSelectStep.js +11 -1
  19. package/dist/FormSteps/SmartSelectStep/SmartSelectStep.staleOptions.test.js +100 -0
  20. package/dist/FormSteps/Step.js +0 -16
  21. package/dist/FormSteps/StepFunctions.js +0 -14
  22. package/dist/FormSteps/StepFunctions.test.js +0 -54
  23. package/dist/FormSteps/StepHooks.d.ts +0 -21
  24. package/dist/FormSteps/StepHooks.js +8 -55
  25. package/dist/FormSteps/ciudadesICAQuery.d.ts +8 -0
  26. package/dist/FormSteps/ciudadesICAQuery.js +31 -0
  27. package/dist/FormSteps/ciudadesICAQuery.test.js +39 -0
  28. package/dist/Shared/ErkDatePicker/ErkDatePicker.js +3 -1
  29. package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.d.ts +3 -2
  30. package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.js +2 -1
  31. package/dist/Shared/ErkSmartSelect/ErkSmartSelect.js +4 -14
  32. package/dist/Shared/ErkSmartSelect/ErkSmartSelect.test.js +21 -1
  33. package/dist/Utils/AxiosWidget.js +1 -9
  34. package/dist/constants/FormStepTypes.d.ts +1 -5
  35. package/dist/constants/FormStepTypes.js +0 -4
  36. package/dist/index.lib.d.ts +2 -4
  37. package/dist/index.lib.js +1 -3
  38. package/package.json +1 -2
  39. package/dist/@Types/AvailabilityFormStep.d.ts +0 -48
  40. package/dist/@Types/AvailabilityFormStep.js +0 -24
  41. package/dist/@Types/BankAccountFormStep.d.ts +0 -67
  42. package/dist/@Types/BankAccountFormStep.js +0 -14
  43. package/dist/@Types/BookingFormStep.d.ts +0 -197
  44. package/dist/@Types/BookingFormStep.js +0 -44
  45. package/dist/@Types/CalendarFormStep.d.ts +0 -209
  46. package/dist/@Types/CalendarFormStep.js +0 -55
  47. package/dist/@Types/CommunicationChannelFormStep.d.ts +0 -51
  48. package/dist/@Types/CommunicationChannelFormStep.js +0 -15
  49. package/dist/@Types/ConsentFormStep.d.ts +0 -36
  50. package/dist/@Types/ConsentFormStep.js +0 -8
  51. package/dist/@Types/EntityFormFormStep.d.ts +0 -66
  52. package/dist/@Types/EntityFormFormStep.js +0 -20
  53. package/dist/@Types/EventFormStep.d.ts +0 -52
  54. package/dist/@Types/EventFormStep.js +0 -13
  55. package/dist/@Types/ExternalReferenceFormStep.d.ts +0 -74
  56. package/dist/@Types/ExternalReferenceFormStep.js +0 -20
  57. package/dist/@Types/LocationFormStep.d.ts +0 -159
  58. package/dist/@Types/LocationFormStep.js +0 -46
  59. package/dist/@Types/NumericFormSteps.d.ts +0 -108
  60. package/dist/@Types/NumericFormSteps.js +0 -20
  61. package/dist/@Types/PredefinedSelectorFormStep.d.ts +0 -51
  62. package/dist/@Types/PredefinedSelectorFormStep.js +0 -39
  63. package/dist/@Types/StepRef.d.ts +0 -135
  64. package/dist/@Types/StepRef.js +0 -49
  65. package/dist/FormSteps/AvailabilityStep/AvailabilityStep.d.ts +0 -7
  66. package/dist/FormSteps/AvailabilityStep/AvailabilityStep.js +0 -14
  67. package/dist/FormSteps/AvailabilityStep/MaterialAvailabilityStep/MaterialAvailabilityStep.d.ts +0 -8
  68. package/dist/FormSteps/AvailabilityStep/MaterialAvailabilityStep/MaterialAvailabilityStep.js +0 -32
  69. package/dist/FormSteps/BookingStep/BookingStep.d.ts +0 -17
  70. package/dist/FormSteps/BookingStep/BookingStep.js +0 -14
  71. package/dist/FormSteps/BookingStep/MaterialBookingStep/MaterialBookingStep.d.ts +0 -14
  72. package/dist/FormSteps/BookingStep/MaterialBookingStep/MaterialBookingStep.js +0 -133
  73. package/dist/FormSteps/ClassifierSelectorStep/ClassifierSelectorStep.lateClassifiers.test.js +0 -70
  74. package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.d.ts +0 -12
  75. package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.js +0 -35
  76. package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.test.js +0 -31
  77. package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.d.ts +0 -27
  78. package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.js +0 -64
  79. package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.test.d.ts +0 -1
  80. package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.test.js +0 -95
  81. package/dist/FormSteps/LocationStep/LocationStep.d.ts +0 -10
  82. package/dist/FormSteps/LocationStep/LocationStep.js +0 -14
  83. package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.d.ts +0 -3
  84. package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.js +0 -54
  85. package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.module.css +0 -18
  86. package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.d.ts +0 -3
  87. package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.js +0 -170
  88. package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.module.css +0 -96
  89. package/dist/FormSteps/NumberStep/NumberStep.d.ts +0 -10
  90. package/dist/FormSteps/NumberStep/NumberStep.js +0 -14
  91. package/dist/FormSteps/StepHooks.test.d.ts +0 -1
  92. package/dist/FormSteps/StepHooks.test.js +0 -92
  93. package/dist/FormSteps/isStepHiddenByCondition.test.d.ts +0 -1
  94. package/dist/FormSteps/isStepHiddenByCondition.test.js +0 -42
  95. package/dist/Icons/AddIcon.d.ts +0 -3
  96. package/dist/Icons/AddIcon.js +0 -7
  97. package/dist/Icons/EditIcon.d.ts +0 -3
  98. package/dist/Icons/EditIcon.js +0 -7
  99. package/dist/Icons/RemoveIcon.d.ts +0 -3
  100. package/dist/Icons/RemoveIcon.js +0 -7
  101. package/dist/Icons/ViewDayIcon.d.ts +0 -3
  102. package/dist/Icons/ViewDayIcon.js +0 -7
  103. package/dist/Icons/ViewWeekIcon.d.ts +0 -3
  104. package/dist/Icons/ViewWeekIcon.js +0 -7
  105. package/dist/Services/BookingService.d.ts +0 -79
  106. package/dist/Services/BookingService.js +0 -66
  107. package/dist/Services/BookingService.test.d.ts +0 -1
  108. package/dist/Services/BookingService.test.js +0 -57
  109. package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.d.ts +0 -19
  110. package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.js +0 -80
  111. package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.module.css +0 -88
  112. package/dist/Shared/ErkAddressAutocomplete/googlePlaces.d.ts +0 -29
  113. package/dist/Shared/ErkAddressAutocomplete/googlePlaces.js +0 -139
  114. package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.d.ts +0 -25
  115. package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.js +0 -112
  116. package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.module.css +0 -88
  117. package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.test.d.ts +0 -1
  118. package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.test.js +0 -73
  119. package/dist/Shared/ErkBookingPicker/ErkBookingPicker.d.ts +0 -54
  120. package/dist/Shared/ErkBookingPicker/ErkBookingPicker.js +0 -294
  121. package/dist/Shared/ErkBookingPicker/ErkBookingPicker.module.css +0 -608
  122. package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.d.ts +0 -28
  123. package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.js +0 -117
  124. package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.test.d.ts +0 -1
  125. package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.test.js +0 -49
  126. package/dist/Shared/ErkBookingPicker/ErkBookingPicker.test.d.ts +0 -1
  127. package/dist/Shared/ErkBookingPicker/ErkBookingPicker.test.js +0 -171
  128. package/dist/Shared/ErkIconButton/ErkIconButton.d.ts +0 -17
  129. package/dist/Shared/ErkIconButton/ErkIconButton.js +0 -11
  130. package/dist/Shared/ErkIconButton/ErkIconButton.module.css +0 -41
  131. package/dist/Shared/ErkLocationField/ErkLocationField.d.ts +0 -24
  132. package/dist/Shared/ErkLocationField/ErkLocationField.js +0 -128
  133. package/dist/Shared/ErkLocationField/ErkLocationField.module.css +0 -164
  134. package/dist/Shared/ErkLocationField/ErkLocationField.test.d.ts +0 -1
  135. package/dist/Shared/ErkLocationField/ErkLocationField.test.js +0 -82
  136. package/dist/Shared/ErkLocationField/addressFields.d.ts +0 -12
  137. package/dist/Shared/ErkLocationField/addressFields.js +0 -34
  138. package/dist/Shared/ErkLocationField/locationRestrictions.d.ts +0 -6
  139. package/dist/Shared/ErkLocationField/locationRestrictions.js +0 -51
  140. package/dist/Shared/ErkLocationInput/ErkLocationInput.d.ts +0 -15
  141. package/dist/Shared/ErkLocationInput/ErkLocationInput.js +0 -502
  142. package/dist/Shared/ErkLocationInput/ErkLocationInput.module.css +0 -128
  143. package/dist/Shared/ErkNumberField/ErkNumberField.d.ts +0 -42
  144. package/dist/Shared/ErkNumberField/ErkNumberField.js +0 -169
  145. /package/dist/FormSteps/{ClassifierSelectorStep/ClassifierSelectorStep.lateClassifiers.test.d.ts → SmartSelectStep/SmartSelectStep.staleOptions.test.d.ts} +0 -0
  146. /package/dist/FormSteps/{EntityValueStep/entityValueDependencyValue.test.d.ts → ciudadesICAQuery.test.d.ts} +0 -0
@@ -1,17 +0,0 @@
1
- import { BookingStep } from '../../@Types/BookingFormStep';
2
- import { BookingSlot } from '../../@Types/BookingFormStep';
3
- import { StepProps } from '../Step';
4
- export interface BookingStepProps extends StepProps {
5
- step: BookingStep;
6
- /**
7
- * Callback to fetch available slots for a given person + date. A host that provides it replaces
8
- * the form's public booking edge entirely (stories, previews). When omitted, the step reads its
9
- * offer, days, slots and holds from that edge.
10
- */
11
- fetchSlots?: (params: {
12
- personId?: string;
13
- date: string;
14
- }) => Promise<BookingSlot[]>;
15
- }
16
- declare function BookingStepComponent(props: BookingStepProps): JSX.Element;
17
- export default BookingStepComponent;
@@ -1,14 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { FormStyleTypes } from '../../constants/FormStepTypes';
3
- import MaterialBookingStep from './MaterialBookingStep/MaterialBookingStep';
4
- import { useAppSelector } from '../../hooks';
5
- function BookingStepComponent(props) {
6
- const { formStyle } = useAppSelector((state) => state.global);
7
- switch (formStyle.type) {
8
- case FormStyleTypes.MATERIAL:
9
- default: {
10
- return _jsx(MaterialBookingStep, { ...props });
11
- }
12
- }
13
- }
14
- export default BookingStepComponent;
@@ -1,14 +0,0 @@
1
- import { BookingStepProps } from '../BookingStep';
2
- /**
3
- * Conector del paso BOOKING: enlaza el estado del formulario (`useFormStep`) y el theming del form
4
- * con `ErkBookingPicker`, y habla con el borde público de agendamiento del formulario.
5
- *
6
- * Todo lo que el picker muestra sale de la oferta que publica el backend, no del paso guardado: las
7
- * personas llegan como handles firmados (nunca ids de agente), los días son los que tienen cupo, y
8
- * las horas se leen en la zona horaria de la organización. Confirmar en el picker bloquea el slot;
9
- * enviar el formulario es lo que lo convierte en cita, y "Cambiar" lo devuelve a la oferta.
10
- *
11
- * Un host que pase `fetchSlots` sustituye al borde por completo (historias, previsualizaciones).
12
- */
13
- declare function MaterialBookingStep({ step, editable, fetchSlots: customFetchSlots }: BookingStepProps): JSX.Element;
14
- export default MaterialBookingStep;
@@ -1,133 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
3
- import { PersonSelectionMode } from '../../../@Types/BookingFormStep';
4
- import { useFormStep } from '../../StepHooks';
5
- import FormContext from '../../../Contexts/FormContext';
6
- import { selectBreakPoint, useAppSelector } from '../../../hooks';
7
- import { calcStepWidth } from '../../StepFunctions';
8
- import ErkBookingPicker from '../../../Shared/ErkBookingPicker/ErkBookingPicker';
9
- import { bookingErrorMessage, fetchBookingOffer, fetchBookingSlots, holdBookingSlot, nonEmpty, releaseBookingSlot, toPickerSlot, } from '../../../Services/BookingService';
10
- /** Una reserva se renueva a mitad de su vida, y nunca más seguido que cada minuto. */
11
- const MIN_RENEW_MS = 60000;
12
- const DEFAULT_LOCK_MINUTES = 15;
13
- /**
14
- * Conector del paso BOOKING: enlaza el estado del formulario (`useFormStep`) y el theming del form
15
- * con `ErkBookingPicker`, y habla con el borde público de agendamiento del formulario.
16
- *
17
- * Todo lo que el picker muestra sale de la oferta que publica el backend, no del paso guardado: las
18
- * personas llegan como handles firmados (nunca ids de agente), los días son los que tienen cupo, y
19
- * las horas se leen en la zona horaria de la organización. Confirmar en el picker bloquea el slot;
20
- * enviar el formulario es lo que lo convierte en cita, y "Cambiar" lo devuelve a la oferta.
21
- *
22
- * Un host que pase `fetchSlots` sustituye al borde por completo (historias, previsualizaciones).
23
- */
24
- function MaterialBookingStep({ step, editable, fetchSlots: customFetchSlots }) {
25
- const currentBreakPoint = useAppSelector(selectBreakPoint);
26
- const { postview, formStyle, idOrganization, internal, apiKey: globalApiKey, } = useAppSelector((state) => state.global);
27
- const formCtx = useContext(FormContext);
28
- const isReadOnly = !editable || postview;
29
- const widthStyle = currentBreakPoint <= step.size ? '100%' : calcStepWidth(step.size, formCtx.size);
30
- const cssVars = {
31
- width: widthStyle,
32
- '--eureka-outline': formStyle.outlineColor,
33
- '--eureka-primary': formStyle.primaryColor,
34
- '--eureka-text': formStyle.textColor,
35
- '--eureka-bg': formStyle.standAloneBackgroundColor ?? '#fff',
36
- '--booking-accent': formStyle.secondaryContrastColor,
37
- };
38
- const { ref, value, onChange, error } = useFormStep(step, {
39
- defaultValue: null,
40
- rules: { required: step.required ? 'Selecciona una cita' : undefined },
41
- });
42
- const apiKey = formCtx.apiKey ?? globalApiKey;
43
- const route = useMemo(() => (apiKey ? { apiKey, idStep: step.id, idOrganization: idOrganization || undefined, internal } : undefined), [apiKey, step.id, idOrganization, internal]);
44
- const usesEdge = !customFetchSlots && !isReadOnly && !!route;
45
- const [offer, setOffer] = useState(undefined);
46
- const [offerError, setOfferError] = useState(undefined);
47
- useEffect(() => {
48
- if (!usesEdge || !route)
49
- return;
50
- let cancelled = false;
51
- fetchBookingOffer(route)
52
- .then((loaded) => {
53
- if (!cancelled)
54
- setOffer(loaded);
55
- })
56
- .catch((e) => {
57
- if (!cancelled)
58
- setOfferError(bookingErrorMessage(e));
59
- });
60
- return () => {
61
- cancelled = true;
62
- };
63
- }, [usesEdge, route]);
64
- const persons = useMemo(() => offer?.persons?.map((person) => ({
65
- id: person.token,
66
- name: person.name,
67
- role: person.role,
68
- avatarUrl: person.avatarUrl,
69
- description: person.description,
70
- })), [offer]);
71
- const fetchDays = useCallback(async ({ personId }) => {
72
- if (!route || !offer)
73
- return [];
74
- // The offer already answered for "anybody"; one person's days are that person's offer.
75
- return personId ? (await fetchBookingOffer(route, personId)).days : offer.days;
76
- }, [route, offer]);
77
- const fetchSlots = useCallback(async ({ personId, date }) => {
78
- if (!route || !offer)
79
- return [];
80
- const slots = await fetchBookingSlots(route, date, personId);
81
- return slots.map((slot) => toPickerSlot(slot, offer.timeZone));
82
- }, [route, offer]);
83
- const holdSlot = useCallback(async ({ slot, contact }) => {
84
- if (!route)
85
- throw new Error('No pudimos reservar ese horario.');
86
- try {
87
- return await holdBookingSlot(route, {
88
- slot: slot.id,
89
- contact: contact?.name ? { name: contact.name, email: nonEmpty(contact.email) } : undefined,
90
- });
91
- }
92
- catch (e) {
93
- throw new Error(bookingErrorMessage(e));
94
- }
95
- }, [route]);
96
- // A held slot is somebody's calendar taken off the offer; giving it back the moment the requester
97
- // changes their mind is what keeps "Cambiar" from costing the organization the slot for the whole lock.
98
- const handleChange = useCallback((next) => {
99
- if (next === null && usesEdge && route && value?.appointment && value.hold) {
100
- void releaseBookingSlot(route, { appointment: value.appointment, hold: value.hold }).catch(() => undefined);
101
- }
102
- onChange(next);
103
- }, [onChange, usesEdge, route, value]);
104
- // The hold outlives a slow form by being renewed with its own token; a renewal that fails (the slot
105
- // handle expired, the network went) is left alone — the lock simply lapses and the slot is offered again.
106
- const renewal = useRef(undefined);
107
- useEffect(() => {
108
- clearInterval(renewal.current);
109
- if (!usesEdge || !route || !value?.appointment || !value.hold || !value.slotId || value.status !== 'PENDING') {
110
- return;
111
- }
112
- const lockMs = (step.temporaryLockMinutes ?? DEFAULT_LOCK_MINUTES) * 60000;
113
- const { slotId, hold, contactName, contactEmail } = value;
114
- renewal.current = setInterval(() => {
115
- void holdBookingSlot(route, {
116
- slot: slotId,
117
- hold,
118
- contact: contactName ? { name: contactName, email: nonEmpty(contactEmail) } : undefined,
119
- }).catch(() => undefined);
120
- }, Math.max(MIN_RENEW_MS, lockMs / 2));
121
- return () => clearInterval(renewal.current);
122
- }, [usesEdge, route, value, step.temporaryLockMinutes]);
123
- // The server decides how people are presented: a step that resolves to one calendar offers no choice.
124
- const personSelectionMode = usesEdge
125
- ? (offer?.personSelection ?? PersonSelectionMode.NONE)
126
- : step.personSelectionMode;
127
- return (_jsx("div", { ref: ref, style: cssVars, children: _jsx(ErkBookingPicker, { value: value, onChange: handleChange, label: step.label, description: step.description, durationMinutes: offer?.durationMinutes ?? step.durationMinutes, bufferMinutes: step.bufferMinutes, bookingMode: step.bookingMode, temporaryLockMinutes: step.temporaryLockMinutes, personSelectionMode: personSelectionMode, persons: usesEdge ? persons : step.persons,
128
- // Whoever holds a slot must be named unless the step lets strangers book; asking for the name
129
- // whenever it is required keeps the hold from being refused for a step that never turned the
130
- // contact fields on.
131
- collectContact: !step.allowAnonymous || step.collectContact === true, requireContact: !step.allowAnonymous, fetchSlots: usesEdge ? fetchSlots : customFetchSlots, fetchDays: usesEdge ? fetchDays : undefined, holdSlot: usesEdge ? holdSlot : undefined, disabled: usesEdge && !offer, readOnly: isReadOnly, error: error?.message ?? offerError }) }));
132
- }
133
- export default MaterialBookingStep;
@@ -1,70 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { render, screen } from '@testing-library/react';
3
- import userEvent from '@testing-library/user-event';
4
- import { describe, expect, it } from 'vitest';
5
- import '@testing-library/jest-dom';
6
- import { Provider } from 'react-redux';
7
- import { FormProvider, useForm } from 'react-hook-form';
8
- import { configureStore } from '@reduxjs/toolkit';
9
- import { EurekaFormsReducer, defaultRootState } from '../../Utils/store';
10
- import { RootApi } from '../../Utils/_api';
11
- import FormStepTypes from '../../constants/FormStepTypes';
12
- import { StoreContext } from '../../Utils/StoreContext';
13
- import FormContext, { IdFormContext } from '../../Contexts/FormContext';
14
- import SectionContext from '../../Contexts/SectionContext';
15
- import MaterialProviders from '../../Utils/MaterialProviders';
16
- import InternalFormStyle from '../../constants/InternalFormStyle';
17
- import ClassifierSelectorStep from './ClassifierSelectorStep';
18
- const ID_FORM = 'LATE_CLASSIFIERS_FORM';
19
- const step = {
20
- id: 'tipo-step',
21
- idSection: 'SECTION_1',
22
- stepPath: ['tipo-step'],
23
- type: FormStepTypes.CLASSIFIER_SELECTOR,
24
- idClassifier: 'tipo',
25
- label: 'Tipo de solicitud',
26
- description: '',
27
- searchable: true,
28
- options: {},
29
- required: false,
30
- size: 2,
31
- };
32
- /** The project's classifiers, as the host resolves them (asynchronously) and passes them to the form. */
33
- const classifiers = {
34
- tipo: { _id: 'tipo', name: 'Tipo de solicitud', children: ['bug', 'mejora'] },
35
- bug: { _id: 'bug', name: 'Error / Bug', children: [] },
36
- mejora: { _id: 'mejora', name: 'Propuesta de mejora', children: [] },
37
- };
38
- const form = {
39
- firstSection: 'SECTION_1',
40
- sections: {
41
- SECTION_1: { id: 'SECTION_1', name: 'Sección 1', steps: ['tipo-step'], nextSection: null },
42
- },
43
- steps: { 'tipo-step': step },
44
- confirmationMessage: { blocks: [], entityMap: {} },
45
- showLink: false,
46
- size: { blockSize: 200, blockNum: 4, spacingSize: 10 },
47
- };
48
- function makeStore() {
49
- return configureStore({
50
- reducer: { forms: EurekaFormsReducer, [RootApi.reducerPath]: RootApi.reducer },
51
- preloadedState: { forms: { [ID_FORM]: { ...defaultRootState } } },
52
- middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(RootApi.middleware),
53
- });
54
- }
55
- function Harness({ store, formClassifiers, }) {
56
- const methods = useForm({ mode: 'onTouched' });
57
- return (_jsx(MaterialProviders, { formStyle: InternalFormStyle, children: _jsx(Provider, { store: store, context: StoreContext, children: _jsx(IdFormContext.Provider, { value: ID_FORM, children: _jsx(FormContext.Provider, { value: { ...form, classifiers: formClassifiers }, children: _jsx(SectionContext.Provider, { value: "SECTION_1", children: _jsx(FormProvider, { ...methods, children: _jsx(ClassifierSelectorStep, { step: step, editable: true }) }) }) }) }) }) }));
58
- }
59
- describe('ClassifierSelectorStep with classifiers that arrive after the first render', () => {
60
- it('renders nothing while the classifiers are unknown, then the selector with its options', async () => {
61
- const user = userEvent.setup();
62
- const store = makeStore();
63
- const { rerender } = render(_jsx(Harness, { store: store, formClassifiers: undefined }));
64
- expect(screen.queryByRole('combobox')).not.toBeInTheDocument();
65
- rerender(_jsx(Harness, { store: store, formClassifiers: classifiers }));
66
- await user.click(await screen.findByRole('combobox'));
67
- expect(await screen.findByRole('option', { name: 'Error / Bug' })).toBeInTheDocument();
68
- expect(screen.getByRole('option', { name: 'Propuesta de mejora' })).toBeInTheDocument();
69
- });
70
- });
@@ -1,12 +0,0 @@
1
- import { StepDependency } from '../../Form/Form';
2
- /**
3
- * Serializes the current value of a dependency step into the string an entity-picker STEP filter
4
- * sends as `values.<idProperty>` query param.
5
- *
6
- * Entity values (and any id-bearing object) resolve to their id. The answer of a Selector or
7
- * Classifier step is a `{ label, value }` option: a Selector keeps `value === label`, so its `value`
8
- * is the text the entity property stores; a Classifier's `value` is the classifier id, which no
9
- * entity property holds, so it resolves to its `label`. Returns undefined when the dependency has
10
- * no usable value, so the caller treats the filter as unresolved.
11
- */
12
- export declare function entityValueDependencyValue(dependency: StepDependency | undefined): string | undefined;
@@ -1,35 +0,0 @@
1
- import FormStepTypes from '../../constants/FormStepTypes';
2
- /**
3
- * Serializes the current value of a dependency step into the string an entity-picker STEP filter
4
- * sends as `values.<idProperty>` query param.
5
- *
6
- * Entity values (and any id-bearing object) resolve to their id. The answer of a Selector or
7
- * Classifier step is a `{ label, value }` option: a Selector keeps `value === label`, so its `value`
8
- * is the text the entity property stores; a Classifier's `value` is the classifier id, which no
9
- * entity property holds, so it resolves to its `label`. Returns undefined when the dependency has
10
- * no usable value, so the caller treats the filter as unresolved.
11
- */
12
- export function entityValueDependencyValue(dependency) {
13
- const currentValue = dependency?.value;
14
- if (currentValue === null || currentValue === undefined || currentValue === '')
15
- return undefined;
16
- if (typeof currentValue === 'string')
17
- return currentValue;
18
- if (typeof currentValue === 'number' || typeof currentValue === 'boolean')
19
- return String(currentValue);
20
- if (currentValue instanceof Date)
21
- return currentValue.toISOString();
22
- if (typeof currentValue !== 'object')
23
- return undefined;
24
- const record = currentValue;
25
- // A Selector's `value` is the stored text; every other step's `value` may be an id, so its `label` wins.
26
- const keys = dependency?.type === FormStepTypes.SELECTOR ? ['_id', 'id', 'value', 'label'] : ['_id', 'id', 'label', 'value'];
27
- for (const key of keys) {
28
- const candidate = record[key];
29
- if (typeof candidate === 'string' && candidate !== '')
30
- return candidate;
31
- if (typeof candidate === 'number')
32
- return String(candidate);
33
- }
34
- return undefined;
35
- }
@@ -1,31 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import FormStepTypes from '../../constants/FormStepTypes';
3
- import { entityValueDependencyValue } from './entityValueDependencyValue';
4
- const dep = (type, value) => ({
5
- idOriginal: 'dep',
6
- dependents: [],
7
- type,
8
- value,
9
- });
10
- describe('entityValueDependencyValue', () => {
11
- test('an unanswered dependency is unresolved', () => {
12
- expect(entityValueDependencyValue(undefined)).toBeUndefined();
13
- expect(entityValueDependencyValue(dep(FormStepTypes.SELECTOR, null))).toBeUndefined();
14
- expect(entityValueDependencyValue(dep(FormStepTypes.SELECTOR, ''))).toBeUndefined();
15
- expect(entityValueDependencyValue(dep(FormStepTypes.SELECTOR, {}))).toBeUndefined();
16
- });
17
- test('plain answers are sent as text', () => {
18
- expect(entityValueDependencyValue(dep(FormStepTypes.TEXTINPUT, 'Torre 3'))).toBe('Torre 3');
19
- expect(entityValueDependencyValue(dep(FormStepTypes.TEXTINPUT, 7))).toBe('7');
20
- expect(entityValueDependencyValue(dep(FormStepTypes.DATEPICKER, new Date('2026-01-02T00:00:00.000Z')))).toBe('2026-01-02T00:00:00.000Z');
21
- });
22
- test('an entity value resolves to its id', () => {
23
- expect(entityValueDependencyValue(dep(FormStepTypes.ENTITYVALUEPICKER, { _id: 'ev-1', label: 'Morros' }))).toBe('ev-1');
24
- expect(entityValueDependencyValue(dep(FormStepTypes.API_SELECTOR, { id: 'api-1', label: 'X' }))).toBe('api-1');
25
- });
26
- test('a selector option resolves to its value, a classifier option to its label', () => {
27
- expect(entityValueDependencyValue(dep(FormStepTypes.SELECTOR, { label: 'Piso 2', value: 'Piso 2' }))).toBe('Piso 2');
28
- expect(entityValueDependencyValue(dep(FormStepTypes.SELECTOR, { label: 'Dos', value: '2' }))).toBe('2');
29
- expect(entityValueDependencyValue(dep(FormStepTypes.CLASSIFIER_SELECTOR, { label: 'Piso 2', value: '65f0c1a2b3c4d5e6f7a8b9c0' }))).toBe('Piso 2');
30
- });
31
- });
@@ -1,27 +0,0 @@
1
- import { EntityValuePicker } from '../../@Types/FormStep';
2
- /**
3
- * The steps an entity picker reads a value from that `step.dependencies` does not already list:
4
- * the STEP hops of `step.path` and every STEP filter, required or not.
5
- *
6
- * `step.dependencies` is recomputed server-side only when the form is saved
7
- * (`FormDependencyFunctions.calcStepDependencies`), so it describes the form as it was at the last
8
- * save. In the editor's live preview of an unsaved draft — and in any form whose stored
9
- * dependencies went stale — a path hop or a filter added since then is missing from it, and the
10
- * renderer would never watch the step it points at. The picker refetches its options when a watched
11
- * value changes, so a filter the picker does not watch never triggers the fetch that would honour
12
- * it: a required one leaves the select stuck with no options at all, an optional one leaves it
13
- * showing options the filter should have narrowed.
14
- *
15
- * The `required` flag is deliberately not consulted: required or not, the filter's value is what
16
- * has to trigger the refetch. Steps the last save already registered are skipped because the
17
- * renderer watches `step.dependencies` anyway.
18
- */
19
- export declare function entityValuePickerWatchedSteps(step: EntityValuePicker): string[];
20
- /**
21
- * The subset of `entityValuePickerWatchedSteps` whose value the picker cannot do without: every
22
- * STEP hop of the path, and the STEP filters flagged `required`. Those are exactly the cases where
23
- * `getEntityValueOptions` gives up and answers `null` — its "dependency not met" contract — so
24
- * while they hold no value the select has to read as a missing dependency rather than as a failed
25
- * load.
26
- */
27
- export declare function entityValuePickerBlockingSteps(step: EntityValuePicker): string[];
@@ -1,64 +0,0 @@
1
- import { EntityValueDataTypes } from '../../constants/FormStepTypes';
2
- const push = (step, idStep, into) => {
3
- if (!idStep)
4
- return;
5
- /**
6
- * A draft can point a filter or a path hop at the picker that holds it (the editor lists the
7
- * step among the pickable ones before the form is saved and the backend rejects it). A step is
8
- * never its own dependency, and watching itself would close a cycle in the dependency walk.
9
- */
10
- if (idStep === step.id)
11
- return;
12
- if (step.dependencies?.includes(idStep))
13
- return;
14
- if (!into.includes(idStep))
15
- into.push(idStep);
16
- };
17
- /**
18
- * The steps an entity picker reads a value from that `step.dependencies` does not already list:
19
- * the STEP hops of `step.path` and every STEP filter, required or not.
20
- *
21
- * `step.dependencies` is recomputed server-side only when the form is saved
22
- * (`FormDependencyFunctions.calcStepDependencies`), so it describes the form as it was at the last
23
- * save. In the editor's live preview of an unsaved draft — and in any form whose stored
24
- * dependencies went stale — a path hop or a filter added since then is missing from it, and the
25
- * renderer would never watch the step it points at. The picker refetches its options when a watched
26
- * value changes, so a filter the picker does not watch never triggers the fetch that would honour
27
- * it: a required one leaves the select stuck with no options at all, an optional one leaves it
28
- * showing options the filter should have narrowed.
29
- *
30
- * The `required` flag is deliberately not consulted: required or not, the filter's value is what
31
- * has to trigger the refetch. Steps the last save already registered are skipped because the
32
- * renderer watches `step.dependencies` anyway.
33
- */
34
- export function entityValuePickerWatchedSteps(step) {
35
- const watched = [];
36
- for (const path of step.path) {
37
- if (path.type === EntityValueDataTypes.STEP)
38
- push(step, path.idStep, watched);
39
- }
40
- for (const filter of step.filters) {
41
- if (filter.type === EntityValueDataTypes.STEP)
42
- push(step, filter.idStep, watched);
43
- }
44
- return watched;
45
- }
46
- /**
47
- * The subset of `entityValuePickerWatchedSteps` whose value the picker cannot do without: every
48
- * STEP hop of the path, and the STEP filters flagged `required`. Those are exactly the cases where
49
- * `getEntityValueOptions` gives up and answers `null` — its "dependency not met" contract — so
50
- * while they hold no value the select has to read as a missing dependency rather than as a failed
51
- * load.
52
- */
53
- export function entityValuePickerBlockingSteps(step) {
54
- const blocking = [];
55
- for (const path of step.path) {
56
- if (path.type === EntityValueDataTypes.STEP)
57
- push(step, path.idStep, blocking);
58
- }
59
- for (const filter of step.filters) {
60
- if (filter.type === EntityValueDataTypes.STEP && filter.required)
61
- push(step, filter.idStep, blocking);
62
- }
63
- return blocking;
64
- }
@@ -1,95 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import FormStepTypes, { EntityValueDataTypes } from '../../constants/FormStepTypes';
3
- import { entityValuePickerBlockingSteps, entityValuePickerWatchedSteps } from './entityValuePickerWatchedSteps';
4
- const picker = (picker) => ({
5
- id: 'picker',
6
- idSection: 'section',
7
- type: FormStepTypes.ENTITYVALUEPICKER,
8
- idEntity: 'entity',
9
- path: [],
10
- filters: [],
11
- options: {},
12
- ...picker,
13
- });
14
- const stepFilter = (idStep, required) => ({
15
- idProperty: 'prop-' + idStep,
16
- type: EntityValueDataTypes.STEP,
17
- idStep,
18
- any: false,
19
- required,
20
- });
21
- const stepPath = (idStep) => ({
22
- idEntity: 'parent',
23
- type: EntityValueDataTypes.STEP,
24
- idStep,
25
- any: false,
26
- });
27
- describe('entityValuePickerWatchedSteps', () => {
28
- test('watches a STEP filter the saved dependencies do not list, required or not', () => {
29
- const step = picker({ filters: [stepFilter('required', true), stepFilter('optional', false)] });
30
- expect(entityValuePickerWatchedSteps(step)).toEqual(['required', 'optional']);
31
- });
32
- test('skips the steps the last save already registered', () => {
33
- const step = picker({
34
- dependencies: ['required'],
35
- filters: [stepFilter('required', true), stepFilter('optional', false)],
36
- });
37
- expect(entityValuePickerWatchedSteps(step)).toEqual(['optional']);
38
- });
39
- test('watches the STEP hops of an unsaved path', () => {
40
- const step = picker({
41
- dependencies: ['saved'],
42
- path: [stepPath('saved'), stepPath('added'), { idEntity: 'e', type: EntityValueDataTypes.VALUE }],
43
- });
44
- expect(entityValuePickerWatchedSteps(step)).toEqual(['added']);
45
- });
46
- test('ignores filters that read no step, and a path hop with no step picked yet', () => {
47
- const step = picker({
48
- path: [{ idEntity: 'e', type: EntityValueDataTypes.STEP, any: true }],
49
- filters: [
50
- { idProperty: 'a', type: EntityValueDataTypes.VALUE, value: 'x' },
51
- { idProperty: 'b', type: EntityValueDataTypes.CURRENT_AGENT },
52
- { idProperty: 'c', type: EntityValueDataTypes.INTEGRATION, idIntegration: 'i', values: {} },
53
- ],
54
- });
55
- expect(entityValuePickerWatchedSteps(step)).toEqual([]);
56
- });
57
- test('never repeats a step read twice', () => {
58
- const step = picker({
59
- path: [stepPath('shared')],
60
- filters: [stepFilter('shared', true)],
61
- });
62
- expect(entityValuePickerWatchedSteps(step)).toEqual(['shared']);
63
- });
64
- test('ignores a draft filter or path hop pointing back at the picker itself', () => {
65
- const step = picker({
66
- path: [stepPath('picker'), stepPath('hop')],
67
- filters: [stepFilter('picker', true), stepFilter('picker', false), stepFilter('other', false)],
68
- });
69
- expect(entityValuePickerWatchedSteps(step)).toEqual(['hop', 'other']);
70
- });
71
- });
72
- describe('entityValuePickerBlockingSteps', () => {
73
- test('only the path hops and the required filters block the fetch', () => {
74
- const step = picker({
75
- path: [stepPath('hop')],
76
- filters: [stepFilter('required', true), stepFilter('optional', false)],
77
- });
78
- expect(entityValuePickerBlockingSteps(step)).toEqual(['hop', 'required']);
79
- });
80
- test('a saved dependency is already watched deeply, so it is not repeated', () => {
81
- const step = picker({
82
- dependencies: ['hop', 'required'],
83
- path: [stepPath('hop')],
84
- filters: [stepFilter('required', true)],
85
- });
86
- expect(entityValuePickerBlockingSteps(step)).toEqual([]);
87
- });
88
- test('ignores a draft filter or path hop pointing back at the picker itself', () => {
89
- const step = picker({
90
- path: [stepPath('picker')],
91
- filters: [stepFilter('picker', true)],
92
- });
93
- expect(entityValuePickerBlockingSteps(step)).toEqual([]);
94
- });
95
- });
@@ -1,10 +0,0 @@
1
- import { LocationStep } from '../../@Types/LocationFormStep';
2
- import { StepProps } from '../Step';
3
- export interface LocationStepProps extends StepProps {
4
- /** The LocationStep to display */
5
- step: LocationStep;
6
- /** The icon to display */
7
- IconComponent?: React.ElementType;
8
- }
9
- declare function LocationStepComponent(props: LocationStepProps): JSX.Element;
10
- export default LocationStepComponent;
@@ -1,14 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { FormStyleTypes } from '../../constants/FormStepTypes';
3
- import MaterialLocationStep from './MaterialLocationStep/MaterialLocationStep';
4
- import { useAppSelector } from '../../hooks';
5
- function LocationStepComponent(props) {
6
- const { formStyle } = useAppSelector((state) => state.global);
7
- switch (formStyle.type) {
8
- case FormStyleTypes.MATERIAL:
9
- default: {
10
- return _jsx(MaterialLocationStep, { ...props });
11
- }
12
- }
13
- }
14
- export default LocationStepComponent;
@@ -1,3 +0,0 @@
1
- import { LocationStepProps } from '../LocationStep';
2
- declare function MaterialLocationStep({ step, editable }: LocationStepProps): JSX.Element;
3
- export default MaterialLocationStep;
@@ -1,54 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useContext } from 'react';
3
- import { AddressFieldMode, LocationInputMode } from '../../../@Types/LocationFormStep';
4
- import { useFormStep } from '../../StepHooks';
5
- import FormContext from '../../../Contexts/FormContext';
6
- import { selectBreakPoint, useAppSelector } from '../../../hooks';
7
- import { calcStepWidth } from '../../StepFunctions';
8
- import ErkLocationField from '../../../Shared/ErkLocationField/ErkLocationField';
9
- import { fieldConfig } from '../../../Shared/ErkLocationField/addressFields';
10
- import { validateRestrictions } from '../../../Shared/ErkLocationField/locationRestrictions';
11
- import styles from './MaterialLocationStep.module.css';
12
- function MaterialLocationStep({ step, editable }) {
13
- const currentBreakPoint = useAppSelector(selectBreakPoint);
14
- const { postview, formStyle } = useAppSelector((state) => state.global);
15
- const form = useContext(FormContext);
16
- const isReadOnly = !editable || postview;
17
- const widthStyle = currentBreakPoint <= step.size ? '100%' : calcStepWidth(step.size, form.size);
18
- const { ref, value, onChange, error } = useFormStep(step, {
19
- defaultValue: step.defaultValue ?? null,
20
- rules: {
21
- required: step.required ? 'La ubicación es obligatoria' : undefined,
22
- validate: (val) => {
23
- if (!val)
24
- return step.required ? 'La ubicación es obligatoria' : true;
25
- if (val.source === LocationInputMode.MANUAL) {
26
- // Un campo es obligatorio en manual solo si no está omitido (FIXED lo llena solo).
27
- const detail = val.addressDetail;
28
- const isRequired = (key) => fieldConfig(step.addressFields, key).mode !== AddressFieldMode.OMIT;
29
- if (step.required && isRequired('street') && !detail?.street)
30
- return 'Por favor completa la calle en el formulario manual.';
31
- if (step.required && isRequired('city') && !detail?.city)
32
- return 'Por favor completa la ciudad en el formulario manual.';
33
- if (step.required && isRequired('country') && !detail?.country)
34
- return 'Por favor completa el país en el formulario manual.';
35
- return true;
36
- }
37
- if (val.latitude === undefined || val.longitude === undefined) {
38
- return step.required ? 'Coordenadas geográficas no capturadas.' : true;
39
- }
40
- // Restricciones geográficas (radio / geofence).
41
- return validateRestrictions(val.latitude, val.longitude, step.restrictions) ?? true;
42
- },
43
- },
44
- });
45
- return (_jsxs("div", { className: styles.container, style: {
46
- width: widthStyle,
47
- '--eureka-outline': formStyle.outlineColor,
48
- '--eureka-primary': formStyle.primaryColor,
49
- '--eureka-text': formStyle.textColor,
50
- '--eureka-error': formStyle.errorColor,
51
- '--eureka-bg': formStyle.standAloneBackgroundColor ?? '#fff',
52
- }, children: [step.label && (_jsxs("div", { className: styles.label, children: [step.label, step.required && _jsx("span", { className: styles.required, children: " *" })] })), _jsx(ErkLocationField, { value: value, onChange: onChange, allowedModes: step.allowedModes, defaultMode: step.defaultMode, addressFields: step.addressFields, helperText: error?.message ?? step.description, required: step.required, error: !!error, readOnly: isReadOnly, inputRef: ref })] }));
53
- }
54
- export default MaterialLocationStep;
@@ -1,18 +0,0 @@
1
- .container {
2
- max-width: 100%;
3
- display: flex;
4
- flex-direction: column;
5
- gap: 6px;
6
- padding: 5px 10px 0;
7
- box-sizing: border-box;
8
- }
9
-
10
- .label {
11
- font-size: 14px;
12
- font-weight: 500;
13
- color: var(--eureka-text, #333);
14
- }
15
-
16
- .required {
17
- color: var(--eureka-error, #e53935);
18
- }
@@ -1,3 +0,0 @@
1
- import { NumberStepProps } from '../NumberStep';
2
- declare function MaterialNumberStep({ step, editable }: NumberStepProps): JSX.Element;
3
- export default MaterialNumberStep;