@wix/headless-bookings 0.0.83 → 0.0.85
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/__mocks__/time-slots.d.ts +50 -0
- package/cjs/dist/__mocks__/time-slots.js +95 -0
- package/cjs/dist/react/core/service-list/ServiceList.d.ts +1 -1
- package/cjs/dist/react/service-list/ServiceList.d.ts +0 -2
- package/cjs/dist/react/service-list/ServiceList.js +4 -27
- package/cjs/dist/react/time-slot-list/TimeSlot.d.ts +12 -0
- package/cjs/dist/react/time-slot-list/TimeSlot.js +1 -1
- package/cjs/dist/react/time-slot-list/TimeSlotList.d.ts +12 -0
- package/cjs/dist/react/time-slot-list/TimeSlotList.js +1 -1
- package/cjs/dist/services/service-list/service-list.d.ts +1 -1
- package/cjs/dist/services/service-list/service-list.js +0 -1
- package/cjs/dist/services/time-slot-list/time-slot-list.d.ts +6 -0
- package/cjs/dist/services/time-slot-list/time-slot-list.js +5 -1
- package/dist/__mocks__/time-slots.d.ts +50 -0
- package/dist/__mocks__/time-slots.js +95 -0
- package/dist/react/core/service-list/ServiceList.d.ts +1 -1
- package/dist/react/service-list/ServiceList.d.ts +0 -2
- package/dist/react/service-list/ServiceList.js +4 -27
- package/dist/react/time-slot-list/TimeSlot.d.ts +12 -0
- package/dist/react/time-slot-list/TimeSlot.js +1 -1
- package/dist/react/time-slot-list/TimeSlotList.d.ts +12 -0
- package/dist/react/time-slot-list/TimeSlotList.js +1 -1
- package/dist/services/service-list/service-list.d.ts +1 -1
- package/dist/services/service-list/service-list.js +0 -1
- package/dist/services/time-slot-list/time-slot-list.d.ts +6 -0
- package/dist/services/time-slot-list/time-slot-list.js +5 -1
- package/package.json +2 -2
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
import React from 'react';
|
|
1
3
|
import type { TimeSlot } from '@wix/auto_sdk_bookings_availability-time-slots';
|
|
2
4
|
import type { TimeSlotListServiceConfig, TimeSlotListServiceAPI } from '../services/time-slot-list/time-slot-list.def.js';
|
|
3
5
|
import type { BookingService } from '../services/booking/booking.js';
|
|
6
|
+
import type { StaffMemberData } from '../react/time-slot-list/TimeSlot.js';
|
|
4
7
|
export declare function createTimeSlotListService(overrides?: Partial<TimeSlotListServiceConfig>): {
|
|
5
8
|
service: TimeSlotListServiceAPI;
|
|
6
9
|
bookingService: BookingService;
|
|
@@ -26,3 +29,50 @@ export declare const mockCursorPagingMetadataNoMore: {
|
|
|
26
29
|
cursors: {};
|
|
27
30
|
};
|
|
28
31
|
export declare function createMockTimeSlotListService(config?: Partial<TimeSlotListServiceConfig>): TimeSlotListServiceAPI;
|
|
32
|
+
export interface CoreTimeSlotMockConfig {
|
|
33
|
+
timeSlot: TimeSlot;
|
|
34
|
+
staffMembers: StaffMemberData[];
|
|
35
|
+
selectTimeSlot: ReturnType<typeof vi.fn>;
|
|
36
|
+
clearStaffSelection: ReturnType<typeof vi.fn>;
|
|
37
|
+
selectStaffMember: ReturnType<typeof vi.fn>;
|
|
38
|
+
}
|
|
39
|
+
export declare function createCoreTimeSlotMock(config: CoreTimeSlotMockConfig): {
|
|
40
|
+
Root: import("vitest").Mock<({ children, config: cfg }: any) => import("react/jsx-runtime").JSX.Element>;
|
|
41
|
+
Info: import("vitest").Mock<({ children }: any) => any>;
|
|
42
|
+
Actions: import("vitest").Mock<({ children }: any) => any>;
|
|
43
|
+
StaffMembers: import("vitest").Mock<({ children }: any) => any>;
|
|
44
|
+
StaffMemberProvider: import("vitest").Mock<({ children, staffMember }: any) => import("react/jsx-runtime").JSX.Element>;
|
|
45
|
+
StaffMemberInfo: import("vitest").Mock<({ children }: any) => any>;
|
|
46
|
+
StaffMemberActions: import("vitest").Mock<({ children }: any) => any>;
|
|
47
|
+
};
|
|
48
|
+
export interface CoreTimeSlotListMockConfig {
|
|
49
|
+
timeSlots: TimeSlot[];
|
|
50
|
+
timezone?: string;
|
|
51
|
+
displayName?: string;
|
|
52
|
+
startDate?: Date;
|
|
53
|
+
endDate?: Date;
|
|
54
|
+
}
|
|
55
|
+
export declare function createCoreTimeSlotListMock(config?: CoreTimeSlotListMockConfig): {
|
|
56
|
+
Root: import("vitest").Mock<({ children }: any) => import("react/jsx-runtime").JSX.Element>;
|
|
57
|
+
Timezone: import("vitest").Mock<({ children }: any) => any>;
|
|
58
|
+
ListData: import("vitest").Mock<({ children }: any) => any>;
|
|
59
|
+
DateRange: import("vitest").Mock<({ children }: any) => any>;
|
|
60
|
+
};
|
|
61
|
+
export declare function createCoreTimeSlotInfoMock(timeSlot?: TimeSlot): {
|
|
62
|
+
Root: import("vitest").Mock<({ children, config: cfg }: any) => import("react/jsx-runtime").JSX.Element>;
|
|
63
|
+
Info: import("vitest").Mock<({ children }: any) => any>;
|
|
64
|
+
};
|
|
65
|
+
declare const GenericListContext: React.Context<{
|
|
66
|
+
items: any[];
|
|
67
|
+
} | null>;
|
|
68
|
+
export declare function createGenericListMock(): {
|
|
69
|
+
GenericList: {
|
|
70
|
+
Root: import("vitest").Mock<({ children, items, className, ...props }: any) => import("react/jsx-runtime").JSX.Element>;
|
|
71
|
+
Items: import("vitest").Mock<({ children, emptyState }: any) => any>;
|
|
72
|
+
Repeater: import("vitest").Mock<({ itemWrapper, children }: any) => import("react/jsx-runtime").JSX.Element | null>;
|
|
73
|
+
Actions: {
|
|
74
|
+
LoadMore: import("vitest").Mock<({ children, ...props }: any) => import("react/jsx-runtime").JSX.Element>;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
export { GenericListContext };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
1
2
|
import { vi } from 'vitest';
|
|
3
|
+
import React from 'react';
|
|
2
4
|
import { TimeSlotListService } from '../services/time-slot-list/time-slot-list.js';
|
|
3
5
|
import { createMockBookingService, createMockSignalsService, mockSignal, } from './booking.js';
|
|
4
6
|
export function createTimeSlotListService(overrides = {}) {
|
|
@@ -115,3 +117,96 @@ export function createMockTimeSlotListService(config = {}) {
|
|
|
115
117
|
dispose: vi.fn(),
|
|
116
118
|
};
|
|
117
119
|
}
|
|
120
|
+
export function createCoreTimeSlotMock(config) {
|
|
121
|
+
const { timeSlot, staffMembers, selectTimeSlot, clearStaffSelection, selectStaffMember, } = config;
|
|
122
|
+
const startDate = new Date(timeSlot.localStartDate);
|
|
123
|
+
const endDate = new Date(timeSlot.localEndDate);
|
|
124
|
+
const durationInMinutes = Math.round((endDate.getTime() - startDate.getTime()) / (1000 * 60));
|
|
125
|
+
return {
|
|
126
|
+
Root: vi.fn(({ children, config: cfg }) => (_jsx("div", { "data-timeslot-id": cfg.timeSlot.scheduleId, children: children }))),
|
|
127
|
+
Info: vi.fn(({ children }) => children({
|
|
128
|
+
startDate,
|
|
129
|
+
endDate,
|
|
130
|
+
durationInMinutes,
|
|
131
|
+
locationName: timeSlot.location?.name ?? '',
|
|
132
|
+
bookable: timeSlot.bookable ?? false,
|
|
133
|
+
isSelected: false,
|
|
134
|
+
timeSlot,
|
|
135
|
+
})),
|
|
136
|
+
Actions: vi.fn(({ children }) => children({
|
|
137
|
+
selectTimeSlot,
|
|
138
|
+
clearStaffSelection,
|
|
139
|
+
timeSlot,
|
|
140
|
+
bookable: timeSlot.bookable ?? false,
|
|
141
|
+
isSelected: false,
|
|
142
|
+
})),
|
|
143
|
+
StaffMembers: vi.fn(({ children }) => children({ staffMembers, selectStaffMember: vi.fn() })),
|
|
144
|
+
StaffMemberProvider: vi.fn(({ children, staffMember }) => (_jsx("div", { "data-staff-id": staffMember.id, children: children }))),
|
|
145
|
+
StaffMemberInfo: vi.fn(({ children }) => children({
|
|
146
|
+
name: staffMembers[0]?.name ?? '',
|
|
147
|
+
isSelected: false,
|
|
148
|
+
staffMember: staffMembers[0],
|
|
149
|
+
})),
|
|
150
|
+
StaffMemberActions: vi.fn(({ children }) => children({
|
|
151
|
+
selectStaffMember,
|
|
152
|
+
isSelected: false,
|
|
153
|
+
staffMember: staffMembers[0],
|
|
154
|
+
})),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
export function createCoreTimeSlotListMock(config = { timeSlots: mockTimeSlots }) {
|
|
158
|
+
const { timeSlots, timezone = 'America/New_York', displayName = 'Eastern Standard Time', startDate = new Date('2024-01-15'), endDate = new Date('2024-01-22'), } = config;
|
|
159
|
+
return {
|
|
160
|
+
Root: vi.fn(({ children }) => _jsx(_Fragment, { children: children })),
|
|
161
|
+
Timezone: vi.fn(({ children }) => children({ timezone, displayName })),
|
|
162
|
+
ListData: vi.fn(({ children }) => children({
|
|
163
|
+
timeSlots,
|
|
164
|
+
hasMore: false,
|
|
165
|
+
isLoading: false,
|
|
166
|
+
error: null,
|
|
167
|
+
loadMore: vi.fn(),
|
|
168
|
+
hasSelectedTimeSlot: false,
|
|
169
|
+
})),
|
|
170
|
+
DateRange: vi.fn(({ children }) => children({
|
|
171
|
+
startDate,
|
|
172
|
+
endDate,
|
|
173
|
+
setDateRange: vi.fn(),
|
|
174
|
+
})),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
export function createCoreTimeSlotInfoMock(timeSlot = mockTimeSlot) {
|
|
178
|
+
return {
|
|
179
|
+
Root: vi.fn(({ children, config: cfg }) => (_jsx("div", { "data-timeslot-id": cfg.timeSlot.scheduleId, children: children }))),
|
|
180
|
+
Info: vi.fn(({ children }) => children({
|
|
181
|
+
startDate: new Date(timeSlot.localStartDate),
|
|
182
|
+
endDate: new Date(timeSlot.localEndDate),
|
|
183
|
+
durationInMinutes: 60,
|
|
184
|
+
locationName: timeSlot.location?.name ?? '',
|
|
185
|
+
bookable: timeSlot.bookable ?? false,
|
|
186
|
+
isSelected: false,
|
|
187
|
+
timeSlot,
|
|
188
|
+
})),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
const GenericListContext = React.createContext(null);
|
|
192
|
+
export function createGenericListMock() {
|
|
193
|
+
return {
|
|
194
|
+
GenericList: {
|
|
195
|
+
Root: vi.fn(({ children, items, className, ...props }) => (_jsx(GenericListContext.Provider, { value: { items }, children: _jsx("div", { className: className, ...props, children: children }) }))),
|
|
196
|
+
Items: vi.fn(({ children, emptyState }) => {
|
|
197
|
+
const ctx = React.useContext(GenericListContext);
|
|
198
|
+
return ctx?.items?.length ? _jsx("div", { children: children }) : emptyState || null;
|
|
199
|
+
}),
|
|
200
|
+
Repeater: vi.fn(({ itemWrapper, children }) => {
|
|
201
|
+
const ctx = React.useContext(GenericListContext);
|
|
202
|
+
if (!ctx?.items?.length)
|
|
203
|
+
return null;
|
|
204
|
+
return (_jsx(_Fragment, { children: ctx.items.map((item, i) => itemWrapper({ item, index: i, children })) }));
|
|
205
|
+
}),
|
|
206
|
+
Actions: {
|
|
207
|
+
LoadMore: vi.fn(({ children, ...props }) => (_jsx("button", { ...props, children: children }))),
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
export { GenericListContext };
|
|
@@ -49,7 +49,7 @@ export interface ServicesRenderProps {
|
|
|
49
49
|
/** Whether more services can be loaded */
|
|
50
50
|
hasMore: boolean;
|
|
51
51
|
/** Function to load more services */
|
|
52
|
-
loadMore: (count
|
|
52
|
+
loadMore: (count?: number) => Promise<void>;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* Component that provides services list data through render props.
|
|
@@ -15,8 +15,6 @@ export interface ServiceListRootProps {
|
|
|
15
15
|
serviceListConfig?: ServiceListServiceConfig;
|
|
16
16
|
className?: string;
|
|
17
17
|
variant?: ListVariant;
|
|
18
|
-
/** Number of items to load per page. Defaults to config limit or 100 */
|
|
19
|
-
pageSize?: number;
|
|
20
18
|
}
|
|
21
19
|
/**
|
|
22
20
|
* Root component that provides the ServiceList service context for rendering services lists.
|
|
@@ -10,10 +10,6 @@ import { ServiceListServiceDefinition } from '../../services/service-list/servic
|
|
|
10
10
|
import * as CoreServiceList from '../core/service-list/ServiceList.js';
|
|
11
11
|
import * as CoreServiceListFilter from '../core/service-list/ServiceListFilter.js';
|
|
12
12
|
import * as Service from '../service/Service.js';
|
|
13
|
-
/**
|
|
14
|
-
* Booking app ID constant
|
|
15
|
-
*/
|
|
16
|
-
const BOOKING_APP_ID = '13d21c63-b5ec-5912-8397-c3a5ddb27a97';
|
|
17
13
|
var TestIds;
|
|
18
14
|
(function (TestIds) {
|
|
19
15
|
TestIds["serviceListRoot"] = "service-list-root";
|
|
@@ -46,40 +42,21 @@ var TestIds;
|
|
|
46
42
|
* ```
|
|
47
43
|
*/
|
|
48
44
|
export const Root = React.forwardRef((props, ref) => {
|
|
49
|
-
const { children, serviceListConfig, className, variant
|
|
50
|
-
|
|
51
|
-
services: [],
|
|
52
|
-
options: {
|
|
53
|
-
appId: BOOKING_APP_ID,
|
|
54
|
-
pagingMetadata: {
|
|
55
|
-
limit: 0,
|
|
56
|
-
offset: 0,
|
|
57
|
-
hasNext: false,
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
// Calculate effective page size: prop > config limit > default
|
|
62
|
-
const effectivePageSize = pageSize ??
|
|
63
|
-
serviceListConfig?.options?.pagingMetadata?.limit ??
|
|
64
|
-
DEFAULT_PAGE_SIZE;
|
|
65
|
-
return (_jsx(CoreServiceList.Root, { serviceListConfig: serviceConfig, children: _jsx(RootContent, { className: className, ref: ref, variant: variant, pageSize: effectivePageSize, children: children }) }));
|
|
45
|
+
const { children, serviceListConfig = {}, className, variant } = props;
|
|
46
|
+
return (_jsx(CoreServiceList.Root, { serviceListConfig: serviceListConfig, children: _jsx(RootContent, { className: className, ref: ref, variant: variant, children: children }) }));
|
|
66
47
|
});
|
|
67
48
|
Root.displayName = 'ServiceList.Root';
|
|
68
|
-
/**
|
|
69
|
-
* Default page size for load more
|
|
70
|
-
*/
|
|
71
|
-
const DEFAULT_PAGE_SIZE = 100;
|
|
72
49
|
/**
|
|
73
50
|
* Internal component to handle the Root content with service access
|
|
74
51
|
*/
|
|
75
52
|
const RootContent = React.forwardRef((props, ref) => {
|
|
76
|
-
const { children, className, variant
|
|
53
|
+
const { children, className, variant } = props;
|
|
77
54
|
return (_jsx(CoreServiceList.Services, { children: ({ services: servicesList, isLoading, hasMore, loadMore, error }) => {
|
|
78
55
|
const items = servicesList.map((service) => ({
|
|
79
56
|
...service,
|
|
80
57
|
id: service._id,
|
|
81
58
|
}));
|
|
82
|
-
return (_jsx(GenericList.Root, { items: items, loadMore: () => loadMore(
|
|
59
|
+
return (_jsx(GenericList.Root, { items: items, loadMore: () => loadMore(), hasMore: hasMore, isLoading: isLoading, error: error, className: className, ref: ref, "data-testid": TestIds.serviceListRoot, variant: variant, children: children }));
|
|
83
60
|
} }));
|
|
84
61
|
});
|
|
85
62
|
/**
|
|
@@ -33,6 +33,18 @@ export interface RootProps {
|
|
|
33
33
|
* ```
|
|
34
34
|
*/
|
|
35
35
|
export declare const Root: React.ForwardRefExoticComponent<RootProps & React.RefAttributes<HTMLElement>>;
|
|
36
|
+
export declare enum TestIds {
|
|
37
|
+
timeSlotStartDate = "time-slot-start-date",
|
|
38
|
+
timeSlotEndDate = "time-slot-end-date",
|
|
39
|
+
timeSlotDuration = "time-slot-duration",
|
|
40
|
+
timeSlotActionSelect = "time-slot-action-select",
|
|
41
|
+
timeSlotActionClearStaffSelection = "time-slot-action-clear-staff-selection",
|
|
42
|
+
timeSlotLocationName = "time-slot-location-name",
|
|
43
|
+
timeSlotStaffMembers = "time-slot-staff-members",
|
|
44
|
+
timeSlotStaffMember = "time-slot-staff-member",
|
|
45
|
+
timeSlotStaffMemberName = "time-slot-staff-member-name",
|
|
46
|
+
timeSlotStaffMemberActionSelect = "time-slot-staff-member-action-select"
|
|
47
|
+
}
|
|
36
48
|
/**
|
|
37
49
|
* Props for TimeSlot.StartDate component
|
|
38
50
|
*/
|
|
@@ -31,7 +31,7 @@ Root.displayName = 'TimeSlot.Root';
|
|
|
31
31
|
// ============================================================================
|
|
32
32
|
// TestIds
|
|
33
33
|
// ============================================================================
|
|
34
|
-
var TestIds;
|
|
34
|
+
export var TestIds;
|
|
35
35
|
(function (TestIds) {
|
|
36
36
|
TestIds["timeSlotStartDate"] = "time-slot-start-date";
|
|
37
37
|
TestIds["timeSlotEndDate"] = "time-slot-end-date";
|
|
@@ -8,6 +8,18 @@ import { AsChildChildren } from '@wix/headless-utils/react';
|
|
|
8
8
|
import type { TimeSlot as TimeSlotType } from '@wix/auto_sdk_bookings_availability-time-slots';
|
|
9
9
|
import type { TimeSlotListServiceConfig } from '../../services/time-slot-list/time-slot-list.def.js';
|
|
10
10
|
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
|
+
/**
|
|
12
|
+
* TimeSlot with required id field for GenericList
|
|
13
|
+
*/
|
|
14
|
+
export declare enum TestIds {
|
|
15
|
+
timeSlotListRoot = "time-slot-list-root",
|
|
16
|
+
timeSlotListTimeSlots = "time-slot-list-time-slots",
|
|
17
|
+
timeSlotListTimeSlot = "time-slot-list-time-slot",
|
|
18
|
+
timeSlotListTimezone = "time-slot-list-timezone",
|
|
19
|
+
timeSlotListLoadMore = "time-slot-list-load-more",
|
|
20
|
+
timeSlotListContinue = "time-slot-list-continue",
|
|
21
|
+
timeSlotListDateRangeInput = "time-slot-list-date-range-input"
|
|
22
|
+
}
|
|
11
23
|
/**
|
|
12
24
|
* Render props for TimeSlotList.Timezone component
|
|
13
25
|
*/
|
|
@@ -21,7 +21,7 @@ function toISODateString(date) {
|
|
|
21
21
|
/**
|
|
22
22
|
* TimeSlot with required id field for GenericList
|
|
23
23
|
*/
|
|
24
|
-
var TestIds;
|
|
24
|
+
export var TestIds;
|
|
25
25
|
(function (TestIds) {
|
|
26
26
|
TestIds["timeSlotListRoot"] = "time-slot-list-root";
|
|
27
27
|
TestIds["timeSlotListTimeSlots"] = "time-slot-list-time-slots";
|
|
@@ -24,7 +24,7 @@ export interface ServiceListServiceConfig {
|
|
|
24
24
|
* Actions object for service list operations
|
|
25
25
|
*/
|
|
26
26
|
export interface ServiceListActions {
|
|
27
|
-
loadMore: (count
|
|
27
|
+
loadMore: (count?: number) => Promise<void>;
|
|
28
28
|
setQueryOptions: (options: QueryOptions) => void;
|
|
29
29
|
setFilter: (filter: Filter) => void;
|
|
30
30
|
resetFilter: () => void;
|
|
@@ -256,7 +256,6 @@ export const ServiceListService = implementService.withConfig()(ServiceListServi
|
|
|
256
256
|
const nextPaging = {
|
|
257
257
|
limit: count || DEFAULT_QUERY_LIMIT,
|
|
258
258
|
offset: nextOffset,
|
|
259
|
-
hasNext: false, // Will be updated after query
|
|
260
259
|
};
|
|
261
260
|
// Get effective filter from computed signal (includes location from BookingService)
|
|
262
261
|
const effectiveFilter = effectiveFilterSignal.get();
|
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { Service } from '@wix/auto_sdk_bookings_services';
|
|
6
6
|
import { type TimeSlotListServiceConfig, type TimeSlotsFilters } from './time-slot-list.def.js';
|
|
7
|
+
import { TimeSlot } from '@wix/auto_sdk_bookings_event-time-slots';
|
|
8
|
+
/**
|
|
9
|
+
* Helper to get staff member name from time slots by ID
|
|
10
|
+
* @internal - exported for testing
|
|
11
|
+
*/
|
|
12
|
+
export declare const getStaffName: (staffMemberId: string, slots: TimeSlot[]) => string | undefined;
|
|
7
13
|
export declare const TimeSlotListService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
8
14
|
__api: import("./time-slot-list.def.js").TimeSlotListServiceAPI;
|
|
9
15
|
__config: {};
|
|
@@ -16,7 +16,11 @@ const getClientTimezone = () => {
|
|
|
16
16
|
? Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
17
17
|
: undefined;
|
|
18
18
|
};
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Helper to get staff member name from time slots by ID
|
|
21
|
+
* @internal - exported for testing
|
|
22
|
+
*/
|
|
23
|
+
export const getStaffName = (staffMemberId, slots) => {
|
|
20
24
|
return (slots
|
|
21
25
|
.flatMap((slot) => slot.availableResources[0].resources)
|
|
22
26
|
.find((r) => r._id === staffMemberId)?.name ?? undefined);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
2
|
+
import React from 'react';
|
|
1
3
|
import type { TimeSlot } from '@wix/auto_sdk_bookings_availability-time-slots';
|
|
2
4
|
import type { TimeSlotListServiceConfig, TimeSlotListServiceAPI } from '../services/time-slot-list/time-slot-list.def.js';
|
|
3
5
|
import type { BookingService } from '../services/booking/booking.js';
|
|
6
|
+
import type { StaffMemberData } from '../react/time-slot-list/TimeSlot.js';
|
|
4
7
|
export declare function createTimeSlotListService(overrides?: Partial<TimeSlotListServiceConfig>): {
|
|
5
8
|
service: TimeSlotListServiceAPI;
|
|
6
9
|
bookingService: BookingService;
|
|
@@ -26,3 +29,50 @@ export declare const mockCursorPagingMetadataNoMore: {
|
|
|
26
29
|
cursors: {};
|
|
27
30
|
};
|
|
28
31
|
export declare function createMockTimeSlotListService(config?: Partial<TimeSlotListServiceConfig>): TimeSlotListServiceAPI;
|
|
32
|
+
export interface CoreTimeSlotMockConfig {
|
|
33
|
+
timeSlot: TimeSlot;
|
|
34
|
+
staffMembers: StaffMemberData[];
|
|
35
|
+
selectTimeSlot: ReturnType<typeof vi.fn>;
|
|
36
|
+
clearStaffSelection: ReturnType<typeof vi.fn>;
|
|
37
|
+
selectStaffMember: ReturnType<typeof vi.fn>;
|
|
38
|
+
}
|
|
39
|
+
export declare function createCoreTimeSlotMock(config: CoreTimeSlotMockConfig): {
|
|
40
|
+
Root: import("vitest").Mock<({ children, config: cfg }: any) => import("react/jsx-runtime").JSX.Element>;
|
|
41
|
+
Info: import("vitest").Mock<({ children }: any) => any>;
|
|
42
|
+
Actions: import("vitest").Mock<({ children }: any) => any>;
|
|
43
|
+
StaffMembers: import("vitest").Mock<({ children }: any) => any>;
|
|
44
|
+
StaffMemberProvider: import("vitest").Mock<({ children, staffMember }: any) => import("react/jsx-runtime").JSX.Element>;
|
|
45
|
+
StaffMemberInfo: import("vitest").Mock<({ children }: any) => any>;
|
|
46
|
+
StaffMemberActions: import("vitest").Mock<({ children }: any) => any>;
|
|
47
|
+
};
|
|
48
|
+
export interface CoreTimeSlotListMockConfig {
|
|
49
|
+
timeSlots: TimeSlot[];
|
|
50
|
+
timezone?: string;
|
|
51
|
+
displayName?: string;
|
|
52
|
+
startDate?: Date;
|
|
53
|
+
endDate?: Date;
|
|
54
|
+
}
|
|
55
|
+
export declare function createCoreTimeSlotListMock(config?: CoreTimeSlotListMockConfig): {
|
|
56
|
+
Root: import("vitest").Mock<({ children }: any) => import("react/jsx-runtime").JSX.Element>;
|
|
57
|
+
Timezone: import("vitest").Mock<({ children }: any) => any>;
|
|
58
|
+
ListData: import("vitest").Mock<({ children }: any) => any>;
|
|
59
|
+
DateRange: import("vitest").Mock<({ children }: any) => any>;
|
|
60
|
+
};
|
|
61
|
+
export declare function createCoreTimeSlotInfoMock(timeSlot?: TimeSlot): {
|
|
62
|
+
Root: import("vitest").Mock<({ children, config: cfg }: any) => import("react/jsx-runtime").JSX.Element>;
|
|
63
|
+
Info: import("vitest").Mock<({ children }: any) => any>;
|
|
64
|
+
};
|
|
65
|
+
declare const GenericListContext: React.Context<{
|
|
66
|
+
items: any[];
|
|
67
|
+
} | null>;
|
|
68
|
+
export declare function createGenericListMock(): {
|
|
69
|
+
GenericList: {
|
|
70
|
+
Root: import("vitest").Mock<({ children, items, className, ...props }: any) => import("react/jsx-runtime").JSX.Element>;
|
|
71
|
+
Items: import("vitest").Mock<({ children, emptyState }: any) => any>;
|
|
72
|
+
Repeater: import("vitest").Mock<({ itemWrapper, children }: any) => import("react/jsx-runtime").JSX.Element | null>;
|
|
73
|
+
Actions: {
|
|
74
|
+
LoadMore: import("vitest").Mock<({ children, ...props }: any) => import("react/jsx-runtime").JSX.Element>;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
export { GenericListContext };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
1
2
|
import { vi } from 'vitest';
|
|
3
|
+
import React from 'react';
|
|
2
4
|
import { TimeSlotListService } from '../services/time-slot-list/time-slot-list.js';
|
|
3
5
|
import { createMockBookingService, createMockSignalsService, mockSignal, } from './booking.js';
|
|
4
6
|
export function createTimeSlotListService(overrides = {}) {
|
|
@@ -115,3 +117,96 @@ export function createMockTimeSlotListService(config = {}) {
|
|
|
115
117
|
dispose: vi.fn(),
|
|
116
118
|
};
|
|
117
119
|
}
|
|
120
|
+
export function createCoreTimeSlotMock(config) {
|
|
121
|
+
const { timeSlot, staffMembers, selectTimeSlot, clearStaffSelection, selectStaffMember, } = config;
|
|
122
|
+
const startDate = new Date(timeSlot.localStartDate);
|
|
123
|
+
const endDate = new Date(timeSlot.localEndDate);
|
|
124
|
+
const durationInMinutes = Math.round((endDate.getTime() - startDate.getTime()) / (1000 * 60));
|
|
125
|
+
return {
|
|
126
|
+
Root: vi.fn(({ children, config: cfg }) => (_jsx("div", { "data-timeslot-id": cfg.timeSlot.scheduleId, children: children }))),
|
|
127
|
+
Info: vi.fn(({ children }) => children({
|
|
128
|
+
startDate,
|
|
129
|
+
endDate,
|
|
130
|
+
durationInMinutes,
|
|
131
|
+
locationName: timeSlot.location?.name ?? '',
|
|
132
|
+
bookable: timeSlot.bookable ?? false,
|
|
133
|
+
isSelected: false,
|
|
134
|
+
timeSlot,
|
|
135
|
+
})),
|
|
136
|
+
Actions: vi.fn(({ children }) => children({
|
|
137
|
+
selectTimeSlot,
|
|
138
|
+
clearStaffSelection,
|
|
139
|
+
timeSlot,
|
|
140
|
+
bookable: timeSlot.bookable ?? false,
|
|
141
|
+
isSelected: false,
|
|
142
|
+
})),
|
|
143
|
+
StaffMembers: vi.fn(({ children }) => children({ staffMembers, selectStaffMember: vi.fn() })),
|
|
144
|
+
StaffMemberProvider: vi.fn(({ children, staffMember }) => (_jsx("div", { "data-staff-id": staffMember.id, children: children }))),
|
|
145
|
+
StaffMemberInfo: vi.fn(({ children }) => children({
|
|
146
|
+
name: staffMembers[0]?.name ?? '',
|
|
147
|
+
isSelected: false,
|
|
148
|
+
staffMember: staffMembers[0],
|
|
149
|
+
})),
|
|
150
|
+
StaffMemberActions: vi.fn(({ children }) => children({
|
|
151
|
+
selectStaffMember,
|
|
152
|
+
isSelected: false,
|
|
153
|
+
staffMember: staffMembers[0],
|
|
154
|
+
})),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
export function createCoreTimeSlotListMock(config = { timeSlots: mockTimeSlots }) {
|
|
158
|
+
const { timeSlots, timezone = 'America/New_York', displayName = 'Eastern Standard Time', startDate = new Date('2024-01-15'), endDate = new Date('2024-01-22'), } = config;
|
|
159
|
+
return {
|
|
160
|
+
Root: vi.fn(({ children }) => _jsx(_Fragment, { children: children })),
|
|
161
|
+
Timezone: vi.fn(({ children }) => children({ timezone, displayName })),
|
|
162
|
+
ListData: vi.fn(({ children }) => children({
|
|
163
|
+
timeSlots,
|
|
164
|
+
hasMore: false,
|
|
165
|
+
isLoading: false,
|
|
166
|
+
error: null,
|
|
167
|
+
loadMore: vi.fn(),
|
|
168
|
+
hasSelectedTimeSlot: false,
|
|
169
|
+
})),
|
|
170
|
+
DateRange: vi.fn(({ children }) => children({
|
|
171
|
+
startDate,
|
|
172
|
+
endDate,
|
|
173
|
+
setDateRange: vi.fn(),
|
|
174
|
+
})),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
export function createCoreTimeSlotInfoMock(timeSlot = mockTimeSlot) {
|
|
178
|
+
return {
|
|
179
|
+
Root: vi.fn(({ children, config: cfg }) => (_jsx("div", { "data-timeslot-id": cfg.timeSlot.scheduleId, children: children }))),
|
|
180
|
+
Info: vi.fn(({ children }) => children({
|
|
181
|
+
startDate: new Date(timeSlot.localStartDate),
|
|
182
|
+
endDate: new Date(timeSlot.localEndDate),
|
|
183
|
+
durationInMinutes: 60,
|
|
184
|
+
locationName: timeSlot.location?.name ?? '',
|
|
185
|
+
bookable: timeSlot.bookable ?? false,
|
|
186
|
+
isSelected: false,
|
|
187
|
+
timeSlot,
|
|
188
|
+
})),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
const GenericListContext = React.createContext(null);
|
|
192
|
+
export function createGenericListMock() {
|
|
193
|
+
return {
|
|
194
|
+
GenericList: {
|
|
195
|
+
Root: vi.fn(({ children, items, className, ...props }) => (_jsx(GenericListContext.Provider, { value: { items }, children: _jsx("div", { className: className, ...props, children: children }) }))),
|
|
196
|
+
Items: vi.fn(({ children, emptyState }) => {
|
|
197
|
+
const ctx = React.useContext(GenericListContext);
|
|
198
|
+
return ctx?.items?.length ? _jsx("div", { children: children }) : emptyState || null;
|
|
199
|
+
}),
|
|
200
|
+
Repeater: vi.fn(({ itemWrapper, children }) => {
|
|
201
|
+
const ctx = React.useContext(GenericListContext);
|
|
202
|
+
if (!ctx?.items?.length)
|
|
203
|
+
return null;
|
|
204
|
+
return (_jsx(_Fragment, { children: ctx.items.map((item, i) => itemWrapper({ item, index: i, children })) }));
|
|
205
|
+
}),
|
|
206
|
+
Actions: {
|
|
207
|
+
LoadMore: vi.fn(({ children, ...props }) => (_jsx("button", { ...props, children: children }))),
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
export { GenericListContext };
|
|
@@ -49,7 +49,7 @@ export interface ServicesRenderProps {
|
|
|
49
49
|
/** Whether more services can be loaded */
|
|
50
50
|
hasMore: boolean;
|
|
51
51
|
/** Function to load more services */
|
|
52
|
-
loadMore: (count
|
|
52
|
+
loadMore: (count?: number) => Promise<void>;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* Component that provides services list data through render props.
|
|
@@ -15,8 +15,6 @@ export interface ServiceListRootProps {
|
|
|
15
15
|
serviceListConfig?: ServiceListServiceConfig;
|
|
16
16
|
className?: string;
|
|
17
17
|
variant?: ListVariant;
|
|
18
|
-
/** Number of items to load per page. Defaults to config limit or 100 */
|
|
19
|
-
pageSize?: number;
|
|
20
18
|
}
|
|
21
19
|
/**
|
|
22
20
|
* Root component that provides the ServiceList service context for rendering services lists.
|
|
@@ -10,10 +10,6 @@ import { ServiceListServiceDefinition } from '../../services/service-list/servic
|
|
|
10
10
|
import * as CoreServiceList from '../core/service-list/ServiceList.js';
|
|
11
11
|
import * as CoreServiceListFilter from '../core/service-list/ServiceListFilter.js';
|
|
12
12
|
import * as Service from '../service/Service.js';
|
|
13
|
-
/**
|
|
14
|
-
* Booking app ID constant
|
|
15
|
-
*/
|
|
16
|
-
const BOOKING_APP_ID = '13d21c63-b5ec-5912-8397-c3a5ddb27a97';
|
|
17
13
|
var TestIds;
|
|
18
14
|
(function (TestIds) {
|
|
19
15
|
TestIds["serviceListRoot"] = "service-list-root";
|
|
@@ -46,40 +42,21 @@ var TestIds;
|
|
|
46
42
|
* ```
|
|
47
43
|
*/
|
|
48
44
|
export const Root = React.forwardRef((props, ref) => {
|
|
49
|
-
const { children, serviceListConfig, className, variant
|
|
50
|
-
|
|
51
|
-
services: [],
|
|
52
|
-
options: {
|
|
53
|
-
appId: BOOKING_APP_ID,
|
|
54
|
-
pagingMetadata: {
|
|
55
|
-
limit: 0,
|
|
56
|
-
offset: 0,
|
|
57
|
-
hasNext: false,
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
// Calculate effective page size: prop > config limit > default
|
|
62
|
-
const effectivePageSize = pageSize ??
|
|
63
|
-
serviceListConfig?.options?.pagingMetadata?.limit ??
|
|
64
|
-
DEFAULT_PAGE_SIZE;
|
|
65
|
-
return (_jsx(CoreServiceList.Root, { serviceListConfig: serviceConfig, children: _jsx(RootContent, { className: className, ref: ref, variant: variant, pageSize: effectivePageSize, children: children }) }));
|
|
45
|
+
const { children, serviceListConfig = {}, className, variant } = props;
|
|
46
|
+
return (_jsx(CoreServiceList.Root, { serviceListConfig: serviceListConfig, children: _jsx(RootContent, { className: className, ref: ref, variant: variant, children: children }) }));
|
|
66
47
|
});
|
|
67
48
|
Root.displayName = 'ServiceList.Root';
|
|
68
|
-
/**
|
|
69
|
-
* Default page size for load more
|
|
70
|
-
*/
|
|
71
|
-
const DEFAULT_PAGE_SIZE = 100;
|
|
72
49
|
/**
|
|
73
50
|
* Internal component to handle the Root content with service access
|
|
74
51
|
*/
|
|
75
52
|
const RootContent = React.forwardRef((props, ref) => {
|
|
76
|
-
const { children, className, variant
|
|
53
|
+
const { children, className, variant } = props;
|
|
77
54
|
return (_jsx(CoreServiceList.Services, { children: ({ services: servicesList, isLoading, hasMore, loadMore, error }) => {
|
|
78
55
|
const items = servicesList.map((service) => ({
|
|
79
56
|
...service,
|
|
80
57
|
id: service._id,
|
|
81
58
|
}));
|
|
82
|
-
return (_jsx(GenericList.Root, { items: items, loadMore: () => loadMore(
|
|
59
|
+
return (_jsx(GenericList.Root, { items: items, loadMore: () => loadMore(), hasMore: hasMore, isLoading: isLoading, error: error, className: className, ref: ref, "data-testid": TestIds.serviceListRoot, variant: variant, children: children }));
|
|
83
60
|
} }));
|
|
84
61
|
});
|
|
85
62
|
/**
|
|
@@ -33,6 +33,18 @@ export interface RootProps {
|
|
|
33
33
|
* ```
|
|
34
34
|
*/
|
|
35
35
|
export declare const Root: React.ForwardRefExoticComponent<RootProps & React.RefAttributes<HTMLElement>>;
|
|
36
|
+
export declare enum TestIds {
|
|
37
|
+
timeSlotStartDate = "time-slot-start-date",
|
|
38
|
+
timeSlotEndDate = "time-slot-end-date",
|
|
39
|
+
timeSlotDuration = "time-slot-duration",
|
|
40
|
+
timeSlotActionSelect = "time-slot-action-select",
|
|
41
|
+
timeSlotActionClearStaffSelection = "time-slot-action-clear-staff-selection",
|
|
42
|
+
timeSlotLocationName = "time-slot-location-name",
|
|
43
|
+
timeSlotStaffMembers = "time-slot-staff-members",
|
|
44
|
+
timeSlotStaffMember = "time-slot-staff-member",
|
|
45
|
+
timeSlotStaffMemberName = "time-slot-staff-member-name",
|
|
46
|
+
timeSlotStaffMemberActionSelect = "time-slot-staff-member-action-select"
|
|
47
|
+
}
|
|
36
48
|
/**
|
|
37
49
|
* Props for TimeSlot.StartDate component
|
|
38
50
|
*/
|
|
@@ -31,7 +31,7 @@ Root.displayName = 'TimeSlot.Root';
|
|
|
31
31
|
// ============================================================================
|
|
32
32
|
// TestIds
|
|
33
33
|
// ============================================================================
|
|
34
|
-
var TestIds;
|
|
34
|
+
export var TestIds;
|
|
35
35
|
(function (TestIds) {
|
|
36
36
|
TestIds["timeSlotStartDate"] = "time-slot-start-date";
|
|
37
37
|
TestIds["timeSlotEndDate"] = "time-slot-end-date";
|
|
@@ -8,6 +8,18 @@ import { AsChildChildren } from '@wix/headless-utils/react';
|
|
|
8
8
|
import type { TimeSlot as TimeSlotType } from '@wix/auto_sdk_bookings_availability-time-slots';
|
|
9
9
|
import type { TimeSlotListServiceConfig } from '../../services/time-slot-list/time-slot-list.def.js';
|
|
10
10
|
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
|
+
/**
|
|
12
|
+
* TimeSlot with required id field for GenericList
|
|
13
|
+
*/
|
|
14
|
+
export declare enum TestIds {
|
|
15
|
+
timeSlotListRoot = "time-slot-list-root",
|
|
16
|
+
timeSlotListTimeSlots = "time-slot-list-time-slots",
|
|
17
|
+
timeSlotListTimeSlot = "time-slot-list-time-slot",
|
|
18
|
+
timeSlotListTimezone = "time-slot-list-timezone",
|
|
19
|
+
timeSlotListLoadMore = "time-slot-list-load-more",
|
|
20
|
+
timeSlotListContinue = "time-slot-list-continue",
|
|
21
|
+
timeSlotListDateRangeInput = "time-slot-list-date-range-input"
|
|
22
|
+
}
|
|
11
23
|
/**
|
|
12
24
|
* Render props for TimeSlotList.Timezone component
|
|
13
25
|
*/
|
|
@@ -21,7 +21,7 @@ function toISODateString(date) {
|
|
|
21
21
|
/**
|
|
22
22
|
* TimeSlot with required id field for GenericList
|
|
23
23
|
*/
|
|
24
|
-
var TestIds;
|
|
24
|
+
export var TestIds;
|
|
25
25
|
(function (TestIds) {
|
|
26
26
|
TestIds["timeSlotListRoot"] = "time-slot-list-root";
|
|
27
27
|
TestIds["timeSlotListTimeSlots"] = "time-slot-list-time-slots";
|
|
@@ -24,7 +24,7 @@ export interface ServiceListServiceConfig {
|
|
|
24
24
|
* Actions object for service list operations
|
|
25
25
|
*/
|
|
26
26
|
export interface ServiceListActions {
|
|
27
|
-
loadMore: (count
|
|
27
|
+
loadMore: (count?: number) => Promise<void>;
|
|
28
28
|
setQueryOptions: (options: QueryOptions) => void;
|
|
29
29
|
setFilter: (filter: Filter) => void;
|
|
30
30
|
resetFilter: () => void;
|
|
@@ -256,7 +256,6 @@ export const ServiceListService = implementService.withConfig()(ServiceListServi
|
|
|
256
256
|
const nextPaging = {
|
|
257
257
|
limit: count || DEFAULT_QUERY_LIMIT,
|
|
258
258
|
offset: nextOffset,
|
|
259
|
-
hasNext: false, // Will be updated after query
|
|
260
259
|
};
|
|
261
260
|
// Get effective filter from computed signal (includes location from BookingService)
|
|
262
261
|
const effectiveFilter = effectiveFilterSignal.get();
|
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { Service } from '@wix/auto_sdk_bookings_services';
|
|
6
6
|
import { type TimeSlotListServiceConfig, type TimeSlotsFilters } from './time-slot-list.def.js';
|
|
7
|
+
import { TimeSlot } from '@wix/auto_sdk_bookings_event-time-slots';
|
|
8
|
+
/**
|
|
9
|
+
* Helper to get staff member name from time slots by ID
|
|
10
|
+
* @internal - exported for testing
|
|
11
|
+
*/
|
|
12
|
+
export declare const getStaffName: (staffMemberId: string, slots: TimeSlot[]) => string | undefined;
|
|
7
13
|
export declare const TimeSlotListService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
8
14
|
__api: import("./time-slot-list.def.js").TimeSlotListServiceAPI;
|
|
9
15
|
__config: {};
|
|
@@ -16,7 +16,11 @@ const getClientTimezone = () => {
|
|
|
16
16
|
? Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
17
17
|
: undefined;
|
|
18
18
|
};
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Helper to get staff member name from time slots by ID
|
|
21
|
+
* @internal - exported for testing
|
|
22
|
+
*/
|
|
23
|
+
export const getStaffName = (staffMemberId, slots) => {
|
|
20
24
|
return (slots
|
|
21
25
|
.flatMap((slot) => slot.availableResources[0].resources)
|
|
22
26
|
.find((r) => r._id === staffMemberId)?.name ?? undefined);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/headless-bookings",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.85",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"groupId": "com.wixpress.headless-components"
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
|
-
"falconPackageHash": "
|
|
75
|
+
"falconPackageHash": "b386a6976f3f900e07276420a47b689690f92ec0e7d855efc476cefe"
|
|
76
76
|
}
|