@arquimedes.co/eureka-forms 3.0.68-test → 3.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README +33 -1
- package/dist/@Types/AvailabilityFormStep.d.ts +48 -0
- package/dist/@Types/AvailabilityFormStep.js +24 -0
- package/dist/@Types/BankAccountFormStep.d.ts +67 -0
- package/dist/@Types/BankAccountFormStep.js +14 -0
- package/dist/@Types/BookingFormStep.d.ts +197 -0
- package/dist/@Types/BookingFormStep.js +44 -0
- package/dist/@Types/CalendarFormStep.d.ts +209 -0
- package/dist/@Types/CalendarFormStep.js +55 -0
- package/dist/@Types/CommunicationChannelFormStep.d.ts +51 -0
- package/dist/@Types/CommunicationChannelFormStep.js +15 -0
- package/dist/@Types/ConsentFormStep.d.ts +36 -0
- package/dist/@Types/ConsentFormStep.js +8 -0
- package/dist/@Types/EntityFormFormStep.d.ts +66 -0
- package/dist/@Types/EntityFormFormStep.js +20 -0
- package/dist/@Types/EventFormStep.d.ts +52 -0
- package/dist/@Types/EventFormStep.js +13 -0
- package/dist/@Types/ExternalReferenceFormStep.d.ts +74 -0
- package/dist/@Types/ExternalReferenceFormStep.js +20 -0
- package/dist/@Types/FormStep.d.ts +7 -2
- package/dist/@Types/FormStep.js +2 -1
- package/dist/@Types/LocationFormStep.d.ts +159 -0
- package/dist/@Types/LocationFormStep.js +46 -0
- package/dist/@Types/NumericFormSteps.d.ts +108 -0
- package/dist/@Types/NumericFormSteps.js +20 -0
- package/dist/@Types/PredefinedSelectorFormStep.d.ts +51 -0
- package/dist/@Types/PredefinedSelectorFormStep.js +39 -0
- package/dist/@Types/StepRef.d.ts +135 -0
- package/dist/@Types/StepRef.js +49 -0
- package/dist/App/App.stories.d.ts +10 -0
- package/dist/App/App.stories.js +189 -0
- package/dist/App/AppHooks.js +8 -0
- package/dist/App/AppHooks.test.js +8 -0
- package/dist/Form/Form.js +7 -6
- package/dist/Form/FormFunctions.d.ts +17 -0
- package/dist/Form/FormFunctions.js +22 -0
- package/dist/Form/FormFunctions.test.js +28 -1
- package/dist/FormSteps/AvailabilityStep/AvailabilityStep.d.ts +7 -0
- package/dist/FormSteps/AvailabilityStep/AvailabilityStep.js +14 -0
- package/dist/FormSteps/AvailabilityStep/MaterialAvailabilityStep/MaterialAvailabilityStep.d.ts +8 -0
- package/dist/FormSteps/AvailabilityStep/MaterialAvailabilityStep/MaterialAvailabilityStep.js +32 -0
- package/dist/FormSteps/BookingStep/BookingStep.d.ts +17 -0
- package/dist/FormSteps/BookingStep/BookingStep.js +14 -0
- package/dist/FormSteps/BookingStep/MaterialBookingStep/MaterialBookingStep.d.ts +14 -0
- package/dist/FormSteps/BookingStep/MaterialBookingStep/MaterialBookingStep.js +129 -0
- package/dist/FormSteps/CheckBoxStep/CheckBoxStep.mobileLabel.test.js +20 -12
- package/dist/FormSteps/CheckBoxStep/MaterialCheckBoxStep/MaterialCheckBoxStep.js +6 -13
- package/dist/FormSteps/CheckBoxStep/MaterialCheckBoxStep/MaterialCheckBoxStep.module.css +2 -13
- package/dist/FormSteps/ClassifierSelectorStep/ClassifierSelectorStep.lateClassifiers.test.d.ts +1 -0
- package/dist/FormSteps/ClassifierSelectorStep/ClassifierSelectorStep.lateClassifiers.test.js +70 -0
- package/dist/FormSteps/ClassifierSelectorStep/MaterialClassifierSelectorStep/MaterialClassifierSelectorStep.js +3 -1
- package/dist/FormSteps/EntityValueStep/MaterialEntityValuePickerStep/MaterialEntityValuePickerStep.js +26 -26
- package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.d.ts +12 -0
- package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.js +35 -0
- package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.test.d.ts +1 -0
- package/dist/FormSteps/EntityValueStep/entityValueDependencyValue.test.js +31 -0
- package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.d.ts +27 -0
- package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.js +64 -0
- package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.test.d.ts +1 -0
- package/dist/FormSteps/EntityValueStep/entityValuePickerWatchedSteps.test.js +95 -0
- package/dist/FormSteps/LocationStep/LocationStep.d.ts +10 -0
- package/dist/FormSteps/LocationStep/LocationStep.js +14 -0
- package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.d.ts +3 -0
- package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.js +54 -0
- package/dist/FormSteps/LocationStep/MaterialLocationStep/MaterialLocationStep.module.css +18 -0
- package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.d.ts +3 -0
- package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.js +170 -0
- package/dist/FormSteps/NumberStep/MaterialNumberStep/MaterialNumberStep.module.css +96 -0
- package/dist/FormSteps/NumberStep/NumberStep.d.ts +10 -0
- package/dist/FormSteps/NumberStep/NumberStep.js +14 -0
- package/dist/FormSteps/Step.js +16 -0
- package/dist/FormSteps/StepFunctions.js +14 -0
- package/dist/FormSteps/StepFunctions.test.js +54 -0
- package/dist/FormSteps/StepHooks.d.ts +21 -0
- package/dist/FormSteps/StepHooks.js +55 -8
- package/dist/FormSteps/StepHooks.test.d.ts +1 -0
- package/dist/FormSteps/StepHooks.test.js +92 -0
- package/dist/FormSteps/isStepHiddenByCondition.test.d.ts +1 -0
- package/dist/FormSteps/isStepHiddenByCondition.test.js +42 -0
- package/dist/Icons/AddIcon.d.ts +3 -0
- package/dist/Icons/AddIcon.js +7 -0
- package/dist/Icons/EditIcon.d.ts +3 -0
- package/dist/Icons/EditIcon.js +7 -0
- package/dist/Icons/RemoveIcon.d.ts +3 -0
- package/dist/Icons/RemoveIcon.js +7 -0
- package/dist/Icons/ViewDayIcon.d.ts +3 -0
- package/dist/Icons/ViewDayIcon.js +7 -0
- package/dist/Icons/ViewWeekIcon.d.ts +3 -0
- package/dist/Icons/ViewWeekIcon.js +7 -0
- package/dist/Services/BookingService.d.ts +79 -0
- package/dist/Services/BookingService.js +66 -0
- package/dist/Services/BookingService.test.d.ts +1 -0
- package/dist/Services/BookingService.test.js +57 -0
- package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.d.ts +19 -0
- package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.js +80 -0
- package/dist/Shared/ErkAddressAutocomplete/ErkAddressAutocomplete.module.css +88 -0
- package/dist/Shared/ErkAddressAutocomplete/googlePlaces.d.ts +29 -0
- package/dist/Shared/ErkAddressAutocomplete/googlePlaces.js +139 -0
- package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.d.ts +25 -0
- package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.js +112 -0
- package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.module.css +88 -0
- package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.test.d.ts +1 -0
- package/dist/Shared/ErkAvailabilityPicker/ErkAvailabilityPicker.test.js +73 -0
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.d.ts +52 -0
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.js +292 -0
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.module.css +608 -0
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.d.ts +28 -0
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.js +117 -0
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.test.d.ts +1 -0
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.stories.test.js +49 -0
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.test.d.ts +1 -0
- package/dist/Shared/ErkBookingPicker/ErkBookingPicker.test.js +157 -0
- package/dist/Shared/ErkDatePicker/ErkDatePicker.js +1 -3
- package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.d.ts +2 -3
- package/dist/Shared/ErkDateRangePicker/ErkDateRangePicker.js +1 -2
- package/dist/Shared/ErkIconButton/ErkIconButton.d.ts +17 -0
- package/dist/Shared/ErkIconButton/ErkIconButton.js +11 -0
- package/dist/Shared/ErkIconButton/ErkIconButton.module.css +41 -0
- package/dist/Shared/ErkLocationField/ErkLocationField.d.ts +24 -0
- package/dist/Shared/ErkLocationField/ErkLocationField.js +128 -0
- package/dist/Shared/ErkLocationField/ErkLocationField.module.css +164 -0
- package/dist/Shared/ErkLocationField/ErkLocationField.test.d.ts +1 -0
- package/dist/Shared/ErkLocationField/ErkLocationField.test.js +82 -0
- package/dist/Shared/ErkLocationField/addressFields.d.ts +12 -0
- package/dist/Shared/ErkLocationField/addressFields.js +34 -0
- package/dist/Shared/ErkLocationField/locationRestrictions.d.ts +6 -0
- package/dist/Shared/ErkLocationField/locationRestrictions.js +51 -0
- package/dist/Shared/ErkLocationInput/ErkLocationInput.d.ts +15 -0
- package/dist/Shared/ErkLocationInput/ErkLocationInput.js +502 -0
- package/dist/Shared/ErkLocationInput/ErkLocationInput.module.css +128 -0
- package/dist/Shared/ErkNumberField/ErkNumberField.d.ts +42 -0
- package/dist/Shared/ErkNumberField/ErkNumberField.js +169 -0
- package/dist/Utils/AxiosWidget.js +9 -1
- package/dist/constants/FormStepTypes.d.ts +5 -1
- package/dist/constants/FormStepTypes.js +4 -0
- package/dist/index.lib.d.ts +4 -2
- package/dist/index.lib.js +3 -1
- package/package.json +2 -1
|
@@ -4,6 +4,23 @@ import { CustomStep } from '../FormSteps/CustomStep';
|
|
|
4
4
|
import { CBRFormStep } from '../@Types/CBRFormStep';
|
|
5
5
|
import { MapperElement } from '../@Types/MapperElement';
|
|
6
6
|
import { ValuesStore } from '../States/SiteSlice';
|
|
7
|
+
/** The reCAPTCHA widget surface a submission needs: the response it holds, and the challenge that mints one. */
|
|
8
|
+
export interface CaptchaWidget {
|
|
9
|
+
getValue(): string | null;
|
|
10
|
+
executeAsync(): Promise<string | null>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Resolve the reCAPTCHA response to send with a submission, running the invisible challenge when the widget
|
|
14
|
+
* is not holding one yet.
|
|
15
|
+
*
|
|
16
|
+
* An unsolved invisible widget answers `getValue()` with an EMPTY STRING rather than null, so emptiness —
|
|
17
|
+
* not nullishness — is what decides whether the challenge still has to run. A submission that skips the
|
|
18
|
+
* challenge carries no token, and the API rejects every captcha-protected public form with a 403.
|
|
19
|
+
*
|
|
20
|
+
* Yields null when no widget is mounted, leaving the caller to submit tokenless rather than throwing out of
|
|
21
|
+
* the submit handler.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveCaptchaToken(captcha: CaptchaWidget | null | undefined): Promise<string | null>;
|
|
7
24
|
/**
|
|
8
25
|
* Function that cals the value of a step to output on submit
|
|
9
26
|
*/
|
|
@@ -3,6 +3,28 @@ import FormStepTypes, { EntityValueDataTypes } from '../constants/FormStepTypes'
|
|
|
3
3
|
import { calcStepDeps } from '../FormSteps/StepHooks';
|
|
4
4
|
import { calcRecursiveData } from '../Utils/FormStepFunctions';
|
|
5
5
|
import { isValidPhoneNumber } from '../Utils/PhoneFunctions';
|
|
6
|
+
/**
|
|
7
|
+
* Resolve the reCAPTCHA response to send with a submission, running the invisible challenge when the widget
|
|
8
|
+
* is not holding one yet.
|
|
9
|
+
*
|
|
10
|
+
* An unsolved invisible widget answers `getValue()` with an EMPTY STRING rather than null, so emptiness —
|
|
11
|
+
* not nullishness — is what decides whether the challenge still has to run. A submission that skips the
|
|
12
|
+
* challenge carries no token, and the API rejects every captcha-protected public form with a 403.
|
|
13
|
+
*
|
|
14
|
+
* Yields null when no widget is mounted, leaving the caller to submit tokenless rather than throwing out of
|
|
15
|
+
* the submit handler.
|
|
16
|
+
*/
|
|
17
|
+
export async function resolveCaptchaToken(captcha) {
|
|
18
|
+
if (!captcha)
|
|
19
|
+
return null;
|
|
20
|
+
const held = captcha.getValue();
|
|
21
|
+
if (held)
|
|
22
|
+
return held;
|
|
23
|
+
const solved = await captcha.executeAsync();
|
|
24
|
+
if (solved)
|
|
25
|
+
return solved;
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
6
28
|
/**
|
|
7
29
|
* Function that cals the value of a step to output on submit
|
|
8
30
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/require-await */
|
|
2
2
|
import { ContentState, EditorState } from 'draft-js';
|
|
3
3
|
import FormStepTypes, { EntityValueDataTypes } from '../constants/FormStepTypes';
|
|
4
|
-
import { calcDependencies, calcValue } from './FormFunctions';
|
|
4
|
+
import { calcDependencies, calcValue, resolveCaptchaToken } from './FormFunctions';
|
|
5
5
|
import { stringToDraft } from '../Utils/DraftFunctions';
|
|
6
6
|
import { describe, expect, test } from 'vitest';
|
|
7
7
|
describe('FormFunctions', function () {
|
|
@@ -455,4 +455,31 @@ describe('FormFunctions', function () {
|
|
|
455
455
|
expect(dependencyStore.idStep.dependents.length).toBe(1);
|
|
456
456
|
});
|
|
457
457
|
});
|
|
458
|
+
describe('resolveCaptchaToken', function () {
|
|
459
|
+
test('Uses the token the widget already holds without re-running the challenge', async () => {
|
|
460
|
+
let executed = false;
|
|
461
|
+
const token = await resolveCaptchaToken({
|
|
462
|
+
getValue: () => 'already-solved',
|
|
463
|
+
executeAsync: async () => {
|
|
464
|
+
executed = true;
|
|
465
|
+
return 'freshly-solved';
|
|
466
|
+
},
|
|
467
|
+
});
|
|
468
|
+
expect(token).toBe('already-solved');
|
|
469
|
+
expect(executed).toBe(false);
|
|
470
|
+
});
|
|
471
|
+
test('Runs the challenge when the invisible widget reports an empty response', async () => {
|
|
472
|
+
// An unsolved invisible captcha answers `getValue()` with '' — not null — so emptiness is what
|
|
473
|
+
// must decide whether the challenge still has to run. Treating only nullish as unsolved leaves
|
|
474
|
+
// the submission tokenless and the API answers 403.
|
|
475
|
+
const token = await resolveCaptchaToken({
|
|
476
|
+
getValue: () => '',
|
|
477
|
+
executeAsync: async () => 'freshly-solved',
|
|
478
|
+
});
|
|
479
|
+
expect(token).toBe('freshly-solved');
|
|
480
|
+
});
|
|
481
|
+
test('Yields no token when the widget is not mounted', async () => {
|
|
482
|
+
expect(await resolveCaptchaToken(null)).toBeNull();
|
|
483
|
+
});
|
|
484
|
+
});
|
|
458
485
|
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AvailabilityStep } from '../../@Types/CalendarFormStep';
|
|
2
|
+
import { StepProps } from '../Step';
|
|
3
|
+
export interface AvailabilityStepProps extends StepProps {
|
|
4
|
+
step: AvailabilityStep;
|
|
5
|
+
}
|
|
6
|
+
declare function AvailabilityStepComponent(props: AvailabilityStepProps): JSX.Element;
|
|
7
|
+
export default AvailabilityStepComponent;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { FormStyleTypes } from '../../constants/FormStepTypes';
|
|
3
|
+
import MaterialAvailabilityStep from './MaterialAvailabilityStep/MaterialAvailabilityStep';
|
|
4
|
+
import { useAppSelector } from '../../hooks';
|
|
5
|
+
function AvailabilityStepComponent(props) {
|
|
6
|
+
const { formStyle } = useAppSelector((state) => state.global);
|
|
7
|
+
switch (formStyle.type) {
|
|
8
|
+
case FormStyleTypes.MATERIAL:
|
|
9
|
+
default: {
|
|
10
|
+
return _jsx(MaterialAvailabilityStep, { ...props });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export default AvailabilityStepComponent;
|
package/dist/FormSteps/AvailabilityStep/MaterialAvailabilityStep/MaterialAvailabilityStep.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AvailabilityStepProps } from '../AvailabilityStep';
|
|
2
|
+
/**
|
|
3
|
+
* Conector del paso AVAILABILITY: pregunta de disponibilidad compacta
|
|
4
|
+
* (grid semanal día × hora). El calendario completo vive en el admin; el form
|
|
5
|
+
* solo captura ventanas disponibles que un paso BOOKING puede consumir.
|
|
6
|
+
*/
|
|
7
|
+
declare function MaterialAvailabilityStep({ step, editable }: AvailabilityStepProps): JSX.Element;
|
|
8
|
+
export default MaterialAvailabilityStep;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from 'react';
|
|
3
|
+
import { useFormStep } from '../../StepHooks';
|
|
4
|
+
import FormContext from '../../../Contexts/FormContext';
|
|
5
|
+
import { selectBreakPoint, useAppSelector } from '../../../hooks';
|
|
6
|
+
import { calcStepWidth } from '../../StepFunctions';
|
|
7
|
+
import ErkAvailabilityPicker from '../../../Shared/ErkAvailabilityPicker/ErkAvailabilityPicker';
|
|
8
|
+
/**
|
|
9
|
+
* Conector del paso AVAILABILITY: pregunta de disponibilidad compacta
|
|
10
|
+
* (grid semanal día × hora). El calendario completo vive en el admin; el form
|
|
11
|
+
* solo captura ventanas disponibles que un paso BOOKING puede consumir.
|
|
12
|
+
*/
|
|
13
|
+
function MaterialAvailabilityStep({ step, editable }) {
|
|
14
|
+
const currentBreakPoint = useAppSelector(selectBreakPoint);
|
|
15
|
+
const { postview, formStyle } = useAppSelector((state) => state.global);
|
|
16
|
+
const formCtx = useContext(FormContext);
|
|
17
|
+
const isReadOnly = !editable || postview;
|
|
18
|
+
const widthStyle = currentBreakPoint <= step.size ? '100%' : calcStepWidth(step.size, formCtx.size);
|
|
19
|
+
const cssVars = {
|
|
20
|
+
width: widthStyle,
|
|
21
|
+
'--eureka-outline': formStyle.outlineColor,
|
|
22
|
+
'--eureka-primary': formStyle.primaryColor,
|
|
23
|
+
'--eureka-text': formStyle.textColor,
|
|
24
|
+
'--eureka-bg': formStyle.standAloneBackgroundColor ?? '#fff',
|
|
25
|
+
};
|
|
26
|
+
const { ref, value, onChange, error } = useFormStep(step, {
|
|
27
|
+
defaultValue: null,
|
|
28
|
+
rules: { required: step.required ? 'Marca tu disponibilidad' : undefined },
|
|
29
|
+
});
|
|
30
|
+
return (_jsx("div", { ref: ref, style: cssVars, children: _jsx(ErkAvailabilityPicker, { value: value, onChange: onChange, label: step.label, description: step.description, minTime: step.minTime, maxTime: step.maxTime, showWeekends: step.showWeekends, timezone: step.timezone, readOnly: isReadOnly, error: error?.message }) }));
|
|
31
|
+
}
|
|
32
|
+
export default MaterialAvailabilityStep;
|
|
@@ -0,0 +1,17 @@
|
|
|
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;
|
|
@@ -0,0 +1,14 @@
|
|
|
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;
|
|
@@ -0,0 +1,14 @@
|
|
|
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;
|
|
@@ -0,0 +1,129 @@
|
|
|
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, collectContact: step.collectContact, fetchSlots: usesEdge ? fetchSlots : customFetchSlots, fetchDays: usesEdge ? fetchDays : undefined, holdSlot: usesEdge ? holdSlot : undefined, disabled: usesEdge && !offer, readOnly: isReadOnly, error: error?.message ?? offerError }) }));
|
|
128
|
+
}
|
|
129
|
+
export default MaterialBookingStep;
|
|
@@ -48,7 +48,7 @@ function makeStore(currentBreakPoint) {
|
|
|
48
48
|
...defaultRootState,
|
|
49
49
|
widthStats: {
|
|
50
50
|
currentBreakPoint,
|
|
51
|
-
isMobile: currentBreakPoint <=
|
|
51
|
+
isMobile: currentBreakPoint <= 1,
|
|
52
52
|
isResponsive: true,
|
|
53
53
|
},
|
|
54
54
|
},
|
|
@@ -57,15 +57,15 @@ function makeStore(currentBreakPoint) {
|
|
|
57
57
|
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(RootApi.middleware),
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
-
function Harness({ currentBreakPoint }) {
|
|
60
|
+
function Harness({ currentBreakPoint, step = checkBoxStep, }) {
|
|
61
61
|
const methods = useForm({ mode: 'onTouched' });
|
|
62
|
-
return (_jsx(MaterialProviders, { formStyle: InternalFormStyle, children: _jsx(Provider, { store: makeStore(currentBreakPoint), context: StoreContext, children: _jsx(IdFormContext.Provider, { value: STORY_FORM_ID, children: _jsx(FormContext.Provider, { value: form, children: _jsx(SectionContext.Provider, { value: "SECTION_1", children: _jsx(FormProvider, { ...methods, children: _jsx(CheckBoxStep, { step:
|
|
62
|
+
return (_jsx(MaterialProviders, { formStyle: InternalFormStyle, children: _jsx(Provider, { store: makeStore(currentBreakPoint), context: StoreContext, children: _jsx(IdFormContext.Provider, { value: STORY_FORM_ID, children: _jsx(FormContext.Provider, { value: { ...form, steps: { ...form.steps, [step.id]: step } }, children: _jsx(SectionContext.Provider, { value: "SECTION_1", children: _jsx(FormProvider, { ...methods, children: _jsx(CheckBoxStep, { step: step, editable: true }) }) }) }) }) }) }));
|
|
63
63
|
}
|
|
64
64
|
function getLabelDiv() {
|
|
65
65
|
// the leaf div holding only the label text (the wrapping column also matches by textContent)
|
|
66
66
|
return screen.getByText((_, element) => element?.tagName === 'DIV' && element.children.length === 0 && element.textContent === `${LONG_LABEL}:`);
|
|
67
67
|
}
|
|
68
|
-
/** Makes every element report a
|
|
68
|
+
/** Makes every element report a 1-line-clamped overflow (jsdom has no layout). */
|
|
69
69
|
function mockLabelOverflow() {
|
|
70
70
|
Object.defineProperty(HTMLElement.prototype, 'scrollHeight', {
|
|
71
71
|
configurable: true,
|
|
@@ -76,7 +76,7 @@ function mockLabelOverflow() {
|
|
|
76
76
|
Object.defineProperty(HTMLElement.prototype, 'clientHeight', {
|
|
77
77
|
configurable: true,
|
|
78
78
|
get() {
|
|
79
|
-
return
|
|
79
|
+
return 24;
|
|
80
80
|
},
|
|
81
81
|
});
|
|
82
82
|
}
|
|
@@ -85,22 +85,30 @@ afterEach(() => {
|
|
|
85
85
|
delete HTMLElement.prototype.scrollHeight;
|
|
86
86
|
delete HTMLElement.prototype.clientHeight;
|
|
87
87
|
});
|
|
88
|
-
describe('CheckBoxStep
|
|
89
|
-
it('
|
|
88
|
+
describe('CheckBoxStep long labels', () => {
|
|
89
|
+
it('clamps the label to 1 line with a toggle instead of a plain ellipsis when the step collapses to 100% width', () => {
|
|
90
90
|
// breakpoint 1 <= size 2 → MaterialInputContainer renders the step at width: 100%
|
|
91
91
|
render(_jsx(Harness, { currentBreakPoint: 1 }));
|
|
92
92
|
const label = getLabelDiv();
|
|
93
93
|
expect(label.className).toBe(styles.clampLbl);
|
|
94
|
-
|
|
95
|
-
// the fixed desktop pixel maxWidth must not constrain the collapsed label
|
|
94
|
+
// no fixed desktop pixel maxWidth constrains the label
|
|
96
95
|
expect(label.style.maxWidth).toBe('');
|
|
97
96
|
});
|
|
98
|
-
it('
|
|
97
|
+
it('also clamps (with "ver más") when the step keeps a fixed width on a phone where 2 columns fit', () => {
|
|
98
|
+
// regression: a size-1 checkbox at breakpoint 2 used to render a single-line ellipsis with
|
|
99
|
+
// no way to read the full label
|
|
100
|
+
mockLabelOverflow();
|
|
101
|
+
render(_jsx(Harness, { currentBreakPoint: 2, step: { ...checkBoxStep, size: 1 } }));
|
|
102
|
+
const label = getLabelDiv();
|
|
103
|
+
expect(label.className).toBe(styles.clampLbl);
|
|
104
|
+
expect(label.style.maxWidth).toBe('');
|
|
105
|
+
expect(screen.getByRole('button', { name: 'ver más' })).toBeInTheDocument();
|
|
106
|
+
});
|
|
107
|
+
it('clamps on desktop widths too, without a toggle while the label fits', () => {
|
|
99
108
|
// breakpoint 4 > size 2 → the step keeps its fixed desktop width
|
|
100
109
|
render(_jsx(Harness, { currentBreakPoint: 4 }));
|
|
101
110
|
const label = getLabelDiv();
|
|
102
|
-
expect(label.className).toBe(styles.
|
|
103
|
-
expect(label.style.maxWidth).not.toBe('');
|
|
111
|
+
expect(label.className).toBe(styles.clampLbl);
|
|
104
112
|
expect(screen.queryByRole('button', { name: 'ver más' })).not.toBeInTheDocument();
|
|
105
113
|
});
|
|
106
114
|
it('shows no "ver más" toggle when the label fits in the clamp', () => {
|
|
@@ -8,7 +8,6 @@ import { useAppSelector, selectWidthStats } from '../../../hooks';
|
|
|
8
8
|
import { useFormStep } from '../../StepHooks';
|
|
9
9
|
import StepFillerContainer from '../../Utils/@StepFiller/StepFiller';
|
|
10
10
|
import MaterialInputContainer from '../../Utils/MaterialInputContainer/MaterialInputContainer';
|
|
11
|
-
import { calcStepWidth, resolveStepSpan } from '../../StepFunctions';
|
|
12
11
|
function CheckBoxStep({ step, editable }) {
|
|
13
12
|
const { ref, value, onChange, error, field } = useFormStep(step, {
|
|
14
13
|
defaultValue: step.defaultValue ?? false,
|
|
@@ -20,15 +19,15 @@ function CheckBoxStep({ step, editable }) {
|
|
|
20
19
|
const { formStyle, postview } = useAppSelector((state) => state.global);
|
|
21
20
|
const form = useContext(FormContext);
|
|
22
21
|
const widthStats = useAppSelector(selectWidthStats);
|
|
23
|
-
|
|
24
|
-
//
|
|
25
|
-
// the
|
|
26
|
-
|
|
22
|
+
// The label is clamped to 1 line with a "ver más" toggle at every width. A plain
|
|
23
|
+
// ellipsis was used while the step kept its fixed desktop pixel width, but that left long
|
|
24
|
+
// labels unreadable wherever the step is narrow (e.g. a size-1 checkbox on a phone where 2
|
|
25
|
+
// columns fit).
|
|
27
26
|
const labelRef = useRef(null);
|
|
28
27
|
const [expanded, setExpanded] = useState(false);
|
|
29
28
|
const [clamped, setClamped] = useState(false);
|
|
30
29
|
useLayoutEffect(() => {
|
|
31
|
-
if (
|
|
30
|
+
if (expanded)
|
|
32
31
|
return;
|
|
33
32
|
const measure = () => {
|
|
34
33
|
const label = labelRef.current;
|
|
@@ -38,7 +37,7 @@ function CheckBoxStep({ step, editable }) {
|
|
|
38
37
|
measure();
|
|
39
38
|
window.addEventListener('resize', measure);
|
|
40
39
|
return () => window.removeEventListener('resize', measure);
|
|
41
|
-
}, [
|
|
40
|
+
}, [expanded, step.label, widthStats.currentBreakPoint]);
|
|
42
41
|
const renderNested = () => {
|
|
43
42
|
const steps = value ? step.steps : step.uncheckedSteps;
|
|
44
43
|
return (_jsx(React.Fragment, { children: steps?.map((idStep) => {
|
|
@@ -48,18 +47,12 @@ function CheckBoxStep({ step, editable }) {
|
|
|
48
47
|
};
|
|
49
48
|
const renderLabel = (colon = false) => {
|
|
50
49
|
const label = `${step.label}${step.required ? ' *' : ''}${colon ? ':' : ''}`;
|
|
51
|
-
if (!collapsed) {
|
|
52
|
-
return (_jsx("div", { className: span === 4 ? styles.checkboxLbl : styles.overflowLbl, style: {
|
|
53
|
-
maxWidth: calcStepWidth(span, form.size) - 45,
|
|
54
|
-
}, children: label }));
|
|
55
|
-
}
|
|
56
50
|
return (_jsxs("div", { className: styles.labelColumn, children: [_jsx("div", { ref: labelRef, className: expanded ? styles.expandedLbl : styles.clampLbl, children: label }), (clamped || expanded) && (_jsx("button", { type: "button", className: styles.toggleLbl, style: { color: formStyle.primaryColor }, onClick: (event) => {
|
|
57
51
|
event.stopPropagation();
|
|
58
52
|
setExpanded(!expanded);
|
|
59
53
|
}, children: expanded ? 'ver menos' : 'ver más' }))] }));
|
|
60
54
|
};
|
|
61
55
|
return (_jsxs(StepFillerContainer, { step: step, children: [_jsx(MaterialInputContainer, { step: step, editable: editable, maxHeight: step.size < 4, children: _jsxs("div", { className: styles.container, children: [_jsxs("div", { className: styles.labelCheckBoxContainer, style: {
|
|
62
|
-
height: span < 4 && !collapsed ? 31 : undefined,
|
|
63
56
|
minHeight: 31,
|
|
64
57
|
alignItems: step.isList ? 'start' : 'center',
|
|
65
58
|
}, children: [step.label && !step.isList && renderLabel(true), _jsx(ErkCheckBox, { ...field, padding: "0px", inputRef: ref, error: !!error, checked: value, onChange: onChange, "data-testid": step.id, readOnly: !editable || postview }), step.label && step.isList && renderLabel()] }), (step.description ?? !!error) && (_jsx("div", { className: styles.descriptionPar, style: {
|
|
@@ -3,17 +3,6 @@
|
|
|
3
3
|
flex-direction: column;
|
|
4
4
|
max-width: 100%;
|
|
5
5
|
}
|
|
6
|
-
.checkboxLbl,
|
|
7
|
-
.overflowLbl {
|
|
8
|
-
font-size: 18px;
|
|
9
|
-
margin-right: 10px;
|
|
10
|
-
margin-left: 10px;
|
|
11
|
-
}
|
|
12
|
-
.overflowLbl {
|
|
13
|
-
white-space: nowrap;
|
|
14
|
-
overflow: hidden;
|
|
15
|
-
text-overflow: ellipsis;
|
|
16
|
-
}
|
|
17
6
|
.labelColumn {
|
|
18
7
|
display: flex;
|
|
19
8
|
flex-direction: column;
|
|
@@ -30,8 +19,8 @@
|
|
|
30
19
|
.clampLbl {
|
|
31
20
|
display: -webkit-box;
|
|
32
21
|
-webkit-box-orient: vertical;
|
|
33
|
-
-webkit-line-clamp:
|
|
34
|
-
line-clamp:
|
|
22
|
+
-webkit-line-clamp: 1;
|
|
23
|
+
line-clamp: 1;
|
|
35
24
|
overflow: hidden;
|
|
36
25
|
}
|
|
37
26
|
.toggleLbl {
|
package/dist/FormSteps/ClassifierSelectorStep/ClassifierSelectorStep.lateClassifiers.test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
});
|
|
@@ -50,8 +50,10 @@ function ClassifierSelectorStep({ step, editable }) {
|
|
|
50
50
|
};
|
|
51
51
|
}) ?? []);
|
|
52
52
|
},
|
|
53
|
+
// The classifiers dictionary can arrive after the first render (see useSetupApp), so the
|
|
54
|
+
// options must follow it, not only the dependency values.
|
|
53
55
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
54
|
-
[dependenciesValues]);
|
|
56
|
+
[dependenciesValues, classifier, form.classifiers]);
|
|
55
57
|
useEffect(() => {
|
|
56
58
|
if (value && !options?.find((option) => option.value === value?.value)) {
|
|
57
59
|
onChange('');
|