@arquimedes.co/eureka-forms 3.0.49-new-steps → 3.0.50-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 (145) hide show
  1. package/dist/@Types/Condition.d.ts +6 -4
  2. package/dist/@Types/ErkValue.d.ts +16 -0
  3. package/dist/@Types/ErkValue.js +1 -0
  4. package/dist/@Types/Form.d.ts +1 -0
  5. package/dist/@Types/FormStep.d.ts +10 -8
  6. package/dist/@Types/FormStep.js +1 -2
  7. package/dist/@Types/User.d.ts +13 -0
  8. package/dist/@Types/User.js +1 -0
  9. package/dist/App/App.js +1 -1
  10. package/dist/App/AppFunctions.js +8 -3
  11. package/dist/App/AppHooks.js +20 -1
  12. package/dist/Form/Form.js +6 -2
  13. package/dist/Form/Form.module.css +48 -39
  14. package/dist/FormSteps/ApiSelectorStep/MaterialApiSelectorStep/MaterialApiSelectorStep.js +8 -4
  15. package/dist/FormSteps/CBRStepMapper.js +1 -1
  16. package/dist/FormSteps/ClassifierSelectorStep/MaterialClassifierSelectorStep/MaterialClassifierSelectorStep.js +2 -2
  17. package/dist/FormSteps/DatePickerRangeStep/MaterialDatePickerRangeStep/MaterialDatePickerRangeStep.js +1 -1
  18. package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValuePickerStep.js +52 -4
  19. package/dist/FormSteps/FileUploadStep/MaterialFileUploadStep/FileComponent/FileComponent.js +1 -1
  20. package/dist/FormSteps/FileUploadStep/MaterialFileUploadStep/FileComponent/FileComponent.module.css +1 -1
  21. package/dist/FormSteps/FileUploadStep/MaterialFileUploadStep/MaterialFileUploadStep.js +48 -17
  22. package/dist/FormSteps/FileUploadStep/MaterialFileUploadStep/MaterialFileUploadStep.module.css +16 -0
  23. package/dist/FormSteps/Step.js +0 -16
  24. package/dist/FormSteps/StepFunctions.js +6 -23
  25. package/dist/FormSteps/StepFunctions.test.js +3 -57
  26. package/dist/FormSteps/TitleStep/MaterialTitleStep/MaterialTitleStep.js +2 -1
  27. package/dist/Icons/@ErkIcon.d.ts +2 -2
  28. package/dist/Icons/@ErkIcon.js +2 -2
  29. package/dist/Icons/EmailIcon.d.ts +3 -0
  30. package/dist/Icons/{EditIcon.js → EmailIcon.js} +3 -3
  31. package/dist/Icons/Entities/SchoolIcon.d.ts +3 -0
  32. package/dist/Icons/Entities/SchoolIcon.js +7 -0
  33. package/dist/Icons/GroupIcon.d.ts +3 -0
  34. package/dist/Icons/GroupIcon.js +7 -0
  35. package/dist/Icons/LockedIcon.d.ts +3 -0
  36. package/dist/Icons/LockedIcon.js +7 -0
  37. package/dist/Login/Login.module.css +135 -0
  38. package/dist/Login/LoginLayout.module.css +68 -0
  39. package/dist/Login/LoginPage.d.ts +10 -0
  40. package/dist/Login/LoginPage.js +101 -0
  41. package/dist/Login/LoginTextField.d.ts +14 -0
  42. package/dist/Login/LoginTextField.js +29 -0
  43. package/dist/Services/ApiSelectorService.d.ts +366 -0
  44. package/dist/Services/ApiSelectorService.js +173 -0
  45. package/dist/Services/ApiSelectorService.test.d.ts +1 -0
  46. package/dist/Services/ApiSelectorService.test.js +87 -0
  47. package/dist/Services/DraftService.js +4 -1
  48. package/dist/Services/IntegrationService.d.ts +21 -0
  49. package/dist/Services/IntegrationService.js +22 -0
  50. package/dist/Services/UserService.d.ts +10 -0
  51. package/dist/Services/UserService.js +21 -0
  52. package/dist/Shared/ErkDatePicker/ErkDatePicker.js +11 -4
  53. package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.d.ts +3 -2
  54. package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.js +10 -4
  55. package/dist/Shared/ErkSelect/ErkSelect.d.ts +2 -2
  56. package/dist/Shared/InputIcon/InputIcon.js +6 -0
  57. package/dist/Shared/Navbar/Navbar.d.ts +2 -1
  58. package/dist/Shared/Navbar/Navbar.js +22 -3
  59. package/dist/Shared/Navbar/Navbar.module.css +22 -8
  60. package/dist/Shared/SmartDraftRenderer/LinkDecorator.d.ts +14 -0
  61. package/dist/Shared/SmartDraftRenderer/LinkDecorator.js +48 -0
  62. package/dist/Shared/SmartDraftRenderer/SmartDraftRenderer.js +10 -3
  63. package/dist/States/GlobalSlice.d.ts +4 -1
  64. package/dist/States/GlobalSlice.js +8 -1
  65. package/dist/constants/ErkIconTypes.d.ts +3 -1
  66. package/dist/constants/ErkIconTypes.js +2 -0
  67. package/dist/constants/ErkValueTypes.d.ts +6 -0
  68. package/dist/constants/ErkValueTypes.js +7 -0
  69. package/dist/constants/FormStepTypes.d.ts +3 -6
  70. package/dist/constants/FormStepTypes.js +1 -4
  71. package/dist/hooks.d.ts +3 -0
  72. package/dist/hooks.js +17 -1
  73. package/package.json +9 -3
  74. package/dist/@Types/AvailabilityFormStep.d.ts +0 -48
  75. package/dist/@Types/AvailabilityFormStep.js +0 -24
  76. package/dist/@Types/BankAccountFormStep.d.ts +0 -67
  77. package/dist/@Types/BankAccountFormStep.js +0 -14
  78. package/dist/@Types/BookingFormStep.d.ts +0 -156
  79. package/dist/@Types/BookingFormStep.js +0 -44
  80. package/dist/@Types/CalendarFormStep.d.ts +0 -192
  81. package/dist/@Types/CalendarFormStep.js +0 -48
  82. package/dist/@Types/CommunicationChannelFormStep.d.ts +0 -51
  83. package/dist/@Types/CommunicationChannelFormStep.js +0 -15
  84. package/dist/@Types/ConsentFormStep.d.ts +0 -36
  85. package/dist/@Types/ConsentFormStep.js +0 -8
  86. package/dist/@Types/EntityFormFormStep.d.ts +0 -66
  87. package/dist/@Types/EntityFormFormStep.js +0 -20
  88. package/dist/@Types/EventFormStep.d.ts +0 -52
  89. package/dist/@Types/EventFormStep.js +0 -13
  90. package/dist/@Types/ExternalReferenceFormStep.d.ts +0 -74
  91. package/dist/@Types/ExternalReferenceFormStep.js +0 -20
  92. package/dist/@Types/LocationFormStep.d.ts +0 -159
  93. package/dist/@Types/LocationFormStep.js +0 -46
  94. package/dist/@Types/NumericFormSteps.d.ts +0 -108
  95. package/dist/@Types/NumericFormSteps.js +0 -20
  96. package/dist/@Types/PredefinedSelectorFormStep.d.ts +0 -51
  97. package/dist/@Types/PredefinedSelectorFormStep.js +0 -39
  98. package/dist/@Types/StepRef.d.ts +0 -135
  99. package/dist/@Types/StepRef.js +0 -49
  100. package/dist/FormSteps/BookingStep/BookingStep.d.ts +0 -17
  101. package/dist/FormSteps/BookingStep/BookingStep.js +0 -14
  102. package/dist/FormSteps/BookingStep/MaterialBookingStep/MaterialBookingStep.d.ts +0 -3
  103. package/dist/FormSteps/BookingStep/MaterialBookingStep/MaterialBookingStep.js +0 -362
  104. package/dist/FormSteps/BookingStep/MaterialBookingStep/MaterialBookingStep.module.css +0 -174
  105. package/dist/FormSteps/CalendarStep/CalendarStep.d.ts +0 -7
  106. package/dist/FormSteps/CalendarStep/CalendarStep.js +0 -14
  107. package/dist/FormSteps/CalendarStep/MaterialCalendarStep/MaterialCalendarStep.d.ts +0 -3
  108. package/dist/FormSteps/CalendarStep/MaterialCalendarStep/MaterialCalendarStep.js +0 -269
  109. package/dist/FormSteps/CalendarStep/MaterialCalendarStep/MaterialCalendarStep.module.css +0 -531
  110. package/dist/FormSteps/LocationStep/LocationStep.d.ts +0 -10
  111. package/dist/FormSteps/LocationStep/LocationStep.js +0 -14
  112. package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.d.ts +0 -3
  113. package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.js +0 -47
  114. package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.module.css +0 -18
  115. package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.d.ts +0 -3
  116. package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.js +0 -168
  117. package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.module.css +0 -94
  118. package/dist/FormSteps/NumberStep/NumberStep.d.ts +0 -10
  119. package/dist/FormSteps/NumberStep/NumberStep.js +0 -14
  120. package/dist/Icons/AddIcon.d.ts +0 -3
  121. package/dist/Icons/AddIcon.js +0 -7
  122. package/dist/Icons/EditIcon.d.ts +0 -3
  123. package/dist/Icons/RemoveIcon.d.ts +0 -3
  124. package/dist/Icons/RemoveIcon.js +0 -7
  125. package/dist/Icons/ViewDayIcon.d.ts +0 -3
  126. package/dist/Icons/ViewDayIcon.js +0 -7
  127. package/dist/Icons/ViewWeekIcon.d.ts +0 -3
  128. package/dist/Icons/ViewWeekIcon.js +0 -7
  129. package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.d.ts +0 -19
  130. package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.js +0 -80
  131. package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.module.css +0 -82
  132. package/dist/Shared/ErkAddressAutocomplete/googlePlaces.d.ts +0 -29
  133. package/dist/Shared/ErkAddressAutocomplete/googlePlaces.js +0 -139
  134. package/dist/Shared/ErkLocationField/ErkLocationField.d.ts +0 -23
  135. package/dist/Shared/ErkLocationField/ErkLocationField.js +0 -73
  136. package/dist/Shared/ErkLocationField/ErkLocationField.module.css +0 -29
  137. package/dist/Shared/ErkLocationField/addressFields.d.ts +0 -12
  138. package/dist/Shared/ErkLocationField/addressFields.js +0 -34
  139. package/dist/Shared/ErkLocationField/locationRestrictions.d.ts +0 -6
  140. package/dist/Shared/ErkLocationField/locationRestrictions.js +0 -51
  141. package/dist/Shared/ErkLocationInput/ErkLocationInput.d.ts +0 -15
  142. package/dist/Shared/ErkLocationInput/ErkLocationInput.js +0 -499
  143. package/dist/Shared/ErkLocationInput/ErkLocationInput.module.css +0 -115
  144. package/dist/Shared/ErkNumberField/ErkNumberField.d.ts +0 -42
  145. package/dist/Shared/ErkNumberField/ErkNumberField.js +0 -170
@@ -1,135 +0,0 @@
1
- /**
2
- * DRAFT — Sistema de referencias dinámicas entre steps
3
- *
4
- * Permite que la configuración de un paso use el valor en tiempo de ejecución
5
- * de otro step del mismo formulario, en lugar de un literal fijo.
6
- *
7
- * Patrón de uso:
8
- *
9
- * // Valor fijo definido en la configuración del formulario
10
- * suffix: { type: 'FIXED', value: 'km' }
11
- *
12
- * // Valor tomado del step 'step_unidad' cuando el usuario interactúa
13
- * suffix: { type: 'STEP_REF', idStep: 'step_unidad', fallback: 'm' }
14
- *
15
- * Se puede aplicar a cualquier campo de configuración cuyo valor deba
16
- * responder a la selección previa del usuario: sufijos, unidades, monedas,
17
- * títulos dinámicos, límites numéricos, etc.
18
- */
19
- /**
20
- * Representa un valor estático/literal configurado en tiempo de diseño.
21
- * No cambia dinámicamente según las respuestas del usuario.
22
- *
23
- * @typeParam T - Tipo de dato del valor estático.
24
- */
25
- export interface FixedRef<T> {
26
- /**
27
- * Indica que el valor es fijo.
28
- */
29
- type: 'FIXED';
30
- /**
31
- * El valor estático de tipo T.
32
- * @example "km"
33
- * @example 50
34
- */
35
- value: T;
36
- }
37
- /**
38
- * Referencia dinámica al valor actual de otro step en el mismo formulario.
39
- * El runtime del formulario sustituye esta referencia por el valor que el usuario
40
- * haya ingresado en el step indicado.
41
- *
42
- * @typeParam TAllowed - Literal(es) de tipo de step permitidos como origen.
43
- * Por defecto es `string` (cualquier tipo de step). Pasar un literal union
44
- * permite al Form Builder filtrar la lista de steps disponibles en la UI.
45
- *
46
- * @example
47
- * ```ts
48
- * // Referencia a cualquier tipo de step
49
- * const ref: StepRef = {
50
- * type: 'STEP_REF',
51
- * idStep: 'step_unidad_medida',
52
- * fallback: 'm'
53
- * }
54
- *
55
- * // Referencia restringida únicamente a pasos de tipo LOCATION
56
- * const refLocation: StepRef<'LOCATION'> = {
57
- * type: 'STEP_REF',
58
- * idStep: 'step_destino_cliente',
59
- * allowedStepTypes: ['LOCATION']
60
- * }
61
- * ```
62
- */
63
- export interface StepRef<TAllowed extends string = string> {
64
- /**
65
- * Indica que el valor se toma dinámicamente de otro paso.
66
- */
67
- type: 'STEP_REF';
68
- /**
69
- * ID del paso origen en el formulario del cual se leerá el valor en tiempo de ejecución.
70
- * @example "step_ubicacion_cliente"
71
- */
72
- idStep: string;
73
- /**
74
- * Valor de respaldo (fallback) en formato de texto a utilizar mientras el paso referenciado
75
- * no contenga ningún valor (ej: porque el usuario aún no llega a ese paso).
76
- * Si se omite, el campo referenciador se comportará como vacío o sin unidad.
77
- *
78
- * @example "m"
79
- */
80
- fallback?: string;
81
- /**
82
- * Lista de tipos de pasos permitidos para esta referencia.
83
- * Ayuda al Form Builder a filtrar la interfaz de selección de campos y es
84
- * validada por el backend al guardar la configuración del formulario.
85
- * Si no se define, se permite referenciar cualquier tipo de paso.
86
- *
87
- * @example ["LOCATION"]
88
- * @example ["PREDEFINED_SELECTOR", "CHECKBOX"]
89
- */
90
- allowedStepTypes?: TAllowed[];
91
- }
92
- /**
93
- * Tipo genérico para campos que admiten tanto un valor estático como una referencia dinámica.
94
- *
95
- * @typeParam T - Tipo del valor cuando es FIXED (ej: `string`, `number`, `boolean`).
96
- * @typeParam TAllowed - Tipos de paso de origen permitidos si es STEP_REF.
97
- *
98
- * @example
99
- * ```ts
100
- * // Un sufijo de texto dinámico:
101
- * const sufijo: DynamicRef<string> = { type: 'FIXED', value: 'km' };
102
- *
103
- * // Una coordenada geográfica que debe venir de un paso de mapa:
104
- * const origen: DynamicRef<LocationCoords, 'LOCATION'> = {
105
- * type: 'STEP_REF',
106
- * idStep: 'step_mapa_inicio',
107
- * allowedStepTypes: ['LOCATION']
108
- * };
109
- * ```
110
- */
111
- export type DynamicRef<T, TAllowed extends string = string> = FixedRef<T> | StepRef<TAllowed>;
112
- /**
113
- * Comprueba si la referencia dinámica recibida es de tipo FIXED.
114
- * Funciona como Type Guard para TypeScript.
115
- *
116
- * @example
117
- * ```ts
118
- * if (isFixedRef(miRef)) {
119
- * console.log("El valor es:", miRef.value);
120
- * }
121
- * ```
122
- */
123
- export declare function isFixedRef<T, TAllowed extends string = string>(ref: DynamicRef<T, TAllowed>): ref is FixedRef<T>;
124
- /**
125
- * Comprueba si la referencia dinámica recibida es de tipo STEP_REF.
126
- * Funciona como Type Guard para TypeScript.
127
- *
128
- * @example
129
- * ```ts
130
- * if (isStepRef(miRef)) {
131
- * console.log("Apunta al step:", miRef.idStep);
132
- * }
133
- * ```
134
- */
135
- export declare function isStepRef<T, TAllowed extends string = string>(ref: DynamicRef<T, TAllowed>): ref is StepRef<TAllowed>;
@@ -1,49 +0,0 @@
1
- /**
2
- * DRAFT — Sistema de referencias dinámicas entre steps
3
- *
4
- * Permite que la configuración de un paso use el valor en tiempo de ejecución
5
- * de otro step del mismo formulario, en lugar de un literal fijo.
6
- *
7
- * Patrón de uso:
8
- *
9
- * // Valor fijo definido en la configuración del formulario
10
- * suffix: { type: 'FIXED', value: 'km' }
11
- *
12
- * // Valor tomado del step 'step_unidad' cuando el usuario interactúa
13
- * suffix: { type: 'STEP_REF', idStep: 'step_unidad', fallback: 'm' }
14
- *
15
- * Se puede aplicar a cualquier campo de configuración cuyo valor deba
16
- * responder a la selección previa del usuario: sufijos, unidades, monedas,
17
- * títulos dinámicos, límites numéricos, etc.
18
- */
19
- // ---------------------------------------------------------------------------
20
- // Helpers de narrowing
21
- // ---------------------------------------------------------------------------
22
- /**
23
- * Comprueba si la referencia dinámica recibida es de tipo FIXED.
24
- * Funciona como Type Guard para TypeScript.
25
- *
26
- * @example
27
- * ```ts
28
- * if (isFixedRef(miRef)) {
29
- * console.log("El valor es:", miRef.value);
30
- * }
31
- * ```
32
- */
33
- export function isFixedRef(ref) {
34
- return ref.type === 'FIXED';
35
- }
36
- /**
37
- * Comprueba si la referencia dinámica recibida es de tipo STEP_REF.
38
- * Funciona como Type Guard para TypeScript.
39
- *
40
- * @example
41
- * ```ts
42
- * if (isStepRef(miRef)) {
43
- * console.log("Apunta al step:", miRef.idStep);
44
- * }
45
- * ```
46
- */
47
- export function isStepRef(ref) {
48
- return ref.type === 'STEP_REF';
49
- }
@@ -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.
8
- * The form host wires this to their availability API.
9
- * If omitted, the component shows an empty slot list.
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,3 +0,0 @@
1
- import { BookingStepProps } from '../BookingStep';
2
- declare function MaterialBookingStep({ step, editable, fetchSlots }: BookingStepProps): JSX.Element;
3
- export default MaterialBookingStep;
@@ -1,362 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useContext, useState, useCallback, useEffect, useId } from 'react';
3
- import { Dialog, DialogTitle, DialogContent, Avatar, CircularProgress, InputAdornment, styled, } from '@mui/material';
4
- import { alpha, useTheme } from '@mui/material/styles';
5
- import { format, addDays, startOfDay, isSameDay, isToday } from 'date-fns';
6
- import { es } from 'date-fns/locale';
7
- import { PersonSelectionMode } from '../../../@Types/BookingFormStep';
8
- import { useFormStep } from '../../StepHooks';
9
- import FormContext from '../../../Contexts/FormContext';
10
- import { selectBreakPoint, useAppSelector } from '../../../hooks';
11
- import { calcStepWidth } from '../../StepFunctions';
12
- import { StyledTextField } from '../../../Shared/ErkTextField/ErkTextField';
13
- import ErkButton from '../../../Shared/ErkButton/ErkButton';
14
- import CalendarIcon from '../../../Icons/CalendarIcon';
15
- import CloseIcon from '../../../Icons/CloseIcon';
16
- import ArrowLeftIcon from '../../../Icons/ArrowLeftIcon';
17
- import ArrowRightIcon from '../../../Icons/ArrowRightIcon';
18
- import PersonIcon from '../../../Icons/PersonIcon';
19
- import styles from './MaterialBookingStep.module.css';
20
- // ---------------------------------------------------------------------------
21
- // Theme-aware styled components
22
- // ---------------------------------------------------------------------------
23
- const SummaryCard = styled('div')(({ theme }) => ({
24
- display: 'flex',
25
- alignItems: 'center',
26
- gap: 12,
27
- padding: '12px 16px',
28
- border: `1px solid ${theme.palette.outline.main}`,
29
- borderRadius: 10,
30
- backgroundColor: theme.palette.stepBackgroundColor.default,
31
- }));
32
- const EmptyReadOnly = styled('div')(({ theme }) => ({
33
- display: 'flex',
34
- alignItems: 'center',
35
- gap: 10,
36
- padding: '14px 16px',
37
- border: `1px solid ${theme.palette.outline.main}`,
38
- borderRadius: 10,
39
- backgroundColor: theme.palette.stepBackgroundColor.default,
40
- color: alpha(theme.palette.text.primary, 0.45),
41
- fontSize: 14,
42
- }));
43
- const PersonCard = styled('div')(({ theme, active }) => ({
44
- display: 'flex',
45
- alignItems: 'center',
46
- gap: 14,
47
- padding: '14px 20px',
48
- cursor: 'pointer',
49
- borderBottom: `1px solid ${alpha(theme.palette.text.primary, 0.06)}`,
50
- backgroundColor: active ? alpha(theme.palette.primary.main, 0.05) : 'transparent',
51
- transition: 'background 0.15s',
52
- '&:last-child': { borderBottom: 'none' },
53
- '&:hover': { backgroundColor: alpha(theme.palette.text.primary, 0.03) },
54
- }));
55
- const PersonChip = styled('button')(({ theme }) => ({
56
- display: 'inline-flex',
57
- alignItems: 'center',
58
- gap: 8,
59
- marginTop: 10,
60
- padding: '6px 12px 6px 8px',
61
- border: `1px solid ${theme.palette.outline.main}`,
62
- borderRadius: 10,
63
- background: 'none',
64
- cursor: 'pointer',
65
- fontSize: 13,
66
- fontWeight: 500,
67
- color: 'inherit',
68
- fontFamily: 'inherit',
69
- transition: 'border-color 0.2s, background 0.2s',
70
- '&:hover': {
71
- borderColor: theme.palette.primary.main,
72
- background: alpha(theme.palette.primary.main, 0.04),
73
- },
74
- }));
75
- const DateChipButton = styled('button', {
76
- shouldForwardProp: (p) => p !== 'selected' && p !== 'todayHighlight',
77
- })(({ theme, selected, todayHighlight }) => ({
78
- display: 'flex',
79
- flexDirection: 'column',
80
- alignItems: 'center',
81
- justifyContent: 'center',
82
- flex: 1,
83
- minWidth: 0,
84
- padding: '8px 4px',
85
- border: `1px solid ${selected || todayHighlight ? theme.palette.primary.main : theme.palette.outline.main}`,
86
- borderRadius: 10,
87
- cursor: 'pointer',
88
- background: selected ? theme.palette.primary.main : 'transparent',
89
- color: selected ? theme.palette.primary.contrastText ?? '#fff' : 'inherit',
90
- fontFamily: 'inherit',
91
- transition: 'border-color 0.15s, background 0.15s, color 0.15s',
92
- gap: 1,
93
- '&:hover:not(:disabled)': {
94
- borderColor: theme.palette.primary.main,
95
- background: selected ? theme.palette.primary.main : alpha(theme.palette.primary.main, 0.05),
96
- },
97
- '&:disabled': {
98
- opacity: 0.35,
99
- cursor: 'default',
100
- },
101
- }));
102
- const SlotRowButton = styled('button')(({ theme }) => ({
103
- padding: '12px 16px',
104
- border: `1.5px solid ${theme.palette.outline.main}`,
105
- borderRadius: 10,
106
- cursor: 'pointer',
107
- background: 'transparent',
108
- fontSize: 15,
109
- fontWeight: 500,
110
- textAlign: 'left',
111
- color: theme.palette.text.primary,
112
- fontFamily: 'inherit',
113
- transition: 'border-color 0.15s, background 0.15s, color 0.15s',
114
- '&:hover': {
115
- borderColor: theme.palette.primary.main,
116
- background: alpha(theme.palette.primary.main, 0.04),
117
- color: theme.palette.primary.main,
118
- },
119
- }));
120
- const IconBtn = styled('button')(({ theme }) => ({
121
- display: 'flex',
122
- alignItems: 'center',
123
- justifyContent: 'center',
124
- padding: 6,
125
- border: 'none',
126
- borderRadius: '50%',
127
- background: 'none',
128
- cursor: 'pointer',
129
- color: 'inherit',
130
- opacity: 0.6,
131
- flexShrink: 0,
132
- transition: 'opacity 0.15s, background 0.15s',
133
- '&:hover': {
134
- opacity: 1,
135
- background: alpha(theme.palette.text.primary, 0.06),
136
- },
137
- }));
138
- const StripArrowBtn = styled('button')(({ theme }) => ({
139
- flexShrink: 0,
140
- display: 'flex',
141
- alignItems: 'center',
142
- justifyContent: 'center',
143
- padding: 4,
144
- border: 'none',
145
- borderRadius: '50%',
146
- background: 'none',
147
- cursor: 'pointer',
148
- color: 'inherit',
149
- opacity: 0.6,
150
- transition: 'opacity 0.15s, background 0.15s',
151
- '&:hover:not(:disabled)': {
152
- opacity: 1,
153
- background: alpha(theme.palette.text.primary, 0.06),
154
- },
155
- '&:disabled': { opacity: 0.2, cursor: 'default' },
156
- }));
157
- const ClearBtn = styled('button')(({ theme }) => ({
158
- flexShrink: 0,
159
- display: 'flex',
160
- alignItems: 'center',
161
- justifyContent: 'center',
162
- padding: 4,
163
- border: 'none',
164
- borderRadius: '50%',
165
- background: 'none',
166
- cursor: 'pointer',
167
- color: 'inherit',
168
- opacity: 0.45,
169
- transition: 'opacity 0.15s, background 0.15s',
170
- '&:hover': {
171
- opacity: 1,
172
- background: alpha(theme.palette.text.primary, 0.06),
173
- },
174
- }));
175
- // ---------------------------------------------------------------------------
176
- // Helpers
177
- // ---------------------------------------------------------------------------
178
- function formatDate(date) {
179
- return format(date, 'yyyy-MM-dd');
180
- }
181
- function formatDisplayDate(date) {
182
- return format(date, 'd \'de\' MMMM', { locale: es });
183
- }
184
- function initials(name) {
185
- return name
186
- .split(' ')
187
- .slice(0, 2)
188
- .map((w) => w[0])
189
- .join('')
190
- .toUpperCase();
191
- }
192
- // ---------------------------------------------------------------------------
193
- // Component
194
- // ---------------------------------------------------------------------------
195
- function MaterialBookingStep({ step, editable, fetchSlots }) {
196
- const currentBreakPoint = useAppSelector(selectBreakPoint);
197
- const { postview } = useAppSelector((state) => state.global);
198
- const form = useContext(FormContext);
199
- const theme = useTheme();
200
- const triggerId = useId();
201
- const isReadOnly = !editable || postview;
202
- const widthStyle = currentBreakPoint <= step.size ? '100%' : calcStepWidth(step.size, form.size);
203
- const needsPerson = step.personSelectionMode && step.personSelectionMode !== PersonSelectionMode.NONE;
204
- const personsOptional = step.personSelectionMode === PersonSelectionMode.OPTIONAL;
205
- // ------------------------------------------------------------------
206
- // Form state
207
- // ------------------------------------------------------------------
208
- const { ref, value, onChange, error } = useFormStep(step, {
209
- defaultValue: null,
210
- rules: {
211
- required: step.required ? 'Selecciona una cita' : undefined,
212
- },
213
- });
214
- // ------------------------------------------------------------------
215
- // Dialog state
216
- // ------------------------------------------------------------------
217
- const [open, setOpen] = useState(false);
218
- const [phase, setPhase] = useState(needsPerson ? 'person' : 'datetime');
219
- const [selectedPersonId, setSelectedPersonId] = useState(undefined);
220
- const [selectedPerson, setSelectedPerson] = useState(undefined);
221
- const [weekStart, setWeekStart] = useState(() => startOfDay(new Date()));
222
- const [selectedDate, setSelectedDate] = useState(() => startOfDay(new Date()));
223
- const [slots, setSlots] = useState([]);
224
- const [loadingSlots, setLoadingSlots] = useState(false);
225
- const STRIP_DAYS = 7;
226
- const days = Array.from({ length: STRIP_DAYS }, (_, i) => addDays(weekStart, i));
227
- // ------------------------------------------------------------------
228
- // Fetch slots when date or person changes
229
- // ------------------------------------------------------------------
230
- const loadSlots = useCallback(async (date, personId) => {
231
- if (!fetchSlots)
232
- return;
233
- setLoadingSlots(true);
234
- setSlots([]);
235
- try {
236
- const result = await fetchSlots({ personId, date: formatDate(date) });
237
- setSlots(result);
238
- }
239
- catch {
240
- setSlots([]);
241
- }
242
- finally {
243
- setLoadingSlots(false);
244
- }
245
- }, [fetchSlots]);
246
- useEffect(() => {
247
- if (open && phase === 'datetime') {
248
- void loadSlots(selectedDate, selectedPersonId);
249
- }
250
- }, [open, phase, selectedDate, selectedPersonId, loadSlots]);
251
- // ------------------------------------------------------------------
252
- // Handlers
253
- // ------------------------------------------------------------------
254
- const handleOpen = () => {
255
- if (isReadOnly)
256
- return;
257
- setPhase(needsPerson ? 'person' : 'datetime');
258
- setSelectedDate(startOfDay(new Date()));
259
- setWeekStart(startOfDay(new Date()));
260
- setSlots([]);
261
- setOpen(true);
262
- };
263
- const handleClose = () => setOpen(false);
264
- const handleSelectPerson = (person) => {
265
- setSelectedPersonId(person?.id);
266
- setSelectedPerson(person);
267
- setPhase('datetime');
268
- };
269
- const handleSkipPerson = () => {
270
- setSelectedPersonId(undefined);
271
- setSelectedPerson(undefined);
272
- setPhase('datetime');
273
- };
274
- const handleSelectDate = (date) => {
275
- setSelectedDate(date);
276
- };
277
- const handleSelectSlot = (slot) => {
278
- const bookingValue = {
279
- type: 'BOOKING_VALUE',
280
- slotId: slot.id,
281
- date: formatDate(selectedDate),
282
- startTime: slot.startTime,
283
- endTime: slot.endTime,
284
- personId: selectedPersonId,
285
- personName: selectedPerson?.name,
286
- status: 'PENDING',
287
- };
288
- onChange(bookingValue);
289
- handleClose();
290
- };
291
- const handleClear = (e) => {
292
- e.stopPropagation();
293
- onChange(null);
294
- };
295
- // ------------------------------------------------------------------
296
- // Display value for the trigger field
297
- // ------------------------------------------------------------------
298
- const displayValue = value
299
- ? [
300
- value.personName,
301
- formatDisplayDate(new Date(value.date + 'T00:00:00')),
302
- `${value.startTime}–${value.endTime}`,
303
- ]
304
- .filter(Boolean)
305
- .join(' · ')
306
- : '';
307
- // ------------------------------------------------------------------
308
- // Render: Read-only summary
309
- // ------------------------------------------------------------------
310
- if (isReadOnly) {
311
- return (_jsx("div", { className: styles.container, style: { width: widthStyle }, children: value ? (_jsxs(SummaryCard, { children: [_jsx(CalendarIcon, { size: 26, style: { color: theme.palette.primary.main, flexShrink: 0 } }), _jsxs("div", { className: styles.summaryDetails, children: [_jsx("span", { className: styles.summaryLabel, children: step.label }), _jsxs("span", { className: styles.summaryMain, children: [value.personName && (_jsxs("span", { style: { color: theme.palette.primary.main, fontWeight: 600 }, children: [value.personName, " \u00B7", ' '] })), formatDisplayDate(new Date(value.date + 'T00:00:00')), " \u00B7 ", value.startTime, "\u2013", value.endTime] })] })] })) : (_jsxs(EmptyReadOnly, { children: [_jsx(CalendarIcon, { size: 20, style: { flexShrink: 0 } }), _jsx("span", { children: step.label })] })) }));
312
- }
313
- // ------------------------------------------------------------------
314
- // Render: Trigger + Dialog
315
- // ------------------------------------------------------------------
316
- return (_jsxs("div", { ref: ref, className: styles.container, style: { width: widthStyle }, children: [_jsx(StyledTextField, { id: triggerId, label: step.label, value: displayValue, variant: "outlined", fullWidth: true, required: step.required, error: !!error, errorBorder: !!error, helperText: error?.message ?? step.description ?? ' ', onClick: handleOpen, sx: { '& input': { cursor: 'pointer', caretColor: 'transparent', userSelect: 'none' } }, slotProps: {
317
- inputLabel: { shrink: !!value },
318
- input: {
319
- readOnly: true,
320
- notched: !!value,
321
- endAdornment: (_jsx(InputAdornment, { position: "end", children: value ? (_jsx(ClearBtn, { type: "button", onClick: handleClear, tabIndex: -1, "aria-label": "Limpiar", children: _jsx(CloseIcon, { size: 16 }) })) : (_jsx(CalendarIcon, { size: 20, style: {
322
- fill: alpha(theme.palette.text.primary, 0.45),
323
- flexShrink: 0,
324
- } })) })),
325
- },
326
- } }), _jsxs(Dialog, { open: open, onClose: handleClose, maxWidth: "sm", fullWidth: true, slotProps: {
327
- paper: {
328
- sx: {
329
- borderRadius: '20px',
330
- height: '580px',
331
- maxHeight: '90vh',
332
- display: 'flex',
333
- flexDirection: 'column',
334
- backgroundColor: theme.palette.background.paper,
335
- },
336
- },
337
- }, children: [_jsxs(DialogTitle, { sx: {
338
- padding: '16px 20px 8px',
339
- borderBottom: `1px solid ${alpha(theme.palette.text.primary, 0.08)}`,
340
- }, children: [_jsxs("div", { className: styles.dialogTitleInner, children: [phase === 'datetime' && needsPerson && (_jsx(IconBtn, { type: "button", onClick: () => setPhase('person'), "aria-label": "Volver", children: _jsx(ArrowLeftIcon, { size: 20 }) })), _jsx("span", { className: styles.dialogTitleText, children: phase === 'person' ? 'Seleccionar profesional' : 'Seleccionar fecha y hora' }), _jsx(IconBtn, { type: "button", onClick: handleClose, "aria-label": "Cerrar", children: _jsx(CloseIcon, { size: 18 }) })] }), phase === 'datetime' && needsPerson && (_jsxs(PersonChip, { type: "button", onClick: () => setPhase('person'), children: [selectedPerson ? (_jsxs(_Fragment, { children: [_jsx(Avatar, { src: selectedPerson.avatarUrl, sx: { width: 22, height: 22, fontSize: 10 }, children: initials(selectedPerson.name) }), _jsx("span", { children: selectedPerson.name })] })) : (_jsxs(_Fragment, { children: [_jsx(PersonIcon, { size: 16 }), _jsx("span", { children: "Sin preferencia" })] })), _jsx(ArrowRightIcon, { size: 14, style: { opacity: 0.4 } })] }))] }), _jsxs(DialogContent, { sx: { padding: '0 !important', display: 'flex', flexDirection: 'column', flex: 1, overflow: 'hidden', minHeight: 0 }, children: [phase === 'person' && (_jsxs("div", { className: styles.personList, children: [personsOptional && (_jsxs(PersonCard, { active: !selectedPersonId, onClick: handleSkipPerson, role: "button", tabIndex: 0, onKeyDown: (e) => e.key === 'Enter' && handleSkipPerson(), children: [_jsx(Avatar, { sx: {
341
- width: 48,
342
- height: 48,
343
- bgcolor: alpha(theme.palette.text.primary, 0.08),
344
- color: alpha(theme.palette.text.primary, 0.45),
345
- }, children: _jsx(PersonIcon, { size: 24 }) }), _jsxs("div", { className: styles.personInfo, children: [_jsx("span", { className: styles.personName, children: "Sin preferencia" }), _jsx("span", { className: styles.personRole, children: "M\u00E1xima disponibilidad" })] }), _jsx(ErkButton, { variant: "outlined", size: "small", children: "Seleccionar" })] })), (step.persons ?? []).map((person) => (_jsxs(PersonCard, { active: selectedPersonId === person.id, onClick: () => handleSelectPerson(person), role: "button", tabIndex: 0, onKeyDown: (e) => e.key === 'Enter' && handleSelectPerson(person), children: [_jsx(Avatar, { src: person.avatarUrl, sx: {
346
- width: 48,
347
- height: 48,
348
- bgcolor: theme.palette.primary.main,
349
- fontSize: 16,
350
- }, children: initials(person.name) }), _jsxs("div", { className: styles.personInfo, children: [_jsx("span", { className: styles.personName, children: person.name }), person.role && _jsx("span", { className: styles.personRole, children: person.role }), person.description && (_jsx("span", { className: styles.personDesc, children: person.description }))] }), _jsx(ErkButton, { variant: "outlined", size: "small", children: "Seleccionar" })] }, person.id)))] })), phase === 'datetime' && (_jsxs("div", { className: styles.datetimePhase, children: [_jsx("div", { className: styles.dateSectionTitle, children: "Selecciona una fecha" }), _jsxs("div", { className: styles.dateStrip, children: [_jsx(StripArrowBtn, { type: "button", onClick: () => setWeekStart((d) => {
351
- const next = addDays(d, -STRIP_DAYS);
352
- return next < startOfDay(new Date()) ? startOfDay(new Date()) : next;
353
- }), disabled: weekStart <= startOfDay(new Date()), children: _jsx(ArrowLeftIcon, { size: 20 }) }), _jsx("div", { className: styles.dateChips, children: days.map((day) => {
354
- const isPast = day < startOfDay(new Date());
355
- const isSelected = isSameDay(day, selectedDate);
356
- return (_jsxs(DateChipButton, { type: "button", disabled: isPast, onClick: () => handleSelectDate(day), selected: isSelected, todayHighlight: isToday(day) && !isSelected, children: [_jsx("span", { className: styles.chipDow, children: format(day, 'EEE', { locale: es }) }), _jsx("span", { className: styles.chipNum, children: format(day, 'd') }), _jsx("span", { className: styles.chipMonth, children: format(day, 'MMM', { locale: es }) })] }, day.toISOString()));
357
- }) }), _jsx(StripArrowBtn, { type: "button", onClick: () => setWeekStart((d) => addDays(d, STRIP_DAYS)), children: _jsx(ArrowRightIcon, { size: 20 }) })] }), _jsx("div", { className: styles.dateSectionTitle, children: "Escoge una hora" }), _jsxs("div", { className: styles.slotList, children: [loadingSlots && (_jsx("div", { className: styles.slotsLoading, children: _jsx(CircularProgress, { size: 24 }) })), !loadingSlots && slots.length === 0 && (_jsx("div", { className: styles.slotsEmpty, children: "No hay horarios disponibles para este d\u00EDa." })), !loadingSlots &&
358
- slots
359
- .filter((s) => s.available)
360
- .map((slot) => (_jsx(SlotRowButton, { type: "button", onClick: () => handleSelectSlot(slot), children: slot.startTime }, slot.id)))] })] }))] })] })] }));
361
- }
362
- export default MaterialBookingStep;