@wix/headless-bookings 0.0.11 → 0.0.13

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 (59) hide show
  1. package/cjs/dist/api/index.d.ts +1 -0
  2. package/cjs/dist/api/index.js +1 -0
  3. package/cjs/dist/api/query-services/index.d.ts +6 -7
  4. package/cjs/dist/api/query-services/index.js +4 -4
  5. package/cjs/dist/api/time-slot-list/index.d.ts +53 -0
  6. package/cjs/dist/api/time-slot-list/index.js +133 -0
  7. package/cjs/dist/react/core/booking/Booking.d.ts +7 -7
  8. package/cjs/dist/react/core/booking/Booking.js +5 -5
  9. package/cjs/dist/react/core/location/Location.d.ts +3 -3
  10. package/cjs/dist/react/core/location/Location.js +2 -2
  11. package/cjs/dist/react/core/service/Service.d.ts +8 -8
  12. package/cjs/dist/react/core/service-list/ServiceList.d.ts +2 -2
  13. package/cjs/dist/react/location/Location.d.ts +3 -3
  14. package/cjs/dist/react/service/Service.d.ts +9 -9
  15. package/cjs/dist/react/service/Service.js +5 -5
  16. package/cjs/dist/react/service-list/ServiceList.d.ts +3 -3
  17. package/cjs/dist/services/booking/booking.d.ts +25 -16
  18. package/cjs/dist/services/booking/booking.js +50 -16
  19. package/cjs/dist/services/index.d.ts +2 -1
  20. package/cjs/dist/services/index.js +1 -0
  21. package/cjs/dist/services/service/service.d.ts +5 -5
  22. package/cjs/dist/services/service/service.js +20 -21
  23. package/cjs/dist/services/service-list/service-list.d.ts +3 -3
  24. package/cjs/dist/services/time-slot-list/index.d.ts +6 -0
  25. package/cjs/dist/services/time-slot-list/index.js +6 -0
  26. package/cjs/dist/services/time-slot-list/time-slot-list.d.ts +58 -0
  27. package/cjs/dist/services/time-slot-list/time-slot-list.def.d.ts +84 -0
  28. package/cjs/dist/services/time-slot-list/time-slot-list.def.js +17 -0
  29. package/cjs/dist/services/time-slot-list/time-slot-list.js +349 -0
  30. package/dist/api/index.d.ts +1 -0
  31. package/dist/api/index.js +1 -0
  32. package/dist/api/query-services/index.d.ts +6 -7
  33. package/dist/api/query-services/index.js +4 -4
  34. package/dist/api/time-slot-list/index.d.ts +53 -0
  35. package/dist/api/time-slot-list/index.js +133 -0
  36. package/dist/react/core/booking/Booking.d.ts +7 -7
  37. package/dist/react/core/booking/Booking.js +5 -5
  38. package/dist/react/core/location/Location.d.ts +3 -3
  39. package/dist/react/core/location/Location.js +2 -2
  40. package/dist/react/core/service/Service.d.ts +8 -8
  41. package/dist/react/core/service-list/ServiceList.d.ts +2 -2
  42. package/dist/react/location/Location.d.ts +3 -3
  43. package/dist/react/service/Service.d.ts +9 -9
  44. package/dist/react/service/Service.js +5 -5
  45. package/dist/react/service-list/ServiceList.d.ts +3 -3
  46. package/dist/services/booking/booking.d.ts +25 -16
  47. package/dist/services/booking/booking.js +50 -16
  48. package/dist/services/index.d.ts +2 -1
  49. package/dist/services/index.js +1 -0
  50. package/dist/services/service/service.d.ts +5 -5
  51. package/dist/services/service/service.js +20 -21
  52. package/dist/services/service-list/service-list.d.ts +3 -3
  53. package/dist/services/time-slot-list/index.d.ts +6 -0
  54. package/dist/services/time-slot-list/index.js +6 -0
  55. package/dist/services/time-slot-list/time-slot-list.d.ts +58 -0
  56. package/dist/services/time-slot-list/time-slot-list.def.d.ts +84 -0
  57. package/dist/services/time-slot-list/time-slot-list.def.js +17 -0
  58. package/dist/services/time-slot-list/time-slot-list.js +349 -0
  59. package/package.json +2 -2
@@ -4,15 +4,20 @@
4
4
  * Persists across page navigation in SPA until page refresh
5
5
  */
6
6
  import { type Signal } from '@wix/services-definitions/core-services/signals';
7
- import type { services, availabilityTimeSlots } from '@wix/bookings';
7
+ import type { Service } from '@wix/auto_sdk_bookings_services';
8
+ import type { TimeSlot, Resource, NestedTimeSlot } from '@wix/auto_sdk_bookings_availability-time-slots';
8
9
  import type { FormValues } from '@wix/form-public';
9
10
  /**
10
- * ServiceSelection contains the service AND its related selections
11
+ * BookingSelection contains the service AND its related selections
11
12
  */
12
- export interface ServiceSelection {
13
- service: services.Service;
13
+ export interface BookingSelection {
14
+ /** Unique identifier for this booking instance (allows same service multiple times) */
15
+ instanceId: string;
16
+ service: Service;
14
17
  /** Selected resources (staff members, rooms, etc.) */
15
- resources?: availabilityTimeSlots.Resource[];
18
+ staff?: Resource;
19
+ /** Per-service slot data from nested slots (for multi-service bookings) */
20
+ nestedSlotData?: NestedTimeSlot;
16
21
  }
17
22
  export interface Location {
18
23
  id: string;
@@ -22,12 +27,16 @@ export interface Location {
22
27
  * BookingService actions - setters only, no API calls
23
28
  */
24
29
  export interface BookingServiceActions {
25
- setServices(services: ServiceSelection[]): void;
26
- addService(service: ServiceSelection): void;
27
- updateService(serviceId: string, updates: Partial<ServiceSelection>): void;
28
- removeService(serviceId: string): void;
30
+ /** Clears all booking selections and sets a single service (instanceId is auto-generated) */
31
+ setService(service: Omit<BookingSelection, 'instanceId'>): string;
32
+ /** Adds a service and returns the generated instanceId */
33
+ addService(service: Omit<BookingSelection, 'instanceId'>): string;
34
+ /** Updates a booking selection. If no instanceId provided, updates the first selection. */
35
+ updateBookingSelection(updates: Partial<Omit<BookingSelection, 'instanceId'>>, instanceId?: string): void;
36
+ /** Removes a booking selection. If no instanceId provided, removes the first selection. */
37
+ removeBookingSelection(instanceId?: string): void;
29
38
  clearServices(): void;
30
- setTimeSlot(slot: availabilityTimeSlots.TimeSlot | null): void;
39
+ setTimeSlot(slot: TimeSlot | null): void;
31
40
  clearTimeSlot(): void;
32
41
  setLocation(location: Location | null): void;
33
42
  clearLocation(): void;
@@ -40,10 +49,10 @@ export interface BookingServiceActions {
40
49
  * Pure state management - no API calls
41
50
  */
42
51
  export interface BookingService {
43
- /** Signal containing the currently selected services with their selections */
44
- services: Signal<ServiceSelection[]>;
52
+ /** Signal containing the booking selections (services with their related data) */
53
+ bookingSelections: Signal<BookingSelection[]>;
45
54
  /** Signal containing the currently selected time slot */
46
- timeSlot: Signal<availabilityTimeSlots.TimeSlot | null>;
55
+ timeSlot: Signal<TimeSlot | null>;
47
56
  /** Signal containing the selected location (derived from timeSlot) */
48
57
  location: Signal<Location | null>;
49
58
  /** Signal containing the form values */
@@ -64,10 +73,10 @@ export declare const BookingServiceDefinition: string & {
64
73
  * Note: location is NOT in config - it's derived internally from timeSlot
65
74
  */
66
75
  export interface BookingServiceConfig {
67
- /** Optional initial services to pre-populate */
68
- initialServices?: ServiceSelection[];
76
+ /** Optional initial booking selections to pre-populate */
77
+ initialBookingSelections?: BookingSelection[];
69
78
  /** Optional initial time slot to pre-populate */
70
- initialTimeSlot?: availabilityTimeSlots.TimeSlot | null;
79
+ initialTimeSlot?: TimeSlot | null;
71
80
  /** Optional initial form values */
72
81
  initialFormValues?: FormValues | null;
73
82
  }
@@ -5,6 +5,15 @@
5
5
  */
6
6
  import { defineService, implementService } from '@wix/services-definitions';
7
7
  import { SignalsServiceDefinition, } from '@wix/services-definitions/core-services/signals';
8
+ // ============================================================================
9
+ // Types
10
+ // ============================================================================
11
+ /**
12
+ * Generates a unique instance ID for service selections
13
+ */
14
+ function generateInstanceId() {
15
+ return crypto.randomUUID();
16
+ }
8
17
  /**
9
18
  * Service definition for Booking
10
19
  */
@@ -39,7 +48,12 @@ export const BookingServiceDefinition = defineService('booking');
39
48
  export const BookingService = implementService.withConfig()(BookingServiceDefinition, ({ getService, config }) => {
40
49
  const signalsService = getService(SignalsServiceDefinition);
41
50
  // Initialize signals with config values
42
- const servicesSignal = signalsService.signal(config.initialServices || []);
51
+ // Ensure all initial booking selections have instanceIds
52
+ const initialSelectionsWithIds = (config.initialBookingSelections || []).map((s) => ({
53
+ ...s,
54
+ instanceId: s.instanceId || generateInstanceId(),
55
+ }));
56
+ const bookingSelectionsSignal = signalsService.signal(initialSelectionsWithIds);
43
57
  const timeSlotSignal = signalsService.signal(config.initialTimeSlot || null);
44
58
  // Location is derived internally - initialize as null
45
59
  const locationSignal = signalsService.signal(null);
@@ -49,25 +63,45 @@ export const BookingService = implementService.withConfig()(BookingServiceDefini
49
63
  // ========================================================================
50
64
  const actions = {
51
65
  // Services actions
52
- setServices(newServices) {
53
- servicesSignal.set(newServices);
66
+ setService(service) {
67
+ const instanceId = generateInstanceId();
68
+ const newSelection = {
69
+ ...service,
70
+ instanceId,
71
+ };
72
+ bookingSelectionsSignal.set([newSelection]);
73
+ return instanceId;
54
74
  },
55
75
  addService(service) {
56
- const current = servicesSignal.get();
57
- servicesSignal.set([...current, service]);
76
+ const instanceId = generateInstanceId();
77
+ const current = bookingSelectionsSignal.get();
78
+ const newSelection = {
79
+ ...service,
80
+ instanceId,
81
+ };
82
+ bookingSelectionsSignal.set([...current, newSelection]);
83
+ return instanceId;
58
84
  },
59
- updateService(serviceId, updates) {
60
- const current = servicesSignal.get();
61
- const updated = current.map((s) => s.service._id === serviceId ? { ...s, ...updates } : s);
62
- servicesSignal.set(updated);
85
+ updateBookingSelection(updates, instanceId) {
86
+ const current = bookingSelectionsSignal.get();
87
+ // If no instanceId provided, update the first selection (index 0)
88
+ const targetId = instanceId ?? current[0]?.instanceId;
89
+ const updated = current.map((s) => s.instanceId === targetId ? { ...s, ...updates } : s);
90
+ bookingSelectionsSignal.set(updated);
63
91
  },
64
- removeService(serviceId) {
65
- const current = servicesSignal.get();
66
- const filtered = current.filter((s) => s.service._id !== serviceId);
67
- servicesSignal.set(filtered);
92
+ removeBookingSelection(instanceId) {
93
+ const current = bookingSelectionsSignal.get();
94
+ if (!instanceId) {
95
+ // Remove first selection if no instanceId provided
96
+ bookingSelectionsSignal.set(current.slice(1));
97
+ }
98
+ else {
99
+ const filtered = current.filter((s) => s.instanceId !== instanceId);
100
+ bookingSelectionsSignal.set(filtered);
101
+ }
68
102
  },
69
103
  clearServices() {
70
- servicesSignal.set([]);
104
+ bookingSelectionsSignal.set([]);
71
105
  },
72
106
  // Time Slot actions
73
107
  setTimeSlot(slot) {
@@ -92,14 +126,14 @@ export const BookingService = implementService.withConfig()(BookingServiceDefini
92
126
  },
93
127
  // Clear all
94
128
  clearAll() {
95
- servicesSignal.set([]);
129
+ bookingSelectionsSignal.set([]);
96
130
  timeSlotSignal.set(null);
97
131
  locationSignal.set(null);
98
132
  formValuesSignal.set(null);
99
133
  },
100
134
  };
101
135
  return {
102
- services: servicesSignal,
136
+ bookingSelections: bookingSelectionsSignal,
103
137
  timeSlot: timeSlotSignal,
104
138
  location: locationSignal,
105
139
  formValues: formValuesSignal,
@@ -3,5 +3,6 @@
3
3
  * Main export file for all service definitions and implementations
4
4
  */
5
5
  export { ServiceService, ServiceServiceDefinition, type ServiceServiceAPI, type ServiceServiceConfig, type ServiceActions, type ServicePaymentData, loadServiceServiceInitialData, type SuccessServiceServiceConfigResult, type NotFoundServiceServiceConfigResult, } from './service/service.js';
6
- export { BookingService, BookingServiceDefinition, type BookingServiceConfig, type ServiceSelection, type Location, type BookingServiceActions, } from './booking/booking.js';
6
+ export { BookingService, BookingServiceDefinition, type BookingServiceConfig, type BookingSelection, type Location, type BookingServiceActions, } from './booking/booking.js';
7
+ export { TimeSlotListService, TimeSlotListServiceDefinition, ViewMode, loadTimeSlotListConfig, type TimeSlotListServiceAPI, type TimeSlotListServiceActions, type TimeSlotListServiceConfig, type SlotSelection, type LoadTimeSlotListConfigOptions, type LoadTimeSlotListConfigResult, } from './time-slot-list/index.js';
7
8
  export { ServiceListService, ServiceListServiceDefinition, type ServiceListServiceAPI, type ServiceListServiceConfig, type ServiceListActions, type QueryOptions, loadServiceListServiceInitialData, type SuccessServiceListServiceConfigResult, type ErrorServiceListServiceConfigResult, } from './service-list/service-list.js';
@@ -4,4 +4,5 @@
4
4
  */
5
5
  export { ServiceService, ServiceServiceDefinition, loadServiceServiceInitialData, } from './service/service.js';
6
6
  export { BookingService, BookingServiceDefinition, } from './booking/booking.js';
7
+ export { TimeSlotListService, TimeSlotListServiceDefinition, ViewMode, loadTimeSlotListConfig, } from './time-slot-list/index.js';
7
8
  export { ServiceListService, ServiceListServiceDefinition, loadServiceListServiceInitialData, } from './service-list/service-list.js';
@@ -3,7 +3,7 @@
3
3
  * Handles loading and managing a single service's data, loading state, and errors.
4
4
  */
5
5
  import { type Signal, type ReadOnlySignal } from '@wix/services-definitions/core-services/signals';
6
- import { services } from '@wix/bookings';
6
+ import { type Service, type Payment } from '@wix/auto_sdk_bookings_services';
7
7
  import type { MoneyData } from '@wix/headless-components/react';
8
8
  /**
9
9
  * Actions object for service selection
@@ -23,9 +23,9 @@ export interface ServiceActions {
23
23
  */
24
24
  export interface ServicePaymentData {
25
25
  /** The service payment information from the service */
26
- servicePayment: services.Payment | undefined;
26
+ servicePayment: Payment | undefined;
27
27
  /** The rate type of the service (FIXED, VARIED, CUSTOM, NO_FEE, etc.) */
28
- rateType: services.Payment['rateType'] | undefined;
28
+ rateType: Payment['rateType'] | undefined;
29
29
  /** Primary price (used for FIXED or VARIED default) */
30
30
  money: MoneyData | null;
31
31
  /** Minimum price (used for VARIED) */
@@ -46,7 +46,7 @@ export interface ServicePaymentData {
46
46
  */
47
47
  export interface ServiceServiceAPI {
48
48
  /** Reactive signal containing the current service data */
49
- serviceSignal: Signal<services.Service>;
49
+ serviceSignal: Signal<Service>;
50
50
  /** Reactive signal indicating if a service is currently being loaded */
51
51
  isLoadingSignal: Signal<boolean>;
52
52
  /** Reactive signal containing any error message, or null if no error */
@@ -83,7 +83,7 @@ export declare const ServiceServiceDefinition: string & {
83
83
  */
84
84
  export interface ServiceServiceConfig {
85
85
  /** The initial service data to configure the service with */
86
- service?: services.Service;
86
+ service?: Service;
87
87
  /** The service ID to load if no initial service is provided */
88
88
  serviceId?: string;
89
89
  /** The service slug to load if no initial service is provided */
@@ -4,9 +4,9 @@
4
4
  */
5
5
  import { defineService, implementService } from '@wix/services-definitions';
6
6
  import { SignalsServiceDefinition, } from '@wix/services-definitions/core-services/signals';
7
- import { services } from '@wix/bookings';
7
+ import { ServiceType, RateType, } from '@wix/auto_sdk_bookings_services';
8
8
  import { getServiceById, getServiceBySlug, } from '../../api/query-services/index.js';
9
- import { BookingServiceDefinition, } from '../booking/booking.js';
9
+ import { BookingServiceDefinition } from '../booking/booking.js';
10
10
  import { convertToMoneyData } from '../../utils/money.js';
11
11
  /**
12
12
  * Booking app ID constant
@@ -81,15 +81,15 @@ export const ServiceService = implementService.withConfig()(ServiceServiceDefini
81
81
  const currentService = serviceSignal.get();
82
82
  if (!currentService._id)
83
83
  return false;
84
- const services = bookingService.services.get();
85
- return services.some((selection) => selection.service._id === currentService._id);
84
+ const selections = bookingService.bookingSelections.get();
85
+ return selections.some((selection) => selection.service._id === currentService._id);
86
86
  });
87
87
  // requiresAvailability signal - true for APPOINTMENT and CLASS types
88
88
  const requiresAvailabilitySignal = signalsService.computed(() => {
89
89
  const currentService = serviceSignal.get();
90
90
  const serviceType = currentService.type;
91
- return (serviceType === services.ServiceType.APPOINTMENT ||
92
- serviceType === services.ServiceType.CLASS);
91
+ return (serviceType === ServiceType.APPOINTMENT ||
92
+ serviceType === ServiceType.CLASS);
93
93
  });
94
94
  // paymentData signal - computed payment data from service
95
95
  const paymentDataSignal = signalsService.computed(() => {
@@ -104,21 +104,21 @@ export const ServiceService = implementService.withConfig()(ServiceServiceDefini
104
104
  // Extract pricing based on rate type
105
105
  if (payment) {
106
106
  switch (rateType) {
107
- case services.RateType.FIXED:
107
+ case RateType.FIXED:
108
108
  // FIXED: Use payment.fixed.price
109
109
  money = convertToMoneyData(payment.fixed?.price);
110
110
  break;
111
- case services.RateType.VARIED:
111
+ case RateType.VARIED:
112
112
  // VARIED: Use defaultPrice as money, plus min/max for range
113
113
  money = convertToMoneyData(payment.varied?.defaultPrice);
114
114
  minPrice = convertToMoneyData(payment.varied?.minPrice);
115
115
  maxPrice = convertToMoneyData(payment.varied?.maxPrice);
116
116
  break;
117
- case services.RateType.CUSTOM:
117
+ case RateType.CUSTOM:
118
118
  // CUSTOM: Use description text (no numeric price)
119
119
  priceDescription = payment.custom?.description || null;
120
120
  break;
121
- case services.RateType.NO_FEE:
121
+ case RateType.NO_FEE:
122
122
  // NO_FEE: Free service (amount = 0)
123
123
  money = { amount: 0, currency: 'USD' };
124
124
  break;
@@ -185,27 +185,26 @@ export const ServiceService = implementService.withConfig()(ServiceServiceDefini
185
185
  if (!bookableSignal.get() || !bookingService)
186
186
  return;
187
187
  const currentService = serviceSignal.get();
188
- const selection = {
189
- service: currentService,
190
- };
191
- bookingService.actions.setServices([selection]);
188
+ bookingService.actions.setService({ service: currentService });
192
189
  },
193
190
  add: () => {
194
191
  if (!bookableSignal.get() || !bookingService)
195
192
  return;
196
193
  const currentService = serviceSignal.get();
197
- const selection = {
198
- service: currentService,
199
- };
200
- bookingService.actions.addService(selection);
194
+ bookingService.actions.addService({ service: currentService });
201
195
  },
202
196
  remove: () => {
203
197
  if (!bookableSignal.get() || !bookingService)
204
198
  return;
205
199
  const currentService = serviceSignal.get();
206
- if (currentService._id) {
207
- bookingService.actions.removeService(currentService._id);
208
- }
200
+ // Remove all instances of this service (by serviceId)
201
+ const selections = bookingService.bookingSelections.get();
202
+ const instancesToRemove = selections
203
+ .filter((s) => s.service._id === currentService._id)
204
+ .map((s) => s.instanceId);
205
+ instancesToRemove.forEach((instanceId) => {
206
+ bookingService.actions.removeBookingSelection(instanceId);
207
+ });
209
208
  },
210
209
  };
211
210
  return {
@@ -3,7 +3,7 @@
3
3
  * Handles querying and pagination of services list (NO selection management)
4
4
  */
5
5
  import { type Signal, type ReadOnlySignal } from '@wix/services-definitions/core-services/signals';
6
- import { services } from '@wix/bookings';
6
+ import type { Service } from '@wix/auto_sdk_bookings_services';
7
7
  import type { QueryServicesRequest, PagingMetadata } from '../../api/query-services/index.js';
8
8
  export type { ServiceListFilters } from '../../api/query-services/index.js';
9
9
  /**
@@ -15,7 +15,7 @@ export type QueryOptions = Omit<QueryServicesRequest, 'pagingMetadata'>;
15
15
  * Configuration for the ServiceList service
16
16
  */
17
17
  export interface ServiceListServiceConfig {
18
- services?: services.Service[];
18
+ services?: Service[];
19
19
  options?: QueryServicesRequest;
20
20
  }
21
21
  /**
@@ -30,7 +30,7 @@ export interface ServiceListActions {
30
30
  */
31
31
  export interface ServiceListServiceAPI {
32
32
  /** Reactive signal containing the list of services */
33
- servicesSignal: Signal<services.Service[]>;
33
+ servicesSignal: Signal<Service[]>;
34
34
  /** Reactive signal containing current query options (appId, filters, sort) - changes trigger re-fetch */
35
35
  queryOptionsSignal: Signal<QueryOptions>;
36
36
  /** Reactive signal containing pagination metadata (limit, offset, count, hasNext) - updated after fetches */
@@ -0,0 +1,6 @@
1
+ /**
2
+ * TimeSlotList Service
3
+ * Main export file for time slot list service
4
+ */
5
+ export { TimeSlotListServiceDefinition, ViewMode, type TimeSlotListServiceAPI, type TimeSlotListServiceActions, type TimeSlotListServiceConfig, type SlotSelection, } from './time-slot-list.def.js';
6
+ export { TimeSlotListService, loadTimeSlotListConfig, type LoadTimeSlotListConfigOptions, type LoadTimeSlotListConfigResult, } from './time-slot-list.js';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * TimeSlotList Service
3
+ * Main export file for time slot list service
4
+ */
5
+ export { TimeSlotListServiceDefinition, ViewMode, } from './time-slot-list.def.js';
6
+ export { TimeSlotListService, loadTimeSlotListConfig, } from './time-slot-list.js';
@@ -0,0 +1,58 @@
1
+ /**
2
+ * TimeSlotList Service Implementation
3
+ * Manages time slot fetching, selection, and state
4
+ */
5
+ import type { Service } from '@wix/auto_sdk_bookings_services';
6
+ import { type TimeSlotListServiceConfig, ViewMode } from './time-slot-list.def.js';
7
+ export declare const TimeSlotListService: import("@wix/services-definitions").ServiceFactory<string & {
8
+ __api: import("./time-slot-list.def.js").TimeSlotListServiceAPI;
9
+ __config: {};
10
+ isServiceDefinition?: boolean;
11
+ } & import("./time-slot-list.def.js").TimeSlotListServiceAPI, TimeSlotListServiceConfig>;
12
+ /**
13
+ * Options for loading time slots configuration on the server
14
+ */
15
+ export interface LoadTimeSlotListConfigOptions {
16
+ /** Services to fetch time slots for */
17
+ services?: Service[];
18
+ /** Start date for the time range (defaults to current date) */
19
+ startDate?: Date;
20
+ /** End date for the time range (defaults to 7 days from start) */
21
+ endDate?: Date;
22
+ /** Timezone for formatting (defaults to UTC) */
23
+ timezone?: string;
24
+ /** View mode (defaults to CLASSIC) */
25
+ viewMode?: ViewMode;
26
+ }
27
+ /**
28
+ * Result type for SSR loader - either success with config or error
29
+ */
30
+ export type LoadTimeSlotListConfigResult = {
31
+ type: 'success';
32
+ config: TimeSlotListServiceConfig;
33
+ } | {
34
+ type: 'error';
35
+ error: string;
36
+ };
37
+ /**
38
+ * SSR Loader: Pre-fetches time slots for server-side rendering
39
+ * Use this in Astro/Next.js getServerSideProps or page loaders
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * // In Astro page
44
+ * const loadResult = await loadTimeSlotListConfig({
45
+ * services: bookingServices,
46
+ * startDate: new Date(),
47
+ * endDate: addDays(new Date(), 7),
48
+ * timezone: 'America/New_York',
49
+ * });
50
+ *
51
+ * if (loadResult.type === 'error') {
52
+ * // Handle error
53
+ * }
54
+ *
55
+ * const timeSlotListConfig = loadResult.config;
56
+ * ```
57
+ */
58
+ export declare function loadTimeSlotListConfig(options: LoadTimeSlotListConfigOptions): Promise<LoadTimeSlotListConfigResult>;
@@ -0,0 +1,84 @@
1
+ /**
2
+ * TimeSlotList Service Definition
3
+ * Defines interfaces and service contract for time slot management
4
+ */
5
+ import type { Signal } from '@wix/services-definitions/core-services/signals';
6
+ import type { TimeSlot as ApiTimeSlot } from '@wix/auto_sdk_bookings_availability-time-slots';
7
+ import type { Service } from '@wix/auto_sdk_bookings_services';
8
+ export declare enum ViewMode {
9
+ CLASSIC = "classic",
10
+ AGENDA = "agenda"
11
+ }
12
+ /**
13
+ * Maps a location to its available staff members
14
+ */
15
+ export interface StaffByLocation {
16
+ location: {
17
+ id: string;
18
+ name: string;
19
+ };
20
+ staffMembers: {
21
+ id: string;
22
+ name: string;
23
+ }[];
24
+ }
25
+ /**
26
+ * Grouped time slot that represents a unique time with all available locations/staff
27
+ * Extends the API TimeSlot type but replaces location-specific fields with aggregated data
28
+ */
29
+ export interface TimeSlot extends Omit<ApiTimeSlot, 'location' | 'availableResources'> {
30
+ /** Maps each location to its available staff members */
31
+ staffByLocation: StaffByLocation[];
32
+ /** Original API slots for this time (needed for booking service) */
33
+ originalSlots: ApiTimeSlot[];
34
+ /** Unique identifier for the time slot */
35
+ id: string;
36
+ }
37
+ /**
38
+ * User's selection state
39
+ */
40
+ export interface SlotSelection {
41
+ slot: TimeSlot;
42
+ locationId: string | null;
43
+ staffMemberId: string | null;
44
+ }
45
+ export interface TimeSlotListServiceConfig {
46
+ /** Services to fetch time slots for */
47
+ services?: Service[];
48
+ /** Pre-loaded time slots (from SSR) - already grouped by time */
49
+ timeSlots?: TimeSlot[];
50
+ /** Start date for the time range */
51
+ startDate?: Date;
52
+ /** End date for the time range */
53
+ endDate?: Date;
54
+ /** Timezone for formatting */
55
+ timezone?: string;
56
+ /** View mode */
57
+ viewMode?: ViewMode;
58
+ }
59
+ export interface TimeSlotListServiceActions {
60
+ selectSlot: (slot: TimeSlot) => void;
61
+ selectLocation: (locationId: string) => void;
62
+ selectStaffMember: (staffMemberId: string) => void;
63
+ clearPreferences: () => void;
64
+ loadMore: () => Promise<void>;
65
+ setDateRange: (start: Date, end: Date) => void;
66
+ setTimezone: (tz: string) => void;
67
+ }
68
+ export interface TimeSlotListServiceAPI {
69
+ timeSlots: Signal<TimeSlot[]>;
70
+ selection: Signal<SlotSelection | null>;
71
+ isLoading: Signal<boolean>;
72
+ error: Signal<string | null>;
73
+ hasMore: Signal<boolean>;
74
+ viewMode: Signal<ViewMode>;
75
+ startDate: Signal<Date>;
76
+ endDate: Signal<Date>;
77
+ timezone: Signal<string | undefined>;
78
+ actions: TimeSlotListServiceActions;
79
+ }
80
+ export declare const TimeSlotListServiceDefinition: string & {
81
+ __api: TimeSlotListServiceAPI;
82
+ __config: {};
83
+ isServiceDefinition?: boolean;
84
+ } & TimeSlotListServiceAPI;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * TimeSlotList Service Definition
3
+ * Defines interfaces and service contract for time slot management
4
+ */
5
+ import { defineService } from '@wix/services-definitions';
6
+ // ============================================================================
7
+ // Enums
8
+ // ============================================================================
9
+ export var ViewMode;
10
+ (function (ViewMode) {
11
+ ViewMode["CLASSIC"] = "classic";
12
+ ViewMode["AGENDA"] = "agenda";
13
+ })(ViewMode || (ViewMode = {}));
14
+ // ============================================================================
15
+ // Service Definition
16
+ // ============================================================================
17
+ export const TimeSlotListServiceDefinition = defineService('time-slot-list');