@wix/headless-restaurants-olo 0.0.14 → 0.0.16
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/mappers/operation-mapper.d.ts +3 -0
- package/cjs/dist/mappers/operation-mapper.js +95 -0
- package/cjs/dist/react/ItemDetails.d.ts +4 -162
- package/cjs/dist/react/ItemDetails.js +6 -78
- package/cjs/dist/react/ModifierGroup.d.ts +57 -0
- package/cjs/dist/react/ModifierGroup.js +61 -0
- package/cjs/dist/react/OLO.d.ts +3 -2
- package/cjs/dist/react/OLOMenus.d.ts +20 -0
- package/cjs/dist/react/OLOMenus.js +22 -0
- package/cjs/dist/react/Settings.d.ts +160 -0
- package/cjs/dist/react/Settings.js +94 -0
- package/cjs/dist/react/core/ItemDetails.d.ts +1 -11
- package/cjs/dist/react/core/ItemDetails.js +4 -21
- package/cjs/dist/react/core/ModifierGroup.d.ts +42 -0
- package/cjs/dist/react/core/ModifierGroup.js +67 -0
- package/cjs/dist/react/core/OLO.js +16 -2
- package/cjs/dist/react/core/OLOMenus.d.ts +7 -0
- package/cjs/dist/react/core/OLOMenus.js +12 -0
- package/cjs/dist/react/core/Settings.d.ts +157 -0
- package/cjs/dist/react/core/Settings.js +192 -0
- package/cjs/dist/react/core/index.d.ts +1 -0
- package/cjs/dist/react/core/index.js +1 -0
- package/cjs/dist/react/index.d.ts +3 -0
- package/cjs/dist/react/index.js +3 -0
- package/cjs/dist/services/common-types.d.ts +18 -0
- package/cjs/dist/services/common-types.js +10 -0
- package/cjs/dist/services/fulfillments-service.d.ts +13 -0
- package/cjs/dist/services/fulfillments-service.js +64 -0
- package/cjs/dist/services/index.d.ts +1 -0
- package/cjs/dist/services/index.js +1 -0
- package/cjs/dist/services/item-details-service.d.ts +2 -0
- package/cjs/dist/services/item-details-service.js +8 -1
- package/cjs/dist/services/olo-settings-service.d.ts +14 -8
- package/cjs/dist/services/olo-settings-service.js +24 -5
- package/cjs/dist/services/utils.d.ts +17 -0
- package/cjs/dist/services/utils.js +104 -0
- package/cjs/dist/types/fulfillments-types.d.ts +33 -0
- package/cjs/dist/types/fulfillments-types.js +7 -0
- package/cjs/dist/types/operation.d.ts +57 -0
- package/cjs/dist/types/operation.js +1 -0
- package/cjs/dist/utils/fulfillments-utils.d.ts +23 -0
- package/cjs/dist/utils/fulfillments-utils.js +144 -0
- package/dist/mappers/operation-mapper.d.ts +3 -0
- package/dist/mappers/operation-mapper.js +95 -0
- package/dist/react/ItemDetails.d.ts +4 -162
- package/dist/react/ItemDetails.js +6 -78
- package/dist/react/ModifierGroup.d.ts +57 -0
- package/dist/react/ModifierGroup.js +61 -0
- package/dist/react/OLO.d.ts +3 -2
- package/dist/react/OLOMenus.d.ts +20 -0
- package/dist/react/OLOMenus.js +22 -0
- package/dist/react/Settings.d.ts +160 -0
- package/dist/react/Settings.js +94 -0
- package/dist/react/core/ItemDetails.d.ts +1 -11
- package/dist/react/core/ItemDetails.js +4 -21
- package/dist/react/core/ModifierGroup.d.ts +42 -0
- package/dist/react/core/ModifierGroup.js +67 -0
- package/dist/react/core/OLO.js +16 -2
- package/dist/react/core/OLOMenus.d.ts +7 -0
- package/dist/react/core/OLOMenus.js +12 -0
- package/dist/react/core/Settings.d.ts +157 -0
- package/dist/react/core/Settings.js +192 -0
- package/dist/react/core/index.d.ts +1 -0
- package/dist/react/core/index.js +1 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.js +3 -0
- package/dist/services/common-types.d.ts +18 -0
- package/dist/services/common-types.js +10 -0
- package/dist/services/fulfillments-service.d.ts +13 -0
- package/dist/services/fulfillments-service.js +64 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/item-details-service.d.ts +2 -0
- package/dist/services/item-details-service.js +8 -1
- package/dist/services/olo-settings-service.d.ts +14 -8
- package/dist/services/olo-settings-service.js +24 -5
- package/dist/services/utils.d.ts +17 -0
- package/dist/services/utils.js +104 -0
- package/dist/types/fulfillments-types.d.ts +33 -0
- package/dist/types/fulfillments-types.js +7 -0
- package/dist/types/operation.d.ts +57 -0
- package/dist/types/operation.js +1 -0
- package/dist/utils/fulfillments-utils.d.ts +23 -0
- package/dist/utils/fulfillments-utils.js +144 -0
- package/package.json +5 -6
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AsChildChildren } from '@wix/headless-utils/react';
|
|
3
|
+
/**
|
|
4
|
+
* Root headless component for OLO Settings
|
|
5
|
+
* Provides access to current details, fulfillment options, location, and extra data
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* <Settings.Root>
|
|
10
|
+
* {({ currentDetails, currentFulfillment, currentLocation, extraData, isLoading, error }) => (
|
|
11
|
+
* isLoading ? (
|
|
12
|
+
* <div>Loading settings...</div>
|
|
13
|
+
* ) : error ? (
|
|
14
|
+
* <div>Error: {error}</div>
|
|
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
|
+
* )}
|
|
26
|
+
* </Settings.Root>
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
interface CurrentTimeSlotProps {
|
|
30
|
+
/** Children render prop that receives the current details */
|
|
31
|
+
children?: AsChildChildren<{
|
|
32
|
+
timeSlot: string;
|
|
33
|
+
}>;
|
|
34
|
+
/** CSS classes to apply to the default element */
|
|
35
|
+
className?: string;
|
|
36
|
+
/** Whether to render as a child component */
|
|
37
|
+
asChild?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Headless component for current store details
|
|
41
|
+
* Provides access to store name, address, contact info, and hours
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```tsx
|
|
45
|
+
* <Settings.CurrentTimeSlot>
|
|
46
|
+
* {({ details, hasDetails }) => (
|
|
47
|
+
* hasDetails ? (
|
|
48
|
+
* <div>
|
|
49
|
+
* <h3>{details.name}</h3>
|
|
50
|
+
* <p>{details.address}</p>
|
|
51
|
+
* <p>{details.phone}</p>
|
|
52
|
+
* <p>{details.email}</p>
|
|
53
|
+
* </div>
|
|
54
|
+
* ) : (
|
|
55
|
+
* <div>No store details available</div>
|
|
56
|
+
* )
|
|
57
|
+
* )}
|
|
58
|
+
* </Settings.CurrentTimeSlot>
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare const CurrentTimeSlot: React.ForwardRefExoticComponent<CurrentTimeSlotProps & React.RefAttributes<HTMLElement>>;
|
|
62
|
+
/**
|
|
63
|
+
* Headless component for current fulfillment options
|
|
64
|
+
* Provides access to pickup, delivery, and dine-in options
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```tsx
|
|
68
|
+
* <Settings.CurrentFulfillment>
|
|
69
|
+
* {({ fulfillment, availableOptions }) => (
|
|
70
|
+
* <div>
|
|
71
|
+
* <h3>Available Options:</h3>
|
|
72
|
+
* {availableOptions.map(option => (
|
|
73
|
+
* <div key={option}>
|
|
74
|
+
* {option}: {fulfillment[option]?.enabled ? 'Available' : 'Unavailable'}
|
|
75
|
+
* {fulfillment[option]?.estimatedTime && (
|
|
76
|
+
* <span> - {fulfillment[option].estimatedTime} mins</span>
|
|
77
|
+
* )}
|
|
78
|
+
* </div>
|
|
79
|
+
* ))}
|
|
80
|
+
* </div>
|
|
81
|
+
* )}
|
|
82
|
+
* </Settings.CurrentFulfillment>
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
interface CurrentLocationProps {
|
|
86
|
+
/** Whether to render as a child component */
|
|
87
|
+
asChild?: boolean;
|
|
88
|
+
/** CSS classes to apply to the default element */
|
|
89
|
+
className?: string;
|
|
90
|
+
/** Children render prop that receives the location data */
|
|
91
|
+
children?: AsChildChildren<{
|
|
92
|
+
currentLocation: {
|
|
93
|
+
name: string;
|
|
94
|
+
};
|
|
95
|
+
hasLocation: boolean;
|
|
96
|
+
}>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Headless component for current location data
|
|
100
|
+
* Provides access to store location and coordinates
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```tsx
|
|
104
|
+
* <Settings.CurrentLocation>
|
|
105
|
+
* {({ location, hasLocation }) => (
|
|
106
|
+
* <div>
|
|
107
|
+
* <p>{currentLocation.name}</p>
|
|
108
|
+
* {hasLocation && (
|
|
109
|
+
* <p>Coordinates: {location.latitude}, {location.longitude}</p>
|
|
110
|
+
* )}
|
|
111
|
+
* </div>
|
|
112
|
+
* )}
|
|
113
|
+
* </Settings.CurrentLocation>
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
export declare const CurrentLocation: React.FC<CurrentLocationProps>;
|
|
117
|
+
interface ExtraDataProps {
|
|
118
|
+
/** Children render prop that receives the extra settings data */
|
|
119
|
+
children: (props: {
|
|
120
|
+
extraData: {
|
|
121
|
+
acceptingOrders: boolean;
|
|
122
|
+
deliveryFee?: number;
|
|
123
|
+
minOrderAmount?: number;
|
|
124
|
+
freeDeliveryThreshold?: number;
|
|
125
|
+
taxRate?: number;
|
|
126
|
+
serviceCharge?: number;
|
|
127
|
+
isOnline?: boolean;
|
|
128
|
+
orderingDisabledReason?: string;
|
|
129
|
+
};
|
|
130
|
+
hasExtraData: boolean;
|
|
131
|
+
}) => React.ReactNode;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Headless component for extra settings data
|
|
135
|
+
* Provides access to ordering status, fees, and thresholds
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```tsx
|
|
139
|
+
* <Settings.ExtraData>
|
|
140
|
+
* {({ extraData, hasExtraData }) => (
|
|
141
|
+
* hasExtraData ? (
|
|
142
|
+
* <div>
|
|
143
|
+
* <p>Status: {extraData.acceptingOrders ? 'Open' : 'Closed'}</p>
|
|
144
|
+
* {extraData.orderingDisabledReason && (
|
|
145
|
+
* <p>Reason: {extraData.orderingDisabledReason}</p>
|
|
146
|
+
* )}
|
|
147
|
+
* <p>Delivery Fee: ${extraData.deliveryFee}</p>
|
|
148
|
+
* <p>Min Order: ${extraData.minOrderAmount}</p>
|
|
149
|
+
* <p>Free Delivery: ${extraData.freeDeliveryThreshold}</p>
|
|
150
|
+
* <p>Tax Rate: {extraData.taxRate}%</p>
|
|
151
|
+
* </div>
|
|
152
|
+
* ) : (
|
|
153
|
+
* <div>No additional settings available</div>
|
|
154
|
+
* )
|
|
155
|
+
* )}
|
|
156
|
+
* </Settings.ExtraData>
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
export declare const ExtraData: React.FC<ExtraDataProps>;
|
|
160
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { CoreSettings } from './core/index.js';
|
|
4
|
+
// import { OLOSettingsServiceConfig } from '../services/olo-settings-service.js';
|
|
5
|
+
import { AsChildSlot } from '@wix/headless-utils/react';
|
|
6
|
+
/**
|
|
7
|
+
* Headless component for current store details
|
|
8
|
+
* Provides access to store name, address, contact info, and hours
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <Settings.CurrentTimeSlot>
|
|
13
|
+
* {({ details, hasDetails }) => (
|
|
14
|
+
* hasDetails ? (
|
|
15
|
+
* <div>
|
|
16
|
+
* <h3>{details.name}</h3>
|
|
17
|
+
* <p>{details.address}</p>
|
|
18
|
+
* <p>{details.phone}</p>
|
|
19
|
+
* <p>{details.email}</p>
|
|
20
|
+
* </div>
|
|
21
|
+
* ) : (
|
|
22
|
+
* <div>No store details available</div>
|
|
23
|
+
* )
|
|
24
|
+
* )}
|
|
25
|
+
* </Settings.CurrentTimeSlot>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
// export const CurrentTimeSlot2: React.FC<CurrentTimeSlotProps> = ({ children }) => {
|
|
29
|
+
// return <CoreSettings.CurrentTimeSlot>{children}</CoreSettings.CurrentTimeSlot>;
|
|
30
|
+
// };
|
|
31
|
+
export const CurrentTimeSlot = React.forwardRef(({ asChild, children, className, ...rest }, ref) => {
|
|
32
|
+
return (_jsx(CoreSettings.CurrentTimeSlot, { children: ({ timeSlot, hasDetails }) => (_jsxs(AsChildSlot, { ref: ref, asChild: asChild,
|
|
33
|
+
// testId={TestIds.currentTimeSlot}
|
|
34
|
+
className: className, customElement: children, customElementProps: { timeSlot, hasDetails }, content: timeSlot, ...rest, children: [timeSlot?.dispatchType, timeSlot?.startTime.toLocaleString() +
|
|
35
|
+
' - ' +
|
|
36
|
+
timeSlot?.endTime.toLocaleString()] })) }));
|
|
37
|
+
});
|
|
38
|
+
CurrentTimeSlot.displayName = 'Settings.CurrentTimeSlot';
|
|
39
|
+
/**
|
|
40
|
+
* Headless component for current location data
|
|
41
|
+
* Provides access to store location and coordinates
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```tsx
|
|
45
|
+
* <Settings.CurrentLocation>
|
|
46
|
+
* {({ location, hasLocation }) => (
|
|
47
|
+
* <div>
|
|
48
|
+
* <p>{currentLocation.name}</p>
|
|
49
|
+
* {hasLocation && (
|
|
50
|
+
* <p>Coordinates: {location.latitude}, {location.longitude}</p>
|
|
51
|
+
* )}
|
|
52
|
+
* </div>
|
|
53
|
+
* )}
|
|
54
|
+
* </Settings.CurrentLocation>
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export const CurrentLocation = ({ children, className, asChild, }) => {
|
|
58
|
+
return (_jsx(CoreSettings.CurrentLocation, { children: ({ location, hasLocation }) => (_jsx(AsChildSlot
|
|
59
|
+
// ref={ref}
|
|
60
|
+
, {
|
|
61
|
+
// ref={ref}
|
|
62
|
+
asChild: asChild,
|
|
63
|
+
// testId={TestIds.currentLocation}
|
|
64
|
+
className: className, customElement: children, customElementProps: { location, hasLocation }, content: location.name, children: location.name })) }));
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Headless component for extra settings data
|
|
68
|
+
* Provides access to ordering status, fees, and thresholds
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```tsx
|
|
72
|
+
* <Settings.ExtraData>
|
|
73
|
+
* {({ extraData, hasExtraData }) => (
|
|
74
|
+
* hasExtraData ? (
|
|
75
|
+
* <div>
|
|
76
|
+
* <p>Status: {extraData.acceptingOrders ? 'Open' : 'Closed'}</p>
|
|
77
|
+
* {extraData.orderingDisabledReason && (
|
|
78
|
+
* <p>Reason: {extraData.orderingDisabledReason}</p>
|
|
79
|
+
* )}
|
|
80
|
+
* <p>Delivery Fee: ${extraData.deliveryFee}</p>
|
|
81
|
+
* <p>Min Order: ${extraData.minOrderAmount}</p>
|
|
82
|
+
* <p>Free Delivery: ${extraData.freeDeliveryThreshold}</p>
|
|
83
|
+
* <p>Tax Rate: {extraData.taxRate}%</p>
|
|
84
|
+
* </div>
|
|
85
|
+
* ) : (
|
|
86
|
+
* <div>No additional settings available</div>
|
|
87
|
+
* )
|
|
88
|
+
* )}
|
|
89
|
+
* </Settings.ExtraData>
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export const ExtraData = ({ children }) => {
|
|
93
|
+
return _jsx(CoreSettings.ExtraData, { children: children });
|
|
94
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type LineItem } from '@wix/ecom/services';
|
|
3
3
|
import { ItemServiceConfig } from '../../services/item-details-service.js';
|
|
4
|
-
import {
|
|
4
|
+
import { EnhancedVariant } from '@wix/headless-restaurants-menus/services';
|
|
5
5
|
import { AvailabilityStatus, AvailabilityStatusMap } from '../../services/common-types.js';
|
|
6
6
|
interface ItemDetailsRootProps {
|
|
7
7
|
children: (props: {
|
|
@@ -45,16 +45,6 @@ interface ItemDetailsVariantsProps {
|
|
|
45
45
|
}) => React.ReactNode;
|
|
46
46
|
}
|
|
47
47
|
export declare const VariantsComponent: React.FC<ItemDetailsVariantsProps>;
|
|
48
|
-
interface ItemDetailsModifiersProps {
|
|
49
|
-
children: (props: {
|
|
50
|
-
selectedModifierIds: string[];
|
|
51
|
-
onToggle: (modifierId: string) => void;
|
|
52
|
-
modifierGroup: EnhancedModifierGroup;
|
|
53
|
-
modifiers: EnhancedModifier[];
|
|
54
|
-
}) => React.ReactNode;
|
|
55
|
-
singleSelect?: boolean;
|
|
56
|
-
}
|
|
57
|
-
export declare const ModifiersComponent: React.FC<ItemDetailsModifiersProps>;
|
|
58
48
|
interface ItemDetailsAvailabilityProps {
|
|
59
49
|
availabilityStatusMap: AvailabilityStatusMap;
|
|
60
50
|
children: (props: {
|
|
@@ -4,17 +4,18 @@ import { useService, WixServices } from '@wix/services-manager-react';
|
|
|
4
4
|
import { createServicesMap } from '@wix/services-manager';
|
|
5
5
|
import { ItemService, ItemServiceDefinition, loadItemServiceConfig, } from '../../services/item-details-service.js';
|
|
6
6
|
import { OLOSettingsServiceDefinition } from '../../services/olo-settings-service.js';
|
|
7
|
-
import { useItemContext
|
|
7
|
+
import { useItemContext } from '@wix/headless-restaurants-menus/react';
|
|
8
8
|
import { AvailabilityStatus, } from '../../services/common-types.js';
|
|
9
|
-
import { convertModifierToFormModifier } from '../../services/utils.js';
|
|
10
9
|
export const Root = ({ children, itemDetailsServiceConfig, }) => {
|
|
11
10
|
const service = useService(OLOSettingsServiceDefinition);
|
|
12
11
|
const selectedItem = service.selectedItem?.get();
|
|
12
|
+
console.log('selectedItem', selectedItem, itemDetailsServiceConfig);
|
|
13
13
|
let config = itemDetailsServiceConfig;
|
|
14
14
|
if (!config) {
|
|
15
15
|
config = loadItemServiceConfig({
|
|
16
16
|
item: selectedItem,
|
|
17
|
-
|
|
17
|
+
// @ts-expect-error - operation is not typed
|
|
18
|
+
operationId: service.operation?.get()?.id ?? '',
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
21
|
if (config.item) {
|
|
@@ -86,24 +87,6 @@ export const VariantsComponent = ({ children, }) => {
|
|
|
86
87
|
selectedVariant,
|
|
87
88
|
});
|
|
88
89
|
};
|
|
89
|
-
export const ModifiersComponent = ({ children, singleSelect, }) => {
|
|
90
|
-
const service = useService(ItemServiceDefinition);
|
|
91
|
-
const { modifierGroup } = useModifierGroupContext();
|
|
92
|
-
// Get selected modifier IDs for this group
|
|
93
|
-
const groupId = modifierGroup._id;
|
|
94
|
-
const groupSelectedModifierIds = service.getSelectedModifiers?.(groupId ?? '');
|
|
95
|
-
const onToggle = (modifierId) => {
|
|
96
|
-
if (groupId) {
|
|
97
|
-
service.toggleModifier?.(groupId, modifierId, singleSelect);
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
return children({
|
|
101
|
-
selectedModifierIds: groupSelectedModifierIds,
|
|
102
|
-
onToggle,
|
|
103
|
-
modifierGroup,
|
|
104
|
-
modifiers: modifierGroup.modifiers.map(convertModifierToFormModifier),
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
90
|
export const AvailabilityComponent = ({ children, availabilityStatusMap, }) => {
|
|
108
91
|
const oloSettingsService = useService(OLOSettingsServiceDefinition);
|
|
109
92
|
const availabilityDispatchAction = oloSettingsService.availabilityDispatchAction?.get?.();
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { EnhancedModifier, EnhancedModifierGroup } from '@wix/headless-restaurants-menus/services';
|
|
3
|
+
import { RuleType, RuleTypeMap } from '../../services/common-types.js';
|
|
4
|
+
interface ModifiersContextValue {
|
|
5
|
+
selectedModifierIds: string[];
|
|
6
|
+
onToggle: (modifierId: string) => void;
|
|
7
|
+
modifierGroup: EnhancedModifierGroup;
|
|
8
|
+
modifiers: EnhancedModifier[];
|
|
9
|
+
ruleType: RuleType;
|
|
10
|
+
isSingleSelect: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function useModifiersContext(): ModifiersContextValue;
|
|
13
|
+
interface ModifierGroupComponentProps {
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
}
|
|
16
|
+
export declare const ModifierGroupComponent: React.FC<ModifierGroupComponentProps>;
|
|
17
|
+
interface ModifiersComponentProps {
|
|
18
|
+
children: (props: {
|
|
19
|
+
selectedModifierIds: string[];
|
|
20
|
+
onToggle: (modifierId: string) => void;
|
|
21
|
+
modifierGroup: EnhancedModifierGroup;
|
|
22
|
+
modifiers: EnhancedModifier[];
|
|
23
|
+
isSingleSelect: boolean;
|
|
24
|
+
singleSelectedModifierId: string;
|
|
25
|
+
}) => React.ReactNode;
|
|
26
|
+
}
|
|
27
|
+
export declare const ModifiersComponent: React.FC<ModifiersComponentProps>;
|
|
28
|
+
interface DescriptionProps {
|
|
29
|
+
ruleTypeMap: RuleTypeMap;
|
|
30
|
+
children: (props: {
|
|
31
|
+
description: string | undefined;
|
|
32
|
+
}) => React.ReactNode;
|
|
33
|
+
}
|
|
34
|
+
export declare const Description: React.FC<DescriptionProps>;
|
|
35
|
+
interface GroupErrorProps {
|
|
36
|
+
ruleTypeMap: RuleTypeMap;
|
|
37
|
+
children: (props: {
|
|
38
|
+
error: string | undefined;
|
|
39
|
+
}) => React.ReactNode;
|
|
40
|
+
}
|
|
41
|
+
export declare const GroupError: React.FC<GroupErrorProps>;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React, { createContext } from 'react';
|
|
3
|
+
import { useService } from '@wix/services-manager-react';
|
|
4
|
+
import { useModifierGroupContext } from '@wix/headless-restaurants-menus/react';
|
|
5
|
+
import { convertModifierToFormModifier, getModifierGroupRuleType, getRuleTypeMapValue, isSingleSelectRule, } from '../../services/utils.js';
|
|
6
|
+
import { ItemServiceDefinition } from '../../services/item-details-service.js';
|
|
7
|
+
const ModifiersContext = createContext(null);
|
|
8
|
+
export function useModifiersContext() {
|
|
9
|
+
const context = React.useContext(ModifiersContext);
|
|
10
|
+
if (!context) {
|
|
11
|
+
throw new Error('useModifiersContext must be used within a ModifierGroupComponent');
|
|
12
|
+
}
|
|
13
|
+
return context;
|
|
14
|
+
}
|
|
15
|
+
export const ModifierGroupComponent = ({ children, }) => {
|
|
16
|
+
const service = useService(ItemServiceDefinition);
|
|
17
|
+
const { modifierGroup } = useModifierGroupContext();
|
|
18
|
+
const rule = modifierGroup.rule;
|
|
19
|
+
const isSingleSelect = Boolean(rule ? isSingleSelectRule(rule) : false);
|
|
20
|
+
const groupId = modifierGroup._id;
|
|
21
|
+
const groupSelectedModifierIds = service.getSelectedModifiers?.(groupId ?? '');
|
|
22
|
+
const onToggle = (modifierId) => {
|
|
23
|
+
if (groupId) {
|
|
24
|
+
service.toggleModifier?.(groupId, modifierId, isSingleSelect);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const ruleType = getModifierGroupRuleType(modifierGroup.rule);
|
|
28
|
+
const contextValue = {
|
|
29
|
+
selectedModifierIds: groupSelectedModifierIds,
|
|
30
|
+
onToggle,
|
|
31
|
+
modifierGroup,
|
|
32
|
+
modifiers: modifierGroup.modifiers.map(convertModifierToFormModifier),
|
|
33
|
+
isSingleSelect,
|
|
34
|
+
ruleType,
|
|
35
|
+
};
|
|
36
|
+
return (_jsx(ModifiersContext.Provider, { value: contextValue, children: children }));
|
|
37
|
+
};
|
|
38
|
+
export const ModifiersComponent = ({ children, }) => {
|
|
39
|
+
const { selectedModifierIds, onToggle, modifierGroup, modifiers, isSingleSelect, } = useModifiersContext();
|
|
40
|
+
const singleSelectedModifierId = selectedModifierIds.length > 0 ? (selectedModifierIds[0] ?? '') : '';
|
|
41
|
+
return children({
|
|
42
|
+
selectedModifierIds,
|
|
43
|
+
onToggle,
|
|
44
|
+
modifierGroup,
|
|
45
|
+
modifiers,
|
|
46
|
+
isSingleSelect,
|
|
47
|
+
singleSelectedModifierId,
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
export const Description = ({ ruleTypeMap, children, }) => {
|
|
51
|
+
const { ruleType, modifierGroup } = useModifiersContext();
|
|
52
|
+
const modifierGroupName = modifierGroup.name || '';
|
|
53
|
+
const description = getRuleTypeMapValue(ruleTypeMap, ruleType, modifierGroupName, modifierGroup.rule);
|
|
54
|
+
return children({ description });
|
|
55
|
+
};
|
|
56
|
+
export const GroupError = ({ ruleTypeMap, children, }) => {
|
|
57
|
+
const service = useService(ItemServiceDefinition);
|
|
58
|
+
const { ruleType, modifierGroup } = useModifiersContext();
|
|
59
|
+
const groupId = modifierGroup._id || '';
|
|
60
|
+
const modifierGroupErrors = service.modifierGroupError?.get() || {};
|
|
61
|
+
const modifierGroupName = modifierGroup.name || '';
|
|
62
|
+
let error;
|
|
63
|
+
if (modifierGroupErrors[groupId]) {
|
|
64
|
+
error = getRuleTypeMapValue(ruleTypeMap, ruleType, modifierGroupName, modifierGroup.rule);
|
|
65
|
+
}
|
|
66
|
+
return children({ error });
|
|
67
|
+
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect } from 'react';
|
|
2
|
+
import { useEffect, useState } 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';
|
|
7
8
|
/**
|
|
8
9
|
* Core OLO Root component that sets up service management
|
|
9
10
|
* Provides ItemService and CurrentCartService to child components
|
|
@@ -24,6 +25,9 @@ import { OLOSettingsService, OLOSettingsServiceDefinition, } from '@wix/headless
|
|
|
24
25
|
* ```
|
|
25
26
|
*/
|
|
26
27
|
export const Root = ({ itemId, itemServiceConfig, cartServiceConfig, oloSettingsServiceConfig, children, }) => {
|
|
28
|
+
const [fulfillmentsServiceConfig, setFulfillmentsServiceConfig] = useState({
|
|
29
|
+
operation: oloSettingsServiceConfig?.operation ?? undefined,
|
|
30
|
+
});
|
|
27
31
|
// const [servicesManager, setServicesManager] = useState<ServicesManager | null>(null);
|
|
28
32
|
// const [isLoading, setIsLoading] = useState(true);
|
|
29
33
|
// const [error, setError] = useState<string | undefined>();
|
|
@@ -86,7 +90,17 @@ export const Root = ({ itemId, itemServiceConfig, cartServiceConfig, oloSettings
|
|
|
86
90
|
// hasServices
|
|
87
91
|
// });
|
|
88
92
|
console.log('oloSettingsServiceConfig', oloSettingsServiceConfig);
|
|
89
|
-
|
|
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 }));
|
|
90
104
|
};
|
|
91
105
|
/**
|
|
92
106
|
* Convenience wrapper that combines Root with ServicesManagerProvider
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MenusServiceConfig } from '@wix/headless-restaurants-menus/services';
|
|
3
|
+
export interface OLOMenusRootProps {
|
|
4
|
+
config: MenusServiceConfig;
|
|
5
|
+
children: (updatedConfig: MenusServiceConfig) => React.ReactNode;
|
|
6
|
+
}
|
|
7
|
+
export declare const Root: React.ForwardRefExoticComponent<OLOMenusRootProps & React.RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { OLOSettingsServiceDefinition } from '../../services/olo-settings-service.js';
|
|
3
|
+
import { useService } from '@wix/services-manager-react';
|
|
4
|
+
export const Root = React.forwardRef(function OLOMenusRoot({ config, children }) {
|
|
5
|
+
const service = useService(OLOSettingsServiceDefinition);
|
|
6
|
+
const filteredMenus = service.filterMenus(config.menus);
|
|
7
|
+
const hasMenus = Array.isArray(filteredMenus) && filteredMenus.length > 0;
|
|
8
|
+
if (!hasMenus)
|
|
9
|
+
return null;
|
|
10
|
+
config.menus = filteredMenus;
|
|
11
|
+
return children(config);
|
|
12
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import React from 'react';
|
|
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;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Core Settings component that provides access to OLO settings data
|
|
37
|
+
* Integrates with OLOSettingsService to expose operation and operation group data
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```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
|
+
* )}
|
|
55
|
+
* </CoreSettings.Root>
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare const Root: React.FC<SettingsRootProps>;
|
|
59
|
+
interface CurrentTimeSlotProps {
|
|
60
|
+
children: (props: {
|
|
61
|
+
timeSlot: TimeSlot;
|
|
62
|
+
hasDetails: boolean;
|
|
63
|
+
}) => React.ReactNode;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Component that provides access to current store details
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```tsx
|
|
70
|
+
* <CoreSettings.CurrentTimeSlot>
|
|
71
|
+
* {({ details, hasDetails }) => (
|
|
72
|
+
* hasDetails ? (
|
|
73
|
+
* <div>
|
|
74
|
+
* <h3>{details.timeSlot}</h3>
|
|
75
|
+
* </div>
|
|
76
|
+
* ) : (
|
|
77
|
+
* <div>No store details available</div>
|
|
78
|
+
* )
|
|
79
|
+
* )}
|
|
80
|
+
* </CoreSettings.CurrentTimeSlot>
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare const CurrentTimeSlot: React.FC<CurrentTimeSlotProps>;
|
|
84
|
+
interface CurrentFulfillmentProps {
|
|
85
|
+
children: (props: {
|
|
86
|
+
fulfillment: CurrentFulfillment;
|
|
87
|
+
hasFulfillment: boolean;
|
|
88
|
+
availableOptions: string[];
|
|
89
|
+
}) => React.ReactNode;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Component that provides access to current fulfillment options
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```tsx
|
|
96
|
+
* <CoreSettings.CurrentFulfillment>
|
|
97
|
+
* {({ fulfillment, availableOptions }) => (
|
|
98
|
+
* <div>
|
|
99
|
+
* <h3>Available Options:</h3>
|
|
100
|
+
* {availableOptions.map(option => (
|
|
101
|
+
* <div key={option}>{option}: Available</div>
|
|
102
|
+
* ))}
|
|
103
|
+
* </div>
|
|
104
|
+
* )}
|
|
105
|
+
* </CoreSettings.CurrentFulfillment>
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare const CurrentFulfillment: React.FC<CurrentFulfillmentProps>;
|
|
109
|
+
interface CurrentLocationProps {
|
|
110
|
+
children: (props: {
|
|
111
|
+
location: CurrentLocation;
|
|
112
|
+
hasLocation: boolean;
|
|
113
|
+
}) => React.ReactNode;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Component that provides access to current location data
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```tsx
|
|
120
|
+
* <CoreSettings.CurrentLocation>
|
|
121
|
+
* {({ location, hasCoordinates }) => (
|
|
122
|
+
* <div>
|
|
123
|
+
* <p>{location.address}</p>
|
|
124
|
+
* {hasCoordinates && (
|
|
125
|
+
* <p>Coordinates: {location.latitude}, {location.longitude}</p>
|
|
126
|
+
* )}
|
|
127
|
+
* </div>
|
|
128
|
+
* )}
|
|
129
|
+
* </CoreSettings.CurrentLocation>
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export declare const CurrentLocation: React.FC<CurrentLocationProps>;
|
|
133
|
+
interface ExtraDataProps {
|
|
134
|
+
children: (props: {
|
|
135
|
+
extraData: ExtraData;
|
|
136
|
+
hasExtraData: boolean;
|
|
137
|
+
}) => React.ReactNode;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Component that provides access to extra settings data
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```tsx
|
|
144
|
+
* <CoreSettings.ExtraData>
|
|
145
|
+
* {({ extraData }) => (
|
|
146
|
+
* <div>
|
|
147
|
+
* <p>Accepting Orders: {extraData.acceptingOrders ? 'Yes' : 'No'}</p>
|
|
148
|
+
* <p>Delivery Fee: ${extraData.deliveryFee}</p>
|
|
149
|
+
* <p>Min Order: ${extraData.minOrderAmount}</p>
|
|
150
|
+
* <p>Free Delivery: ${extraData.freeDeliveryThreshold}</p>
|
|
151
|
+
* </div>
|
|
152
|
+
* )}
|
|
153
|
+
* </CoreSettings.ExtraData>
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export declare const ExtraData: React.FC<ExtraDataProps>;
|
|
157
|
+
export {};
|