@wix/headless-bookings 0.0.32 → 0.0.33

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.
@@ -4,14 +4,6 @@
4
4
  import type { Resource } from '@wix/auto_sdk_bookings_availability-time-slots';
5
5
  import type { FormValues } from '@wix/form-public';
6
6
  import type { ServiceSelection, ServiceSelectionTimeSlot, Location, BookingServiceConfig } from '../services/booking/booking.js';
7
- /**
8
- * Mock time slot data
9
- */
10
- export declare const mockTimeSlot: ServiceSelectionTimeSlot;
11
- /**
12
- * Mock time slot for afternoon
13
- */
14
- export declare const mockTimeSlotAfternoon: ServiceSelectionTimeSlot;
15
7
  /**
16
8
  * Mock resource (staff member)
17
9
  */
@@ -24,6 +16,22 @@ export declare const mockResourceTwo: Resource;
24
16
  * Mock resource (room)
25
17
  */
26
18
  export declare const mockResourceRoom: Resource;
19
+ /**
20
+ * Mock location
21
+ */
22
+ export declare const mockLocation: Location;
23
+ /**
24
+ * Mock location (second)
25
+ */
26
+ export declare const mockLocationTwo: Location;
27
+ /**
28
+ * Mock time slot data
29
+ */
30
+ export declare const mockTimeSlot: ServiceSelectionTimeSlot;
31
+ /**
32
+ * Mock time slot for afternoon
33
+ */
34
+ export declare const mockTimeSlotAfternoon: ServiceSelectionTimeSlot;
27
35
  /**
28
36
  * Mock service selection with all data
29
37
  */
@@ -36,14 +44,6 @@ export declare const mockServiceSelectionWithoutTimeSlot: ServiceSelection;
36
44
  * Mock service selection for class
37
45
  */
38
46
  export declare const mockServiceSelectionClass: ServiceSelection;
39
- /**
40
- * Mock location
41
- */
42
- export declare const mockLocation: Location;
43
- /**
44
- * Mock location (second)
45
- */
46
- export declare const mockLocationTwo: Location;
47
47
  /**
48
48
  * Mock form submission (contact info)
49
49
  */
@@ -2,26 +2,6 @@
2
2
  * Shared mock data for booking service tests
3
3
  */
4
4
  import { mockService, mockServiceClass } from './services.js';
5
- /**
6
- * Mock time slot data
7
- */
8
- export const mockTimeSlot = {
9
- startDate: '2024-03-15T10:00:00Z',
10
- endDate: '2024-03-15T11:00:00Z',
11
- totalCapacity: 10,
12
- remainingCapacity: 5,
13
- scheduleId: 'schedule-123',
14
- };
15
- /**
16
- * Mock time slot for afternoon
17
- */
18
- export const mockTimeSlotAfternoon = {
19
- startDate: '2024-03-15T14:00:00Z',
20
- endDate: '2024-03-15T15:00:00Z',
21
- totalCapacity: 10,
22
- remainingCapacity: 8,
23
- scheduleId: 'schedule-456',
24
- };
25
5
  /**
26
6
  * Mock resource (staff member)
27
7
  */
@@ -48,6 +28,44 @@ export const mockResourceRoom = {
48
28
  name: 'Conference Room A',
49
29
  tag: 'RESOURCE',
50
30
  };
31
+ /**
32
+ * Mock location
33
+ */
34
+ export const mockLocation = {
35
+ id: 'location-1',
36
+ name: 'Main Office',
37
+ };
38
+ /**
39
+ * Mock location (second)
40
+ */
41
+ export const mockLocationTwo = {
42
+ id: 'location-2',
43
+ name: 'Downtown Branch',
44
+ };
45
+ /**
46
+ * Mock time slot data
47
+ */
48
+ export const mockTimeSlot = {
49
+ startDate: '2024-03-15T10:00:00Z',
50
+ endDate: '2024-03-15T11:00:00Z',
51
+ totalCapacity: 10,
52
+ remainingCapacity: 5,
53
+ scheduleId: 'schedule-123',
54
+ resources: [mockResource],
55
+ location: mockLocation,
56
+ };
57
+ /**
58
+ * Mock time slot for afternoon
59
+ */
60
+ export const mockTimeSlotAfternoon = {
61
+ startDate: '2024-03-15T14:00:00Z',
62
+ endDate: '2024-03-15T15:00:00Z',
63
+ totalCapacity: 10,
64
+ remainingCapacity: 8,
65
+ scheduleId: 'schedule-456',
66
+ resources: [mockResourceTwo],
67
+ location: mockLocationTwo,
68
+ };
51
69
  /**
52
70
  * Mock service selection with all data
53
71
  */
@@ -77,20 +95,6 @@ export const mockServiceSelectionClass = {
77
95
  timeSlot: mockTimeSlotAfternoon,
78
96
  totalParticipants: 3,
79
97
  };
80
- /**
81
- * Mock location
82
- */
83
- export const mockLocation = {
84
- id: 'location-1',
85
- name: 'Main Office',
86
- };
87
- /**
88
- * Mock location (second)
89
- */
90
- export const mockLocationTwo = {
91
- id: 'location-2',
92
- name: 'Downtown Branch',
93
- };
94
98
  /**
95
99
  * Mock form submission (contact info)
96
100
  */
@@ -43,8 +43,9 @@ export async function executeBookAction(params) {
43
43
  throw new Error('Failed to create booking');
44
44
  }
45
45
  // Step 2: Create checkout
46
- // businessLocationId comes from location.id for multi-location support
47
- const businessLocationId = params.location?.id ?? undefined;
46
+ // businessLocationId: prefer timeSlot.location, fallback to global location
47
+ const firstSelection = params.serviceSelections[0];
48
+ const businessLocationId = firstSelection?.timeSlot?.location?.id ?? undefined;
48
49
  const checkoutRequest = buildCheckoutRequest({
49
50
  bookingId,
50
51
  contactDetails,
@@ -46,8 +46,10 @@ export function buildBookingRequest(params) {
46
46
  if (!item.timeSlot) {
47
47
  throw new Error('No time slot selected for service selection');
48
48
  }
49
- // Get resource from service selection
50
- const resource = item.resources?.[0];
49
+ // Get resource: prefer timeSlot.resources, fallback to item.resources
50
+ const resource = item.timeSlot.resources?.[0] ?? item.resources?.[0];
51
+ // Get location: prefer timeSlot.location, fallback to params.location
52
+ const slotLocation = item.timeSlot.location ?? location;
51
53
  return {
52
54
  booking: {
53
55
  // Payment option derived from service payment settings
@@ -66,8 +68,8 @@ export function buildBookingRequest(params) {
66
68
  resource: resource
67
69
  ? { _id: resource._id, name: resource.name }
68
70
  : undefined,
69
- location: location
70
- ? { _id: location.id, name: location.name }
71
+ location: slotLocation
72
+ ? { _id: slotLocation.id, name: slotLocation.name }
71
73
  : undefined,
72
74
  },
73
75
  },
@@ -19,6 +19,10 @@ export interface ServiceSelectionTimeSlot {
19
19
  remainingCapacity?: number;
20
20
  scheduleId?: string;
21
21
  eventInfo?: EventInfo;
22
+ /** Resources available in this time slot (populated when slot is selected) */
23
+ resources?: Resource[];
24
+ /** Location of this time slot (populated when slot is selected) */
25
+ location?: Location;
22
26
  }
23
27
  /**
24
28
  * ServiceSelection contains the service AND its related selections
@@ -86,6 +86,14 @@ export const TimeSlotListService = implementService.withConfig()(TimeSlotListSer
86
86
  * - Auto-selects staff only when there is exactly one staff option in this slot
87
87
  */
88
88
  const selectSlot = (slot) => {
89
+ const staffMembersFromSlot = slot.availableResources[0].resources.map((r) => ({
90
+ _id: r._id,
91
+ name: r.name,
92
+ }));
93
+ const slotLocation = {
94
+ id: slot.location?._id,
95
+ name: slot.location?.name ?? undefined,
96
+ };
89
97
  const timeSlot = {
90
98
  startDate: slot.localStartDate,
91
99
  endDate: slot.localEndDate,
@@ -93,15 +101,12 @@ export const TimeSlotListService = implementService.withConfig()(TimeSlotListSer
93
101
  remainingCapacity: slot.remainingCapacity ?? undefined,
94
102
  scheduleId: slot.scheduleId ?? undefined,
95
103
  eventInfo: slot.eventInfo ?? undefined,
104
+ resources: staffMembersFromSlot,
105
+ location: slotLocation,
96
106
  };
97
- bookingService.actions.setLocation({
98
- id: slot.location?._id,
99
- name: slot.location?.name ?? undefined,
100
- });
101
- const staffMembersFromSlot = slot.availableResources[0].resources.map((r) => ({
102
- id: r._id,
103
- name: r.name,
104
- }));
107
+ // Keep setting top-level location (for pre-slot selection use cases)
108
+ bookingService.actions.setLocation(slotLocation);
109
+ // Auto-select resources only when single staff
105
110
  const resources = staffMembersFromSlot.length === 1 ? staffMembersFromSlot : [];
106
111
  bookingService.actions.updateItem({
107
112
  timeSlot,
@@ -4,14 +4,6 @@
4
4
  import type { Resource } from '@wix/auto_sdk_bookings_availability-time-slots';
5
5
  import type { FormValues } from '@wix/form-public';
6
6
  import type { ServiceSelection, ServiceSelectionTimeSlot, Location, BookingServiceConfig } from '../services/booking/booking.js';
7
- /**
8
- * Mock time slot data
9
- */
10
- export declare const mockTimeSlot: ServiceSelectionTimeSlot;
11
- /**
12
- * Mock time slot for afternoon
13
- */
14
- export declare const mockTimeSlotAfternoon: ServiceSelectionTimeSlot;
15
7
  /**
16
8
  * Mock resource (staff member)
17
9
  */
@@ -24,6 +16,22 @@ export declare const mockResourceTwo: Resource;
24
16
  * Mock resource (room)
25
17
  */
26
18
  export declare const mockResourceRoom: Resource;
19
+ /**
20
+ * Mock location
21
+ */
22
+ export declare const mockLocation: Location;
23
+ /**
24
+ * Mock location (second)
25
+ */
26
+ export declare const mockLocationTwo: Location;
27
+ /**
28
+ * Mock time slot data
29
+ */
30
+ export declare const mockTimeSlot: ServiceSelectionTimeSlot;
31
+ /**
32
+ * Mock time slot for afternoon
33
+ */
34
+ export declare const mockTimeSlotAfternoon: ServiceSelectionTimeSlot;
27
35
  /**
28
36
  * Mock service selection with all data
29
37
  */
@@ -36,14 +44,6 @@ export declare const mockServiceSelectionWithoutTimeSlot: ServiceSelection;
36
44
  * Mock service selection for class
37
45
  */
38
46
  export declare const mockServiceSelectionClass: ServiceSelection;
39
- /**
40
- * Mock location
41
- */
42
- export declare const mockLocation: Location;
43
- /**
44
- * Mock location (second)
45
- */
46
- export declare const mockLocationTwo: Location;
47
47
  /**
48
48
  * Mock form submission (contact info)
49
49
  */
@@ -2,26 +2,6 @@
2
2
  * Shared mock data for booking service tests
3
3
  */
4
4
  import { mockService, mockServiceClass } from './services.js';
5
- /**
6
- * Mock time slot data
7
- */
8
- export const mockTimeSlot = {
9
- startDate: '2024-03-15T10:00:00Z',
10
- endDate: '2024-03-15T11:00:00Z',
11
- totalCapacity: 10,
12
- remainingCapacity: 5,
13
- scheduleId: 'schedule-123',
14
- };
15
- /**
16
- * Mock time slot for afternoon
17
- */
18
- export const mockTimeSlotAfternoon = {
19
- startDate: '2024-03-15T14:00:00Z',
20
- endDate: '2024-03-15T15:00:00Z',
21
- totalCapacity: 10,
22
- remainingCapacity: 8,
23
- scheduleId: 'schedule-456',
24
- };
25
5
  /**
26
6
  * Mock resource (staff member)
27
7
  */
@@ -48,6 +28,44 @@ export const mockResourceRoom = {
48
28
  name: 'Conference Room A',
49
29
  tag: 'RESOURCE',
50
30
  };
31
+ /**
32
+ * Mock location
33
+ */
34
+ export const mockLocation = {
35
+ id: 'location-1',
36
+ name: 'Main Office',
37
+ };
38
+ /**
39
+ * Mock location (second)
40
+ */
41
+ export const mockLocationTwo = {
42
+ id: 'location-2',
43
+ name: 'Downtown Branch',
44
+ };
45
+ /**
46
+ * Mock time slot data
47
+ */
48
+ export const mockTimeSlot = {
49
+ startDate: '2024-03-15T10:00:00Z',
50
+ endDate: '2024-03-15T11:00:00Z',
51
+ totalCapacity: 10,
52
+ remainingCapacity: 5,
53
+ scheduleId: 'schedule-123',
54
+ resources: [mockResource],
55
+ location: mockLocation,
56
+ };
57
+ /**
58
+ * Mock time slot for afternoon
59
+ */
60
+ export const mockTimeSlotAfternoon = {
61
+ startDate: '2024-03-15T14:00:00Z',
62
+ endDate: '2024-03-15T15:00:00Z',
63
+ totalCapacity: 10,
64
+ remainingCapacity: 8,
65
+ scheduleId: 'schedule-456',
66
+ resources: [mockResourceTwo],
67
+ location: mockLocationTwo,
68
+ };
51
69
  /**
52
70
  * Mock service selection with all data
53
71
  */
@@ -77,20 +95,6 @@ export const mockServiceSelectionClass = {
77
95
  timeSlot: mockTimeSlotAfternoon,
78
96
  totalParticipants: 3,
79
97
  };
80
- /**
81
- * Mock location
82
- */
83
- export const mockLocation = {
84
- id: 'location-1',
85
- name: 'Main Office',
86
- };
87
- /**
88
- * Mock location (second)
89
- */
90
- export const mockLocationTwo = {
91
- id: 'location-2',
92
- name: 'Downtown Branch',
93
- };
94
98
  /**
95
99
  * Mock form submission (contact info)
96
100
  */
@@ -43,8 +43,9 @@ export async function executeBookAction(params) {
43
43
  throw new Error('Failed to create booking');
44
44
  }
45
45
  // Step 2: Create checkout
46
- // businessLocationId comes from location.id for multi-location support
47
- const businessLocationId = params.location?.id ?? undefined;
46
+ // businessLocationId: prefer timeSlot.location, fallback to global location
47
+ const firstSelection = params.serviceSelections[0];
48
+ const businessLocationId = firstSelection?.timeSlot?.location?.id ?? undefined;
48
49
  const checkoutRequest = buildCheckoutRequest({
49
50
  bookingId,
50
51
  contactDetails,
@@ -46,8 +46,10 @@ export function buildBookingRequest(params) {
46
46
  if (!item.timeSlot) {
47
47
  throw new Error('No time slot selected for service selection');
48
48
  }
49
- // Get resource from service selection
50
- const resource = item.resources?.[0];
49
+ // Get resource: prefer timeSlot.resources, fallback to item.resources
50
+ const resource = item.timeSlot.resources?.[0] ?? item.resources?.[0];
51
+ // Get location: prefer timeSlot.location, fallback to params.location
52
+ const slotLocation = item.timeSlot.location ?? location;
51
53
  return {
52
54
  booking: {
53
55
  // Payment option derived from service payment settings
@@ -66,8 +68,8 @@ export function buildBookingRequest(params) {
66
68
  resource: resource
67
69
  ? { _id: resource._id, name: resource.name }
68
70
  : undefined,
69
- location: location
70
- ? { _id: location.id, name: location.name }
71
+ location: slotLocation
72
+ ? { _id: slotLocation.id, name: slotLocation.name }
71
73
  : undefined,
72
74
  },
73
75
  },
@@ -19,6 +19,10 @@ export interface ServiceSelectionTimeSlot {
19
19
  remainingCapacity?: number;
20
20
  scheduleId?: string;
21
21
  eventInfo?: EventInfo;
22
+ /** Resources available in this time slot (populated when slot is selected) */
23
+ resources?: Resource[];
24
+ /** Location of this time slot (populated when slot is selected) */
25
+ location?: Location;
22
26
  }
23
27
  /**
24
28
  * ServiceSelection contains the service AND its related selections
@@ -86,6 +86,14 @@ export const TimeSlotListService = implementService.withConfig()(TimeSlotListSer
86
86
  * - Auto-selects staff only when there is exactly one staff option in this slot
87
87
  */
88
88
  const selectSlot = (slot) => {
89
+ const staffMembersFromSlot = slot.availableResources[0].resources.map((r) => ({
90
+ _id: r._id,
91
+ name: r.name,
92
+ }));
93
+ const slotLocation = {
94
+ id: slot.location?._id,
95
+ name: slot.location?.name ?? undefined,
96
+ };
89
97
  const timeSlot = {
90
98
  startDate: slot.localStartDate,
91
99
  endDate: slot.localEndDate,
@@ -93,15 +101,12 @@ export const TimeSlotListService = implementService.withConfig()(TimeSlotListSer
93
101
  remainingCapacity: slot.remainingCapacity ?? undefined,
94
102
  scheduleId: slot.scheduleId ?? undefined,
95
103
  eventInfo: slot.eventInfo ?? undefined,
104
+ resources: staffMembersFromSlot,
105
+ location: slotLocation,
96
106
  };
97
- bookingService.actions.setLocation({
98
- id: slot.location?._id,
99
- name: slot.location?.name ?? undefined,
100
- });
101
- const staffMembersFromSlot = slot.availableResources[0].resources.map((r) => ({
102
- id: r._id,
103
- name: r.name,
104
- }));
107
+ // Keep setting top-level location (for pre-slot selection use cases)
108
+ bookingService.actions.setLocation(slotLocation);
109
+ // Auto-select resources only when single staff
105
110
  const resources = staffMembersFromSlot.length === 1 ? staffMembersFromSlot : [];
106
111
  bookingService.actions.updateItem({
107
112
  timeSlot,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-bookings",
3
- "version": "0.0.32",
3
+ "version": "0.0.33",
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": "b165685e9ccb4d9fe0e8d310393e59018c8d44c874e2c7cd0fc9906a"
75
+ "falconPackageHash": "b5f66fe6afde6dde21cff958f2df9ecaa8bb6890eed0ee093057887e"
76
76
  }