@wix/headless-bookings 0.0.18 → 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/dist/api/time-slot-list/index.d.ts +3 -5
- package/cjs/dist/api/time-slot-list/index.js +13 -12
- package/cjs/dist/react/core/booking/Booking.d.ts +6 -7
- package/cjs/dist/react/core/booking/Booking.js +7 -9
- package/cjs/dist/react/time-slot-list/TimeSlotList.d.ts +41 -4
- package/cjs/dist/react/time-slot-list/TimeSlotList.js +20 -5
- package/cjs/dist/services/booking/booking.d.ts +29 -32
- package/cjs/dist/services/booking/booking.js +29 -36
- package/cjs/dist/services/index.d.ts +1 -1
- package/cjs/dist/services/service/service.js +4 -4
- package/cjs/dist/services/time-slot-list/time-slot-list.def.d.ts +11 -2
- package/cjs/dist/services/time-slot-list/time-slot-list.js +8 -10
- package/dist/api/time-slot-list/index.d.ts +3 -5
- package/dist/api/time-slot-list/index.js +13 -12
- package/dist/react/core/booking/Booking.d.ts +6 -7
- package/dist/react/core/booking/Booking.js +7 -9
- package/dist/react/time-slot-list/TimeSlotList.d.ts +41 -4
- package/dist/react/time-slot-list/TimeSlotList.js +20 -5
- package/dist/services/booking/booking.d.ts +29 -32
- package/dist/services/booking/booking.js +29 -36
- package/dist/services/index.d.ts +1 -1
- package/dist/services/service/service.js +4 -4
- package/dist/services/time-slot-list/time-slot-list.def.d.ts +11 -2
- package/dist/services/time-slot-list/time-slot-list.js +8 -10
- package/package.json +4 -3
|
@@ -51,8 +51,6 @@ export interface TimeSlotsFilters {
|
|
|
51
51
|
locations?: Location[];
|
|
52
52
|
/** Filter by specific staff member IDs */
|
|
53
53
|
staffMemberIds?: string[];
|
|
54
|
-
/** Maximum slots to return per day (useful for calendar views) */
|
|
55
|
-
slotsPerDay?: number;
|
|
56
54
|
/** Filter by bookable status. If undefined, returns both bookable and non-bookable */
|
|
57
55
|
bookable?: boolean;
|
|
58
56
|
/** Filter by booking policy violations */
|
|
@@ -61,6 +59,17 @@ export interface TimeSlotsFilters {
|
|
|
61
59
|
tooLateToBook?: boolean;
|
|
62
60
|
bookOnlineDisabled?: boolean;
|
|
63
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* Number of time slots to load per request.
|
|
64
|
+
* Controls how many slots are fetched initially and on each "Load More" action.
|
|
65
|
+
* Default: 1000. Max: 1000.
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* // Load 6 slots at a time
|
|
69
|
+
* filters: { slotsPerPage: 6 }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
slotsPerPage?: number;
|
|
64
73
|
}
|
|
65
74
|
export interface TimeSlotListServiceConfig {
|
|
66
75
|
/** Services to fetch time slots for */
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { implementService } from '@wix/services-definitions';
|
|
6
6
|
import { SignalsServiceDefinition } from '@wix/services-definitions/core-services/signals';
|
|
7
|
+
import { format } from 'date-fns';
|
|
7
8
|
import { TimeSlotListServiceDefinition, ViewMode, } from './time-slot-list.def.js';
|
|
8
9
|
import { fetchAvailability } from '../../api/time-slot-list/index.js';
|
|
9
10
|
import { BookingServiceDefinition, } from '../booking/booking.js';
|
|
@@ -22,13 +23,8 @@ function getClientTimezone() {
|
|
|
22
23
|
* Formats a Date to local ISO string (YYYY-MM-DDThh:mm:ss)
|
|
23
24
|
*/
|
|
24
25
|
function toLocalDateString(date) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
const day = String(date.getDate()).padStart(2, '0');
|
|
28
|
-
const hours = String(date.getHours()).padStart(2, '0');
|
|
29
|
-
const minutes = String(date.getMinutes()).padStart(2, '0');
|
|
30
|
-
const seconds = String(date.getSeconds()).padStart(2, '0');
|
|
31
|
-
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`;
|
|
26
|
+
const pattern = "yyyy-MM-dd'T'HH:mm:ss";
|
|
27
|
+
return format(date, pattern);
|
|
32
28
|
}
|
|
33
29
|
/**
|
|
34
30
|
* Merges new grouped slots with existing ones
|
|
@@ -80,7 +76,7 @@ export const TimeSlotListService = implementService.withConfig()(TimeSlotListSer
|
|
|
80
76
|
const getServices = () => {
|
|
81
77
|
if (config.services?.length)
|
|
82
78
|
return config.services;
|
|
83
|
-
return bookingService.
|
|
79
|
+
return bookingService.serviceSelections.get().map((s) => s.service);
|
|
84
80
|
};
|
|
85
81
|
/**
|
|
86
82
|
* Helper: Get filters from config or BookingService
|
|
@@ -88,7 +84,7 @@ export const TimeSlotListService = implementService.withConfig()(TimeSlotListSer
|
|
|
88
84
|
const getFilters = () => {
|
|
89
85
|
// Get BookingService selections (these take priority)
|
|
90
86
|
const location = bookingService.location.get();
|
|
91
|
-
const selections = bookingService.
|
|
87
|
+
const selections = bookingService.serviceSelections.get();
|
|
92
88
|
const selectedStaffMemberIds = selections
|
|
93
89
|
.map(({ resources }) => resources.map((r) => r._id))
|
|
94
90
|
.flat();
|
|
@@ -114,6 +110,7 @@ export const TimeSlotListService = implementService.withConfig()(TimeSlotListSer
|
|
|
114
110
|
isLoadingSignal.set(true);
|
|
115
111
|
errorSignal.set(null);
|
|
116
112
|
cursorSignal.set(undefined);
|
|
113
|
+
timeSlotsSignal.set([]);
|
|
117
114
|
try {
|
|
118
115
|
const response = await fetchAvailability({
|
|
119
116
|
services: selectedServices,
|
|
@@ -121,6 +118,7 @@ export const TimeSlotListService = implementService.withConfig()(TimeSlotListSer
|
|
|
121
118
|
toLocalDate: toLocalDateString(endDateSignal.get()),
|
|
122
119
|
timeZone: timezoneSignal.get(),
|
|
123
120
|
viewMode: viewModeSignal.get(),
|
|
121
|
+
cursor: cursorSignal.get(),
|
|
124
122
|
...filters,
|
|
125
123
|
});
|
|
126
124
|
timeSlotsSignal.set(response.timeSlots);
|
|
@@ -312,7 +310,7 @@ export const TimeSlotListService = implementService.withConfig()(TimeSlotListSer
|
|
|
312
310
|
fromLocalDate: toLocalDateString(startDateSignal.get()),
|
|
313
311
|
toLocalDate: toLocalDateString(endDateSignal.get()),
|
|
314
312
|
timeZone: timezoneSignal.get(),
|
|
315
|
-
|
|
313
|
+
cursor,
|
|
316
314
|
viewMode: viewModeSignal.get(),
|
|
317
315
|
...filters,
|
|
318
316
|
});
|
|
@@ -15,8 +15,6 @@ export interface FetchAvailabilityOptions {
|
|
|
15
15
|
staffMemberIds?: string[];
|
|
16
16
|
cursorPaging?: CursorPaging;
|
|
17
17
|
viewMode?: ViewMode;
|
|
18
|
-
/** Maximum slots to return per day (useful for calendar views) */
|
|
19
|
-
slotsPerDay?: number;
|
|
20
18
|
/** Filter by bookable status. If undefined, returns both bookable and non-bookable */
|
|
21
19
|
bookable?: boolean;
|
|
22
20
|
/** Filter by booking policy violations */
|
|
@@ -54,20 +52,20 @@ export interface FetchAvailabilityResponse {
|
|
|
54
52
|
* // response.timeSlots are grouped by time
|
|
55
53
|
* ```
|
|
56
54
|
*/
|
|
57
|
-
export declare function fetchAvailability({ services: selectedServices, viewMode, fromLocalDate, toLocalDate, timeZone, locations, staffMemberIds,
|
|
55
|
+
export declare function fetchAvailability({ services: selectedServices, viewMode, fromLocalDate, toLocalDate, timeZone, locations, staffMemberIds, cursor, slotsPerPage, bookable, bookingPolicyViolations, }: {
|
|
58
56
|
services: Service[];
|
|
59
57
|
fromLocalDate: string;
|
|
60
58
|
toLocalDate: string;
|
|
61
59
|
timeZone?: string;
|
|
62
60
|
locations?: Location[];
|
|
63
61
|
staffMemberIds?: string[];
|
|
64
|
-
|
|
62
|
+
cursor?: string;
|
|
65
63
|
viewMode?: ViewMode;
|
|
66
|
-
slotsPerDay?: number;
|
|
67
64
|
bookable?: boolean;
|
|
68
65
|
bookingPolicyViolations?: {
|
|
69
66
|
tooEarlyToBook?: boolean;
|
|
70
67
|
tooLateToBook?: boolean;
|
|
71
68
|
bookOnlineDisabled?: boolean;
|
|
72
69
|
};
|
|
70
|
+
slotsPerPage?: number;
|
|
73
71
|
}): Promise<FetchAvailabilityResponse>;
|
|
@@ -15,6 +15,7 @@ var FlowType;
|
|
|
15
15
|
FlowType["MULTI_SERVICE"] = "multi_service";
|
|
16
16
|
FlowType["CLASS"] = "class";
|
|
17
17
|
})(FlowType || (FlowType = {}));
|
|
18
|
+
const STAFF_RESOURCE_TYPE_ID = '1cd44cf8-756f-41c3-bd90-3e2ffcaf1155';
|
|
18
19
|
// ============================================================================
|
|
19
20
|
// Grouping Functions
|
|
20
21
|
// ============================================================================
|
|
@@ -102,16 +103,14 @@ function detectFlow(bookingServices, viewMode) {
|
|
|
102
103
|
* // response.timeSlots are grouped by time
|
|
103
104
|
* ```
|
|
104
105
|
*/
|
|
105
|
-
export async function fetchAvailability({ services: selectedServices, viewMode = ViewMode.CLASSIC, fromLocalDate, toLocalDate, timeZone, locations, staffMemberIds,
|
|
106
|
+
export async function fetchAvailability({ services: selectedServices, viewMode = ViewMode.CLASSIC, fromLocalDate, toLocalDate, timeZone, locations, staffMemberIds, cursor, slotsPerPage, bookable, bookingPolicyViolations, }) {
|
|
106
107
|
const flow = detectFlow(selectedServices, viewMode);
|
|
107
108
|
const serviceIds = selectedServices.map((s) => s._id);
|
|
108
109
|
if (flow === FlowType.SINGLE_SERVICE) {
|
|
109
|
-
// Build resourceTypes filter for staff members
|
|
110
|
-
// Staff member resource type ID is 1cd44cf8-756f-41c3-bd90-3e2ffcaf1155
|
|
111
110
|
const resourceTypes = staffMemberIds?.length
|
|
112
111
|
? [
|
|
113
112
|
{
|
|
114
|
-
resourceTypeId:
|
|
113
|
+
resourceTypeId: STAFF_RESOURCE_TYPE_ID,
|
|
115
114
|
resourceIds: staffMemberIds,
|
|
116
115
|
},
|
|
117
116
|
]
|
|
@@ -122,11 +121,14 @@ export async function fetchAvailability({ services: selectedServices, viewMode =
|
|
|
122
121
|
toLocalDate,
|
|
123
122
|
timeZone,
|
|
124
123
|
locations,
|
|
125
|
-
cursorPaging
|
|
124
|
+
cursorPaging: {
|
|
125
|
+
cursor,
|
|
126
|
+
limit: slotsPerPage,
|
|
127
|
+
},
|
|
126
128
|
resourceTypes,
|
|
127
|
-
timeSlotsPerDay: slotsPerDay,
|
|
128
129
|
bookable,
|
|
129
130
|
bookingPolicyViolations,
|
|
131
|
+
includeResourceTypeIds: [STAFF_RESOURCE_TYPE_ID],
|
|
130
132
|
});
|
|
131
133
|
return {
|
|
132
134
|
timeSlots: groupTimeSlotsByTime(response.timeSlots || []),
|
|
@@ -152,13 +154,12 @@ export async function fetchAvailability({ services: selectedServices, viewMode =
|
|
|
152
154
|
toLocalDate,
|
|
153
155
|
timeZone,
|
|
154
156
|
serviceIds: serviceIds.length ? serviceIds : undefined,
|
|
155
|
-
cursorPaging
|
|
157
|
+
cursorPaging: {
|
|
158
|
+
cursor,
|
|
159
|
+
limit: slotsPerPage,
|
|
160
|
+
},
|
|
156
161
|
eventFilter: Object.keys(eventFilter).length ? eventFilter : undefined,
|
|
157
|
-
|
|
158
|
-
// bookable=true means only bookable, so includeNonBookable=false
|
|
159
|
-
// bookable=false means only non-bookable, so includeNonBookable=true
|
|
160
|
-
// bookable=undefined means both, so includeNonBookable=true (default)
|
|
161
|
-
includeNonBookable: bookable === undefined ? undefined : !bookable,
|
|
162
|
+
includeNonBookable: bookable ? !bookable : undefined,
|
|
162
163
|
bookingPolicyViolations,
|
|
163
164
|
});
|
|
164
165
|
return {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Provides low-level access to BookingService via render props and service setup
|
|
4
4
|
*/
|
|
5
5
|
import React from 'react';
|
|
6
|
-
import { type BookingServiceConfig, type
|
|
6
|
+
import { type BookingServiceConfig, type ServiceSelection, type Location, type BookingServiceActions } from '../../../services/booking/booking.js';
|
|
7
7
|
import type { FormValues } from '@wix/form-public';
|
|
8
8
|
/**
|
|
9
9
|
* Props for Booking.Root component
|
|
@@ -33,10 +33,9 @@ export declare function Root(props: RootProps): React.ReactNode;
|
|
|
33
33
|
* Mirrors BookingServiceConfig structure with actions
|
|
34
34
|
*/
|
|
35
35
|
export interface BookingData {
|
|
36
|
-
|
|
36
|
+
serviceSelections: ServiceSelection[];
|
|
37
37
|
location: Location | null;
|
|
38
|
-
|
|
39
|
-
numberOfParticipants: number;
|
|
38
|
+
formSubmission: FormValues | null;
|
|
40
39
|
actions: BookingServiceActions;
|
|
41
40
|
}
|
|
42
41
|
/**
|
|
@@ -53,9 +52,9 @@ export interface DataProps {
|
|
|
53
52
|
* @example
|
|
54
53
|
* ```tsx
|
|
55
54
|
* <Booking.Data>
|
|
56
|
-
* {({
|
|
57
|
-
*
|
|
58
|
-
* <div>{
|
|
55
|
+
* {({ serviceSelections, location, formSubmission, actions }) => (
|
|
56
|
+
* serviceSelections.length > 0 ? (
|
|
57
|
+
* <div>{serviceSelections.map(item => item.service.name).join(', ')}</div>
|
|
59
58
|
* ) : (
|
|
60
59
|
* <div>No services selected</div>
|
|
61
60
|
* )
|
|
@@ -28,9 +28,9 @@ export function Root(props) {
|
|
|
28
28
|
* @example
|
|
29
29
|
* ```tsx
|
|
30
30
|
* <Booking.Data>
|
|
31
|
-
* {({
|
|
32
|
-
*
|
|
33
|
-
* <div>{
|
|
31
|
+
* {({ serviceSelections, location, formSubmission, actions }) => (
|
|
32
|
+
* serviceSelections.length > 0 ? (
|
|
33
|
+
* <div>{serviceSelections.map(item => item.service.name).join(', ')}</div>
|
|
34
34
|
* ) : (
|
|
35
35
|
* <div>No services selected</div>
|
|
36
36
|
* )
|
|
@@ -41,16 +41,14 @@ export function Root(props) {
|
|
|
41
41
|
export function Data(props) {
|
|
42
42
|
const { children } = props;
|
|
43
43
|
const bookingService = useService(BookingServiceDefinition);
|
|
44
|
-
const
|
|
44
|
+
const serviceSelections = bookingService.serviceSelections.get();
|
|
45
45
|
const location = bookingService.location.get();
|
|
46
|
-
const
|
|
47
|
-
const numberOfParticipants = bookingService.numberOfParticipants.get();
|
|
46
|
+
const formSubmission = bookingService.formSubmission.get();
|
|
48
47
|
const { actions } = bookingService;
|
|
49
48
|
return children({
|
|
50
|
-
|
|
49
|
+
serviceSelections,
|
|
51
50
|
location,
|
|
52
|
-
|
|
53
|
-
numberOfParticipants,
|
|
51
|
+
formSubmission,
|
|
54
52
|
actions,
|
|
55
53
|
});
|
|
56
54
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
import { ListVariant } from '@wix/headless-components/react';
|
|
7
7
|
import { AsChildChildren } from '@wix/headless-utils/react';
|
|
8
|
-
import type { TimeSlotListServiceConfig } from '../../services/time-slot-list/time-slot-list.def.js';
|
|
8
|
+
import type { TimeSlotListServiceConfig, TimeSlot as TimeSlotType } from '../../services/time-slot-list/time-slot-list.def.js';
|
|
9
9
|
export type { StartDateProps as TimeSlotStartDateProps, EndDateProps as TimeSlotEndDateProps, DurationProps as TimeSlotDurationProps, SelectProps as TimeSlotSelectProps, LocationsProps as TimeSlotLocationsProps, LocationRepeaterProps as TimeSlotLocationRepeaterProps, LocationNameProps as TimeSlotLocationNameProps, SelectLocationProps as TimeSlotSelectLocationProps, StaffMembersProps as TimeSlotStaffMembersProps, StaffMemberRepeaterProps as TimeSlotStaffMemberRepeaterProps, StaffMemberNameProps as TimeSlotStaffMemberNameProps, SelectStaffMemberProps as TimeSlotSelectStaffMemberProps, } from './TimeSlot.js';
|
|
10
10
|
/**
|
|
11
11
|
* Render props for TimeSlotList.Timezone component
|
|
@@ -81,17 +81,23 @@ export declare const Root: React.ForwardRefExoticComponent<RootProps & React.Ref
|
|
|
81
81
|
*/
|
|
82
82
|
export interface TimeSlotsProps {
|
|
83
83
|
children: React.ReactNode;
|
|
84
|
+
/** Content to display when no time slots are available */
|
|
84
85
|
emptyState?: React.ReactNode;
|
|
86
|
+
/** Content to display while time slots are loading */
|
|
87
|
+
loadingState?: React.ReactNode;
|
|
85
88
|
className?: string;
|
|
86
89
|
}
|
|
87
90
|
/**
|
|
88
|
-
* Container for the time slots list with empty state support.
|
|
91
|
+
* Container for the time slots list with empty state and loading state support.
|
|
89
92
|
* Wraps GenericList.Items. Follows List Container Level pattern.
|
|
90
93
|
*
|
|
91
94
|
* @component
|
|
92
95
|
* @example
|
|
93
96
|
* ```tsx
|
|
94
|
-
* <TimeSlotList.TimeSlots
|
|
97
|
+
* <TimeSlotList.TimeSlots
|
|
98
|
+
* emptyState={<div>No slots available</div>}
|
|
99
|
+
* loadingState={<div>Loading...</div>}
|
|
100
|
+
* >
|
|
95
101
|
* <TimeSlotList.TimeSlotRepeater>
|
|
96
102
|
* {children}
|
|
97
103
|
* </TimeSlotList.TimeSlotRepeater>
|
|
@@ -99,11 +105,32 @@ export interface TimeSlotsProps {
|
|
|
99
105
|
* ```
|
|
100
106
|
*/
|
|
101
107
|
export declare const TimeSlots: React.ForwardRefExoticComponent<TimeSlotsProps & React.RefAttributes<HTMLElement>>;
|
|
108
|
+
/**
|
|
109
|
+
* Data provided to TimeSlotRepeater function children
|
|
110
|
+
*/
|
|
111
|
+
export interface TimeSlotRepeaterChildProps {
|
|
112
|
+
/** Whether the slot is currently selected */
|
|
113
|
+
isSelected: boolean;
|
|
114
|
+
/** Whether the slot can be booked */
|
|
115
|
+
bookable: boolean;
|
|
116
|
+
/** Start date/time as ISO string */
|
|
117
|
+
startDate: string | undefined;
|
|
118
|
+
/** End date/time as ISO string */
|
|
119
|
+
endDate: string | undefined;
|
|
120
|
+
/** Duration in minutes */
|
|
121
|
+
durationInMinutes: number | null;
|
|
122
|
+
/** The raw time slot data */
|
|
123
|
+
timeSlot: TimeSlotType;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Children type for TimeSlotRepeater - can be ReactNode or function
|
|
127
|
+
*/
|
|
128
|
+
type TimeSlotRepeaterChildren = React.ReactNode | ((props: TimeSlotRepeaterChildProps) => React.ReactNode);
|
|
102
129
|
/**
|
|
103
130
|
* Props for TimeSlotList.TimeSlotRepeater component
|
|
104
131
|
*/
|
|
105
132
|
export interface TimeSlotRepeaterProps {
|
|
106
|
-
children:
|
|
133
|
+
children: TimeSlotRepeaterChildren;
|
|
107
134
|
}
|
|
108
135
|
/**
|
|
109
136
|
* Repeater component that renders each time slot.
|
|
@@ -113,11 +140,21 @@ export interface TimeSlotRepeaterProps {
|
|
|
113
140
|
* @component
|
|
114
141
|
* @example
|
|
115
142
|
* ```tsx
|
|
143
|
+
* // Standard usage with nested components
|
|
116
144
|
* <TimeSlotList.TimeSlotRepeater>
|
|
117
145
|
* <TimeSlot.StartDate />
|
|
118
146
|
* <TimeSlot.Duration />
|
|
119
147
|
* <TimeSlot.Actions.Select />
|
|
120
148
|
* </TimeSlotList.TimeSlotRepeater>
|
|
149
|
+
*
|
|
150
|
+
* // Function children pattern - all data available directly
|
|
151
|
+
* <TimeSlotList.TimeSlotRepeater>
|
|
152
|
+
* {({ isSelected, bookable, startDate }) => (
|
|
153
|
+
* <button disabled={!bookable} className={isSelected ? 'selected' : ''}>
|
|
154
|
+
* {formatTime(startDate)}
|
|
155
|
+
* </button>
|
|
156
|
+
* )}
|
|
157
|
+
* </TimeSlotList.TimeSlotRepeater>
|
|
121
158
|
* ```
|
|
122
159
|
*/
|
|
123
160
|
export declare const TimeSlotRepeater: React.ForwardRefExoticComponent<TimeSlotRepeaterProps & React.RefAttributes<HTMLElement>>;
|
|
@@ -81,13 +81,16 @@ const RootContent = React.forwardRef((props, ref) => {
|
|
|
81
81
|
});
|
|
82
82
|
RootContent.displayName = 'TimeSlotList.RootContent';
|
|
83
83
|
/**
|
|
84
|
-
* Container for the time slots list with empty state support.
|
|
84
|
+
* Container for the time slots list with empty state and loading state support.
|
|
85
85
|
* Wraps GenericList.Items. Follows List Container Level pattern.
|
|
86
86
|
*
|
|
87
87
|
* @component
|
|
88
88
|
* @example
|
|
89
89
|
* ```tsx
|
|
90
|
-
* <TimeSlotList.TimeSlots
|
|
90
|
+
* <TimeSlotList.TimeSlots
|
|
91
|
+
* emptyState={<div>No slots available</div>}
|
|
92
|
+
* loadingState={<div>Loading...</div>}
|
|
93
|
+
* >
|
|
91
94
|
* <TimeSlotList.TimeSlotRepeater>
|
|
92
95
|
* {children}
|
|
93
96
|
* </TimeSlotList.TimeSlotRepeater>
|
|
@@ -101,10 +104,12 @@ export const TimeSlots = React.forwardRef((props, ref) => {
|
|
|
101
104
|
TimeSlots.displayName = 'TimeSlotList.TimeSlots';
|
|
102
105
|
/**
|
|
103
106
|
* Internal component that wraps each time slot item with context provider.
|
|
104
|
-
*
|
|
107
|
+
* Supports both ReactNode and function children patterns.
|
|
105
108
|
*/
|
|
106
109
|
const TimeSlotItemWrapper = ({ timeSlot, children, }) => {
|
|
107
|
-
return (_jsx(TimeSlotProvider, { timeSlot: timeSlot, children: _jsx(CoreTimeSlotInfo, { children: (
|
|
110
|
+
return (_jsx(TimeSlotProvider, { timeSlot: timeSlot, children: _jsx(CoreTimeSlotInfo, { children: (props) => {
|
|
111
|
+
return (_jsx("div", { "data-testid": TestIds.timeSlotListTimeSlot, "data-bookable": props.bookable, "data-selected": props.isSelected, children: typeof children === 'function' ? children(props) : children }));
|
|
112
|
+
} }) }));
|
|
108
113
|
};
|
|
109
114
|
/**
|
|
110
115
|
* Repeater component that renders each time slot.
|
|
@@ -114,16 +119,26 @@ const TimeSlotItemWrapper = ({ timeSlot, children, }) => {
|
|
|
114
119
|
* @component
|
|
115
120
|
* @example
|
|
116
121
|
* ```tsx
|
|
122
|
+
* // Standard usage with nested components
|
|
117
123
|
* <TimeSlotList.TimeSlotRepeater>
|
|
118
124
|
* <TimeSlot.StartDate />
|
|
119
125
|
* <TimeSlot.Duration />
|
|
120
126
|
* <TimeSlot.Actions.Select />
|
|
121
127
|
* </TimeSlotList.TimeSlotRepeater>
|
|
128
|
+
*
|
|
129
|
+
* // Function children pattern - all data available directly
|
|
130
|
+
* <TimeSlotList.TimeSlotRepeater>
|
|
131
|
+
* {({ isSelected, bookable, startDate }) => (
|
|
132
|
+
* <button disabled={!bookable} className={isSelected ? 'selected' : ''}>
|
|
133
|
+
* {formatTime(startDate)}
|
|
134
|
+
* </button>
|
|
135
|
+
* )}
|
|
136
|
+
* </TimeSlotList.TimeSlotRepeater>
|
|
122
137
|
* ```
|
|
123
138
|
*/
|
|
124
139
|
export const TimeSlotRepeater = React.forwardRef((props, ref) => {
|
|
125
140
|
const { children } = props;
|
|
126
|
-
return (_jsx(GenericList.Repeater, { ref: ref, itemWrapper: ({ item: timeSlot
|
|
141
|
+
return (_jsx(GenericList.Repeater, { ref: ref, itemWrapper: ({ item: timeSlot }) => (_jsx(TimeSlotItemWrapper, { timeSlot: timeSlot, children: children }, timeSlot.id)), children: undefined }));
|
|
127
142
|
});
|
|
128
143
|
TimeSlotRepeater.displayName = 'TimeSlotList.TimeSlotRepeater';
|
|
129
144
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Booking Service - Global booking store
|
|
3
|
-
* Manages booking flow state (selected services, time slot, location, form
|
|
3
|
+
* Manages booking flow state (selected services, time slot, location, form submission)
|
|
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';
|
|
@@ -8,9 +8,9 @@ import type { Service } from '@wix/auto_sdk_bookings_services';
|
|
|
8
8
|
import type { Resource, EventInfo } from '@wix/auto_sdk_bookings_availability-time-slots';
|
|
9
9
|
import type { FormValues } from '@wix/form-public';
|
|
10
10
|
/**
|
|
11
|
-
* Minimal time slot data for
|
|
11
|
+
* Minimal time slot data for service selections
|
|
12
12
|
*/
|
|
13
|
-
export interface
|
|
13
|
+
export interface ServiceSelectionTimeSlot {
|
|
14
14
|
startDate: string;
|
|
15
15
|
endDate: string;
|
|
16
16
|
totalCapacity?: number;
|
|
@@ -19,9 +19,9 @@ export interface BookingItemTimeSlot {
|
|
|
19
19
|
eventInfo?: EventInfo;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* ServiceSelection contains the service AND its related selections
|
|
23
23
|
*/
|
|
24
|
-
export interface
|
|
24
|
+
export interface ServiceSelection {
|
|
25
25
|
/** Unique identifier for this booking instance (allows same service multiple times) */
|
|
26
26
|
instanceId: string;
|
|
27
27
|
/** The selected service */
|
|
@@ -29,7 +29,9 @@ export interface BookingItem {
|
|
|
29
29
|
/** Selected resources (staff members, rooms, etc.) */
|
|
30
30
|
resources: Resource[];
|
|
31
31
|
/** Per-item time slot data */
|
|
32
|
-
timeSlot?:
|
|
32
|
+
timeSlot?: ServiceSelectionTimeSlot;
|
|
33
|
+
/** Number of participants for this service selection */
|
|
34
|
+
totalParticipants?: number;
|
|
33
35
|
}
|
|
34
36
|
export interface Location {
|
|
35
37
|
id: string;
|
|
@@ -39,25 +41,24 @@ export interface Location {
|
|
|
39
41
|
* BookingService actions - setters only, no API calls
|
|
40
42
|
*/
|
|
41
43
|
export interface BookingServiceActions {
|
|
42
|
-
/** Clears all
|
|
43
|
-
setItem(item: Omit<
|
|
44
|
+
/** Clears all service selections and sets a single item (instanceId is auto-generated) */
|
|
45
|
+
setItem(item: Omit<ServiceSelection, 'instanceId'>): string;
|
|
44
46
|
/** Adds an item and returns the generated instanceId */
|
|
45
|
-
addItem(item: Omit<
|
|
46
|
-
/** Updates a
|
|
47
|
-
updateItem(updates: Partial<Omit<
|
|
48
|
-
/** Removes a
|
|
47
|
+
addItem(item: Omit<ServiceSelection, 'instanceId'>): string;
|
|
48
|
+
/** Updates a service selection. If no instanceId provided, updates the first item. */
|
|
49
|
+
updateItem(updates: Partial<Omit<ServiceSelection, 'instanceId'>>, instanceId?: string): void;
|
|
50
|
+
/** Removes a service selection. If no instanceId provided, removes the first item. */
|
|
49
51
|
removeItem(instanceId?: string): void;
|
|
50
|
-
/** Clears all
|
|
52
|
+
/** Clears all service selections */
|
|
51
53
|
clearItems(): void;
|
|
52
|
-
/** Sets a resource by ID within a
|
|
54
|
+
/** Sets a resource by ID within a service selection. If no instanceId provided, uses the first item. */
|
|
53
55
|
setResourceById(resourceId: string, resource: Resource, instanceId?: string): void;
|
|
54
|
-
/** Gets a resource by ID from a
|
|
56
|
+
/** Gets a resource by ID from a service selection. If no instanceId provided, uses the first item. */
|
|
55
57
|
getResourceById(resourceId: string, instanceId?: string): Resource | undefined;
|
|
56
58
|
setLocation(location: Location | null): void;
|
|
57
59
|
clearLocation(): void;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
setNumberOfParticipants(count: number): void;
|
|
60
|
+
setFormSubmission(values: FormValues | null): void;
|
|
61
|
+
clearFormSubmission(): void;
|
|
61
62
|
clearAll(): void;
|
|
62
63
|
}
|
|
63
64
|
/**
|
|
@@ -65,14 +66,12 @@ export interface BookingServiceActions {
|
|
|
65
66
|
* Pure state management - no API calls
|
|
66
67
|
*/
|
|
67
68
|
export interface BookingService {
|
|
68
|
-
/** Signal containing the
|
|
69
|
-
|
|
69
|
+
/** Signal containing the service selections (services with their related data) */
|
|
70
|
+
serviceSelections: Signal<ServiceSelection[]>;
|
|
70
71
|
/** Signal containing the selected location */
|
|
71
72
|
location: Signal<Location | null>;
|
|
72
|
-
/** Signal containing the form
|
|
73
|
-
|
|
74
|
-
/** Signal containing the number of participants */
|
|
75
|
-
numberOfParticipants: Signal<number>;
|
|
73
|
+
/** Signal containing the form submission */
|
|
74
|
+
formSubmission: Signal<FormValues | null>;
|
|
76
75
|
/** Actions for modifying booking state */
|
|
77
76
|
actions: BookingServiceActions;
|
|
78
77
|
}
|
|
@@ -89,14 +88,12 @@ export declare const BookingServiceDefinition: string & {
|
|
|
89
88
|
* Mirrors BookingService structure (without actions and Signal wrappers)
|
|
90
89
|
*/
|
|
91
90
|
export interface BookingServiceConfig {
|
|
92
|
-
/** Optional initial
|
|
93
|
-
|
|
91
|
+
/** Optional initial service selections to pre-populate */
|
|
92
|
+
serviceSelections?: ServiceSelection[];
|
|
94
93
|
/** Optional initial location */
|
|
95
94
|
location?: Location | null;
|
|
96
|
-
/** Optional initial form
|
|
97
|
-
|
|
98
|
-
/** Optional initial number of participants (defaults to 1) */
|
|
99
|
-
numberOfParticipants?: number;
|
|
95
|
+
/** Optional initial form submission */
|
|
96
|
+
formSubmission?: FormValues | null;
|
|
100
97
|
}
|
|
101
98
|
/**
|
|
102
99
|
* Implementation of BookingService
|
|
@@ -116,8 +113,8 @@ export interface BookingServiceConfig {
|
|
|
116
113
|
*
|
|
117
114
|
* // In any page - access booking data
|
|
118
115
|
* <Booking.Data>
|
|
119
|
-
* {({
|
|
120
|
-
* <div>{
|
|
116
|
+
* {({ serviceSelections, location, formSubmission, actions }) => (
|
|
117
|
+
* <div>{serviceSelections.map(item => item.service.name).join(', ')}</div>
|
|
121
118
|
* )}
|
|
122
119
|
* </Booking.Data>
|
|
123
120
|
* ```
|