@wix/headless-bookings 0.0.61 → 0.0.63

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 (65) hide show
  1. package/cjs/dist/__mocks__/time-slots.js +1 -0
  2. package/cjs/dist/api/index.d.ts +2 -2
  3. package/cjs/dist/api/index.js +2 -2
  4. package/cjs/dist/api/query-locations/index.d.ts +14 -0
  5. package/cjs/dist/api/query-locations/index.js +27 -0
  6. package/cjs/dist/api/query-services/index.d.ts +5 -0
  7. package/cjs/dist/api/query-services/index.js +2 -2
  8. package/cjs/dist/react/booking/Book.d.ts +2 -0
  9. package/cjs/dist/react/booking/Book.js +11 -1
  10. package/cjs/dist/react/core/location/Location.d.ts +2 -0
  11. package/cjs/dist/react/core/location/Location.js +14 -1
  12. package/cjs/dist/react/core/time-slot-list/TimeSlot.js +0 -2
  13. package/cjs/dist/react/core/time-slot-list/TimeSlotList.d.ts +47 -3
  14. package/cjs/dist/react/core/time-slot-list/TimeSlotList.js +60 -5
  15. package/cjs/dist/react/index.d.ts +0 -1
  16. package/cjs/dist/react/index.js +1 -1
  17. package/cjs/dist/react/location/Location.d.ts +4 -0
  18. package/cjs/dist/react/location/Location.js +20 -2
  19. package/cjs/dist/react/location/LocationList.d.ts +4 -0
  20. package/cjs/dist/react/location/LocationList.js +33 -7
  21. package/cjs/dist/react/time-slot-list/TimeSlotList.d.ts +30 -7
  22. package/cjs/dist/react/time-slot-list/TimeSlotList.js +27 -8
  23. package/cjs/dist/services/index.d.ts +2 -1
  24. package/cjs/dist/services/index.js +2 -1
  25. package/cjs/dist/services/location-list/location-list.d.ts +1 -0
  26. package/cjs/dist/services/location-list/location-list.js +3 -2
  27. package/cjs/dist/services/time-slot-list/time-slot-list.def.d.ts +1 -0
  28. package/cjs/dist/services/time-slot-list/time-slot-list.js +2 -9
  29. package/cjs/dist/utils/index.d.ts +5 -0
  30. package/cjs/dist/utils/index.js +5 -0
  31. package/cjs/dist/utils/navigation.d.ts +7 -0
  32. package/cjs/dist/utils/navigation.js +75 -0
  33. package/dist/__mocks__/time-slots.js +1 -0
  34. package/dist/api/index.d.ts +2 -2
  35. package/dist/api/index.js +2 -2
  36. package/dist/api/query-locations/index.d.ts +14 -0
  37. package/dist/api/query-locations/index.js +27 -0
  38. package/dist/api/query-services/index.d.ts +5 -0
  39. package/dist/api/query-services/index.js +2 -2
  40. package/dist/react/booking/Book.d.ts +2 -0
  41. package/dist/react/booking/Book.js +11 -1
  42. package/dist/react/core/location/Location.d.ts +2 -0
  43. package/dist/react/core/location/Location.js +14 -1
  44. package/dist/react/core/time-slot-list/TimeSlot.js +0 -2
  45. package/dist/react/core/time-slot-list/TimeSlotList.d.ts +47 -3
  46. package/dist/react/core/time-slot-list/TimeSlotList.js +60 -5
  47. package/dist/react/index.d.ts +0 -1
  48. package/dist/react/index.js +1 -1
  49. package/dist/react/location/Location.d.ts +4 -0
  50. package/dist/react/location/Location.js +20 -2
  51. package/dist/react/location/LocationList.d.ts +4 -0
  52. package/dist/react/location/LocationList.js +33 -7
  53. package/dist/react/time-slot-list/TimeSlotList.d.ts +30 -7
  54. package/dist/react/time-slot-list/TimeSlotList.js +27 -8
  55. package/dist/services/index.d.ts +2 -1
  56. package/dist/services/index.js +2 -1
  57. package/dist/services/location-list/location-list.d.ts +1 -0
  58. package/dist/services/location-list/location-list.js +3 -2
  59. package/dist/services/time-slot-list/time-slot-list.def.d.ts +1 -0
  60. package/dist/services/time-slot-list/time-slot-list.js +2 -9
  61. package/dist/utils/index.d.ts +5 -0
  62. package/dist/utils/index.js +5 -0
  63. package/dist/utils/navigation.d.ts +7 -0
  64. package/dist/utils/navigation.js +75 -0
  65. package/package.json +2 -2
@@ -17,6 +17,10 @@ export interface RootProps {
17
17
  locationListConfig?: LocationListServiceConfig;
18
18
  className?: string;
19
19
  variant?: ListVariant;
20
+ /** Custom label for CUSTOM location type */
21
+ customLocationLabel?: string;
22
+ /** Custom label for CUSTOMER location type */
23
+ customerLocationLabel?: string;
20
24
  }
21
25
  /**
22
26
  * Root component that provides the LocationList service context for rendering locations lists.
@@ -9,9 +9,15 @@ import React from 'react';
9
9
  import { GenericList, } from '@wix/headless-components/react';
10
10
  import { AsChildSlot } from '@wix/headless-utils/react';
11
11
  import { useService } from '@wix/services-manager-react';
12
+ import { LocationType, } from '../../services/location-list/location-list.def.js';
12
13
  import { BookingServiceDefinition } from '../../services/booking/booking.js';
13
14
  import * as CoreLocationList from '../core/location-list/LocationList.js';
14
15
  import * as Location from './Location.js';
16
+ const LocationLabelsContext = React.createContext(null);
17
+ function useLocationLabelsContext() {
18
+ const context = React.useContext(LocationLabelsContext);
19
+ return context || {};
20
+ }
15
21
  // ============================================================================
16
22
  // TestIds
17
23
  // ============================================================================
@@ -45,11 +51,11 @@ var TestIds;
45
51
  * ```
46
52
  */
47
53
  export const Root = React.forwardRef((props, ref) => {
48
- const { children, locationListConfig, className, variant } = props;
54
+ const { children, locationListConfig, className, variant, customLocationLabel, customerLocationLabel, } = props;
49
55
  const config = locationListConfig || {
50
56
  locations: [],
51
57
  };
52
- return (_jsx(CoreLocationList.Root, { locationListServiceConfig: config, children: _jsx(RootContent, { className: className, ref: ref, variant: variant, children: children }) }));
58
+ return (_jsx(LocationLabelsContext.Provider, { value: { customLocationLabel, customerLocationLabel }, children: _jsx(CoreLocationList.Root, { locationListServiceConfig: config, children: _jsx(RootContent, { className: className, ref: ref, variant: variant, children: children }) }) }));
53
59
  });
54
60
  Root.displayName = 'LocationList.Root';
55
61
  /**
@@ -85,15 +91,35 @@ export const Locations = React.forwardRef((props, ref) => {
85
91
  Locations.displayName = 'LocationList.Locations';
86
92
  export const LocationRepeater = React.forwardRef((props, ref) => {
87
93
  const { children } = props;
94
+ const { customLocationLabel, customerLocationLabel } = useLocationLabelsContext();
88
95
  // Custom itemWrapper that wraps each item in Location.Root
89
96
  const locationItemWrapper = ({ item: displayLocation, children: itemChildren, }) => {
90
97
  // Convert DisplayLocation to LocationInput
91
98
  // If location is null, create a SyntheticLocation
92
- const location = displayLocation.location ?? {
93
- locationType: displayLocation.type,
94
- synthetic: true,
95
- _id: displayLocation.id,
96
- };
99
+ let location;
100
+ if (displayLocation.location) {
101
+ location = displayLocation.location;
102
+ }
103
+ else {
104
+ const locationType = displayLocation.type;
105
+ // Determine the name based on labels or defaults
106
+ let name;
107
+ if (locationType === LocationType.CUSTOM &&
108
+ customLocationLabel !== undefined) {
109
+ name = customLocationLabel;
110
+ }
111
+ else if (locationType === LocationType.CUSTOMER &&
112
+ customerLocationLabel !== undefined) {
113
+ name = customerLocationLabel;
114
+ }
115
+ // If no label provided, name will be undefined and defaults will be used in computeLocationRenderProps
116
+ location = {
117
+ locationType,
118
+ synthetic: true,
119
+ _id: displayLocation.id,
120
+ name,
121
+ };
122
+ }
97
123
  return (_jsx(Location.Root, { location: location, "data-testid": TestIds.locationListLocation, "data-location-id": displayLocation.id, "data-location-type": displayLocation.type, "data-item-id": displayLocation.id, children: itemChildren }, displayLocation.id));
98
124
  };
99
125
  return (_jsx(GenericList.Repeater, { ref: ref, itemWrapper: locationItemWrapper, children: children }));
@@ -6,7 +6,9 @@ import React from 'react';
6
6
  import { ListVariant } from '@wix/headless-components/react';
7
7
  import { AsChildChildren } from '@wix/headless-utils/react';
8
8
  import type { TimeSlot as TimeSlotType } from '@wix/auto_sdk_bookings_availability-time-slots';
9
+ import type { Service } from '@wix/auto_sdk_bookings_services';
9
10
  import type { TimeSlotListServiceConfig } from '../../services/time-slot-list/time-slot-list.def.js';
11
+ import { ServiceSelectionTimeSlot } from '../../services/booking/booking.js';
10
12
  export type { StartDateProps as TimeSlotStartDateProps, EndDateProps as TimeSlotEndDateProps, DurationProps as TimeSlotDurationProps, SelectProps as TimeSlotSelectProps, LocationNameProps as TimeSlotLocationNameProps, StaffMembersProps as TimeSlotStaffMembersProps, StaffMemberRepeaterProps as TimeSlotStaffMemberRepeaterProps, StaffMemberNameProps as TimeSlotStaffMemberNameProps, SelectStaffMemberProps as TimeSlotSelectStaffMemberProps, ClearStaffSelectionProps as TimeSlotClearStaffSelectionProps, } from './TimeSlot.js';
11
13
  /**
12
14
  * Render props for TimeSlotList.Timezone component
@@ -49,8 +51,23 @@ export declare const Timezone: React.ForwardRefExoticComponent<TimezoneProps & R
49
51
  * Props for TimeSlotList.Root component
50
52
  */
51
53
  export interface RootProps {
52
- children: React.ReactNode;
54
+ children: React.ReactNode | ((data: {
55
+ navigateToBookingForm: ({ timeSlot, service, }: {
56
+ timeSlot?: ServiceSelectionTimeSlot;
57
+ service?: Service;
58
+ }) => Promise<void>;
59
+ }) => React.ReactNode);
53
60
  config: TimeSlotListServiceConfig;
61
+ /**
62
+ * Function to navigate to the booking form.
63
+ * The timeSlot and service parameters are optional - if not provided,
64
+ * BookingService will be used to get them from the current service selections.
65
+ * If not provided, will use the default navigation utility.
66
+ */
67
+ navigateToBookingForm?: ({ timeSlot, service, }: {
68
+ timeSlot?: ServiceSelectionTimeSlot;
69
+ service?: Service;
70
+ }) => Promise<void>;
54
71
  className?: string;
55
72
  variant?: ListVariant;
56
73
  }
@@ -62,15 +79,21 @@ export interface RootProps {
62
79
  * @example
63
80
  * ```tsx
64
81
  * import { TimeSlotList } from '@wix/bookings/components';
82
+ * import { navigateToBookingForm } from '@wix/headless-bookings/utils';
65
83
  *
66
84
  * function TimeSlotsPage({ config }) {
67
85
  * return (
68
- * <TimeSlotList.Root config={config}>
69
- * <TimeSlotList.TimeSlots>
70
- * <TimeSlotList.TimeSlotRepeater>
71
- * {children}
72
- * </TimeSlotList.TimeSlotRepeater>
73
- * </TimeSlotList.TimeSlots>
86
+ * <TimeSlotList.Root
87
+ * config={config}
88
+ * navigateToBookingForm={navigateToBookingForm}
89
+ * >
90
+ * {({ navigateToBookingForm }) => (
91
+ * <TimeSlotList.TimeSlots>
92
+ * <TimeSlotList.TimeSlotRepeater>
93
+ * {children}
94
+ * </TimeSlotList.TimeSlotRepeater>
95
+ * </TimeSlotList.TimeSlots>
96
+ * )}
74
97
  * </TimeSlotList.Root>
75
98
  * );
76
99
  * }
@@ -9,6 +9,7 @@ import { AsChildSlot } from '@wix/headless-utils/react';
9
9
  import * as CoreTimeSlotList from '../core/time-slot-list/TimeSlotList.js';
10
10
  import * as CoreTimeSlot from '../core/time-slot-list/TimeSlot.js';
11
11
  import { StartDate as TimeSlotStartDate, EndDate as TimeSlotEndDate, Duration, Actions as TimeSlotActions, Location, StaffMembers, StaffMemberRepeater, StaffMember, Root as TimeSlotRoot, } from './TimeSlot.js';
12
+ import { navigateToBookingForm as defaultNavigateToBookingForm } from '../../utils/navigation.js';
12
13
  // ============================================================================
13
14
  // Utilities
14
15
  // ============================================================================
@@ -28,6 +29,7 @@ var TestIds;
28
29
  TestIds["timeSlotListTimeSlot"] = "time-slot-list-time-slot";
29
30
  TestIds["timeSlotListTimezone"] = "time-slot-list-timezone";
30
31
  TestIds["timeSlotListLoadMore"] = "time-slot-list-load-more";
32
+ TestIds["timeSlotListContinue"] = "time-slot-list-continue";
31
33
  TestIds["timeSlotListDateRangeInput"] = "time-slot-list-date-range-input";
32
34
  })(TestIds || (TestIds = {}));
33
35
  /**
@@ -62,23 +64,40 @@ Timezone.displayName = 'TimeSlotList.Timezone';
62
64
  * @example
63
65
  * ```tsx
64
66
  * import { TimeSlotList } from '@wix/bookings/components';
67
+ * import { navigateToBookingForm } from '@wix/headless-bookings/utils';
65
68
  *
66
69
  * function TimeSlotsPage({ config }) {
67
70
  * return (
68
- * <TimeSlotList.Root config={config}>
69
- * <TimeSlotList.TimeSlots>
70
- * <TimeSlotList.TimeSlotRepeater>
71
- * {children}
72
- * </TimeSlotList.TimeSlotRepeater>
73
- * </TimeSlotList.TimeSlots>
71
+ * <TimeSlotList.Root
72
+ * config={config}
73
+ * navigateToBookingForm={navigateToBookingForm}
74
+ * >
75
+ * {({ navigateToBookingForm }) => (
76
+ * <TimeSlotList.TimeSlots>
77
+ * <TimeSlotList.TimeSlotRepeater>
78
+ * {children}
79
+ * </TimeSlotList.TimeSlotRepeater>
80
+ * </TimeSlotList.TimeSlots>
81
+ * )}
74
82
  * </TimeSlotList.Root>
75
83
  * );
76
84
  * }
77
85
  * ```
78
86
  */
79
87
  export const Root = React.forwardRef((props, ref) => {
80
- const { children, config, className, variant } = props;
81
- return (_jsx(CoreTimeSlotList.Root, { config: config, children: _jsx(RootContent, { className: className, ref: ref, variant: variant, children: children }) }));
88
+ const { children, config, className, variant, navigateToBookingForm: providedNavigateToBookingForm, } = props;
89
+ const navigateToBookingForm = providedNavigateToBookingForm ||
90
+ (async ({ timeSlot, service, }) => {
91
+ if (!timeSlot || !service) {
92
+ throw new Error('timeSlot and service are required when using default navigation. Either provide them or ensure BookingService has service selections.');
93
+ }
94
+ return defaultNavigateToBookingForm({ timeSlot, service });
95
+ });
96
+ return (_jsx(CoreTimeSlotList.Root, { config: config, navigateToBookingForm: navigateToBookingForm, children: (coreData) => (_jsx(RootContent, { className: className, ref: ref, variant: variant, children: typeof children === 'function'
97
+ ? children({
98
+ navigateToBookingForm: coreData.navigateToBookingForm,
99
+ })
100
+ : children })) }));
82
101
  });
83
102
  Root.displayName = 'TimeSlotList.Root';
84
103
  /**
@@ -6,8 +6,9 @@ export { ServiceService, ServiceServiceDefinition, type ServiceServiceAPI, type
6
6
  export { BookingService, BookingServiceDefinition, type BookingServiceConfig, type BookingServiceActions, type ServiceSelection, type ServiceSelectionTimeSlot, } from './booking/booking.js';
7
7
  export { TimeSlotListService, TimeSlotListServiceDefinition, TimeSlotService, TimeSlotServiceDefinition, ViewMode, loadTimeSlotListConfig, type TimeSlotListServiceAPI, type TimeSlotListServiceActions, type TimeSlotListServiceConfig, type TimeSlotServiceAPI, type TimeSlotServiceConfig, type LoadTimeSlotListConfigOptions, type LoadTimeSlotListConfigResult, } from './time-slot-list/index.js';
8
8
  export { ServiceListService, ServiceListServiceDefinition, type ServiceListServiceAPI, type ServiceListServiceConfig, type ServiceListFilters, type ServiceListActions, type QueryOptions, loadServiceListServiceInitialData, type SuccessServiceListServiceConfigResult, type ErrorServiceListServiceConfigResult, } from './service-list/service-list.js';
9
+ export { SYNTHETIC_CUSTOM_ID, SYNTHETIC_CUSTOMER_ID, } from '../api/query-services/index.js';
9
10
  export { executeBookAction, canBook, buildBookingRequest, buildCheckoutRequest, type CanBookParams, type BookResult, type BookingError, type BookActionParams, type BookChildProps, type BookProps, type BuildCheckoutParams, } from './booking/book-action/index.js';
10
11
  export { BookingFormService, BookingFormServiceDefinition, type BookingFormServiceAPI, type BookingFormServiceConfig, type BookingFormServiceInternalAPI, type ValidationResult, } from './booking-form/booking-form.js';
11
12
  export { PaymentService, PaymentServiceDefinition, type PaymentServiceAPI, type PaymentServiceConfig, type PaymentDetails, type PricingServiceSelection, type LineItemAdditionalInfo, loadPaymentConfig, type SuccessPaymentConfigResult, type ErrorPaymentConfigResult, } from './payment/payment.js';
12
- export { LocationListService, LocationListServiceDefinition, LocationType, loadLocationListServiceInitialData, locationListServiceBinding, type LocationListServiceAPI, type LocationListServiceConfig, type LocationListActions, type LocationData, type DisplayLocation, type LoadLocationListServiceResult, } from './location-list/location-list.js';
13
+ export { LocationListService, LocationListServiceDefinition, LocationType, loadLocationListServiceInitialData, locationListServiceBinding, type LocationListServiceAPI, type LocationListServiceConfig, type LocationListActions, type LocationData, type DisplayLocation, type LoadLocationListServiceResult, getLocationById, } from './location-list/location-list.js';
13
14
  export { StaffMemberListService, StaffMemberListServiceDefinition, loadStaffMemberListServiceInitialData, staffMemberListServiceBinding, type StaffMemberListServiceAPI, type StaffMemberListServiceConfig, type StaffMemberListActions, type StaffMemberData, type LoadStaffMemberListServiceResult, } from './staff-member-list/staff-member-list.js';
@@ -6,8 +6,9 @@ export { ServiceService, ServiceServiceDefinition, loadServiceServiceInitialData
6
6
  export { BookingService, BookingServiceDefinition, } from './booking/booking.js';
7
7
  export { TimeSlotListService, TimeSlotListServiceDefinition, TimeSlotService, TimeSlotServiceDefinition, ViewMode, loadTimeSlotListConfig, } from './time-slot-list/index.js';
8
8
  export { ServiceListService, ServiceListServiceDefinition, loadServiceListServiceInitialData, } from './service-list/service-list.js';
9
+ export { SYNTHETIC_CUSTOM_ID, SYNTHETIC_CUSTOMER_ID, } from '../api/query-services/index.js';
9
10
  export { executeBookAction, canBook, buildBookingRequest, buildCheckoutRequest, } from './booking/book-action/index.js';
10
11
  export { BookingFormService, BookingFormServiceDefinition, } from './booking-form/booking-form.js';
11
12
  export { PaymentService, PaymentServiceDefinition, loadPaymentConfig, } from './payment/payment.js';
12
- export { LocationListService, LocationListServiceDefinition, LocationType, loadLocationListServiceInitialData, locationListServiceBinding, } from './location-list/location-list.js';
13
+ export { LocationListService, LocationListServiceDefinition, LocationType, loadLocationListServiceInitialData, locationListServiceBinding, getLocationById, } from './location-list/location-list.js';
13
14
  export { StaffMemberListService, StaffMemberListServiceDefinition, loadStaffMemberListServiceInitialData, staffMemberListServiceBinding, } from './staff-member-list/staff-member-list.js';
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import type { ServiceFactoryConfig } from '@wix/services-definitions';
8
8
  import { type LocationData } from './location-list.def.js';
9
+ export { getLocationById } from '../../api/query-locations/index.js';
9
10
  /**
10
11
  * Configuration interface for LocationListService
11
12
  */
@@ -10,14 +10,15 @@ import { LocationType } from '@wix/auto_sdk_bookings_services';
10
10
  import { LocationListServiceDefinition, } from './location-list.def.js';
11
11
  import { BookingServiceDefinition } from '../booking/booking.js';
12
12
  import { queryLocations } from '../../api/query-locations/index.js';
13
+ export { getLocationById } from '../../api/query-locations/index.js';
13
14
  // ============================================================================
14
15
  // Constants
15
16
  // ============================================================================
16
17
  /**
17
18
  * Synthetic location IDs for non-business locations
18
19
  */
19
- const SYNTHETIC_CUSTOM_ID = '__synthetic_custom__';
20
- const SYNTHETIC_CUSTOMER_ID = '__synthetic_customer__';
20
+ const SYNTHETIC_CUSTOM_ID = 'custom';
21
+ const SYNTHETIC_CUSTOMER_ID = 'customer';
21
22
  // ============================================================================
22
23
  // Helper Functions
23
24
  // ============================================================================
@@ -88,6 +88,7 @@ export interface TimeSlotListServiceAPI {
88
88
  hasMore: Signal<boolean>;
89
89
  dateRange: Signal<DateRange>;
90
90
  actions: TimeSlotListServiceActions;
91
+ dispose: () => void;
91
92
  }
92
93
  export declare const TimeSlotListServiceDefinition: string & {
93
94
  __api: TimeSlotListServiceAPI;
@@ -19,15 +19,12 @@ function getClientTimezone() {
19
19
  // Service Implementation
20
20
  // ============================================================================
21
21
  export const TimeSlotListService = implementService.withConfig()(TimeSlotListServiceDefinition, ({ getService, config }) => {
22
- // Get dependent services
23
22
  const signalsService = getService(SignalsServiceDefinition);
24
23
  const bookingService = getService(BookingServiceDefinition);
25
- // Initialize Signals
26
24
  const timeSlotsSignal = signalsService.signal(config.timeSlots || []);
27
25
  const isLoadingSignal = signalsService.signal(false);
28
26
  const errorSignal = signalsService.signal(null);
29
27
  const hasMoreSignal = signalsService.signal(false);
30
- // Internal only - viewMode is auto-detected based on service types
31
28
  const viewModeSignal = signalsService.signal(ViewMode.CLASSIC);
32
29
  const dateRangeSignal = signalsService.signal({
33
30
  start: config.startDate,
@@ -201,8 +198,7 @@ export const TimeSlotListService = implementService.withConfig()(TimeSlotListSer
201
198
  : undefined;
202
199
  });
203
200
  let isFirstRun = true;
204
- signalsService.effect(() => {
205
- // Dependencies - trigger refetch when these change
201
+ const dispose = signalsService.effect(() => {
206
202
  dateRangeSignal.get();
207
203
  bookingService.timezone.get();
208
204
  bookingService.location.get();
@@ -215,16 +211,12 @@ export const TimeSlotListService = implementService.withConfig()(TimeSlotListSer
215
211
  }
216
212
  fetchTimeSlots();
217
213
  });
218
- // Return service API
219
214
  return {
220
- // State Signals
221
215
  timeSlots: timeSlotsSignal,
222
216
  isLoading: isLoadingSignal,
223
217
  error: errorSignal,
224
218
  hasMore: hasMoreSignal,
225
- // Configuration Signals (viewMode is internal only)
226
219
  dateRange: dateRangeSignal,
227
- // Actions
228
220
  actions: {
229
221
  selectSlot,
230
222
  selectStaffMember,
@@ -232,6 +224,7 @@ export const TimeSlotListService = implementService.withConfig()(TimeSlotListSer
232
224
  loadMore,
233
225
  setDateRange,
234
226
  },
227
+ dispose,
235
228
  };
236
229
  });
237
230
  /**
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Bookings Utilities
3
+ * Exports utility functions for the bookings package
4
+ */
5
+ export { navigateToBookingForm, navigateToCheckout } from './navigation.js';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Bookings Utilities
3
+ * Exports utility functions for the bookings package
4
+ */
5
+ export { navigateToBookingForm, navigateToCheckout } from './navigation.js';
@@ -0,0 +1,7 @@
1
+ import type { ServiceSelectionTimeSlot } from '../services/booking/booking.js';
2
+ import type { Service } from '@wix/auto_sdk_bookings_services';
3
+ export declare function navigateToCheckout(checkoutId: string): Promise<void>;
4
+ export declare function navigateToBookingForm({ timeSlot, service, }: {
5
+ timeSlot: ServiceSelectionTimeSlot;
6
+ service: Service;
7
+ }): Promise<void>;
@@ -0,0 +1,75 @@
1
+ import { redirects } from '@wix/redirects';
2
+ import { LocationType as TimeSlotLocationType } from '@wix/auto_sdk_bookings_availability-time-slots';
3
+ import { LocationType as BookingsLocationType } from '@wix/auto_sdk_redirects_redirects';
4
+ export async function navigateToCheckout(checkoutId) {
5
+ const { redirectSession } = await redirects.createRedirectSession({
6
+ ecomCheckout: { checkoutId },
7
+ callbacks: {
8
+ postFlowUrl: window.location.href,
9
+ },
10
+ });
11
+ if (redirectSession?.fullUrl) {
12
+ window.location.href = redirectSession.fullUrl;
13
+ }
14
+ else {
15
+ throw new Error('Failed to create redirect session');
16
+ }
17
+ }
18
+ function mapTimeSlotLocationToBookingLocation(timeSlotLocationType) {
19
+ switch (timeSlotLocationType) {
20
+ case TimeSlotLocationType.BUSINESS:
21
+ return BookingsLocationType.OWNER_BUSINESS;
22
+ case TimeSlotLocationType.CUSTOMER:
23
+ return BookingsLocationType.CUSTOM;
24
+ case TimeSlotLocationType.CUSTOM:
25
+ return BookingsLocationType.OWNER_CUSTOM;
26
+ default:
27
+ return BookingsLocationType.UNDEFINED;
28
+ }
29
+ }
30
+ export async function navigateToBookingForm({ timeSlot, service, }) {
31
+ if (!timeSlot) {
32
+ throw new Error('No time slot provided');
33
+ }
34
+ if (!service) {
35
+ throw new Error('No service provided');
36
+ }
37
+ // Get the first resource (staff member) if available
38
+ const selectedResource = timeSlot.resources?.[0];
39
+ const { redirectSession } = await redirects.createRedirectSession({
40
+ bookingsCheckout: {
41
+ slotAvailability: {
42
+ bookable: true,
43
+ slot: {
44
+ ...timeSlot,
45
+ serviceId: service._id ?? undefined,
46
+ scheduleId: timeSlot.scheduleId,
47
+ startDate: timeSlot.startDate,
48
+ endDate: timeSlot.endDate,
49
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
50
+ resource: selectedResource
51
+ ? {
52
+ _id: selectedResource._id,
53
+ name: selectedResource.name,
54
+ }
55
+ : undefined,
56
+ location: {
57
+ _id: timeSlot.location?._id,
58
+ name: timeSlot.location?.name,
59
+ formattedAddress: timeSlot.location?.formattedAddress,
60
+ locationType: mapTimeSlotLocationToBookingLocation(timeSlot.location?.locationType),
61
+ },
62
+ },
63
+ },
64
+ },
65
+ callbacks: {
66
+ postFlowUrl: window.location.href,
67
+ },
68
+ });
69
+ if (redirectSession?.fullUrl) {
70
+ window.location.href = redirectSession.fullUrl;
71
+ }
72
+ else {
73
+ throw new Error('Failed to create redirect session');
74
+ }
75
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-bookings",
3
- "version": "0.0.61",
3
+ "version": "0.0.63",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -72,5 +72,5 @@
72
72
  "groupId": "com.wixpress.headless-components"
73
73
  }
74
74
  },
75
- "falconPackageHash": "cd07fd84714c0aeec8926487334181ea2b0381b631c601891b559528"
75
+ "falconPackageHash": "96083b204b0065686724c6e3b5716295e35a12be6db784974a6c924d"
76
76
  }