@wix/headless-restaurants-olo 0.0.24 → 0.0.25
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/react/ItemDetails.d.ts +2 -2
- package/cjs/dist/react/ItemDetails.js +1 -9
- package/cjs/dist/react/Settings.d.ts +24 -21
- package/cjs/dist/react/Settings.js +34 -4
- package/cjs/dist/react/core/OLO.js +2 -16
- package/cjs/dist/react/core/Settings.d.ts +41 -65
- package/cjs/dist/react/core/Settings.js +83 -113
- package/cjs/dist/services/fulfillments-service.js +22 -18
- package/cjs/dist/types/fulfillments-types.d.ts +7 -4
- package/dist/react/ItemDetails.d.ts +2 -2
- package/dist/react/ItemDetails.js +1 -9
- package/dist/react/Settings.d.ts +24 -21
- package/dist/react/Settings.js +34 -4
- package/dist/react/core/OLO.js +2 -16
- package/dist/react/core/Settings.d.ts +41 -65
- package/dist/react/core/Settings.js +83 -113
- package/dist/services/fulfillments-service.js +22 -18
- package/dist/types/fulfillments-types.d.ts +7 -4
- package/package.json +2 -2
|
@@ -99,7 +99,7 @@ export interface AddToCartButtonProps {
|
|
|
99
99
|
asChild?: boolean;
|
|
100
100
|
className?: string;
|
|
101
101
|
addToCartLabelMap: Record<AddToCartButtonState, string>;
|
|
102
|
-
children
|
|
102
|
+
children?: AsChildChildren<{
|
|
103
103
|
lineItem: LineItem;
|
|
104
104
|
buttonState: AddToCartButtonState;
|
|
105
105
|
addToCartButtonDisabled?: boolean;
|
|
@@ -109,7 +109,7 @@ export interface AddToCartButtonProps {
|
|
|
109
109
|
label: React.ReactNode;
|
|
110
110
|
formattedPrice: string;
|
|
111
111
|
modifierGroupHasError: boolean;
|
|
112
|
-
}
|
|
112
|
+
}>;
|
|
113
113
|
}
|
|
114
114
|
export declare const AddToCartButton: React.ForwardRefExoticComponent<AddToCartButtonProps & React.RefAttributes<HTMLElement>>;
|
|
115
115
|
export interface ItemDetailsQuantityProps {
|
|
@@ -50,15 +50,7 @@ export const AddToCartButton = React.forwardRef(({ asChild, children, className,
|
|
|
50
50
|
label,
|
|
51
51
|
formattedPrice,
|
|
52
52
|
modifierGroupHasError,
|
|
53
|
-
}, ref: ref, ...props, children: _jsx(Commerce.Actions.AddToCart, { asChild: false, label: label, className: className, lineItems: [lineItem], ...props
|
|
54
|
-
lineItem,
|
|
55
|
-
buttonState,
|
|
56
|
-
addToCartButtonDisabled,
|
|
57
|
-
loadingState,
|
|
58
|
-
label,
|
|
59
|
-
formattedPrice,
|
|
60
|
-
modifierGroupHasError,
|
|
61
|
-
}) }) }));
|
|
53
|
+
}, ref: ref, ...props, children: _jsx(Commerce.Actions.AddToCart, { asChild: false, label: label, className: className, lineItems: [lineItem], ...props }) }));
|
|
62
54
|
} }));
|
|
63
55
|
});
|
|
64
56
|
AddToCartButton.displayName = 'AddToCartButton';
|
|
@@ -1,31 +1,33 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { FulfillmentsServiceConfig } from '../types/fulfillments-types.js';
|
|
2
3
|
import { AsChildChildren } from '@wix/headless-utils/react';
|
|
4
|
+
/**
|
|
5
|
+
* Props for the Settings Root component
|
|
6
|
+
*/
|
|
7
|
+
export interface RootProps {
|
|
8
|
+
/** Child components that will have access to the settings context */
|
|
9
|
+
children: (props: {
|
|
10
|
+
isLoading: boolean;
|
|
11
|
+
}) => React.ReactNode;
|
|
12
|
+
/** Optional pre-loaded fulfillments service configuration */
|
|
13
|
+
fulfillmentsServiceConfig?: FulfillmentsServiceConfig;
|
|
14
|
+
}
|
|
3
15
|
/**
|
|
4
16
|
* Root headless component for OLO Settings
|
|
5
|
-
* Provides
|
|
17
|
+
* Provides service context for settings components
|
|
6
18
|
*
|
|
7
19
|
* @example
|
|
8
20
|
* ```tsx
|
|
9
|
-
* <Settings.Root>
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* <div>
|
|
13
|
-
* )
|
|
14
|
-
*
|
|
15
|
-
* ) : (
|
|
16
|
-
* <div>
|
|
17
|
-
* <h2>{currentDetails.name}</h2>
|
|
18
|
-
* <p>{currentDetails.address}</p>
|
|
19
|
-
* <p>Accepting Orders: {extraData.acceptingOrders ? 'Yes' : 'No'}</p>
|
|
20
|
-
* <p>Delivery Fee: ${extraData.deliveryFee}</p>
|
|
21
|
-
* <p>Min Order: ${extraData.minOrderAmount}</p>
|
|
22
|
-
* <p>Free Delivery: ${extraData.freeDeliveryThreshold}</p>
|
|
23
|
-
* </div>
|
|
24
|
-
* )
|
|
25
|
-
* )}
|
|
21
|
+
* <Settings.Root fulfillmentsServiceConfig={config}>
|
|
22
|
+
* <Settings.CurrentTimeSlot>
|
|
23
|
+
* {({ timeSlot, hasDetails }) => (
|
|
24
|
+
* <div>{timeSlot?.dispatchType}</div>
|
|
25
|
+
* )}
|
|
26
|
+
* </Settings.CurrentTimeSlot>
|
|
26
27
|
* </Settings.Root>
|
|
27
28
|
* ```
|
|
28
29
|
*/
|
|
30
|
+
export declare const Root: React.FC<RootProps>;
|
|
29
31
|
interface CurrentTimeSlotProps {
|
|
30
32
|
/** Children render prop that receives the current details */
|
|
31
33
|
children?: AsChildChildren<{
|
|
@@ -114,9 +116,10 @@ interface CurrentLocationProps {
|
|
|
114
116
|
* ```
|
|
115
117
|
*/
|
|
116
118
|
export declare const CurrentLocation: React.FC<CurrentLocationProps>;
|
|
117
|
-
interface ExtraDataProps {
|
|
119
|
+
interface ExtraDataProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'children'> {
|
|
120
|
+
asChild?: boolean;
|
|
118
121
|
/** Children render prop that receives the extra settings data */
|
|
119
|
-
children
|
|
122
|
+
children?: AsChildChildren<{
|
|
120
123
|
extraData: {
|
|
121
124
|
acceptingOrders: boolean;
|
|
122
125
|
deliveryFee?: number;
|
|
@@ -128,7 +131,7 @@ interface ExtraDataProps {
|
|
|
128
131
|
orderingDisabledReason?: string;
|
|
129
132
|
};
|
|
130
133
|
hasExtraData: boolean;
|
|
131
|
-
}
|
|
134
|
+
}> | React.ReactNode;
|
|
132
135
|
}
|
|
133
136
|
/**
|
|
134
137
|
* Headless component for extra settings data
|
|
@@ -1,8 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { CoreSettings } from './core/index.js';
|
|
4
|
-
// import { OLOSettingsServiceConfig } from '../services/olo-settings-service.js';
|
|
5
4
|
import { AsChildSlot } from '@wix/headless-utils/react';
|
|
5
|
+
// ========================================
|
|
6
|
+
// OLO SETTINGS HEADLESS COMPONENTS
|
|
7
|
+
// ========================================
|
|
8
|
+
// Headless components that wrap CoreSettings and provide convenient service management
|
|
9
|
+
// These components handle service initialization and provide render props for UI
|
|
10
|
+
// ========================================
|
|
11
|
+
// ROOT COMPONENT
|
|
12
|
+
// ========================================
|
|
13
|
+
var TestIds;
|
|
14
|
+
(function (TestIds) {
|
|
15
|
+
TestIds["settingsRoot"] = "settings-root";
|
|
16
|
+
})(TestIds || (TestIds = {}));
|
|
17
|
+
/**
|
|
18
|
+
* Root headless component for OLO Settings
|
|
19
|
+
* Provides service context for settings components
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* <Settings.Root fulfillmentsServiceConfig={config}>
|
|
24
|
+
* <Settings.CurrentTimeSlot>
|
|
25
|
+
* {({ timeSlot, hasDetails }) => (
|
|
26
|
+
* <div>{timeSlot?.dispatchType}</div>
|
|
27
|
+
* )}
|
|
28
|
+
* </Settings.CurrentTimeSlot>
|
|
29
|
+
* </Settings.Root>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export const Root = ({ children, fulfillmentsServiceConfig, }) => {
|
|
33
|
+
return (_jsx(CoreSettings.Root, { fulfillmentsServiceConfig: fulfillmentsServiceConfig, "data-testid": TestIds.settingsRoot, children: ({ isLoading }) => children({ isLoading }) }));
|
|
34
|
+
};
|
|
35
|
+
Root.displayName = 'Settings.Root';
|
|
6
36
|
/**
|
|
7
37
|
* Headless component for current store details
|
|
8
38
|
* Provides access to store name, address, contact info, and hours
|
|
@@ -89,6 +119,6 @@ export const CurrentLocation = ({ children, className, asChild, }) => {
|
|
|
89
119
|
* </Settings.ExtraData>
|
|
90
120
|
* ```
|
|
91
121
|
*/
|
|
92
|
-
export const ExtraData = ({ children }) => {
|
|
93
|
-
return _jsx(CoreSettings.ExtraData, { children: children });
|
|
122
|
+
export const ExtraData = ({ children, asChild, className, ...rest }) => {
|
|
123
|
+
return (_jsx(CoreSettings.ExtraData, { children: ({ extraData, hasExtraData }) => (_jsx(AsChildSlot, { asChild: asChild, className: className, customElement: children, customElementProps: { extraData, hasExtraData }, content: hasExtraData ? (_jsx("div", { children: extraData.acceptingOrders ? 'Accepting Orders' : 'Closed' })) : null, ...rest, children: hasExtraData ? (_jsx("div", { children: extraData.acceptingOrders ? 'Accepting Orders' : 'Closed' })) : null })) }));
|
|
94
124
|
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
3
|
import { createServicesMap } from '@wix/services-manager';
|
|
4
4
|
import { WixServices } from '@wix/services-manager-react';
|
|
5
5
|
// import { ItemService, ItemServiceDefinition, loadItemServiceConfig } from '@/components/restaurants-olo/services/itemDetailsService';
|
|
6
6
|
import { OLOSettingsService, OLOSettingsServiceDefinition, } from '@wix/headless-restaurants-olo/services';
|
|
7
|
-
import { FulfillmentsService, FulfillmentsServiceDefinition, loadFulfillmentsServiceConfig, } from '../../services/fulfillments-service.js';
|
|
8
7
|
/**
|
|
9
8
|
* Core OLO Root component that sets up service management
|
|
10
9
|
* Provides ItemService and CurrentCartService to child components
|
|
@@ -25,9 +24,6 @@ import { FulfillmentsService, FulfillmentsServiceDefinition, loadFulfillmentsSer
|
|
|
25
24
|
* ```
|
|
26
25
|
*/
|
|
27
26
|
export const Root = ({ itemId, itemServiceConfig, cartServiceConfig, oloSettingsServiceConfig, children, }) => {
|
|
28
|
-
const [fulfillmentsServiceConfig, setFulfillmentsServiceConfig] = useState({
|
|
29
|
-
operation: oloSettingsServiceConfig?.operation ?? undefined,
|
|
30
|
-
});
|
|
31
27
|
// const [servicesManager, setServicesManager] = useState<ServicesManager | null>(null);
|
|
32
28
|
// const [isLoading, setIsLoading] = useState(true);
|
|
33
29
|
// const [error, setError] = useState<string | undefined>();
|
|
@@ -90,17 +86,7 @@ export const Root = ({ itemId, itemServiceConfig, cartServiceConfig, oloSettings
|
|
|
90
86
|
// hasServices
|
|
91
87
|
// });
|
|
92
88
|
console.log('oloSettingsServiceConfig', oloSettingsServiceConfig);
|
|
93
|
-
|
|
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 }));
|
|
89
|
+
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(OLOSettingsServiceDefinition, OLOSettingsService, oloSettingsServiceConfig), children: children }));
|
|
104
90
|
};
|
|
105
91
|
/**
|
|
106
92
|
* 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
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
37
|
-
*
|
|
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
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* <div>
|
|
45
|
-
* )
|
|
46
|
-
*
|
|
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<
|
|
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
|
|
33
|
+
* Component that provides access to current time slot
|
|
67
34
|
*
|
|
68
35
|
* @example
|
|
69
36
|
* ```tsx
|
|
70
37
|
* <CoreSettings.CurrentTimeSlot>
|
|
71
|
-
* {({
|
|
38
|
+
* {({ timeSlot, hasDetails }) => (
|
|
72
39
|
* hasDetails ? (
|
|
73
40
|
* <div>
|
|
74
|
-
* <h3>{
|
|
41
|
+
* <h3>{timeSlot.dispatchType}</h3>
|
|
75
42
|
* </div>
|
|
76
43
|
* ) : (
|
|
77
|
-
* <div>No
|
|
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:
|
|
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:
|
|
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,
|
|
92
|
+
* {({ location, hasLocation }) => (
|
|
122
93
|
* <div>
|
|
123
|
-
* <p>{location.
|
|
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:
|
|
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 {
|
|
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
|
|
7
|
-
*
|
|
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
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* <div>
|
|
15
|
-
* )
|
|
16
|
-
*
|
|
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
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
39
|
+
* Component that provides access to current time slot
|
|
81
40
|
*
|
|
82
41
|
* @example
|
|
83
42
|
* ```tsx
|
|
84
43
|
* <CoreSettings.CurrentTimeSlot>
|
|
85
|
-
* {({
|
|
44
|
+
* {({ timeSlot, hasDetails }) => (
|
|
86
45
|
* hasDetails ? (
|
|
87
46
|
* <div>
|
|
88
|
-
* <h3>{
|
|
47
|
+
* <h3>{timeSlot.dispatchType}</h3>
|
|
89
48
|
* </div>
|
|
90
49
|
* ) : (
|
|
91
|
-
* <div>No
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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,
|
|
99
|
+
* {({ location, hasLocation }) => (
|
|
145
100
|
* <div>
|
|
146
|
-
* <p>{location.
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
};
|