@wix/headless-restaurants-olo 0.0.2 → 0.0.5
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/ClickableItem.d.ts +9 -0
- package/cjs/dist/react/ClickableItem.js +14 -0
- package/cjs/dist/react/ItemDetails.d.ts +134 -2
- package/cjs/dist/react/ItemDetails.js +30 -15
- package/cjs/dist/react/OLO.d.ts +179 -0
- package/cjs/dist/react/OLO.js +134 -0
- package/cjs/dist/react/core/ClickableItem.d.ts +13 -0
- package/cjs/dist/react/core/ClickableItem.js +21 -0
- package/cjs/dist/react/core/ItemDetails.d.ts +1 -1
- package/cjs/dist/react/core/ItemDetails.js +14 -8
- package/cjs/dist/react/core/OLO.d.ts +92 -0
- package/cjs/dist/react/core/OLO.js +122 -0
- package/cjs/dist/react/core/index.d.ts +2 -0
- package/cjs/dist/react/core/index.js +2 -0
- package/cjs/dist/react/index.d.ts +3 -1
- package/cjs/dist/react/index.js +3 -1
- package/cjs/dist/services/item-details-service.d.ts +2 -2
- package/dist/react/ClickableItem.d.ts +9 -0
- package/dist/react/ClickableItem.js +14 -0
- package/dist/react/ItemDetails.d.ts +134 -2
- package/dist/react/ItemDetails.js +30 -15
- package/dist/react/OLO.d.ts +179 -0
- package/dist/react/OLO.js +134 -0
- package/dist/react/core/ClickableItem.d.ts +13 -0
- package/dist/react/core/ClickableItem.js +21 -0
- package/dist/react/core/ItemDetails.d.ts +1 -1
- package/dist/react/core/ItemDetails.js +14 -8
- package/dist/react/core/OLO.d.ts +92 -0
- package/dist/react/core/OLO.js +122 -0
- package/dist/react/core/index.d.ts +2 -0
- package/dist/react/core/index.js +2 -0
- package/dist/react/index.d.ts +3 -1
- package/dist/react/index.js +3 -1
- package/dist/services/item-details-service.d.ts +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ItemServiceConfig } from '../services/item-details-service.js';
|
|
3
|
+
interface OLORootProps {
|
|
4
|
+
/** The ID of the item to load */
|
|
5
|
+
itemId?: string;
|
|
6
|
+
/** Pre-loaded item service config (optional) */
|
|
7
|
+
itemServiceConfig?: any;
|
|
8
|
+
/** Pre-loaded OLO settings service config (optional) */
|
|
9
|
+
oloSettingsServiceConfig?: any;
|
|
10
|
+
/** Children render prop that receives the service state */
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Root headless component for OLO service management
|
|
15
|
+
* Wraps CoreOLO.Root and provides service state to children
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* <OLO.Root itemId="item-123">
|
|
20
|
+
* {({ isLoading, hasServices, error, retry }) => (
|
|
21
|
+
* isLoading ? (
|
|
22
|
+
* <LoadingSpinner />
|
|
23
|
+
* ) : error ? (
|
|
24
|
+
* <ErrorMessage error={error} onRetry={retry} />
|
|
25
|
+
* ) : hasServices ? (
|
|
26
|
+
* <ItemDetailsComponents />
|
|
27
|
+
* ) : null
|
|
28
|
+
* )}
|
|
29
|
+
* </OLO.Root>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const Root: React.FC<OLORootProps>;
|
|
33
|
+
interface OLOProviderProps {
|
|
34
|
+
/** The ID of the item to load */
|
|
35
|
+
itemId?: string;
|
|
36
|
+
/** Pre-loaded configurations (optional) */
|
|
37
|
+
configs?: {
|
|
38
|
+
itemServiceConfig?: ItemServiceConfig;
|
|
39
|
+
};
|
|
40
|
+
/** Loading component to show while services are initializing */
|
|
41
|
+
loading?: React.ReactNode;
|
|
42
|
+
/** Error component to show if service initialization fails */
|
|
43
|
+
error?: (props: {
|
|
44
|
+
error: string;
|
|
45
|
+
retry: () => void;
|
|
46
|
+
}) => React.ReactNode;
|
|
47
|
+
/** Children that will receive the services context */
|
|
48
|
+
children: React.ReactNode;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Convenience provider that handles loading and error states automatically
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* <OLO.Provider
|
|
56
|
+
* itemId="item-123"
|
|
57
|
+
* loading={<Spinner />}
|
|
58
|
+
* error={({ error, retry }) => <ErrorBanner message={error} onRetry={retry} />}
|
|
59
|
+
* >
|
|
60
|
+
* <ItemDetailsComponents />
|
|
61
|
+
* </OLO.Provider>
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare const Provider: React.FC<OLOProviderProps>;
|
|
65
|
+
interface OLOItemDetailsProps {
|
|
66
|
+
/** The ID of the item to load */
|
|
67
|
+
itemId: string;
|
|
68
|
+
/** Pre-loaded configurations (optional) */
|
|
69
|
+
configs?: {
|
|
70
|
+
itemServiceConfig?: ItemServiceConfig;
|
|
71
|
+
cartServiceConfig?: any;
|
|
72
|
+
};
|
|
73
|
+
/** Custom loading component */
|
|
74
|
+
loading?: React.ReactNode;
|
|
75
|
+
/** Custom error component */
|
|
76
|
+
error?: (props: {
|
|
77
|
+
error: string;
|
|
78
|
+
retry: () => void;
|
|
79
|
+
}) => React.ReactNode;
|
|
80
|
+
/** Custom not found component */
|
|
81
|
+
notFound?: React.ReactNode;
|
|
82
|
+
/** Children that will have access to item services */
|
|
83
|
+
children: React.ReactNode;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Specialized headless component for item details
|
|
87
|
+
* Includes item-specific error handling (like 404 not found)
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```tsx
|
|
91
|
+
* <OLO.ItemDetails
|
|
92
|
+
* itemId="item-123"
|
|
93
|
+
* notFound={<NotFoundPage />}
|
|
94
|
+
* >
|
|
95
|
+
* <ItemDetailsUI />
|
|
96
|
+
* </OLO.ItemDetails>
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare const ItemDetails: React.FC<OLOItemDetailsProps>;
|
|
100
|
+
interface OLOCartProps {
|
|
101
|
+
/** Pre-loaded cart service config (optional) */
|
|
102
|
+
cartServiceConfig?: any;
|
|
103
|
+
/** Loading component */
|
|
104
|
+
loading?: React.ReactNode;
|
|
105
|
+
/** Error component */
|
|
106
|
+
error?: (props: {
|
|
107
|
+
error: string;
|
|
108
|
+
retry: () => void;
|
|
109
|
+
}) => React.ReactNode;
|
|
110
|
+
/** Children that will have access to cart services */
|
|
111
|
+
children: React.ReactNode;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Headless component for cart-only functionality
|
|
115
|
+
* Doesn't load item services, only cart services
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```tsx
|
|
119
|
+
* <OLO.Cart>
|
|
120
|
+
* <CartComponents />
|
|
121
|
+
* </OLO.Cart>
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export declare const Cart: React.FC<OLOCartProps>;
|
|
125
|
+
interface OLOServicesStatusProps {
|
|
126
|
+
/** The ID of the item to check */
|
|
127
|
+
itemId?: string;
|
|
128
|
+
/** Children render prop that receives service status */
|
|
129
|
+
children: React.ReactNode;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Headless component for checking service status
|
|
133
|
+
* Useful for debugging or conditional rendering
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```tsx
|
|
137
|
+
* <OLO.ServicesStatus itemId="item-123">
|
|
138
|
+
* {({ hasItemService, hasCartService, error }) => (
|
|
139
|
+
* <div>
|
|
140
|
+
* Item Service: {hasItemService ? '✅' : '❌'}
|
|
141
|
+
* Cart Service: {hasCartService ? '✅' : '❌'}
|
|
142
|
+
* {error && <div>Error: {error}</div>}
|
|
143
|
+
* </div>
|
|
144
|
+
* )}
|
|
145
|
+
* </OLO.ServicesStatus>
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export declare const ServicesStatus: React.FC<OLOServicesStatusProps>;
|
|
149
|
+
/**
|
|
150
|
+
* Headless component for Menus service management.
|
|
151
|
+
* Wraps CoreOLO.Menus and provides render props for UI.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```tsx
|
|
155
|
+
* <OLO.Menus>
|
|
156
|
+
* {({ menus, isLoading, error }) => (
|
|
157
|
+
* isLoading ? (
|
|
158
|
+
* <div>Loading...</div>
|
|
159
|
+
* ) : error ? (
|
|
160
|
+
* <div className="text-destructive">{error}</div>
|
|
161
|
+
* ) : (
|
|
162
|
+
* <ul>
|
|
163
|
+
* {menus.map(menu => (
|
|
164
|
+
* <li key={menu.id} className="text-foreground font-paragraph">{menu.name}</li>
|
|
165
|
+
* ))}
|
|
166
|
+
* </ul>
|
|
167
|
+
* )
|
|
168
|
+
* )}
|
|
169
|
+
* </OLO.Menus>
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
interface OLOMenusProps {
|
|
173
|
+
/** Optional menu service config */
|
|
174
|
+
menuServiceConfig?: any;
|
|
175
|
+
/** Children render prop that receives menus state */
|
|
176
|
+
children?: React.ReactNode;
|
|
177
|
+
}
|
|
178
|
+
export declare const Menus: React.FC<OLOMenusProps>;
|
|
179
|
+
export {};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { CoreOLO } from './core/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Root headless component for OLO service management
|
|
6
|
+
* Wraps CoreOLO.Root and provides service state to children
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <OLO.Root itemId="item-123">
|
|
11
|
+
* {({ isLoading, hasServices, error, retry }) => (
|
|
12
|
+
* isLoading ? (
|
|
13
|
+
* <LoadingSpinner />
|
|
14
|
+
* ) : error ? (
|
|
15
|
+
* <ErrorMessage error={error} onRetry={retry} />
|
|
16
|
+
* ) : hasServices ? (
|
|
17
|
+
* <ItemDetailsComponents />
|
|
18
|
+
* ) : null
|
|
19
|
+
* )}
|
|
20
|
+
* </OLO.Root>
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export const Root = ({ itemId, oloSettingsServiceConfig, children, }) => {
|
|
24
|
+
const [retryKey] = React.useState(0);
|
|
25
|
+
// const retry = React.useCallback(() => {
|
|
26
|
+
// setRetryKey(prev => prev + 1);
|
|
27
|
+
// }, []);
|
|
28
|
+
return (_jsx(CoreOLO.Root, { itemId: itemId, oloSettingsServiceConfig: oloSettingsServiceConfig, children: children }, retryKey));
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Convenience provider that handles loading and error states automatically
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* <OLO.Provider
|
|
36
|
+
* itemId="item-123"
|
|
37
|
+
* loading={<Spinner />}
|
|
38
|
+
* error={({ error, retry }) => <ErrorBanner message={error} onRetry={retry} />}
|
|
39
|
+
* >
|
|
40
|
+
* <ItemDetailsComponents />
|
|
41
|
+
* </OLO.Provider>
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export const Provider = ({ itemId, configs,
|
|
45
|
+
// loading = (
|
|
46
|
+
// <div className="flex items-center justify-center p-8">
|
|
47
|
+
// <div className="text-secondary-foreground">Loading services...</div>
|
|
48
|
+
// </div>
|
|
49
|
+
// ),
|
|
50
|
+
// error: errorComponent = ({ error, retry }) => (
|
|
51
|
+
// <div className="flex flex-col items-center justify-center p-8 space-y-4">
|
|
52
|
+
// <div className="text-destructive">Error: {error}</div>
|
|
53
|
+
// <button
|
|
54
|
+
// onClick={retry}
|
|
55
|
+
// className="px-4 py-2 bg-primary text-primary-foreground rounded hover:bg-primary/90"
|
|
56
|
+
// >
|
|
57
|
+
// Retry
|
|
58
|
+
// </button>
|
|
59
|
+
// </div>
|
|
60
|
+
// ),
|
|
61
|
+
children, }) => {
|
|
62
|
+
return (_jsx(Root, { itemId: itemId, itemServiceConfig: configs?.itemServiceConfig, children: children }));
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Specialized headless component for item details
|
|
66
|
+
* Includes item-specific error handling (like 404 not found)
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```tsx
|
|
70
|
+
* <OLO.ItemDetails
|
|
71
|
+
* itemId="item-123"
|
|
72
|
+
* notFound={<NotFoundPage />}
|
|
73
|
+
* >
|
|
74
|
+
* <ItemDetailsUI />
|
|
75
|
+
* </OLO.ItemDetails>
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export const ItemDetails = ({ itemId, configs, loading, error, notFound = (_jsx("div", { className: "flex items-center justify-center p-8", children: _jsx("div", { className: "text-secondary-foreground", children: "Item not found" }) })), children, }) => {
|
|
79
|
+
return (_jsx(Provider, { itemId: itemId, configs: configs, loading: loading, error: ({ error: errorMessage, retry }) => {
|
|
80
|
+
// Handle item not found specifically
|
|
81
|
+
if (errorMessage === 'Item not found') {
|
|
82
|
+
return _jsx(_Fragment, { children: notFound });
|
|
83
|
+
}
|
|
84
|
+
// Use custom error component if provided
|
|
85
|
+
if (error) {
|
|
86
|
+
return _jsx(_Fragment, { children: error({ error: errorMessage, retry }) });
|
|
87
|
+
}
|
|
88
|
+
// Default error handling
|
|
89
|
+
return (_jsxs("div", { className: "flex flex-col items-center justify-center p-8 space-y-4", children: [_jsxs("div", { className: "text-destructive", children: ["Error: ", errorMessage] }), _jsx("button", { onClick: retry, className: "px-4 py-2 bg-primary text-primary-foreground rounded hover:bg-primary/90", children: "Retry" })] }));
|
|
90
|
+
}, children: children }));
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Headless component for cart-only functionality
|
|
94
|
+
* Doesn't load item services, only cart services
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```tsx
|
|
98
|
+
* <OLO.Cart>
|
|
99
|
+
* <CartComponents />
|
|
100
|
+
* </OLO.Cart>
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export const Cart = ({ loading, error, children }) => {
|
|
104
|
+
return (_jsx(Provider, { loading: loading, error: error, children: children }));
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Headless component for checking service status
|
|
108
|
+
* Useful for debugging or conditional rendering
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```tsx
|
|
112
|
+
* <OLO.ServicesStatus itemId="item-123">
|
|
113
|
+
* {({ hasItemService, hasCartService, error }) => (
|
|
114
|
+
* <div>
|
|
115
|
+
* Item Service: {hasItemService ? '✅' : '❌'}
|
|
116
|
+
* Cart Service: {hasCartService ? '✅' : '❌'}
|
|
117
|
+
* {error && <div>Error: {error}</div>}
|
|
118
|
+
* </div>
|
|
119
|
+
* )}
|
|
120
|
+
* </OLO.ServicesStatus>
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export const ServicesStatus = ({ itemId, children, }) => {
|
|
124
|
+
return (_jsx(Root, { itemId: itemId, children: children }));
|
|
125
|
+
};
|
|
126
|
+
export const Menus = ({
|
|
127
|
+
// menuServiceConfig,
|
|
128
|
+
children, }) => {
|
|
129
|
+
// const [retryKey, setRetryKey] = React.useState(0);
|
|
130
|
+
// const [menus, setMenus] = React.useState<any[]>([]);
|
|
131
|
+
// const [isLoading, setIsLoading] = React.useState(true);
|
|
132
|
+
// const [error, setError] = React.useState<string | undefined>(undefined);
|
|
133
|
+
return _jsx(_Fragment, { children: children });
|
|
134
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* CoreMenuItem
|
|
4
|
+
*
|
|
5
|
+
* A core menu item component that displays the item image, name, description, and price
|
|
6
|
+
* using the project's design system for colors and fonts.
|
|
7
|
+
*/
|
|
8
|
+
export declare function CoreClickableItem({ children, }: {
|
|
9
|
+
children: (props: {
|
|
10
|
+
item: any;
|
|
11
|
+
itemSelected: () => void;
|
|
12
|
+
}) => React.ReactNode;
|
|
13
|
+
}): React.ReactNode;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useItemContext, useMenuContext, useSectionContext, } from '@wix/restaurants/components';
|
|
2
|
+
import { useService } from '@wix/services-manager-react';
|
|
3
|
+
import { OLOSettingsServiceDefinition } from '@wix/headless-restaurants-olo/services';
|
|
4
|
+
// import { OLOSettingsServiceDefinition } from "../../services/OLOSettingsService";
|
|
5
|
+
/**
|
|
6
|
+
* CoreMenuItem
|
|
7
|
+
*
|
|
8
|
+
* A core menu item component that displays the item image, name, description, and price
|
|
9
|
+
* using the project's design system for colors and fonts.
|
|
10
|
+
*/
|
|
11
|
+
export function CoreClickableItem({ children, }) {
|
|
12
|
+
const { item } = useItemContext();
|
|
13
|
+
const { section } = useSectionContext();
|
|
14
|
+
const { menu } = useMenuContext();
|
|
15
|
+
const service = useService(OLOSettingsServiceDefinition);
|
|
16
|
+
const itemSelected = () => {
|
|
17
|
+
const selectedItem = { ...item, sectionId: section._id, menuId: menu._id };
|
|
18
|
+
service.selectedItem?.set(selectedItem);
|
|
19
|
+
};
|
|
20
|
+
return children({ item, itemSelected });
|
|
21
|
+
}
|
|
@@ -5,7 +5,7 @@ interface ItemDetailsRootProps {
|
|
|
5
5
|
children: (props: {
|
|
6
6
|
item: unknown;
|
|
7
7
|
}) => React.ReactNode;
|
|
8
|
-
itemDetailsServiceConfig
|
|
8
|
+
itemDetailsServiceConfig?: ItemServiceConfig;
|
|
9
9
|
}
|
|
10
10
|
export declare const Root: React.FC<ItemDetailsRootProps>;
|
|
11
11
|
interface ItemDetailsModifiersRepeaterProps {
|
|
@@ -4,18 +4,24 @@ 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
|
-
export const Root = ({ children }) => {
|
|
7
|
+
export const Root = ({ children, itemDetailsServiceConfig, }) => {
|
|
8
8
|
const service = useService(OLOSettingsServiceDefinition);
|
|
9
9
|
const selectedItem = service.selectedItem?.get();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
let config = itemDetailsServiceConfig;
|
|
11
|
+
if (!config) {
|
|
12
|
+
config = loadItemServiceConfig({
|
|
13
|
+
item: selectedItem,
|
|
14
|
+
operationId: service.operation?.get()?._id ?? '',
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
if (config.item) {
|
|
18
|
+
service.selectedItem?.set(config.item);
|
|
19
|
+
}
|
|
20
|
+
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(ItemServiceDefinition, ItemService, config), children: children({ item: itemDetailsServiceConfig?.item ?? selectedItem }) }));
|
|
15
21
|
};
|
|
16
22
|
export const ModifiersRepeater = ({ children, }) => {
|
|
17
23
|
const service = useService(ItemServiceDefinition);
|
|
18
|
-
const item = service.item
|
|
24
|
+
const item = service.item?.get();
|
|
19
25
|
// TODO: Check if modifiers exist on item type - might be in a different property
|
|
20
26
|
const modifiers = item?.modifiers || [];
|
|
21
27
|
const hasModifiers = modifiers.length > 0;
|
|
@@ -23,7 +29,7 @@ export const ModifiersRepeater = ({ children, }) => {
|
|
|
23
29
|
};
|
|
24
30
|
export const VariantsRepeater = ({ children, }) => {
|
|
25
31
|
const service = useService(ItemServiceDefinition);
|
|
26
|
-
const item = service.item
|
|
32
|
+
const item = service.item?.get();
|
|
27
33
|
// TODO: Check if variants exist on item type - might be in a different property
|
|
28
34
|
const variants = item?.variants || [];
|
|
29
35
|
const hasVariants = variants.length > 0;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { OLOSettingsServiceConfig } from '../../services/olo-settings-service.js';
|
|
3
|
+
import { ItemServiceConfig } from '../../services/item-details-service.js';
|
|
4
|
+
interface CoreOLORootProps {
|
|
5
|
+
/** The ID of the item to load */
|
|
6
|
+
itemId?: string;
|
|
7
|
+
/** Pre-loaded item service config (optional) */
|
|
8
|
+
itemServiceConfig?: ItemServiceConfig;
|
|
9
|
+
/** Pre-loaded cart service config (optional) */
|
|
10
|
+
cartServiceConfig?: any;
|
|
11
|
+
/** Pre-loaded OLO settings service config (optional) */
|
|
12
|
+
oloSettingsServiceConfig?: OLOSettingsServiceConfig;
|
|
13
|
+
/** Children render prop that receives the services manager state */
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Core OLO Root component that sets up service management
|
|
18
|
+
* Provides ItemService and CurrentCartService to child components
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* <CoreOLO.Root itemId="item-123">
|
|
23
|
+
* {({ servicesManager, isLoading, hasServices }) => (
|
|
24
|
+
* hasServices ? (
|
|
25
|
+
* <ServicesManagerProvider servicesManager={servicesManager}>
|
|
26
|
+
* <ItemDetailsComponents />
|
|
27
|
+
* </ServicesManagerProvider>
|
|
28
|
+
* ) : (
|
|
29
|
+
* <LoadingSpinner />
|
|
30
|
+
* )
|
|
31
|
+
* )}
|
|
32
|
+
* </CoreOLO.Root>
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const Root: React.FC<CoreOLORootProps>;
|
|
36
|
+
interface CoreOLOProviderProps {
|
|
37
|
+
/** The ID of the item to load */
|
|
38
|
+
itemId?: string;
|
|
39
|
+
/** Pre-loaded item service config (optional) */
|
|
40
|
+
itemServiceConfig?: ItemServiceConfig;
|
|
41
|
+
/** Pre-loaded cart service config (optional) */
|
|
42
|
+
cartServiceConfig?: any;
|
|
43
|
+
/** Pre-loaded OLO settings service config (optional) */
|
|
44
|
+
oloSettingsServiceConfig?: OLOSettingsServiceConfig;
|
|
45
|
+
/** Loading component to show while services are initializing */
|
|
46
|
+
loading?: React.ReactNode;
|
|
47
|
+
/** Error component to show if service initialization fails */
|
|
48
|
+
error?: (error: string) => React.ReactNode;
|
|
49
|
+
/** Children that will receive the services context */
|
|
50
|
+
children: React.ReactNode;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Convenience wrapper that combines Root with ServicesManagerProvider
|
|
54
|
+
* Automatically provides services context to children
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```tsx
|
|
58
|
+
* <CoreOLO.Provider itemId="item-123">
|
|
59
|
+
* <ItemDetailsComponents />
|
|
60
|
+
* </CoreOLO.Provider>
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare const Provider: React.FC<CoreOLOProviderProps>;
|
|
64
|
+
interface CoreOLOItemDetailsProps {
|
|
65
|
+
/** The ID of the item to load */
|
|
66
|
+
itemId: string;
|
|
67
|
+
/** Pre-loaded configurations (optional) */
|
|
68
|
+
configs?: {
|
|
69
|
+
itemServiceConfig?: ItemServiceConfig;
|
|
70
|
+
cartServiceConfig?: any;
|
|
71
|
+
};
|
|
72
|
+
/** Loading component */
|
|
73
|
+
loading?: React.ReactNode;
|
|
74
|
+
/** Error component */
|
|
75
|
+
error?: (error: string) => React.ReactNode;
|
|
76
|
+
/** Children that will have access to item services */
|
|
77
|
+
children: React.ReactNode;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Specialized wrapper for item details that ensures ItemService is available
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```tsx
|
|
84
|
+
* <CoreOLO.ItemDetails itemId="item-123">
|
|
85
|
+
* <ItemDetailsPrimitive.Root>
|
|
86
|
+
* {({ item }) => <div>{item.name}</div>}
|
|
87
|
+
* </ItemDetailsPrimitive.Root>
|
|
88
|
+
* </CoreOLO.ItemDetails>
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare const ItemDetails: React.FC<CoreOLOItemDetailsProps>;
|
|
92
|
+
export {};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { createServicesMap } from '@wix/services-manager';
|
|
4
|
+
import { WixServices } from '@wix/services-manager-react';
|
|
5
|
+
// import { ItemService, ItemServiceDefinition, loadItemServiceConfig } from '@/components/restaurants-olo/services/itemDetailsService';
|
|
6
|
+
import { OLOSettingsService, OLOSettingsServiceDefinition, } from '@wix/headless-restaurants-olo/services';
|
|
7
|
+
/**
|
|
8
|
+
* Core OLO Root component that sets up service management
|
|
9
|
+
* Provides ItemService and CurrentCartService to child components
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <CoreOLO.Root itemId="item-123">
|
|
14
|
+
* {({ servicesManager, isLoading, hasServices }) => (
|
|
15
|
+
* hasServices ? (
|
|
16
|
+
* <ServicesManagerProvider servicesManager={servicesManager}>
|
|
17
|
+
* <ItemDetailsComponents />
|
|
18
|
+
* </ServicesManagerProvider>
|
|
19
|
+
* ) : (
|
|
20
|
+
* <LoadingSpinner />
|
|
21
|
+
* )
|
|
22
|
+
* )}
|
|
23
|
+
* </CoreOLO.Root>
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export const Root = ({ itemId, itemServiceConfig, cartServiceConfig, oloSettingsServiceConfig, children, }) => {
|
|
27
|
+
// const [servicesManager, setServicesManager] = useState<ServicesManager | null>(null);
|
|
28
|
+
// const [isLoading, setIsLoading] = useState(true);
|
|
29
|
+
// const [error, setError] = useState<string | undefined>();
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
// const initializeServices = async () => {
|
|
32
|
+
// setIsLoading(true);
|
|
33
|
+
// setError(undefined);
|
|
34
|
+
// try {
|
|
35
|
+
// // Load configurations if not provided
|
|
36
|
+
// const loadedConfigs = await Promise.all([
|
|
37
|
+
// cartServiceConfig || loadCurrentCartServiceConfig(),
|
|
38
|
+
// itemServiceConfig || (loadItemServiceConfig(itemId))
|
|
39
|
+
// ]);
|
|
40
|
+
// const [currentCartServiceConfig, itemServiceConfigResult] = loadedConfigs;
|
|
41
|
+
// // Handle item service config result (discriminated union)
|
|
42
|
+
// if (itemServiceConfigResult && 'type' in itemServiceConfigResult) {
|
|
43
|
+
// if (itemServiceConfigResult.type === 'notFound') {
|
|
44
|
+
// setError('Item not found');
|
|
45
|
+
// return;
|
|
46
|
+
// }
|
|
47
|
+
// // Use the config from the success result
|
|
48
|
+
// const finalItemServiceConfig = itemServiceConfigResult.config;
|
|
49
|
+
// // Create services manager with both services
|
|
50
|
+
// const manager = createServicesManager(
|
|
51
|
+
// createServicesMap()
|
|
52
|
+
// .addService(CurrentCartServiceDefinition, CurrentCartService, currentCartServiceConfig)
|
|
53
|
+
// // .addService(ItemServiceDefinition, ItemService, finalItemServiceConfig)
|
|
54
|
+
// );
|
|
55
|
+
// setServicesManager(manager);
|
|
56
|
+
// } else if (itemServiceConfigResult) {
|
|
57
|
+
// // Direct config provided
|
|
58
|
+
// const manager = createServicesManager(
|
|
59
|
+
// createServicesMap()
|
|
60
|
+
// .addService(CurrentCartServiceDefinition, CurrentCartService, currentCartServiceConfig)
|
|
61
|
+
// // .addService(ItemServiceDefinition, ItemService, itemServiceConfigResult)
|
|
62
|
+
// );
|
|
63
|
+
// setServicesManager(manager);
|
|
64
|
+
// } else {
|
|
65
|
+
// // Only cart service, no item service
|
|
66
|
+
// const manager = createServicesManager(
|
|
67
|
+
// createServicesMap()
|
|
68
|
+
// .addService(CurrentCartServiceDefinition, CurrentCartService, currentCartServiceConfig)
|
|
69
|
+
// );
|
|
70
|
+
// setServicesManager(manager);
|
|
71
|
+
// }
|
|
72
|
+
// } catch (err) {
|
|
73
|
+
// console.error('Failed to initialize services:', err);
|
|
74
|
+
// setError('Failed to initialize services');
|
|
75
|
+
// } finally {
|
|
76
|
+
// setIsLoading(false);
|
|
77
|
+
// }
|
|
78
|
+
// };
|
|
79
|
+
// initializeServices();
|
|
80
|
+
}, [itemId, itemServiceConfig, cartServiceConfig]);
|
|
81
|
+
// const hasServices = Boolean(servicesManager);
|
|
82
|
+
// return children({
|
|
83
|
+
// servicesManager,
|
|
84
|
+
// isLoading,
|
|
85
|
+
// error,
|
|
86
|
+
// hasServices
|
|
87
|
+
// });
|
|
88
|
+
console.log('oloSettingsServiceConfig', oloSettingsServiceConfig);
|
|
89
|
+
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(OLOSettingsServiceDefinition, OLOSettingsService, oloSettingsServiceConfig), children: children }));
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Convenience wrapper that combines Root with ServicesManagerProvider
|
|
93
|
+
* Automatically provides services context to children
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```tsx
|
|
97
|
+
* <CoreOLO.Provider itemId="item-123">
|
|
98
|
+
* <ItemDetailsComponents />
|
|
99
|
+
* </CoreOLO.Provider>
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export const Provider = ({ itemId, itemServiceConfig, cartServiceConfig, oloSettingsServiceConfig,
|
|
103
|
+
// loading = <div>Loading services...</div>,
|
|
104
|
+
// error: errorComponent = (error: string) => <div>Error: {error}</div>,
|
|
105
|
+
children, }) => {
|
|
106
|
+
return (_jsx(Root, { itemId: itemId, itemServiceConfig: itemServiceConfig, cartServiceConfig: cartServiceConfig, oloSettingsServiceConfig: oloSettingsServiceConfig, children: children }));
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Specialized wrapper for item details that ensures ItemService is available
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```tsx
|
|
113
|
+
* <CoreOLO.ItemDetails itemId="item-123">
|
|
114
|
+
* <ItemDetailsPrimitive.Root>
|
|
115
|
+
* {({ item }) => <div>{item.name}</div>}
|
|
116
|
+
* </ItemDetailsPrimitive.Root>
|
|
117
|
+
* </CoreOLO.ItemDetails>
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export const ItemDetails = ({ itemId, configs, loading, error, children, }) => {
|
|
121
|
+
return (_jsx(Provider, { itemId: itemId, itemServiceConfig: configs?.itemServiceConfig, cartServiceConfig: configs?.cartServiceConfig, loading: loading, error: error, children: children }));
|
|
122
|
+
};
|
package/dist/react/core/index.js
CHANGED
package/dist/react/index.d.ts
CHANGED
package/dist/react/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { type LineItem } from '@wix/ecom/services';
|
|
|
9
9
|
*/
|
|
10
10
|
export interface ItemServiceAPI {
|
|
11
11
|
/** Reactive signal containing the current item data */
|
|
12
|
-
item
|
|
12
|
+
item?: Signal<items.Item | undefined>;
|
|
13
13
|
quantity: Signal<number>;
|
|
14
14
|
specialRequest: Signal<string>;
|
|
15
15
|
lineItem: Signal<LineItem>;
|
|
@@ -41,7 +41,7 @@ export declare const ItemServiceDefinition: string & {
|
|
|
41
41
|
*/
|
|
42
42
|
export interface ItemServiceConfig {
|
|
43
43
|
/** The initial item data to configure the service with */
|
|
44
|
-
item
|
|
44
|
+
item?: items.Item;
|
|
45
45
|
itemId?: string;
|
|
46
46
|
operationId?: string;
|
|
47
47
|
}
|