@wix/headless-restaurants-olo 0.0.24 → 0.0.26

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.
@@ -1,10 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useEffect, useState } from 'react';
3
2
  import { createServicesMap } from '@wix/services-manager';
4
3
  import { WixServices } from '@wix/services-manager-react';
5
4
  // import { ItemService, ItemServiceDefinition, loadItemServiceConfig } from '@/components/restaurants-olo/services/itemDetailsService';
6
5
  import { OLOSettingsService, OLOSettingsServiceDefinition, } from '@wix/headless-restaurants-olo/services';
7
- import { FulfillmentsService, FulfillmentsServiceDefinition, loadFulfillmentsServiceConfig, } from '../../services/fulfillments-service.js';
8
6
  /**
9
7
  * Core OLO Root component that sets up service management
10
8
  * Provides ItemService and CurrentCartService to child components
@@ -24,83 +22,8 @@ import { FulfillmentsService, FulfillmentsServiceDefinition, loadFulfillmentsSer
24
22
  * </CoreOLO.Root>
25
23
  * ```
26
24
  */
27
- export const Root = ({ itemId, itemServiceConfig, cartServiceConfig, oloSettingsServiceConfig, children, }) => {
28
- const [fulfillmentsServiceConfig, setFulfillmentsServiceConfig] = useState({
29
- operation: oloSettingsServiceConfig?.operation ?? undefined,
30
- });
31
- // const [servicesManager, setServicesManager] = useState<ServicesManager | null>(null);
32
- // const [isLoading, setIsLoading] = useState(true);
33
- // const [error, setError] = useState<string | undefined>();
34
- useEffect(() => {
35
- // const initializeServices = async () => {
36
- // setIsLoading(true);
37
- // setError(undefined);
38
- // try {
39
- // // Load configurations if not provided
40
- // const loadedConfigs = await Promise.all([
41
- // cartServiceConfig || loadCurrentCartServiceConfig(),
42
- // itemServiceConfig || (loadItemServiceConfig(itemId))
43
- // ]);
44
- // const [currentCartServiceConfig, itemServiceConfigResult] = loadedConfigs;
45
- // // Handle item service config result (discriminated union)
46
- // if (itemServiceConfigResult && 'type' in itemServiceConfigResult) {
47
- // if (itemServiceConfigResult.type === 'notFound') {
48
- // setError('Item not found');
49
- // return;
50
- // }
51
- // // Use the config from the success result
52
- // const finalItemServiceConfig = itemServiceConfigResult.config;
53
- // // Create services manager with both services
54
- // const manager = createServicesManager(
55
- // createServicesMap()
56
- // .addService(CurrentCartServiceDefinition, CurrentCartService, currentCartServiceConfig)
57
- // // .addService(ItemServiceDefinition, ItemService, finalItemServiceConfig)
58
- // );
59
- // setServicesManager(manager);
60
- // } else if (itemServiceConfigResult) {
61
- // // Direct config provided
62
- // const manager = createServicesManager(
63
- // createServicesMap()
64
- // .addService(CurrentCartServiceDefinition, CurrentCartService, currentCartServiceConfig)
65
- // // .addService(ItemServiceDefinition, ItemService, itemServiceConfigResult)
66
- // );
67
- // setServicesManager(manager);
68
- // } else {
69
- // // Only cart service, no item service
70
- // const manager = createServicesManager(
71
- // createServicesMap()
72
- // .addService(CurrentCartServiceDefinition, CurrentCartService, currentCartServiceConfig)
73
- // );
74
- // setServicesManager(manager);
75
- // }
76
- // } catch (err) {
77
- // console.error('Failed to initialize services:', err);
78
- // setError('Failed to initialize services');
79
- // } finally {
80
- // setIsLoading(false);
81
- // }
82
- // };
83
- // initializeServices();
84
- }, [itemId, itemServiceConfig, cartServiceConfig]);
85
- // const hasServices = Boolean(servicesManager);
86
- // return children({
87
- // servicesManager,
88
- // isLoading,
89
- // error,
90
- // hasServices
91
- // });
92
- console.log('oloSettingsServiceConfig', oloSettingsServiceConfig);
93
- useEffect(() => {
94
- if (oloSettingsServiceConfig?.operation?._id) {
95
- loadFulfillmentsServiceConfig(oloSettingsServiceConfig.operation).then((config) => {
96
- console.log('config', config);
97
- setFulfillmentsServiceConfig(config);
98
- });
99
- }
100
- }, [oloSettingsServiceConfig?.operation?._id]);
101
- return (_jsx(WixServices, { servicesMap: createServicesMap()
102
- .addService(OLOSettingsServiceDefinition, OLOSettingsService, oloSettingsServiceConfig)
103
- .addService(FulfillmentsServiceDefinition, FulfillmentsService, fulfillmentsServiceConfig), children: children }));
25
+ export const Root = ({ oloSettingsServiceConfig, children, }) => {
26
+ return (_jsx(WixServices, { servicesMap: createServicesMap().addService(OLOSettingsServiceDefinition, OLOSettingsService, oloSettingsServiceConfig), children: children }));
104
27
  };
105
28
  /**
106
29
  * Convenience wrapper that combines Root with ServicesManagerProvider
@@ -1,89 +1,58 @@
1
1
  import React from 'react';
2
2
  import * as operationsSDK from '@wix/auto_sdk_restaurants_operations';
3
- import { TimeSlot } from '../../types/fulfillments-types.js';
4
- interface CurrentTime {
5
- timeSlot: string;
6
- }
7
- interface CurrentFulfillment {
8
- current?: operationsSDK.TimeSlot;
9
- }
10
- interface CurrentLocation {
11
- name: string;
12
- }
13
- interface ExtraData {
14
- acceptingOrders: boolean;
15
- deliveryFee?: number;
16
- minOrderAmount?: number;
17
- freeDeliveryThreshold?: number;
18
- taxRate?: number;
19
- serviceCharge?: number;
20
- isOnline?: boolean;
21
- orderingDisabledReason?: string;
22
- }
23
- interface SettingsData {
24
- currentTime: CurrentTime;
25
- currentFulfillment: CurrentFulfillment;
26
- currentLocation: CurrentLocation;
27
- selectedFulfillment: any;
28
- extraData: ExtraData;
29
- isLoading: boolean;
30
- error?: string | null;
31
- }
32
- interface SettingsRootProps {
33
- children: (props: SettingsData) => React.ReactNode;
3
+ import { FulfillmentsServiceConfig, TimeSlot } from '../../types/fulfillments-types.js';
4
+ export interface RootProps {
5
+ children: (props: {
6
+ isLoading: boolean;
7
+ }) => React.ReactNode;
8
+ fulfillmentsServiceConfig?: FulfillmentsServiceConfig;
34
9
  }
35
10
  /**
36
- * Core Settings component that provides access to OLO settings data
37
- * Integrates with OLOSettingsService to expose operation and operation group data
11
+ * Core Settings Root component that provides service context
12
+ * Wraps children with both OLOSettingsService and FulfillmentsService providers
38
13
  *
39
14
  * @example
40
15
  * ```tsx
41
- * <CoreSettings.Root>
42
- * {({ currentDetails, currentFulfillment, currentLocation, extraData, isLoading, error }) => (
43
- * isLoading ? (
44
- * <div>Loading settings...</div>
45
- * ) : error ? (
46
- * <div>Error: {error}</div>
47
- * ) : (
48
- * <div>
49
- * <h2>{currentDetails.name}</h2>
50
- * <p>Accepting Orders: {extraData.acceptingOrders ? 'Yes' : 'No'}</p>
51
- * <p>Delivery Fee: ${extraData.deliveryFee}</p>
52
- * </div>
53
- * )
54
- * )}
16
+ * <CoreSettings.Root fulfillmentsServiceConfig={config}>
17
+ * <CoreSettings.CurrentTimeSlot>
18
+ * {({ timeSlot, hasDetails }) => (
19
+ * <div>{timeSlot?.dispatchType}</div>
20
+ * )}
21
+ * </CoreSettings.CurrentTimeSlot>
55
22
  * </CoreSettings.Root>
56
23
  * ```
57
24
  */
58
- export declare const Root: React.FC<SettingsRootProps>;
59
- interface CurrentTimeSlotProps {
25
+ export declare const Root: React.FC<RootProps>;
26
+ export interface CurrentTimeSlotProps {
60
27
  children: (props: {
61
28
  timeSlot: TimeSlot;
62
29
  hasDetails: boolean;
63
30
  }) => React.ReactNode;
64
31
  }
65
32
  /**
66
- * Component that provides access to current store details
33
+ * Component that provides access to current time slot
67
34
  *
68
35
  * @example
69
36
  * ```tsx
70
37
  * <CoreSettings.CurrentTimeSlot>
71
- * {({ details, hasDetails }) => (
38
+ * {({ timeSlot, hasDetails }) => (
72
39
  * hasDetails ? (
73
40
  * <div>
74
- * <h3>{details.timeSlot}</h3>
41
+ * <h3>{timeSlot.dispatchType}</h3>
75
42
  * </div>
76
43
  * ) : (
77
- * <div>No store details available</div>
44
+ * <div>No time slot selected</div>
78
45
  * )
79
46
  * )}
80
47
  * </CoreSettings.CurrentTimeSlot>
81
48
  * ```
82
49
  */
83
50
  export declare const CurrentTimeSlot: React.FC<CurrentTimeSlotProps>;
84
- interface CurrentFulfillmentProps {
51
+ export interface CurrentFulfillmentProps {
85
52
  children: (props: {
86
- fulfillment: CurrentFulfillment;
53
+ fulfillment: {
54
+ current?: operationsSDK.TimeSlot;
55
+ };
87
56
  hasFulfillment: boolean;
88
57
  availableOptions: string[];
89
58
  }) => React.ReactNode;
@@ -106,9 +75,11 @@ interface CurrentFulfillmentProps {
106
75
  * ```
107
76
  */
108
77
  export declare const CurrentFulfillment: React.FC<CurrentFulfillmentProps>;
109
- interface CurrentLocationProps {
78
+ export interface CurrentLocationProps {
110
79
  children: (props: {
111
- location: CurrentLocation;
80
+ location: {
81
+ name: string;
82
+ };
112
83
  hasLocation: boolean;
113
84
  }) => React.ReactNode;
114
85
  }
@@ -118,21 +89,27 @@ interface CurrentLocationProps {
118
89
  * @example
119
90
  * ```tsx
120
91
  * <CoreSettings.CurrentLocation>
121
- * {({ location, hasCoordinates }) => (
92
+ * {({ location, hasLocation }) => (
122
93
  * <div>
123
- * <p>{location.address}</p>
124
- * {hasCoordinates && (
125
- * <p>Coordinates: {location.latitude}, {location.longitude}</p>
126
- * )}
94
+ * <p>{location.name}</p>
127
95
  * </div>
128
96
  * )}
129
97
  * </CoreSettings.CurrentLocation>
130
98
  * ```
131
99
  */
132
100
  export declare const CurrentLocation: React.FC<CurrentLocationProps>;
133
- interface ExtraDataProps {
101
+ export interface ExtraDataProps {
134
102
  children: (props: {
135
- extraData: ExtraData;
103
+ extraData: {
104
+ acceptingOrders: boolean;
105
+ deliveryFee?: number;
106
+ minOrderAmount?: number;
107
+ freeDeliveryThreshold?: number;
108
+ taxRate?: number;
109
+ serviceCharge?: number;
110
+ isOnline?: boolean;
111
+ orderingDisabledReason?: string;
112
+ };
136
113
  hasExtraData: boolean;
137
114
  }) => React.ReactNode;
138
115
  }
@@ -154,4 +131,3 @@ interface ExtraDataProps {
154
131
  * ```
155
132
  */
156
133
  export declare const ExtraData: React.FC<ExtraDataProps>;
157
- export {};
@@ -1,109 +1,63 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useService } from '@wix/services-manager-react';
2
+ import { useEffect, useState } from 'react';
3
+ import { WixServices, useService } from '@wix/services-manager-react';
3
4
  import { OLOSettingsServiceDefinition } from '../../services/olo-settings-service.js';
4
- import { FulfillmentsServiceDefinition } from '../../services/fulfillments-service.js';
5
+ import { FulfillmentsService, FulfillmentsServiceDefinition, loadFulfillmentsServiceConfig, } from '../../services/fulfillments-service.js';
6
+ import { createServicesMap } from '@wix/services-manager';
5
7
  /**
6
- * Core Settings component that provides access to OLO settings data
7
- * Integrates with OLOSettingsService to expose operation and operation group data
8
+ * Core Settings Root component that provides service context
9
+ * Wraps children with both OLOSettingsService and FulfillmentsService providers
8
10
  *
9
11
  * @example
10
12
  * ```tsx
11
- * <CoreSettings.Root>
12
- * {({ currentDetails, currentFulfillment, currentLocation, extraData, isLoading, error }) => (
13
- * isLoading ? (
14
- * <div>Loading settings...</div>
15
- * ) : error ? (
16
- * <div>Error: {error}</div>
17
- * ) : (
18
- * <div>
19
- * <h2>{currentDetails.name}</h2>
20
- * <p>Accepting Orders: {extraData.acceptingOrders ? 'Yes' : 'No'}</p>
21
- * <p>Delivery Fee: ${extraData.deliveryFee}</p>
22
- * </div>
23
- * )
24
- * )}
13
+ * <CoreSettings.Root fulfillmentsServiceConfig={config}>
14
+ * <CoreSettings.CurrentTimeSlot>
15
+ * {({ timeSlot, hasDetails }) => (
16
+ * <div>{timeSlot?.dispatchType}</div>
17
+ * )}
18
+ * </CoreSettings.CurrentTimeSlot>
25
19
  * </CoreSettings.Root>
26
20
  * ```
27
21
  */
28
- export const Root = ({ children }) => {
22
+ export const Root = ({ children, fulfillmentsServiceConfig, }) => {
29
23
  const service = useService(OLOSettingsServiceDefinition);
30
- const fulfillmentsService = useService(FulfillmentsServiceDefinition);
31
- const operation = service.operation?.get();
32
- const selectedFulfillment = fulfillmentsService.selectedFulfillment?.get();
33
- console.log('selectedFulfillment', selectedFulfillment);
34
- const isLoading = service.isLoading?.get() ?? false;
35
- const error = service.error?.get();
36
- // Extract current details from operation group
37
- // Note: Using safe property access since the exact API structure may vary
38
- const currentTime = {
39
- timeSlot: 'TODO', // service.currentTimeSlot?.get(),
40
- };
41
- // Extract fulfillment options from operation
42
- // Note: Using safe property access since the exact API structure may vary
43
- const currentFulfillment = {
44
- current: fulfillmentsService.selectedFulfillment?.get() ?? undefined,
45
- };
46
- // Extract location data from operation group
47
- // Note: Using safe property access since the exact API structure may vary
48
- const currentLocation = {
49
- name: operation.locationDetails?.name,
50
- };
51
- // Extract extra data from operation
52
- // Note: Using safe property access since the exact API structure may vary
53
- const extraData = {
54
- acceptingOrders: operation?.status === 'ACTIVE' && !operation?.paused,
55
- deliveryFee: operation?.fulfillment?.delivery?.fee?.amount ||
56
- operation?.deliveryFee,
57
- minOrderAmount: operation?.orderingRules?.minimumOrderValue?.amount ||
58
- operation?.minOrderAmount,
59
- freeDeliveryThreshold: operation?.fulfillment?.delivery?.freeDeliveryThreshold
60
- ?.amount || operation?.freeDeliveryThreshold,
61
- taxRate: operation?.pricing?.taxRate || operation?.taxRate,
62
- serviceCharge: operation?.pricing?.serviceCharge?.amount ||
63
- operation?.serviceCharge,
64
- isOnline: operation?.status === 'ACTIVE',
65
- orderingDisabledReason: operation?.paused
66
- ? operation?.pauseReason
67
- : undefined,
68
- };
69
- return children({
70
- currentTime,
71
- currentFulfillment,
72
- selectedFulfillment,
73
- currentLocation,
74
- extraData,
75
- isLoading,
76
- error,
77
- });
24
+ const [config, setConfig] = useState(fulfillmentsServiceConfig);
25
+ useEffect(() => {
26
+ if (!fulfillmentsServiceConfig) {
27
+ loadFulfillmentsServiceConfig(service.operation?.get()).then((loadedConfig) => {
28
+ setConfig(loadedConfig);
29
+ });
30
+ }
31
+ }, [fulfillmentsServiceConfig]);
32
+ service.isLoading.set(!config);
33
+ if (!config) {
34
+ return children({ isLoading: !config });
35
+ }
36
+ return (_jsx(WixServices, { servicesMap: createServicesMap().addService(FulfillmentsServiceDefinition, FulfillmentsService, config), children: children({ isLoading: !config }) }));
78
37
  };
79
38
  /**
80
- * Component that provides access to current store details
39
+ * Component that provides access to current time slot
81
40
  *
82
41
  * @example
83
42
  * ```tsx
84
43
  * <CoreSettings.CurrentTimeSlot>
85
- * {({ details, hasDetails }) => (
44
+ * {({ timeSlot, hasDetails }) => (
86
45
  * hasDetails ? (
87
46
  * <div>
88
- * <h3>{details.timeSlot}</h3>
47
+ * <h3>{timeSlot.dispatchType}</h3>
89
48
  * </div>
90
49
  * ) : (
91
- * <div>No store details available</div>
50
+ * <div>No time slot selected</div>
92
51
  * )
93
52
  * )}
94
53
  * </CoreSettings.CurrentTimeSlot>
95
54
  * ```
96
55
  */
97
56
  export const CurrentTimeSlot = ({ children, }) => {
98
- return (_jsx(Root, { children: ({ selectedFulfillment }) => {
99
- const hasDetails = Boolean(selectedFulfillment);
100
- console.log('selectedFulfillment', selectedFulfillment);
101
- console.log('timeSlot', selectedFulfillment?.startTime.toLocaleString());
102
- return children({
103
- timeSlot: selectedFulfillment,
104
- hasDetails,
105
- });
106
- } }));
57
+ const fulfillmentsService = useService(FulfillmentsServiceDefinition);
58
+ const selectedTimeSlot = fulfillmentsService.selectedTimeSlot?.get() ?? {};
59
+ const hasDetails = Boolean(fulfillmentsService.selectedTimeSlot?.get());
60
+ return children({ timeSlot: selectedTimeSlot, hasDetails });
107
61
  };
108
62
  /**
109
63
  * Component that provides access to current fulfillment options
@@ -123,17 +77,18 @@ export const CurrentTimeSlot = ({ children, }) => {
123
77
  * ```
124
78
  */
125
79
  export const CurrentFulfillment = ({ children, }) => {
126
- return (_jsx(Root, { children: ({ currentFulfillment }) => {
127
- const availableOptions = [];
128
- // if (currentFulfillment.pickup?.enabled) availableOptions.push('pickup');
129
- // if (currentFulfillment.delivery?.enabled) availableOptions.push('delivery');
130
- const hasFulfillment = availableOptions.length > 0;
131
- return children({
132
- fulfillment: currentFulfillment,
133
- hasFulfillment,
134
- availableOptions,
135
- });
136
- } }));
80
+ const fulfillmentsService = useService(FulfillmentsServiceDefinition);
81
+ const currentFulfillment = {
82
+ current: fulfillmentsService.selectedTimeSlot?.get() ?? undefined,
83
+ };
84
+ const availableOptions = [];
85
+ // TODO: Add logic to determine available options from fulfillments
86
+ const hasFulfillment = availableOptions.length > 0;
87
+ return children({
88
+ fulfillment: currentFulfillment,
89
+ hasFulfillment,
90
+ availableOptions,
91
+ });
137
92
  };
138
93
  /**
139
94
  * Component that provides access to current location data
@@ -141,26 +96,22 @@ export const CurrentFulfillment = ({ children, }) => {
141
96
  * @example
142
97
  * ```tsx
143
98
  * <CoreSettings.CurrentLocation>
144
- * {({ location, hasCoordinates }) => (
99
+ * {({ location, hasLocation }) => (
145
100
  * <div>
146
- * <p>{location.address}</p>
147
- * {hasCoordinates && (
148
- * <p>Coordinates: {location.latitude}, {location.longitude}</p>
149
- * )}
101
+ * <p>{location.name}</p>
150
102
  * </div>
151
103
  * )}
152
104
  * </CoreSettings.CurrentLocation>
153
105
  * ```
154
106
  */
155
107
  export const CurrentLocation = ({ children, }) => {
156
- return (_jsx(Root, { children: ({ currentLocation }) => {
157
- console.log('currentLocation', currentLocation);
158
- const hasLocation = Boolean(currentLocation.name);
159
- return children({
160
- location: currentLocation,
161
- hasLocation,
162
- });
163
- } }));
108
+ const service = useService(OLOSettingsServiceDefinition);
109
+ const operation = service.operation?.get();
110
+ const currentLocation = {
111
+ name: operation?.locationDetails?.name || '',
112
+ };
113
+ const hasLocation = Boolean(currentLocation.name);
114
+ return children({ location: currentLocation, hasLocation });
164
115
  };
165
116
  /**
166
117
  * Component that provides access to extra settings data
@@ -180,13 +131,32 @@ export const CurrentLocation = ({ children, }) => {
180
131
  * ```
181
132
  */
182
133
  export const ExtraData = ({ children }) => {
183
- return (_jsx(Root, { children: ({ extraData }) => {
184
- const hasExtraData = Boolean(extraData.deliveryFee !== undefined ||
185
- extraData.minOrderAmount !== undefined ||
186
- extraData.freeDeliveryThreshold !== undefined);
187
- return children({
188
- extraData,
189
- hasExtraData,
190
- });
191
- } }));
134
+ const service = useService(OLOSettingsServiceDefinition);
135
+ const fulfillmentsService = useService(FulfillmentsServiceDefinition);
136
+ const operation = service.operation?.get();
137
+ const fulfillments = fulfillmentsService.fulfillments?.get();
138
+ const minOrderPrice = fulfillments && fulfillments.length > 0
139
+ ? Math.min(...fulfillments
140
+ .map((f) => Number(f.minOrderPrice ?? 0))
141
+ .filter((x) => x !== undefined))
142
+ : undefined;
143
+ const extraData = {
144
+ acceptingOrders: operation?.status === 'ACTIVE' && !operation?.paused,
145
+ deliveryFee: operation?.fulfillment?.delivery?.fee?.amount ||
146
+ operation?.deliveryFee,
147
+ minOrderAmount: minOrderPrice,
148
+ freeDeliveryThreshold: operation?.fulfillment?.delivery?.freeDeliveryThreshold
149
+ ?.amount || operation?.freeDeliveryThreshold,
150
+ taxRate: operation?.pricing?.taxRate || operation?.taxRate,
151
+ serviceCharge: operation?.pricing?.serviceCharge?.amount ||
152
+ operation?.serviceCharge,
153
+ isOnline: operation?.status === 'ACTIVE',
154
+ orderingDisabledReason: operation?.paused
155
+ ? operation?.pauseReason
156
+ : undefined,
157
+ };
158
+ const hasExtraData = Boolean(extraData.deliveryFee !== undefined ||
159
+ extraData.minOrderAmount !== undefined ||
160
+ extraData.freeDeliveryThreshold !== undefined);
161
+ return children({ extraData, hasExtraData });
192
162
  };
@@ -10,35 +10,38 @@ export const FulfillmentsService = implementService.withConfig()(FulfillmentsSer
10
10
  throw new Error('Operation ID is required');
11
11
  }
12
12
  const signalsService = getService(SignalsServiceDefinition);
13
- const fulfillmentsMap = new Map(config.fulfillments?.map(processFulfillmentTimeSlotByOperationList) ??
14
- []);
15
- const fulfillments = signalsService.signal(
13
+ const timeSlotsMap = new Map(config.timeSlots?.map(processFulfillmentTimeSlotByOperationList) ?? []);
14
+ const fulfillments = signalsService.signal(config.fulfillments ?? []);
15
+ const timeSlots = signalsService.signal(
16
16
  // @ts-expect-error - operation is not typed
17
- fulfillmentsMap.get(config.operation?.id ?? '') ?? []);
17
+ timeSlotsMap.get(config.operation?.id ?? '') ?? []);
18
18
  const isLoading = signalsService.signal(false);
19
19
  const error = signalsService.signal(null);
20
- const initialSelected = fulfillments.get()?.[0] ?? null;
21
- const selectedFulfillment = signalsService.signal(initialSelected);
22
- selectedFulfillment.set(initialSelected);
23
- const setSelectedFulfillment = (fulfillment) => {
24
- selectedFulfillment.set(fulfillment);
20
+ const initialSelected = timeSlots.get()?.[0] ?? null;
21
+ const selectedTimeSlot = signalsService.signal(initialSelected);
22
+ selectedTimeSlot.set(initialSelected);
23
+ const setSelectedTimeSlot = (timeSlot) => {
24
+ selectedTimeSlot.set(timeSlot);
25
25
  };
26
- if (!config.fulfillments && config.operation) {
26
+ if (!config.timeSlots && config.operation) {
27
27
  loadFulfillmentsServiceConfig(config.operation).then((config) => {
28
- const fulfillmentsMap = new Map(config.fulfillments?.map(processFulfillmentTimeSlotByOperationList) ?? []);
29
- fulfillments.set(
28
+ const timeSlotsMap = new Map(config.timeSlots?.map(processFulfillmentTimeSlotByOperationList) ??
29
+ []);
30
+ timeSlots.set(
30
31
  // @ts-expect-error - operation is not typed
31
- fulfillmentsMap.get(config.operation?.id ?? '') ?? []);
32
- const initialSelected = fulfillments.get()?.[0] ?? null;
33
- selectedFulfillment.set(initialSelected);
32
+ timeSlotsMap.get(config.operation?.id ?? '') ?? []);
33
+ const initialSelected = timeSlots.get()?.[0] ?? null;
34
+ selectedTimeSlot.set(initialSelected);
35
+ fulfillments.set(config.fulfillments ?? []);
34
36
  });
35
37
  }
36
38
  return {
39
+ timeSlots,
37
40
  fulfillments,
38
- selectedFulfillment,
41
+ selectedTimeSlot,
39
42
  isLoading,
40
43
  error,
41
- setSelectedFulfillment,
44
+ setSelectedTimeSlot,
42
45
  };
43
46
  });
44
47
  export const loadFulfillmentsServiceConfig = async (operation) => {
@@ -58,7 +61,8 @@ export const loadFulfillmentsServiceConfig = async (operation) => {
58
61
  console.log('fulfillments', fulfillments.items);
59
62
  // const fulfillmentsMap = new Map(fulfillments.timeSlotsPerOperation?.map(processFulfillmentTimeSlotByOperationList));
60
63
  return {
61
- fulfillments: timeSlots.timeSlotsPerOperation, //fulfillmentsMap.get(operationId) ?? [],
64
+ timeSlots: timeSlots.timeSlotsPerOperation, //fulfillmentsMap.get(operationId) ?? [],
62
65
  operation: operation,
66
+ fulfillments: fulfillments.items.filter((f) => f.enabled),
63
67
  };
64
68
  };
@@ -1,5 +1,6 @@
1
1
  import * as operationsSDK from '@wix/auto_sdk_restaurants_operations';
2
2
  import { Signal } from '@wix/services-definitions/core-services/signals';
3
+ import * as fulfillemtMethodsSDK from '@wix/auto_sdk_restaurants_fulfillment-methods';
3
4
  export declare enum DispatchType {
4
5
  /** Pickup fulfillment */
5
6
  PICKUP = "PICKUP",
@@ -21,13 +22,15 @@ export interface Fulfillment {
21
22
  isAvailable: boolean;
22
23
  }
23
24
  export interface FulfillmentsServiceAPI {
24
- fulfillments: Signal<TimeSlot[]>;
25
- selectedFulfillment: Signal<TimeSlot | null>;
25
+ timeSlots: Signal<TimeSlot[]>;
26
+ fulfillments: Signal<fulfillemtMethodsSDK.FulfillmentMethod[]>;
27
+ selectedTimeSlot: Signal<TimeSlot | null>;
26
28
  isLoading: Signal<boolean>;
27
29
  error: Signal<string | null>;
28
- setSelectedFulfillment: (fulfillment: TimeSlot) => void;
30
+ setSelectedTimeSlot: (timeSlot: TimeSlot) => void;
29
31
  }
30
32
  export interface FulfillmentsServiceConfig {
31
- fulfillments?: operationsSDK.TimeSlotForOperation[];
33
+ timeSlots?: operationsSDK.TimeSlotForOperation[];
32
34
  operation?: operationsSDK.Operation;
35
+ fulfillments?: fulfillemtMethodsSDK.FulfillmentMethod[];
33
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-restaurants-olo",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -76,5 +76,5 @@
76
76
  "groupId": "com.wixpress.headless-components"
77
77
  }
78
78
  },
79
- "falconPackageHash": "8a5140aec5569bc45df3f464fbf17f0cdcbc5a879f3cb33e3acfbe36"
79
+ "falconPackageHash": "c63096fd172df6e421d83760d55029ab975469bf1de7554fc384a7b1"
80
80
  }