@wix/headless-bookings 0.0.55 → 0.0.57

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.
@@ -1,58 +1,42 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useMemo } from 'react';
2
+ /**
3
+ * Core BookingForm Component
4
+ *
5
+ * Provides low-level access to booking form functionality via render props.
6
+ * Wraps CoreForm.Root and provides merged field map with booking defaults.
7
+ *
8
+ * Supports two modes:
9
+ * 1. Client-side: Provide formId to load the form dynamically
10
+ * 2. SSR/SSG: Provide a pre-loaded form object for server-side rendering
11
+ */
12
+ import * as React from 'react';
13
+ import { useMemo, useRef, useCallback } from 'react';
3
14
  import { WixServices, useService } from '@wix/services-manager-react';
4
15
  import { createServicesMap } from '@wix/services-manager';
5
- import { BookingFormServiceDefinition, BookingFormService, BOOKING_FORM_NAMESPACE, } from '../../../services/booking-form/booking-form.js';
16
+ import { UniqueFieldSuffixContextProvider, } from '@wix/form-public';
17
+ import { BookingFormServiceDefinition, BookingFormService, BookingFormConfigurationError, BOOKING_FORM_NAMESPACE, extractFormIdFromConfig, } from '../../../services/booking-form/booking-form.js';
18
+ import { BookingServiceDefinition } from '../../../services/booking/booking.js';
6
19
  import { FormServiceDefinition, FormService, } from '@wix/headless-forms/services';
7
- // TODO: remove this when form will be updated to support optional field map
8
- const DEFAULT_BOOKING_FIELD_MAP = {
9
- TEXT_INPUT: () => null,
10
- TEXT_AREA: () => null,
11
- PHONE_INPUT: () => null,
12
- EMAIL_INPUT: () => null,
13
- NUMBER_INPUT: () => null,
14
- CHECKBOX: () => null,
15
- DROPDOWN: () => null,
16
- DATE_PICKER: () => null,
17
- SUBMIT_BUTTON: () => null,
18
- RADIO_GROUP: () => null,
19
- CHECKBOX_GROUP: () => null,
20
- DATE_INPUT: () => null,
21
- DATE_TIME_INPUT: () => null,
22
- TIME_INPUT: () => null,
23
- FILE_UPLOAD: () => null,
24
- SIGNATURE: () => null,
25
- TEXT: () => null,
26
- MULTILINE_ADDRESS: () => null,
27
- RATING_INPUT: () => null,
28
- TAGS: () => null,
29
- PRODUCT_LIST: () => null,
30
- FIXED_PAYMENT: () => null,
31
- PAYMENT_INPUT: () => null,
32
- DONATION: () => null,
33
- APPOINTMENT: () => null,
34
- IMAGE_CHOICE: () => null,
35
- };
36
20
  // ============================================================================
37
21
  // Component
38
22
  // ============================================================================
39
23
  /**
40
24
  * Extracts the form ID from props (either directly or from form object)
25
+ * Returns undefined if formId should be extracted from services by the service layer
41
26
  */
42
27
  function extractFormIdFromProps(props) {
43
- if ('formId' in props && props.formId) {
44
- return props.formId;
45
- }
46
- if ('form' in props && props.form) {
47
- const form = props.form;
48
- const formId = form.id ||
49
- form._id;
50
- if (!formId) {
51
- throw new Error('BookingForm: Could not extract form ID from provided form object.');
52
- }
53
- return formId;
28
+ // Convert props to config-like object for the utility
29
+ const config = props.form
30
+ ? { form: props.form }
31
+ : props.formId
32
+ ? { formId: props.formId }
33
+ : undefined;
34
+ const formId = extractFormIdFromConfig(config);
35
+ // If form was provided but we couldn't extract formId, that's an error
36
+ if (props.form && !formId) {
37
+ throw new Error('BookingForm: Could not extract form ID from provided form object.');
54
38
  }
55
- throw new Error('BookingForm: Either formId or form must be provided.');
39
+ return formId;
56
40
  }
57
41
  /**
58
42
  * Core component that provides booking form data via render props.
@@ -123,41 +107,75 @@ function extractFormIdFromProps(props) {
123
107
  * ```
124
108
  */
125
109
  export function Root(props) {
126
- const { additionalMetadata, fieldMap: userFieldMap, children } = props;
110
+ const { serviceIds, additionalMetadata, fieldMap, children } = props;
127
111
  // Determine if we have a pre-loaded form
128
112
  const hasPreloadedForm = 'form' in props && props.form;
129
113
  const preloadedForm = hasPreloadedForm ? props.form : null;
130
114
  // Extract formId from props
131
- const formId = extractFormIdFromProps(props);
132
- // Merge user's partial field map with booking defaults
133
- const fields = useMemo(() => ({
134
- // ...DEFAULT_BOOKING_FIELD_MAP, // TODO: Add default field map
135
- ...userFieldMap,
136
- }), [userFieldMap]);
115
+ const propsFormId = extractFormIdFromProps(props);
116
+ // Try to get BookingService if available (to extract formId and serviceIds from services)
117
+ let bookingService = null;
118
+ try {
119
+ bookingService = useService(BookingServiceDefinition);
120
+ }
121
+ catch {
122
+ // BookingService not available - that's ok if formId and serviceIds were provided explicitly
123
+ bookingService = null;
124
+ }
125
+ // Determine final formId: use props formId if provided, otherwise extract from services
126
+ let formId = propsFormId;
127
+ if (!formId && bookingService) {
128
+ const serviceSelections = bookingService.serviceSelections.get();
129
+ const services = serviceSelections.length
130
+ ? serviceSelections.map((s) => s.service)
131
+ : [];
132
+ formId = services.find((s) => s.form?._id)?.form?._id;
133
+ }
134
+ // Determine final serviceIds: use props serviceIds if provided, otherwise extract from services
135
+ let resolvedServiceIds = serviceIds;
136
+ if (!resolvedServiceIds && bookingService) {
137
+ const serviceSelections = bookingService.serviceSelections.get();
138
+ resolvedServiceIds = serviceSelections
139
+ .map((s) => s.service._id)
140
+ .filter((id) => Boolean(id));
141
+ }
142
+ // Merge serviceIds into additionalMetadata
143
+ const mergedMetadata = {
144
+ ...additionalMetadata,
145
+ ...(resolvedServiceIds &&
146
+ resolvedServiceIds.length > 0 && { serviceIds: resolvedServiceIds }),
147
+ };
137
148
  // Build formServiceConfig for FormService
138
- // If we have a pre-loaded form, pass it directly; otherwise pass formId
149
+ // If we have a pre-loaded form, pass it directly
150
+ // If we have formId, pass it with namespace and metadata
139
151
  const formServiceConfig = useMemo(() => {
140
152
  if (preloadedForm) {
141
153
  return { form: preloadedForm };
142
154
  }
143
- return {
144
- formId,
145
- namespace: BOOKING_FORM_NAMESPACE,
146
- ...(additionalMetadata && { additionalMetadata }),
147
- };
148
- }, [formId, additionalMetadata, preloadedForm]);
155
+ // Only provide config if formId is available
156
+ if (formId) {
157
+ return {
158
+ formId,
159
+ namespace: BOOKING_FORM_NAMESPACE,
160
+ ...(Object.keys(mergedMetadata).length > 0 && {
161
+ additionalMetadata: mergedMetadata,
162
+ }),
163
+ };
164
+ }
165
+ }, [formId, mergedMetadata, preloadedForm]);
149
166
  // Build bookingFormServiceConfig
150
167
  const bookingFormServiceConfig = useMemo(() => {
151
168
  if (preloadedForm) {
152
169
  return { form: preloadedForm };
153
170
  }
154
- return { formId };
155
- }, [formId, preloadedForm]);
171
+ // formId is optional - service will extract from services if not provided
172
+ return formId ? { formId, serviceIds } : undefined;
173
+ }, [formId, preloadedForm, serviceIds]);
156
174
  // Both FormService and BookingFormService are added to the same WixServices context
157
175
  // This allows BookingFormService to access FormService via getService internally
158
176
  return (_jsx(WixServices, { servicesMap: createServicesMap()
159
177
  .addService(FormServiceDefinition, FormService, formServiceConfig)
160
- .addService(BookingFormServiceDefinition, BookingFormService, bookingFormServiceConfig), children: _jsx(BookingFormContent, { formId: formId, fields: { ...DEFAULT_BOOKING_FIELD_MAP, ...fields }, children: children }) }));
178
+ .addService(BookingFormServiceDefinition, BookingFormService, bookingFormServiceConfig), children: _jsx(UniqueFieldSuffixContextProvider, { children: _jsx(BookingFormContent, { fields: fieldMap, children: children }) }) }));
161
179
  }
162
180
  /**
163
181
  * Internal component that consumes BookingFormService and provides render props.
@@ -165,17 +183,139 @@ export function Root(props) {
165
183
  *
166
184
  * Note: BookingFormService internally accesses FormService to get formValues,
167
185
  * so we only need to consume BookingFormService here.
186
+ *
187
+ * Also automatically syncs form submission to BookingService when available,
188
+ * so Booking.Actions.Book can check canBook() correctly.
189
+ *
190
+ * Note: BookingService must be available in a parent WixServices context
191
+ * (typically provided by Booking.Root) for the sync to work. If BookingService
192
+ * is not available, useService will throw. This is expected since Booking.Actions.Book
193
+ * requires Booking.Root to be in the component tree.
168
194
  */
169
- function BookingFormContent({ formId, fields, children, }) {
195
+ function BookingFormContent({ fields, children, }) {
170
196
  const bookingFormService = useService(BookingFormServiceDefinition);
197
+ // Try to get BookingService from parent context (provided by Booking.Root)
198
+ // Note: useService must be called unconditionally per React hooks rules.
199
+ // If BookingService is not available, useService will throw an error.
200
+ // This is expected - Booking.Actions.Book requires Booking.Root to be in the tree.
201
+ // We use a wrapper component pattern to handle this gracefully.
202
+ // For now, we'll always attempt to get it and let it throw if not available
203
+ // The user should wrap BookingForm with Booking.Root when using Booking.Actions.Book
204
+ const bookingService = useService(BookingServiceDefinition);
205
+ // Create internal ref for form handle
206
+ const formRef = useRef(null);
207
+ // Create validate action that uses the form ref
208
+ const validate = useCallback(() => {
209
+ return formRef.current?.validate() ?? Promise.resolve(false);
210
+ }, []);
211
+ // Wrap setFormSubmission to also sync to BookingService when available
212
+ const setFormSubmission = useCallback((formValues) => {
213
+ // Set in BookingFormService (always)
214
+ bookingFormService.setFormSubmission(formValues);
215
+ // Also set in BookingService if available (for canBook check)
216
+ // This allows Booking.Actions.Book to work correctly
217
+ if (bookingService) {
218
+ bookingService.actions.setFormSubmission(formValues);
219
+ }
220
+ }, [bookingFormService, bookingService]);
171
221
  const formSubmission = bookingFormService.formSubmission.get();
172
222
  const formValues = bookingFormService.formValues.get();
223
+ // Get formId from service (it extracts from services if not provided in config)
224
+ const resolvedFormId = bookingFormService.formId.get();
173
225
  return children({
174
- formId,
226
+ formId: resolvedFormId,
175
227
  formValues,
176
228
  formSubmission,
177
- setFormSubmission: bookingFormService.setFormSubmission,
178
- validateFormSubmission: bookingFormService.validateFormSubmission,
229
+ setFormSubmission,
230
+ validateFormSubmission: validate,
231
+ formRef,
179
232
  fields,
180
233
  });
181
234
  }
235
+ /**
236
+ * Core component that provides booking form actions via render props.
237
+ * Must be used within BookingForm.Root context.
238
+ *
239
+ * @component
240
+ * @example
241
+ * ```tsx
242
+ * <CoreBookingForm.Root formId="form-123">
243
+ * {({ fields }) => (
244
+ * <>
245
+ * <Form.Fields fieldMap={fields} />
246
+ * <CoreBookingForm.Actions>
247
+ * {({ validateFormSubmission, formId }) => (
248
+ * <button onClick={async () => {
249
+ * const result = await validateFormSubmission();
250
+ * console.log('Validation result:', result);
251
+ * }}>
252
+ * Validate Form
253
+ * </button>
254
+ * )}
255
+ * </CoreBookingForm.Actions>
256
+ * </>
257
+ * )}
258
+ * </CoreBookingForm.Root>
259
+ * ```
260
+ */
261
+ export function Actions(props) {
262
+ const bookingFormService = useService(BookingFormServiceDefinition);
263
+ const formSubmission = bookingFormService.formSubmission.get();
264
+ const formValues = bookingFormService.formValues.get();
265
+ const formId = bookingFormService.formId.get();
266
+ return props.children({
267
+ validateFormSubmission: bookingFormService.validateFormSubmission,
268
+ formId,
269
+ formValues,
270
+ formSubmission,
271
+ });
272
+ }
273
+ /**
274
+ * Component to display when BookingForm fails to load due to configuration errors.
275
+ * This component should be used in an error boundary to catch BookingFormConfigurationError.
276
+ *
277
+ * @component
278
+ * @example
279
+ * ```tsx
280
+ * import * as CoreBookingForm from '@wix/headless-bookings/react/core/booking-form';
281
+ *
282
+ * // Default usage with className
283
+ * <CoreBookingForm.LoadError error={error} className="text-destructive p-4" />
284
+ *
285
+ * // Custom content
286
+ * <CoreBookingForm.LoadError error={error}>
287
+ * <div className="error-container">
288
+ * <h3>Error Loading Form</h3>
289
+ * <p>Please try again later.</p>
290
+ * </div>
291
+ * </CoreBookingForm.LoadError>
292
+ *
293
+ * // With asChild for custom components
294
+ * <CoreBookingForm.LoadError error={error} asChild>
295
+ * <CustomErrorComponent />
296
+ * </CoreBookingForm.LoadError>
297
+ * ```
298
+ */
299
+ export const LoadError = React.forwardRef((props, ref) => {
300
+ const { error, asChild, children, className, ...otherProps } = props;
301
+ const errorData = { error, message: error.message };
302
+ if (asChild && React.isValidElement(children)) {
303
+ return React.cloneElement(children, {
304
+ ref,
305
+ className,
306
+ 'data-testid': 'booking-form-load-error',
307
+ role: 'alert',
308
+ ...errorData,
309
+ ...otherProps,
310
+ });
311
+ }
312
+ return (_jsx("div", { ref: ref, className: className, "data-testid": "booking-form-load-error", role: "alert", ...otherProps, children: children ?? error.message }));
313
+ });
314
+ /**
315
+ * Type guard to check if an error is a BookingFormConfigurationError
316
+ */
317
+ export function isBookingFormConfigurationError(error) {
318
+ return error instanceof BookingFormConfigurationError;
319
+ }
320
+ // Re-export the error class for convenience
321
+ export { BookingFormConfigurationError };
@@ -8,6 +8,7 @@
8
8
  import React from 'react';
9
9
  import { AsChildChildren } from '@wix/headless-utils/react';
10
10
  import type { TimeSlot as TimeSlotType } from '@wix/auto_sdk_bookings_availability-time-slots';
11
+ import * as CoreTimeSlot from '../core/time-slot-list/TimeSlot.js';
11
12
  export type { StaffMemberData } from '../core/time-slot-list/TimeSlot.js';
12
13
  /**
13
14
  * Props for TimeSlot.Root component
@@ -131,6 +132,7 @@ export interface SelectProps {
131
132
  }) => React.ReactNode);
132
133
  className?: string;
133
134
  label?: string;
135
+ onClicked?: (timeSlot: TimeSlotType) => void;
134
136
  }
135
137
  /**
136
138
  * Button to select this time slot.
@@ -150,6 +152,13 @@ export interface SelectProps {
150
152
  * <button className="btn-primary">Book this slot</button>
151
153
  * </TimeSlot.Actions.Select>
152
154
  *
155
+ * // With onClicked callback for navigation
156
+ * <TimeSlot.Actions.Select
157
+ * onClicked={(timeSlot) => {
158
+ * router.push(`/booking/confirm/${timeSlot.localStartDate}`);
159
+ * }}
160
+ * />
161
+ *
153
162
  * // Using render prop pattern
154
163
  * <TimeSlot.Actions.Select>
155
164
  * {({ isSelected, bookable, onClick }) => (
@@ -171,6 +180,7 @@ export interface ClearStaffSelectionProps {
171
180
  }) => React.ReactNode);
172
181
  className?: string;
173
182
  label?: string;
183
+ onClicked?: (timeSlot: TimeSlotType) => void;
174
184
  }
175
185
  /**
176
186
  * Button to clear staff selection while keeping the slot selected.
@@ -191,6 +201,13 @@ export interface ClearStaffSelectionProps {
191
201
  * <button className="btn-secondary">Clear staff</button>
192
202
  * </TimeSlot.Actions.ClearStaffSelection>
193
203
  *
204
+ * // With onClicked callback
205
+ * <TimeSlot.Actions.ClearStaffSelection
206
+ * onClicked={(timeSlot) => {
207
+ * console.log('Staff selection cleared for', timeSlot.localStartDate);
208
+ * }}
209
+ * />
210
+ *
194
211
  * // Using render prop pattern
195
212
  * <TimeSlot.Actions.ClearStaffSelection>
196
213
  * {({ onClick }) => <button onClick={onClick}>Change selection</button>}
@@ -324,6 +341,7 @@ export interface SelectStaffMemberProps {
324
341
  }) => React.ReactNode);
325
342
  className?: string;
326
343
  label?: string;
344
+ onClicked?: (staffMember: CoreTimeSlot.StaffMemberData) => void;
327
345
  }
328
346
  /**
329
347
  * Button to select this staff member.
@@ -343,6 +361,13 @@ export interface SelectStaffMemberProps {
343
361
  * <button className="btn-primary">Choose Staff</button>
344
362
  * </TimeSlot.StaffMember.Actions.Select>
345
363
  *
364
+ * // With onClicked callback
365
+ * <TimeSlot.StaffMember.Actions.Select
366
+ * onClicked={(staffMember) => {
367
+ * console.log('Selected staff:', staffMember.name);
368
+ * }}
369
+ * />
370
+ *
346
371
  * // Using render prop pattern
347
372
  * <TimeSlot.StaffMember.Actions.Select>
348
373
  * {({ isSelected, onClick }) => (
@@ -139,6 +139,13 @@ Duration.displayName = 'TimeSlot.Duration';
139
139
  * <button className="btn-primary">Book this slot</button>
140
140
  * </TimeSlot.Actions.Select>
141
141
  *
142
+ * // With onClicked callback for navigation
143
+ * <TimeSlot.Actions.Select
144
+ * onClicked={(timeSlot) => {
145
+ * router.push(`/booking/confirm/${timeSlot.localStartDate}`);
146
+ * }}
147
+ * />
148
+ *
142
149
  * // Using render prop pattern
143
150
  * <TimeSlot.Actions.Select>
144
151
  * {({ isSelected, bookable, onClick }) => (
@@ -150,14 +157,18 @@ Duration.displayName = 'TimeSlot.Duration';
150
157
  * ```
151
158
  */
152
159
  export const Select = React.forwardRef((props, ref) => {
153
- const { asChild, children, className, label = 'Select' } = props;
154
- return (_jsx(CoreTimeSlot.Actions, { children: ({ selectTimeSlot, isSelected, bookable }) => {
160
+ const { asChild, children, className, label = 'Select', onClicked } = props;
161
+ return (_jsx(CoreTimeSlot.Actions, { children: ({ selectTimeSlot, isSelected, bookable, timeSlot }) => {
162
+ const handleClick = () => {
163
+ selectTimeSlot();
164
+ onClicked?.(timeSlot);
165
+ };
155
166
  return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.timeSlotActionSelect, "data-selected": isSelected, "data-bookable": bookable, customElement: children, customElementProps: {
156
- onClick: selectTimeSlot,
167
+ onClick: handleClick,
157
168
  disabled: !bookable,
158
169
  isSelected,
159
170
  bookable,
160
- }, children: _jsx("button", { onClick: selectTimeSlot, disabled: !bookable, children: label }) }));
171
+ }, children: _jsx("button", { onClick: handleClick, disabled: !bookable, children: label }) }));
161
172
  } }));
162
173
  });
163
174
  Select.displayName = 'TimeSlot.Actions.Select';
@@ -180,6 +191,13 @@ Select.displayName = 'TimeSlot.Actions.Select';
180
191
  * <button className="btn-secondary">Clear staff</button>
181
192
  * </TimeSlot.Actions.ClearStaffSelection>
182
193
  *
194
+ * // With onClicked callback
195
+ * <TimeSlot.Actions.ClearStaffSelection
196
+ * onClicked={(timeSlot) => {
197
+ * console.log('Staff selection cleared for', timeSlot.localStartDate);
198
+ * }}
199
+ * />
200
+ *
183
201
  * // Using render prop pattern
184
202
  * <TimeSlot.Actions.ClearStaffSelection>
185
203
  * {({ onClick }) => <button onClick={onClick}>Change selection</button>}
@@ -187,14 +205,18 @@ Select.displayName = 'TimeSlot.Actions.Select';
187
205
  * ```
188
206
  */
189
207
  export const ClearStaffSelection = React.forwardRef((props, ref) => {
190
- const { asChild, children, className, label = 'Change' } = props;
191
- return (_jsx(CoreTimeSlot.Actions, { children: ({ clearStaffSelection }) => {
208
+ const { asChild, children, className, label = 'Change', onClicked } = props;
209
+ return (_jsx(CoreTimeSlot.Actions, { children: ({ clearStaffSelection, timeSlot }) => {
192
210
  if (!clearStaffSelection) {
193
211
  return null;
194
212
  }
213
+ const handleClick = () => {
214
+ clearStaffSelection();
215
+ onClicked?.(timeSlot);
216
+ };
195
217
  return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.timeSlotActionClearStaffSelection, customElement: children, customElementProps: {
196
- onClick: clearStaffSelection,
197
- }, children: _jsx("button", { onClick: clearStaffSelection, children: label }) }));
218
+ onClick: handleClick,
219
+ }, children: _jsx("button", { onClick: handleClick, children: label }) }));
198
220
  } }));
199
221
  });
200
222
  ClearStaffSelection.displayName = 'TimeSlot.Actions.ClearStaffSelection';
@@ -324,6 +346,13 @@ StaffMemberName.displayName = 'TimeSlot.StaffMember.Name';
324
346
  * <button className="btn-primary">Choose Staff</button>
325
347
  * </TimeSlot.StaffMember.Actions.Select>
326
348
  *
349
+ * // With onClicked callback
350
+ * <TimeSlot.StaffMember.Actions.Select
351
+ * onClicked={(staffMember) => {
352
+ * console.log('Selected staff:', staffMember.name);
353
+ * }}
354
+ * />
355
+ *
327
356
  * // Using render prop pattern
328
357
  * <TimeSlot.StaffMember.Actions.Select>
329
358
  * {({ isSelected, onClick }) => (
@@ -335,11 +364,17 @@ StaffMemberName.displayName = 'TimeSlot.StaffMember.Name';
335
364
  * ```
336
365
  */
337
366
  export const SelectStaffMember = React.forwardRef((props, ref) => {
338
- const { asChild, children, className, label = 'Select' } = props;
339
- return (_jsx(CoreTimeSlot.StaffMemberActions, { children: ({ selectStaffMember, isSelected }) => (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.timeSlotStaffMemberActionSelect, "data-selected": isSelected, customElement: children, customElementProps: {
340
- onClick: selectStaffMember,
341
- isSelected,
342
- }, children: _jsx("button", { onClick: selectStaffMember, children: label }) })) }));
367
+ const { asChild, children, className, label = 'Select', onClicked } = props;
368
+ return (_jsx(CoreTimeSlot.StaffMemberActions, { children: ({ selectStaffMember, isSelected, staffMember }) => {
369
+ const handleClick = () => {
370
+ selectStaffMember();
371
+ onClicked?.(staffMember);
372
+ };
373
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.timeSlotStaffMemberActionSelect, "data-selected": isSelected, customElement: children, customElementProps: {
374
+ onClick: handleClick,
375
+ isSelected,
376
+ }, children: _jsx("button", { onClick: handleClick, children: label }) }));
377
+ } }));
343
378
  });
344
379
  SelectStaffMember.displayName = 'TimeSlot.StaffMember.Actions.Select';
345
380
  /**
@@ -25,24 +25,44 @@ export interface ValidationResult {
25
25
  /** Array of validation failure messages */
26
26
  validationFailures: string[];
27
27
  }
28
+ /**
29
+ * Error thrown when BookingFormService cannot be initialized due to missing configuration.
30
+ * This occurs when:
31
+ * - No config (formId or form) was provided
32
+ * - AND the component is not wrapped with Booking.Root (no BookingService available)
33
+ */
34
+ export declare class BookingFormConfigurationError extends Error {
35
+ constructor(message?: string);
36
+ }
28
37
  /**
29
38
  * Configuration for BookingFormService.
30
39
  * Supports two modes:
31
40
  * 1. Client-side loading: Provide formId to fetch the form dynamically
32
41
  * 2. SSR/SSG: Provide a pre-loaded form object (must be from bookings namespace)
33
42
  *
43
+ * Note: The config itself is optional. If not provided, the formId will be
44
+ * extracted from the selected service if available.
45
+ *
34
46
  * @example
35
47
  * ```tsx
36
48
  * // Pattern 1: Client-side loading
37
49
  * const config = { formId: 'form-123' };
38
50
  *
51
+ * // Pattern 1b: Client-side loading with service IDs
52
+ * const config = { formId: 'form-123', serviceIds: ['service-1', 'service-2'] };
53
+ *
39
54
  * // Pattern 2: Pre-loaded form (SSR/SSG)
40
55
  * const config = { form: preloadedForm };
56
+ *
57
+ * // Pattern 3: No config (formId extracted from service)
58
+ * // config = undefined
41
59
  * ```
42
60
  */
43
61
  export type BookingFormServiceConfig = {
44
62
  /** The form ID to load (client-side loading) */
45
63
  formId: string;
64
+ /** Optional list of service IDs associated with this booking form */
65
+ serviceIds?: string[];
46
66
  } | {
47
67
  /** Pre-loaded form object (SSR/SSG) - must be from bookings namespace */
48
68
  form: forms.Form;
@@ -79,18 +99,7 @@ export interface BookingFormServiceInternalAPI extends BookingFormServiceAPI {
79
99
  /** Internal: Register validate callback (called by core component) */
80
100
  _setValidateCallback: (callback: () => Promise<ValidationResult>) => void;
81
101
  }
82
- /**
83
- * Type guard to check if config has formId
84
- */
85
- export declare function hasFormId(config: BookingFormServiceConfig): config is {
86
- formId: string;
87
- };
88
- /**
89
- * Type guard to check if config has pre-loaded form
90
- */
91
- export declare function hasForm(config: BookingFormServiceConfig): config is {
92
- form: forms.Form;
93
- };
102
+ export { hasFormId, hasForm, extractFormIdFromForm, extractFormIdFromConfig, type FormIdConfig, } from './utils.js';
94
103
  /**
95
104
  * Service definition for BookingForm.
96
105
  * Defines the contract that the BookingFormService must implement.
@@ -137,4 +146,4 @@ export declare const BookingFormService: import("@wix/services-definitions").Ser
137
146
  __api: BookingFormServiceAPI;
138
147
  __config: {};
139
148
  isServiceDefinition?: boolean;
140
- } & BookingFormServiceAPI, BookingFormServiceConfig>;
149
+ } & BookingFormServiceAPI, BookingFormServiceConfig | undefined>;