@wix/headless-bookings 0.0.7 → 0.0.8
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/index.d.ts +5 -0
- package/cjs/dist/api/index.js +5 -0
- package/cjs/dist/api/query-service/index.d.ts +23 -0
- package/cjs/dist/api/query-service/index.js +41 -0
- package/cjs/dist/react/booking/Booking.d.ts +35 -0
- package/cjs/dist/react/booking/Booking.js +25 -0
- package/cjs/dist/react/core/booking/Booking.d.ts +58 -0
- package/cjs/dist/react/core/booking/Booking.js +50 -0
- package/cjs/dist/react/core/service/Service.d.ts +106 -0
- package/cjs/dist/react/core/service/Service.js +90 -0
- package/cjs/dist/react/index.d.ts +2 -4
- package/cjs/dist/react/index.js +2 -5
- package/cjs/dist/react/service/Service.d.ts +208 -0
- package/cjs/dist/react/service/Service.js +202 -0
- package/cjs/dist/services/booking/booking.d.ts +85 -0
- package/cjs/dist/services/booking/booking.js +74 -0
- package/cjs/dist/services/index.d.ts +6 -1
- package/cjs/dist/services/index.js +6 -1
- package/cjs/dist/services/{service-service.d.ts → service/service.d.ts} +27 -42
- package/cjs/dist/services/{service-service.js → service/service.js} +49 -48
- package/dist/api/index.d.ts +5 -0
- package/dist/api/index.js +5 -0
- package/dist/api/query-service/index.d.ts +23 -0
- package/dist/api/query-service/index.js +41 -0
- package/dist/react/booking/Booking.d.ts +35 -0
- package/dist/react/booking/Booking.js +25 -0
- package/dist/react/core/booking/Booking.d.ts +58 -0
- package/dist/react/core/booking/Booking.js +50 -0
- package/dist/react/core/service/Service.d.ts +106 -0
- package/dist/react/core/service/Service.js +90 -0
- package/dist/react/index.d.ts +2 -4
- package/dist/react/index.js +2 -5
- package/dist/react/service/Service.d.ts +208 -0
- package/dist/react/service/Service.js +202 -0
- package/dist/services/booking/booking.d.ts +85 -0
- package/dist/services/booking/booking.js +74 -0
- package/dist/services/index.d.ts +6 -1
- package/dist/services/index.js +6 -1
- package/dist/services/{service-service.d.ts → service/service.d.ts} +27 -42
- package/dist/services/{service-service.js → service/service.js} +49 -48
- package/package.json +3 -2
- package/cjs/dist/react/ServiceList.d.ts +0 -50
- package/cjs/dist/react/ServiceList.js +0 -100
- package/cjs/dist/react/ServiceListSort.d.ts +0 -37
- package/cjs/dist/react/ServiceListSort.js +0 -35
- package/cjs/dist/react/core/Service.d.ts +0 -91
- package/cjs/dist/react/core/Service.js +0 -73
- package/cjs/dist/react/core/ServiceList.d.ts +0 -218
- package/cjs/dist/react/core/ServiceList.js +0 -199
- package/cjs/dist/react/test-ids.d.ts +0 -18
- package/cjs/dist/react/test-ids.js +0 -24
- package/cjs/dist/react/types.d.ts +0 -52
- package/cjs/dist/react/types.js +0 -1
- package/cjs/dist/services/services-list-service.d.ts +0 -184
- package/cjs/dist/services/services-list-service.js +0 -168
- package/dist/react/ServiceList.d.ts +0 -50
- package/dist/react/ServiceList.js +0 -100
- package/dist/react/ServiceListSort.d.ts +0 -37
- package/dist/react/ServiceListSort.js +0 -35
- package/dist/react/core/Service.d.ts +0 -91
- package/dist/react/core/Service.js +0 -73
- package/dist/react/core/ServiceList.d.ts +0 -218
- package/dist/react/core/ServiceList.js +0 -199
- package/dist/react/test-ids.d.ts +0 -18
- package/dist/react/test-ids.js +0 -24
- package/dist/react/types.d.ts +0 -52
- package/dist/react/types.js +0 -1
- package/dist/services/services-list-service.d.ts +0 -184
- package/dist/services/services-list-service.js +0 -168
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useService, WixServices } from '@wix/services-manager-react';
|
|
3
|
-
import { createServicesMap } from '@wix/services-manager';
|
|
4
|
-
import { ServicesListService, ServicesListServiceDefinition, } from '../../services/services-list-service.js';
|
|
5
|
-
/**
|
|
6
|
-
* Root component that provides ServiceList service context to its children.
|
|
7
|
-
* This component sets up the necessary services for managing services list state,
|
|
8
|
-
* including filtering, sorting, and pagination functionality.
|
|
9
|
-
*
|
|
10
|
-
* @order 1
|
|
11
|
-
* @component
|
|
12
|
-
* @example
|
|
13
|
-
* ```tsx
|
|
14
|
-
* import { ServiceList, Service } from '@wix/headless-services/react';
|
|
15
|
-
*
|
|
16
|
-
* function ServiceListPage() {
|
|
17
|
-
* return (
|
|
18
|
-
* <ServiceList.Root
|
|
19
|
-
* servicesListConfig={{
|
|
20
|
-
* services: myServices,
|
|
21
|
-
* searchOptions: {
|
|
22
|
-
* cursorPaging: { limit: 10 },
|
|
23
|
-
* sort: [{ fieldName: 'name', order: 'ASC' }]
|
|
24
|
-
* },
|
|
25
|
-
* pagingMetadata: { count: 10, hasNext: true }
|
|
26
|
-
* }}
|
|
27
|
-
* >
|
|
28
|
-
* <ServiceList.Options>
|
|
29
|
-
* <ServiceList.ServiceRepeater>
|
|
30
|
-
* <Service.Name>
|
|
31
|
-
* {({ name }) => <h3>{name}</h3>}
|
|
32
|
-
* </Service.Name>
|
|
33
|
-
* <Service.Price>
|
|
34
|
-
* {({ price }) => price && <div>{price.value} {price.currency}</div>}
|
|
35
|
-
* </Service.Price>
|
|
36
|
-
* </ServiceList.ServiceRepeater>
|
|
37
|
-
* </ServiceList.Options>
|
|
38
|
-
* </ServiceList.Root>
|
|
39
|
-
* );
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export function Root(props) {
|
|
44
|
-
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(ServicesListServiceDefinition, ServicesListService, props.servicesListConfig), children: props.children }));
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Component that renders content when the services list is empty.
|
|
48
|
-
* Only displays its children when there are no services, no loading state, and no errors.
|
|
49
|
-
*
|
|
50
|
-
* @component
|
|
51
|
-
* @example
|
|
52
|
-
* ```tsx
|
|
53
|
-
* import { ServiceList } from '@wix/headless-services/react';
|
|
54
|
-
*
|
|
55
|
-
* function EmptyServicesMessage() {
|
|
56
|
-
* return (
|
|
57
|
-
* <ServiceList.EmptyState>
|
|
58
|
-
* {() => (
|
|
59
|
-
* <div className="empty-state">
|
|
60
|
-
* <h3>No services found</h3>
|
|
61
|
-
* <p>Try adjusting your search or filter criteria</p>
|
|
62
|
-
* <button>Clear Filters</button>
|
|
63
|
-
* </div>
|
|
64
|
-
* )}
|
|
65
|
-
* </ServiceList.EmptyState>
|
|
66
|
-
* );
|
|
67
|
-
* }
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
export function EmptyState(props) {
|
|
71
|
-
const { isLoading, error, services: servicesList, } = useService(ServicesListServiceDefinition);
|
|
72
|
-
const isLoadingValue = isLoading.get();
|
|
73
|
-
const errorValue = error.get();
|
|
74
|
-
const servicesValue = servicesList.get();
|
|
75
|
-
if (!isLoadingValue && !errorValue && servicesValue.length === 0) {
|
|
76
|
-
return typeof props.children === 'function'
|
|
77
|
-
? props.children({})
|
|
78
|
-
: props.children;
|
|
79
|
-
}
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Component that renders content during loading state.
|
|
84
|
-
* Only displays its children when the services list is currently loading.
|
|
85
|
-
*
|
|
86
|
-
* @component
|
|
87
|
-
* @example
|
|
88
|
-
* ```tsx
|
|
89
|
-
* import { ServiceList } from '@wix/headless-services/react';
|
|
90
|
-
*
|
|
91
|
-
* function ServicesLoading() {
|
|
92
|
-
* return (
|
|
93
|
-
* <ServiceList.Loading>
|
|
94
|
-
* {() => (
|
|
95
|
-
* <div className="loading-spinner">
|
|
96
|
-
* <div>Loading services...</div>
|
|
97
|
-
* <div className="spinner"></div>
|
|
98
|
-
* </div>
|
|
99
|
-
* )}
|
|
100
|
-
* </ServiceList.Loading>
|
|
101
|
-
* );
|
|
102
|
-
* }
|
|
103
|
-
* ```
|
|
104
|
-
*/
|
|
105
|
-
export function Loading(props) {
|
|
106
|
-
const { isLoading } = useService(ServicesListServiceDefinition);
|
|
107
|
-
const isLoadingValue = isLoading.get();
|
|
108
|
-
if (isLoadingValue) {
|
|
109
|
-
return typeof props.children === 'function'
|
|
110
|
-
? props.children({})
|
|
111
|
-
: props.children;
|
|
112
|
-
}
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Component that renders content when there's an error loading services.
|
|
117
|
-
* Only displays its children when an error has occurred.
|
|
118
|
-
*
|
|
119
|
-
* @component
|
|
120
|
-
* @example
|
|
121
|
-
* ```tsx
|
|
122
|
-
* import { ServiceList } from '@wix/headless-services/react';
|
|
123
|
-
*
|
|
124
|
-
* function ServicesError() {
|
|
125
|
-
* return (
|
|
126
|
-
* <ServiceList.Error>
|
|
127
|
-
* {({ error }) => (
|
|
128
|
-
* <div className="error-state">
|
|
129
|
-
* <h3>Error loading services</h3>
|
|
130
|
-
* <p>{error}</p>
|
|
131
|
-
* <button onClick={() => window.location.reload()}>
|
|
132
|
-
* Try Again
|
|
133
|
-
* </button>
|
|
134
|
-
* </div>
|
|
135
|
-
* )}
|
|
136
|
-
* </ServiceList.Error>
|
|
137
|
-
* );
|
|
138
|
-
* }
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
141
|
-
export function Error(props) {
|
|
142
|
-
const { error } = useService(ServicesListServiceDefinition);
|
|
143
|
-
const errorValue = error.get();
|
|
144
|
-
if (errorValue) {
|
|
145
|
-
return typeof props.children === 'function'
|
|
146
|
-
? props.children({ error: errorValue })
|
|
147
|
-
: props.children;
|
|
148
|
-
}
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Component that renders content for each service in the list.
|
|
153
|
-
* Maps over all services and provides each service through a service context.
|
|
154
|
-
* Only renders when services are successfully loaded (not loading, no error, and has services).
|
|
155
|
-
*
|
|
156
|
-
* @component
|
|
157
|
-
* @example
|
|
158
|
-
* ```tsx
|
|
159
|
-
* import { ServiceList, Service } from '@wix/headless-services/react';
|
|
160
|
-
*
|
|
161
|
-
* function ServicesGrid() {
|
|
162
|
-
* return (
|
|
163
|
-
* <ServiceList.ItemContent>
|
|
164
|
-
* {({ service }) => (
|
|
165
|
-
* <div className="service-card">
|
|
166
|
-
* <Service.Image>
|
|
167
|
-
* {({ image, alt }) => <img src={image} alt={alt} />}
|
|
168
|
-
* </Service.Image>
|
|
169
|
-
* <Service.Name>
|
|
170
|
-
* {({ name }) => <h3>{name}</h3>}
|
|
171
|
-
* </Service.Name>
|
|
172
|
-
* <Service.Price>
|
|
173
|
-
* {({ price }) => price && <p>{price.value} {price.currency}</p>}
|
|
174
|
-
* </Service.Price>
|
|
175
|
-
* <button>Book Now</button>
|
|
176
|
-
* </div>
|
|
177
|
-
* )}
|
|
178
|
-
* </ServiceList.ItemContent>
|
|
179
|
-
* );
|
|
180
|
-
* }
|
|
181
|
-
* ```
|
|
182
|
-
*/
|
|
183
|
-
export function ItemContent(props) {
|
|
184
|
-
const { services: servicesList, isLoading, error, } = useService(ServicesListServiceDefinition);
|
|
185
|
-
const servicesValue = servicesList.get();
|
|
186
|
-
if (isLoading.get() || error.get() || servicesValue.length === 0) {
|
|
187
|
-
return null;
|
|
188
|
-
}
|
|
189
|
-
return servicesValue.map((service) => (_jsx(WixServices, { servicesMap: createServicesMap(), children: typeof props.children === 'function'
|
|
190
|
-
? props.children({ service })
|
|
191
|
-
: props.children }, service._id)));
|
|
192
|
-
}
|
|
193
|
-
export function Items(props) {
|
|
194
|
-
const { services: servicesList } = useService(ServicesListServiceDefinition);
|
|
195
|
-
const servicesValue = servicesList.get();
|
|
196
|
-
return typeof props.children === 'function'
|
|
197
|
-
? props.children({ services: servicesValue })
|
|
198
|
-
: props.children;
|
|
199
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export declare enum TestIds {
|
|
2
|
-
servicesList = "services-list",
|
|
3
|
-
servicesOptions = "services-options",
|
|
4
|
-
serviceRepeater = "service-repeater",
|
|
5
|
-
serviceRoot = "service-root",
|
|
6
|
-
serviceName = "service-name",
|
|
7
|
-
serviceDescription = "service-description",
|
|
8
|
-
servicePrice = "service-price",
|
|
9
|
-
serviceDuration = "service-duration",
|
|
10
|
-
serviceImage = "service-image",
|
|
11
|
-
serviceCategory = "service-category",
|
|
12
|
-
serviceError = "service-error",
|
|
13
|
-
serviceLoadMore = "service-load-more",
|
|
14
|
-
serviceTotalsDisplayed = "service-totals-displayed",
|
|
15
|
-
serviceSort = "service-sort",
|
|
16
|
-
serviceFilter = "service-filter",
|
|
17
|
-
serviceFilterResetTrigger = "service-filter-reset-trigger"
|
|
18
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export var TestIds;
|
|
2
|
-
(function (TestIds) {
|
|
3
|
-
// Container Level
|
|
4
|
-
TestIds["servicesList"] = "services-list";
|
|
5
|
-
// List Container Level
|
|
6
|
-
TestIds["servicesOptions"] = "services-options";
|
|
7
|
-
// Repeater Level
|
|
8
|
-
TestIds["serviceRepeater"] = "service-repeater";
|
|
9
|
-
// Entity Root and Components
|
|
10
|
-
TestIds["serviceRoot"] = "service-root";
|
|
11
|
-
TestIds["serviceName"] = "service-name";
|
|
12
|
-
TestIds["serviceDescription"] = "service-description";
|
|
13
|
-
TestIds["servicePrice"] = "service-price";
|
|
14
|
-
TestIds["serviceDuration"] = "service-duration";
|
|
15
|
-
TestIds["serviceImage"] = "service-image";
|
|
16
|
-
TestIds["serviceCategory"] = "service-category";
|
|
17
|
-
// Additional Components
|
|
18
|
-
TestIds["serviceError"] = "service-error";
|
|
19
|
-
TestIds["serviceLoadMore"] = "service-load-more";
|
|
20
|
-
TestIds["serviceTotalsDisplayed"] = "service-totals-displayed";
|
|
21
|
-
TestIds["serviceSort"] = "service-sort";
|
|
22
|
-
TestIds["serviceFilter"] = "service-filter";
|
|
23
|
-
TestIds["serviceFilterResetTrigger"] = "service-filter-reset-trigger";
|
|
24
|
-
})(TestIds || (TestIds = {}));
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { services } from '@wix/bookings';
|
|
2
|
-
export interface ServiceListConfig {
|
|
3
|
-
services: services.Service[];
|
|
4
|
-
searchOptions: {
|
|
5
|
-
cursorPaging: {
|
|
6
|
-
limit: number;
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
pagingMetadata: {
|
|
10
|
-
count: number;
|
|
11
|
-
};
|
|
12
|
-
aggregations: {
|
|
13
|
-
results: any[];
|
|
14
|
-
};
|
|
15
|
-
customizations: any[];
|
|
16
|
-
}
|
|
17
|
-
export interface ServiceContextValue {
|
|
18
|
-
service: services.Service;
|
|
19
|
-
}
|
|
20
|
-
export interface ServiceListRenderProps {
|
|
21
|
-
services: services.Service[];
|
|
22
|
-
}
|
|
23
|
-
export interface ServiceRenderProps {
|
|
24
|
-
service: services.Service;
|
|
25
|
-
}
|
|
26
|
-
export interface ErrorRenderProps {
|
|
27
|
-
error: string | null;
|
|
28
|
-
}
|
|
29
|
-
export interface ServiceListState {
|
|
30
|
-
services: services.Service[];
|
|
31
|
-
pagingMetadata: {
|
|
32
|
-
count: number;
|
|
33
|
-
};
|
|
34
|
-
filters: Record<string, any>;
|
|
35
|
-
error: string | null;
|
|
36
|
-
}
|
|
37
|
-
export interface ServiceListServiceValue {
|
|
38
|
-
services: {
|
|
39
|
-
get: () => services.Service[];
|
|
40
|
-
};
|
|
41
|
-
pagingMetadata: {
|
|
42
|
-
get: () => {
|
|
43
|
-
count: number;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
filters: {
|
|
47
|
-
get: () => Record<string, any>;
|
|
48
|
-
};
|
|
49
|
-
error: {
|
|
50
|
-
get: () => string | null;
|
|
51
|
-
};
|
|
52
|
-
}
|
package/cjs/dist/react/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { type Signal, type ReadOnlySignal } from '@wix/services-definitions/core-services/signals';
|
|
2
|
-
import { services } from '@wix/bookings';
|
|
3
|
-
export declare const DEFAULT_QUERY_LIMIT = 100;
|
|
4
|
-
/**
|
|
5
|
-
* Configuration interface for the Services List service.
|
|
6
|
-
* Contains the initial services data, search options, and metadata.
|
|
7
|
-
*
|
|
8
|
-
* @interface ServicesListServiceConfig
|
|
9
|
-
*/
|
|
10
|
-
export interface ServicesListServiceConfig {
|
|
11
|
-
/** Array of service objects to initialize the service with */
|
|
12
|
-
services: services.Service[];
|
|
13
|
-
/** Search options used to fetch the services */
|
|
14
|
-
searchOptions?: {
|
|
15
|
-
cursorPaging?: {
|
|
16
|
-
limit: number;
|
|
17
|
-
};
|
|
18
|
-
filter?: Record<string, any>;
|
|
19
|
-
sort?: Array<{
|
|
20
|
-
fieldName: string;
|
|
21
|
-
order: 'ASC' | 'DESC';
|
|
22
|
-
}>;
|
|
23
|
-
};
|
|
24
|
-
/** Pagination metadata from the search response */
|
|
25
|
-
pagingMetadata?: {
|
|
26
|
-
count: number;
|
|
27
|
-
cursors?: {
|
|
28
|
-
next?: () => Promise<services.ServicesQueryResult>;
|
|
29
|
-
prev?: () => Promise<services.ServicesQueryResult>;
|
|
30
|
-
};
|
|
31
|
-
hasNext?: boolean;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Service definition for the Services List service.
|
|
36
|
-
* This defines the reactive API contract for managing a list of services with search, pagination, and filtering capabilities.
|
|
37
|
-
*
|
|
38
|
-
* @constant
|
|
39
|
-
*/
|
|
40
|
-
export declare const ServicesListServiceDefinition: string & {
|
|
41
|
-
__api: {
|
|
42
|
-
/** Reactive signal containing the list of services */
|
|
43
|
-
services: Signal<services.Service[]>;
|
|
44
|
-
/** Reactive signal containing pagination metadata */
|
|
45
|
-
pagingMetadata: Signal<ServicesListServiceConfig["pagingMetadata"]>;
|
|
46
|
-
/** Reactive signal indicating if services are currently being loaded */
|
|
47
|
-
isLoading: Signal<boolean>;
|
|
48
|
-
/** Reactive signal containing any error message, or null if no error*/
|
|
49
|
-
error: Signal<string | null>;
|
|
50
|
-
/** Reactive signal containing the current sort configuration */
|
|
51
|
-
sort: Signal<{
|
|
52
|
-
fieldName: string;
|
|
53
|
-
order: "ASC" | "DESC";
|
|
54
|
-
}[]>;
|
|
55
|
-
/** Reactive signal containing the current filter configuration */
|
|
56
|
-
filters: Signal<Record<string, any>>;
|
|
57
|
-
/** Function to update sort configuration */
|
|
58
|
-
setSort: (sort: {
|
|
59
|
-
fieldName: string;
|
|
60
|
-
order: "ASC" | "DESC";
|
|
61
|
-
}[]) => void;
|
|
62
|
-
/** Function to update filter configuration */
|
|
63
|
-
setFilter: (filter: Record<string, any>) => void;
|
|
64
|
-
/** Function to reset filter configuration */
|
|
65
|
-
resetFilter: () => void;
|
|
66
|
-
/** Reactive signal indicating if any filters are currently applied */
|
|
67
|
-
isFiltered: () => ReadOnlySignal<boolean>;
|
|
68
|
-
/** Function to load more services */
|
|
69
|
-
loadMore: (count: number) => void;
|
|
70
|
-
/** Reactive signal indicating if there are more services to load */
|
|
71
|
-
hasMoreServices: ReadOnlySignal<boolean>;
|
|
72
|
-
};
|
|
73
|
-
__config: ServicesListServiceConfig;
|
|
74
|
-
isServiceDefinition?: boolean;
|
|
75
|
-
} & {
|
|
76
|
-
/** Reactive signal containing the list of services */
|
|
77
|
-
services: Signal<services.Service[]>;
|
|
78
|
-
/** Reactive signal containing pagination metadata */
|
|
79
|
-
pagingMetadata: Signal<ServicesListServiceConfig["pagingMetadata"]>;
|
|
80
|
-
/** Reactive signal indicating if services are currently being loaded */
|
|
81
|
-
isLoading: Signal<boolean>;
|
|
82
|
-
/** Reactive signal containing any error message, or null if no error*/
|
|
83
|
-
error: Signal<string | null>;
|
|
84
|
-
/** Reactive signal containing the current sort configuration */
|
|
85
|
-
sort: Signal<{
|
|
86
|
-
fieldName: string;
|
|
87
|
-
order: "ASC" | "DESC";
|
|
88
|
-
}[]>;
|
|
89
|
-
/** Reactive signal containing the current filter configuration */
|
|
90
|
-
filters: Signal<Record<string, any>>;
|
|
91
|
-
/** Function to update sort configuration */
|
|
92
|
-
setSort: (sort: {
|
|
93
|
-
fieldName: string;
|
|
94
|
-
order: "ASC" | "DESC";
|
|
95
|
-
}[]) => void;
|
|
96
|
-
/** Function to update filter configuration */
|
|
97
|
-
setFilter: (filter: Record<string, any>) => void;
|
|
98
|
-
/** Function to reset filter configuration */
|
|
99
|
-
resetFilter: () => void;
|
|
100
|
-
/** Reactive signal indicating if any filters are currently applied */
|
|
101
|
-
isFiltered: () => ReadOnlySignal<boolean>;
|
|
102
|
-
/** Function to load more services */
|
|
103
|
-
loadMore: (count: number) => void;
|
|
104
|
-
/** Reactive signal indicating if there are more services to load */
|
|
105
|
-
hasMoreServices: ReadOnlySignal<boolean>;
|
|
106
|
-
};
|
|
107
|
-
/**
|
|
108
|
-
* Implementation of the Services List service that manages reactive services data.
|
|
109
|
-
* This service provides signals for services data, search options, pagination,
|
|
110
|
-
* loading state, and error handling.
|
|
111
|
-
*/
|
|
112
|
-
export declare const ServicesListService: import("@wix/services-definitions").ServiceFactory<string & {
|
|
113
|
-
__api: {
|
|
114
|
-
/** Reactive signal containing the list of services */
|
|
115
|
-
services: Signal<services.Service[]>;
|
|
116
|
-
/** Reactive signal containing pagination metadata */
|
|
117
|
-
pagingMetadata: Signal<ServicesListServiceConfig["pagingMetadata"]>;
|
|
118
|
-
/** Reactive signal indicating if services are currently being loaded */
|
|
119
|
-
isLoading: Signal<boolean>;
|
|
120
|
-
/** Reactive signal containing any error message, or null if no error*/
|
|
121
|
-
error: Signal<string | null>;
|
|
122
|
-
/** Reactive signal containing the current sort configuration */
|
|
123
|
-
sort: Signal<{
|
|
124
|
-
fieldName: string;
|
|
125
|
-
order: "ASC" | "DESC";
|
|
126
|
-
}[]>;
|
|
127
|
-
/** Reactive signal containing the current filter configuration */
|
|
128
|
-
filters: Signal<Record<string, any>>;
|
|
129
|
-
/** Function to update sort configuration */
|
|
130
|
-
setSort: (sort: {
|
|
131
|
-
fieldName: string;
|
|
132
|
-
order: "ASC" | "DESC";
|
|
133
|
-
}[]) => void;
|
|
134
|
-
/** Function to update filter configuration */
|
|
135
|
-
setFilter: (filter: Record<string, any>) => void;
|
|
136
|
-
/** Function to reset filter configuration */
|
|
137
|
-
resetFilter: () => void;
|
|
138
|
-
/** Reactive signal indicating if any filters are currently applied */
|
|
139
|
-
isFiltered: () => ReadOnlySignal<boolean>;
|
|
140
|
-
/** Function to load more services */
|
|
141
|
-
loadMore: (count: number) => void;
|
|
142
|
-
/** Reactive signal indicating if there are more services to load */
|
|
143
|
-
hasMoreServices: ReadOnlySignal<boolean>;
|
|
144
|
-
};
|
|
145
|
-
__config: ServicesListServiceConfig;
|
|
146
|
-
isServiceDefinition?: boolean;
|
|
147
|
-
} & {
|
|
148
|
-
/** Reactive signal containing the list of services */
|
|
149
|
-
services: Signal<services.Service[]>;
|
|
150
|
-
/** Reactive signal containing pagination metadata */
|
|
151
|
-
pagingMetadata: Signal<ServicesListServiceConfig["pagingMetadata"]>;
|
|
152
|
-
/** Reactive signal indicating if services are currently being loaded */
|
|
153
|
-
isLoading: Signal<boolean>;
|
|
154
|
-
/** Reactive signal containing any error message, or null if no error*/
|
|
155
|
-
error: Signal<string | null>;
|
|
156
|
-
/** Reactive signal containing the current sort configuration */
|
|
157
|
-
sort: Signal<{
|
|
158
|
-
fieldName: string;
|
|
159
|
-
order: "ASC" | "DESC";
|
|
160
|
-
}[]>;
|
|
161
|
-
/** Reactive signal containing the current filter configuration */
|
|
162
|
-
filters: Signal<Record<string, any>>;
|
|
163
|
-
/** Function to update sort configuration */
|
|
164
|
-
setSort: (sort: {
|
|
165
|
-
fieldName: string;
|
|
166
|
-
order: "ASC" | "DESC";
|
|
167
|
-
}[]) => void;
|
|
168
|
-
/** Function to update filter configuration */
|
|
169
|
-
setFilter: (filter: Record<string, any>) => void;
|
|
170
|
-
/** Function to reset filter configuration */
|
|
171
|
-
resetFilter: () => void;
|
|
172
|
-
/** Reactive signal indicating if any filters are currently applied */
|
|
173
|
-
isFiltered: () => ReadOnlySignal<boolean>;
|
|
174
|
-
/** Function to load more services */
|
|
175
|
-
loadMore: (count: number) => void;
|
|
176
|
-
/** Reactive signal indicating if there are more services to load */
|
|
177
|
-
hasMoreServices: ReadOnlySignal<boolean>;
|
|
178
|
-
}, ServicesListServiceConfig>;
|
|
179
|
-
/**
|
|
180
|
-
* Loads services list service configuration from the Wix Bookings API for SSR initialization.
|
|
181
|
-
* This function is designed to be used during Server-Side Rendering (SSR) to preload
|
|
182
|
-
* a list of services based on search criteria.
|
|
183
|
-
*/
|
|
184
|
-
export declare function loadServicesListServiceConfig(searchOptions?: ServicesListServiceConfig['searchOptions']): Promise<ServicesListServiceConfig>;
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { defineService, implementService } from '@wix/services-definitions';
|
|
2
|
-
import { SignalsServiceDefinition, } from '@wix/services-definitions/core-services/signals';
|
|
3
|
-
import { services } from '@wix/bookings';
|
|
4
|
-
export const DEFAULT_QUERY_LIMIT = 100;
|
|
5
|
-
/**
|
|
6
|
-
* Fetches services using the Wix Bookings API.
|
|
7
|
-
* This function handles pagination and returns both services and metadata.
|
|
8
|
-
*
|
|
9
|
-
* @param searchOptions - The search options for querying services
|
|
10
|
-
* @returns Promise that resolves to the search result
|
|
11
|
-
*/
|
|
12
|
-
const fetchServices = async (searchOptions = {}) => {
|
|
13
|
-
try {
|
|
14
|
-
let query = services.queryServices();
|
|
15
|
-
// Apply pagination
|
|
16
|
-
if (searchOptions.cursorPaging?.limit) {
|
|
17
|
-
query = query.limit(searchOptions.cursorPaging.limit);
|
|
18
|
-
}
|
|
19
|
-
// Apply sorting
|
|
20
|
-
if (searchOptions.sort?.length) {
|
|
21
|
-
const { order, fieldName } = searchOptions.sort[0];
|
|
22
|
-
if (order === 'ASC') {
|
|
23
|
-
query = query.ascending(fieldName);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
query = query.descending(fieldName);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
const result = await query.find();
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
console.error('Error fetching services:', error);
|
|
34
|
-
throw error;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Service definition for the Services List service.
|
|
39
|
-
* This defines the reactive API contract for managing a list of services with search, pagination, and filtering capabilities.
|
|
40
|
-
*
|
|
41
|
-
* @constant
|
|
42
|
-
*/
|
|
43
|
-
export const ServicesListServiceDefinition = defineService('services-list');
|
|
44
|
-
/**
|
|
45
|
-
* Implementation of the Services List service that manages reactive services data.
|
|
46
|
-
* This service provides signals for services data, search options, pagination,
|
|
47
|
-
* loading state, and error handling.
|
|
48
|
-
*/
|
|
49
|
-
export const ServicesListService = implementService.withConfig()(ServicesListServiceDefinition, ({ getService, config }) => {
|
|
50
|
-
let firstRun = true;
|
|
51
|
-
const signalsService = getService(SignalsServiceDefinition);
|
|
52
|
-
const servicesSignal = signalsService.signal(config.services);
|
|
53
|
-
const pagingMetadataSignal = signalsService.signal(config.pagingMetadata || { count: 0 });
|
|
54
|
-
const isLoadingSignal = signalsService.signal(false);
|
|
55
|
-
const errorSignal = signalsService.signal(null);
|
|
56
|
-
const sortSignal = signalsService.signal(config.searchOptions?.sort || []);
|
|
57
|
-
const filtersSignal = signalsService.signal(config.searchOptions?.filter || {});
|
|
58
|
-
if (typeof window !== 'undefined') {
|
|
59
|
-
signalsService.effect(async () => {
|
|
60
|
-
// Read signals to establish dependencies
|
|
61
|
-
const sort = sortSignal.get();
|
|
62
|
-
const filters = filtersSignal.get();
|
|
63
|
-
if (firstRun) {
|
|
64
|
-
firstRun = false;
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
try {
|
|
68
|
-
isLoadingSignal.set(true);
|
|
69
|
-
const result = await fetchServices({
|
|
70
|
-
cursorPaging: { limit: DEFAULT_QUERY_LIMIT },
|
|
71
|
-
sort,
|
|
72
|
-
filter: filters,
|
|
73
|
-
});
|
|
74
|
-
servicesSignal.set(result.items);
|
|
75
|
-
pagingMetadataSignal.set({
|
|
76
|
-
count: result.totalCount || 0,
|
|
77
|
-
cursors: {
|
|
78
|
-
next: result.next,
|
|
79
|
-
prev: result.prev,
|
|
80
|
-
},
|
|
81
|
-
hasNext: result.hasNext(),
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
catch (error) {
|
|
85
|
-
errorSignal.set(error instanceof Error ? error.message : 'Unknown error');
|
|
86
|
-
}
|
|
87
|
-
finally {
|
|
88
|
-
isLoadingSignal.set(false);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
firstRun = false;
|
|
93
|
-
const loadMoreServices = async () => {
|
|
94
|
-
try {
|
|
95
|
-
isLoadingSignal.set(true);
|
|
96
|
-
const result = await pagingMetadataSignal?.peek()?.cursors?.next?.();
|
|
97
|
-
servicesSignal.set([
|
|
98
|
-
...servicesSignal.peek(),
|
|
99
|
-
...(result?.items ?? []),
|
|
100
|
-
]);
|
|
101
|
-
pagingMetadataSignal.set({
|
|
102
|
-
count: result?.totalCount || 0,
|
|
103
|
-
cursors: {
|
|
104
|
-
next: result?.next,
|
|
105
|
-
prev: result?.prev,
|
|
106
|
-
},
|
|
107
|
-
hasNext: result?.hasNext(),
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
errorSignal.set(error instanceof Error ? error.message : 'Unknown error');
|
|
112
|
-
}
|
|
113
|
-
finally {
|
|
114
|
-
isLoadingSignal.set(false);
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
return {
|
|
118
|
-
services: servicesSignal,
|
|
119
|
-
pagingMetadata: pagingMetadataSignal,
|
|
120
|
-
isLoading: isLoadingSignal,
|
|
121
|
-
error: errorSignal,
|
|
122
|
-
sort: sortSignal,
|
|
123
|
-
filters: filtersSignal,
|
|
124
|
-
setSort: (sort) => {
|
|
125
|
-
sortSignal.set(sort);
|
|
126
|
-
},
|
|
127
|
-
setFilter: (filter) => {
|
|
128
|
-
filtersSignal.set(filter);
|
|
129
|
-
},
|
|
130
|
-
resetFilter: () => {
|
|
131
|
-
filtersSignal.set({});
|
|
132
|
-
},
|
|
133
|
-
isFiltered: () => {
|
|
134
|
-
return signalsService.computed(() => {
|
|
135
|
-
const filters = filtersSignal.peek();
|
|
136
|
-
return Object.keys(filters).length > 0;
|
|
137
|
-
});
|
|
138
|
-
},
|
|
139
|
-
loadMore: loadMoreServices,
|
|
140
|
-
hasMoreServices: signalsService.computed(() => pagingMetadataSignal.get()?.hasNext ?? false),
|
|
141
|
-
};
|
|
142
|
-
});
|
|
143
|
-
/**
|
|
144
|
-
* Loads services list service configuration from the Wix Bookings API for SSR initialization.
|
|
145
|
-
* This function is designed to be used during Server-Side Rendering (SSR) to preload
|
|
146
|
-
* a list of services based on search criteria.
|
|
147
|
-
*/
|
|
148
|
-
export async function loadServicesListServiceConfig(searchOptions) {
|
|
149
|
-
try {
|
|
150
|
-
const result = await fetchServices(searchOptions);
|
|
151
|
-
return {
|
|
152
|
-
services: result.items ?? [],
|
|
153
|
-
searchOptions,
|
|
154
|
-
pagingMetadata: {
|
|
155
|
-
count: result.totalCount ?? 0,
|
|
156
|
-
cursors: {
|
|
157
|
-
next: result.next,
|
|
158
|
-
prev: result.prev,
|
|
159
|
-
},
|
|
160
|
-
hasNext: result.hasNext(),
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
catch (error) {
|
|
165
|
-
console.error('Error loading services configuration:', error);
|
|
166
|
-
throw error;
|
|
167
|
-
}
|
|
168
|
-
}
|