@wix/headless-restaurants-olo 0.0.6 → 0.0.7

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.
@@ -157,8 +157,8 @@ export interface ItemDetailsModifierGroupsProps {
157
157
  }
158
158
  export declare const ModifierGroups: React.ForwardRefExoticComponent<ItemDetailsModifierGroupsProps & React.RefAttributes<HTMLElement>>;
159
159
  /**
160
- * Wrapper component for Item.VariantsRepeater.
161
- * Renders the variants for the item using the headless component.
160
+ * Wrapper component for CoreItemDetails.VariantsComponent.
161
+ * Renders the variants for the item using Radix UI RadioGroup.
162
162
  *
163
163
  * @component
164
164
  * @example
@@ -171,11 +171,16 @@ export declare const ModifierGroups: React.ForwardRefExoticComponent<ItemDetails
171
171
  export interface ItemDetailsVariantsProps {
172
172
  children?: AsChildChildren<{
173
173
  variant: any;
174
+ variants: any[];
175
+ hasVariants: boolean;
176
+ selectedVariantId?: string;
177
+ onVariantChange?: (variantId: string) => void;
174
178
  }>;
175
179
  className?: string;
176
180
  asChild?: boolean;
177
181
  variantNameClassName?: string;
178
182
  variantPriceClassName?: string;
183
+ emptyState?: React.ReactNode;
179
184
  }
180
185
  export declare const Variants: React.ForwardRefExoticComponent<ItemDetailsVariantsProps & React.RefAttributes<HTMLElement>>;
181
186
  export interface AddToCartActionProps {
@@ -3,7 +3,8 @@ import React from 'react';
3
3
  import { Commerce } from '@wix/ecom/components';
4
4
  import { AsChildSlot } from '@wix/headless-utils/react';
5
5
  import { Quantity as QuantityComponent } from '@wix/headless-components/react';
6
- import { Item, Label, Modifier, ModifierGroup, Variant, } from '@wix/restaurants/components';
6
+ import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
7
+ import { Item, Label, Modifier, ModifierGroup, } from '@wix/headless-restaurants-menus/react';
7
8
  import * as CoreItemDetails from './core/ItemDetails.js';
8
9
  var TestIds;
9
10
  (function (TestIds) {
@@ -43,8 +44,20 @@ Labels.displayName = 'ItemDetails.Labels';
43
44
  export const ModifierGroups = React.forwardRef(({ children, className, asChild, modifierNameClassName, modifierPriceClassName, ...rest }) => {
44
45
  return (_jsx(Item.ModifierGroupsRepeater, { ...rest, children: _jsx(AsChildSlot, { asChild: asChild, testId: TestIds.itemModifierGroups, className: className, customElement: children, children: _jsxs(ModifierGroup.ModifiersRepeater, { children: [_jsx(Modifier.Name, { className: modifierNameClassName }), _jsx(Modifier.Price, { className: modifierPriceClassName })] }) }) }));
45
46
  });
46
- export const Variants = React.forwardRef(({ children, className, asChild, variantNameClassName, variantPriceClassName, ...rest }) => {
47
- return (_jsx(Item.VariantsRepeater, { ...rest, children: _jsxs(AsChildSlot, { asChild: asChild, testId: TestIds.itemVariants, className: className, customElement: children, children: [_jsx(Variant.Name, { className: variantNameClassName }), _jsx(Variant.Price, { className: variantPriceClassName })] }) }));
47
+ export const Variants = React.forwardRef(({ children, className, asChild, variantNameClassName, variantPriceClassName, emptyState, }, ref) => {
48
+ return (_jsx(CoreItemDetails.VariantsComponent, { children: ({ variants, hasVariants, selectedVariantId, onVariantChange }) => {
49
+ if (!hasVariants) {
50
+ return emptyState || null;
51
+ }
52
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, testId: TestIds.itemVariants, className: className, customElement: children, customElementProps: {
53
+ variants,
54
+ hasVariants,
55
+ selectedVariantId,
56
+ onVariantChange,
57
+ }, children: _jsx(RadioGroupPrimitive.Root, { value: selectedVariantId, onValueChange: onVariantChange, children: variants.map((variant) => (_jsx(RadioGroupPrimitive.Item, { value: variant._id, children: _jsxs("div", { children: [_jsx("div", { className: variantNameClassName, children: variant.name }), _jsx("div", { className: variantPriceClassName, children: variant.priceInfo?.formattedPrice ||
58
+ variant.priceInfo?.price ||
59
+ '' })] }) }, variant._id))) }) }));
60
+ } }));
48
61
  });
49
62
  Variants.displayName = 'ItemDetails.Variants';
50
63
  ModifierGroups.displayName = 'ItemDetails.ModifierGroups';
@@ -1,4 +1,4 @@
1
- import { useItemContext, useMenuContext, useSectionContext, } from '@wix/restaurants/components';
1
+ import { useItemContext, useMenuContext, useSectionContext, } from '@wix/headless-restaurants-menus/react';
2
2
  import { useService } from '@wix/services-manager-react';
3
3
  import { OLOSettingsServiceDefinition } from '@wix/headless-restaurants-olo/services';
4
4
  // import { OLOSettingsServiceDefinition } from "../../services/OLOSettingsService";
@@ -15,13 +15,6 @@ interface ItemDetailsModifiersRepeaterProps {
15
15
  }) => React.ReactNode;
16
16
  }
17
17
  export declare const ModifiersRepeater: React.FC<ItemDetailsModifiersRepeaterProps>;
18
- interface ItemDetailsVariantsRepeaterProps {
19
- children: (props: {
20
- variants: [];
21
- hasVariants: boolean;
22
- }) => React.ReactNode;
23
- }
24
- export declare const VariantsRepeater: React.FC<ItemDetailsVariantsRepeaterProps>;
25
18
  interface ItemDetailsSpecialRequestProps {
26
19
  children: (props: {
27
20
  value: string;
@@ -47,4 +40,14 @@ interface ItemDetailsQuantityProps {
47
40
  }) => React.ReactNode;
48
41
  }
49
42
  export declare const QuantityComponent: React.FC<ItemDetailsQuantityProps>;
43
+ interface ItemDetailsVariantsProps {
44
+ children: (props: {
45
+ variants: any[];
46
+ hasVariants: boolean;
47
+ selectedVariantId?: string;
48
+ onVariantChange?: (variantId: string) => void;
49
+ selectedVariant?: any;
50
+ }) => React.ReactNode;
51
+ }
52
+ export declare const VariantsComponent: React.FC<ItemDetailsVariantsProps>;
50
53
  export {};
@@ -4,6 +4,7 @@ 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 } from '@wix/headless-restaurants-menus/react';
7
8
  export const Root = ({ children, itemDetailsServiceConfig, }) => {
8
9
  const service = useService(OLOSettingsServiceDefinition);
9
10
  const selectedItem = service.selectedItem?.get();
@@ -27,14 +28,6 @@ export const ModifiersRepeater = ({ children, }) => {
27
28
  const hasModifiers = modifiers.length > 0;
28
29
  return children({ modifiers, hasModifiers });
29
30
  };
30
- export const VariantsRepeater = ({ children, }) => {
31
- const service = useService(ItemServiceDefinition);
32
- const item = service.item?.get();
33
- // TODO: Check if variants exist on item type - might be in a different property
34
- const variants = item?.variants || [];
35
- const hasVariants = variants.length > 0;
36
- return children({ variants, hasVariants });
37
- };
38
31
  export const SpecialRequest = ({ children, }) => {
39
32
  const [value, setValue] = useState('');
40
33
  const service = useService(ItemServiceDefinition);
@@ -77,3 +70,25 @@ export const QuantityComponent = ({ children, }) => {
77
70
  onValueChange,
78
71
  });
79
72
  };
73
+ export const VariantsComponent = ({ children, }) => {
74
+ const service = useService(ItemServiceDefinition);
75
+ const { item } = useItemContext();
76
+ const selectedVariant = service.selectedVariant?.get?.();
77
+ // Get variants from item context
78
+ const variants = item?.priceVariants || [];
79
+ const hasVariants = variants.length > 0;
80
+ const selectedVariantId = selectedVariant?._id ?? undefined;
81
+ const onVariantChange = (variantId) => {
82
+ const variant = variants.find((v) => v._id === variantId);
83
+ if (variant) {
84
+ service.updateSelectedVariant?.(variant);
85
+ }
86
+ };
87
+ return children({
88
+ variants,
89
+ hasVariants,
90
+ selectedVariantId,
91
+ onVariantChange,
92
+ selectedVariant,
93
+ });
94
+ };
@@ -1,6 +1,8 @@
1
1
  import { type Signal } from '@wix/services-definitions/core-services/signals';
2
2
  import * as items from '@wix/auto_sdk_restaurants_items';
3
3
  import { type LineItem } from '@wix/ecom/services';
4
+ import { itemVariants } from '@wix/restaurants';
5
+ type Variant = itemVariants.Variant;
4
6
  /**
5
7
  * API interface for the Item Detailsservice, providing reactive item data management.
6
8
  * This service handles loading and managing a single item's data, loading state, and errors.
@@ -13,6 +15,7 @@ export interface ItemServiceAPI {
13
15
  quantity: Signal<number>;
14
16
  specialRequest: Signal<string>;
15
17
  lineItem: Signal<LineItem>;
18
+ selectedVariant: Signal<Variant | undefined>;
16
19
  /** Reactive signal indicating if a item is currently being loaded */
17
20
  isLoading: Signal<boolean>;
18
21
  /** Reactive signal containing any error message, or null if no error */
@@ -21,6 +24,8 @@ export interface ItemServiceAPI {
21
24
  updateQuantity: (quantity: number) => void;
22
25
  /** Function to update the special request of the item */
23
26
  updateSpecialRequest: (specialRequest: string) => void;
27
+ /** Function to update the selected variant of the item */
28
+ updateSelectedVariant: (variant: Variant) => void;
24
29
  }
25
30
  /**
26
31
  * Service definition for the Item service.
@@ -152,3 +157,4 @@ export declare function loadItemServiceConfig({ item, operationId, }: {
152
157
  item: any;
153
158
  operationId: string;
154
159
  }): ItemServiceConfig;
160
+ export {};
@@ -49,6 +49,9 @@ export const ItemService = implementService.withConfig()(ItemServiceDefinition,
49
49
  const quantity = signalsService.signal(1);
50
50
  const specialRequest = signalsService.signal('');
51
51
  const lineItem = signalsService.signal({});
52
+ const priceVariants = config.item?.priceVariants || [];
53
+ const initialVariant = priceVariants.length > 0 ? priceVariants[0] : undefined;
54
+ const selectedVariant = signalsService.signal(initialVariant);
52
55
  if (config.item) {
53
56
  console.log('config.item', config.item);
54
57
  lineItem.set({
@@ -89,15 +92,20 @@ export const ItemService = implementService.withConfig()(ItemServiceDefinition,
89
92
  },
90
93
  });
91
94
  };
95
+ const updateSelectedVariant = (variant) => {
96
+ selectedVariant.set(variant);
97
+ };
92
98
  return {
93
99
  item,
94
100
  quantity,
95
101
  updateQuantity,
96
102
  updateSpecialRequest,
103
+ updateSelectedVariant,
97
104
  isLoading,
98
105
  error,
99
106
  specialRequest,
100
107
  lineItem,
108
+ selectedVariant,
101
109
  };
102
110
  });
103
111
  /**
@@ -157,8 +157,8 @@ export interface ItemDetailsModifierGroupsProps {
157
157
  }
158
158
  export declare const ModifierGroups: React.ForwardRefExoticComponent<ItemDetailsModifierGroupsProps & React.RefAttributes<HTMLElement>>;
159
159
  /**
160
- * Wrapper component for Item.VariantsRepeater.
161
- * Renders the variants for the item using the headless component.
160
+ * Wrapper component for CoreItemDetails.VariantsComponent.
161
+ * Renders the variants for the item using Radix UI RadioGroup.
162
162
  *
163
163
  * @component
164
164
  * @example
@@ -171,11 +171,16 @@ export declare const ModifierGroups: React.ForwardRefExoticComponent<ItemDetails
171
171
  export interface ItemDetailsVariantsProps {
172
172
  children?: AsChildChildren<{
173
173
  variant: any;
174
+ variants: any[];
175
+ hasVariants: boolean;
176
+ selectedVariantId?: string;
177
+ onVariantChange?: (variantId: string) => void;
174
178
  }>;
175
179
  className?: string;
176
180
  asChild?: boolean;
177
181
  variantNameClassName?: string;
178
182
  variantPriceClassName?: string;
183
+ emptyState?: React.ReactNode;
179
184
  }
180
185
  export declare const Variants: React.ForwardRefExoticComponent<ItemDetailsVariantsProps & React.RefAttributes<HTMLElement>>;
181
186
  export interface AddToCartActionProps {
@@ -3,7 +3,8 @@ import React from 'react';
3
3
  import { Commerce } from '@wix/ecom/components';
4
4
  import { AsChildSlot } from '@wix/headless-utils/react';
5
5
  import { Quantity as QuantityComponent } from '@wix/headless-components/react';
6
- import { Item, Label, Modifier, ModifierGroup, Variant, } from '@wix/restaurants/components';
6
+ import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
7
+ import { Item, Label, Modifier, ModifierGroup, } from '@wix/headless-restaurants-menus/react';
7
8
  import * as CoreItemDetails from './core/ItemDetails.js';
8
9
  var TestIds;
9
10
  (function (TestIds) {
@@ -43,8 +44,20 @@ Labels.displayName = 'ItemDetails.Labels';
43
44
  export const ModifierGroups = React.forwardRef(({ children, className, asChild, modifierNameClassName, modifierPriceClassName, ...rest }) => {
44
45
  return (_jsx(Item.ModifierGroupsRepeater, { ...rest, children: _jsx(AsChildSlot, { asChild: asChild, testId: TestIds.itemModifierGroups, className: className, customElement: children, children: _jsxs(ModifierGroup.ModifiersRepeater, { children: [_jsx(Modifier.Name, { className: modifierNameClassName }), _jsx(Modifier.Price, { className: modifierPriceClassName })] }) }) }));
45
46
  });
46
- export const Variants = React.forwardRef(({ children, className, asChild, variantNameClassName, variantPriceClassName, ...rest }) => {
47
- return (_jsx(Item.VariantsRepeater, { ...rest, children: _jsxs(AsChildSlot, { asChild: asChild, testId: TestIds.itemVariants, className: className, customElement: children, children: [_jsx(Variant.Name, { className: variantNameClassName }), _jsx(Variant.Price, { className: variantPriceClassName })] }) }));
47
+ export const Variants = React.forwardRef(({ children, className, asChild, variantNameClassName, variantPriceClassName, emptyState, }, ref) => {
48
+ return (_jsx(CoreItemDetails.VariantsComponent, { children: ({ variants, hasVariants, selectedVariantId, onVariantChange }) => {
49
+ if (!hasVariants) {
50
+ return emptyState || null;
51
+ }
52
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, testId: TestIds.itemVariants, className: className, customElement: children, customElementProps: {
53
+ variants,
54
+ hasVariants,
55
+ selectedVariantId,
56
+ onVariantChange,
57
+ }, children: _jsx(RadioGroupPrimitive.Root, { value: selectedVariantId, onValueChange: onVariantChange, children: variants.map((variant) => (_jsx(RadioGroupPrimitive.Item, { value: variant._id, children: _jsxs("div", { children: [_jsx("div", { className: variantNameClassName, children: variant.name }), _jsx("div", { className: variantPriceClassName, children: variant.priceInfo?.formattedPrice ||
58
+ variant.priceInfo?.price ||
59
+ '' })] }) }, variant._id))) }) }));
60
+ } }));
48
61
  });
49
62
  Variants.displayName = 'ItemDetails.Variants';
50
63
  ModifierGroups.displayName = 'ItemDetails.ModifierGroups';
@@ -1,4 +1,4 @@
1
- import { useItemContext, useMenuContext, useSectionContext, } from '@wix/restaurants/components';
1
+ import { useItemContext, useMenuContext, useSectionContext, } from '@wix/headless-restaurants-menus/react';
2
2
  import { useService } from '@wix/services-manager-react';
3
3
  import { OLOSettingsServiceDefinition } from '@wix/headless-restaurants-olo/services';
4
4
  // import { OLOSettingsServiceDefinition } from "../../services/OLOSettingsService";
@@ -15,13 +15,6 @@ interface ItemDetailsModifiersRepeaterProps {
15
15
  }) => React.ReactNode;
16
16
  }
17
17
  export declare const ModifiersRepeater: React.FC<ItemDetailsModifiersRepeaterProps>;
18
- interface ItemDetailsVariantsRepeaterProps {
19
- children: (props: {
20
- variants: [];
21
- hasVariants: boolean;
22
- }) => React.ReactNode;
23
- }
24
- export declare const VariantsRepeater: React.FC<ItemDetailsVariantsRepeaterProps>;
25
18
  interface ItemDetailsSpecialRequestProps {
26
19
  children: (props: {
27
20
  value: string;
@@ -47,4 +40,14 @@ interface ItemDetailsQuantityProps {
47
40
  }) => React.ReactNode;
48
41
  }
49
42
  export declare const QuantityComponent: React.FC<ItemDetailsQuantityProps>;
43
+ interface ItemDetailsVariantsProps {
44
+ children: (props: {
45
+ variants: any[];
46
+ hasVariants: boolean;
47
+ selectedVariantId?: string;
48
+ onVariantChange?: (variantId: string) => void;
49
+ selectedVariant?: any;
50
+ }) => React.ReactNode;
51
+ }
52
+ export declare const VariantsComponent: React.FC<ItemDetailsVariantsProps>;
50
53
  export {};
@@ -4,6 +4,7 @@ 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 } from '@wix/headless-restaurants-menus/react';
7
8
  export const Root = ({ children, itemDetailsServiceConfig, }) => {
8
9
  const service = useService(OLOSettingsServiceDefinition);
9
10
  const selectedItem = service.selectedItem?.get();
@@ -27,14 +28,6 @@ export const ModifiersRepeater = ({ children, }) => {
27
28
  const hasModifiers = modifiers.length > 0;
28
29
  return children({ modifiers, hasModifiers });
29
30
  };
30
- export const VariantsRepeater = ({ children, }) => {
31
- const service = useService(ItemServiceDefinition);
32
- const item = service.item?.get();
33
- // TODO: Check if variants exist on item type - might be in a different property
34
- const variants = item?.variants || [];
35
- const hasVariants = variants.length > 0;
36
- return children({ variants, hasVariants });
37
- };
38
31
  export const SpecialRequest = ({ children, }) => {
39
32
  const [value, setValue] = useState('');
40
33
  const service = useService(ItemServiceDefinition);
@@ -77,3 +70,25 @@ export const QuantityComponent = ({ children, }) => {
77
70
  onValueChange,
78
71
  });
79
72
  };
73
+ export const VariantsComponent = ({ children, }) => {
74
+ const service = useService(ItemServiceDefinition);
75
+ const { item } = useItemContext();
76
+ const selectedVariant = service.selectedVariant?.get?.();
77
+ // Get variants from item context
78
+ const variants = item?.priceVariants || [];
79
+ const hasVariants = variants.length > 0;
80
+ const selectedVariantId = selectedVariant?._id ?? undefined;
81
+ const onVariantChange = (variantId) => {
82
+ const variant = variants.find((v) => v._id === variantId);
83
+ if (variant) {
84
+ service.updateSelectedVariant?.(variant);
85
+ }
86
+ };
87
+ return children({
88
+ variants,
89
+ hasVariants,
90
+ selectedVariantId,
91
+ onVariantChange,
92
+ selectedVariant,
93
+ });
94
+ };
@@ -1,6 +1,8 @@
1
1
  import { type Signal } from '@wix/services-definitions/core-services/signals';
2
2
  import * as items from '@wix/auto_sdk_restaurants_items';
3
3
  import { type LineItem } from '@wix/ecom/services';
4
+ import { itemVariants } from '@wix/restaurants';
5
+ type Variant = itemVariants.Variant;
4
6
  /**
5
7
  * API interface for the Item Detailsservice, providing reactive item data management.
6
8
  * This service handles loading and managing a single item's data, loading state, and errors.
@@ -13,6 +15,7 @@ export interface ItemServiceAPI {
13
15
  quantity: Signal<number>;
14
16
  specialRequest: Signal<string>;
15
17
  lineItem: Signal<LineItem>;
18
+ selectedVariant: Signal<Variant | undefined>;
16
19
  /** Reactive signal indicating if a item is currently being loaded */
17
20
  isLoading: Signal<boolean>;
18
21
  /** Reactive signal containing any error message, or null if no error */
@@ -21,6 +24,8 @@ export interface ItemServiceAPI {
21
24
  updateQuantity: (quantity: number) => void;
22
25
  /** Function to update the special request of the item */
23
26
  updateSpecialRequest: (specialRequest: string) => void;
27
+ /** Function to update the selected variant of the item */
28
+ updateSelectedVariant: (variant: Variant) => void;
24
29
  }
25
30
  /**
26
31
  * Service definition for the Item service.
@@ -152,3 +157,4 @@ export declare function loadItemServiceConfig({ item, operationId, }: {
152
157
  item: any;
153
158
  operationId: string;
154
159
  }): ItemServiceConfig;
160
+ export {};
@@ -49,6 +49,9 @@ export const ItemService = implementService.withConfig()(ItemServiceDefinition,
49
49
  const quantity = signalsService.signal(1);
50
50
  const specialRequest = signalsService.signal('');
51
51
  const lineItem = signalsService.signal({});
52
+ const priceVariants = config.item?.priceVariants || [];
53
+ const initialVariant = priceVariants.length > 0 ? priceVariants[0] : undefined;
54
+ const selectedVariant = signalsService.signal(initialVariant);
52
55
  if (config.item) {
53
56
  console.log('config.item', config.item);
54
57
  lineItem.set({
@@ -89,15 +92,20 @@ export const ItemService = implementService.withConfig()(ItemServiceDefinition,
89
92
  },
90
93
  });
91
94
  };
95
+ const updateSelectedVariant = (variant) => {
96
+ selectedVariant.set(variant);
97
+ };
92
98
  return {
93
99
  item,
94
100
  quantity,
95
101
  updateQuantity,
96
102
  updateSpecialRequest,
103
+ updateSelectedVariant,
97
104
  isLoading,
98
105
  error,
99
106
  specialRequest,
100
107
  lineItem,
108
+ selectedVariant,
101
109
  };
102
110
  });
103
111
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-restaurants-olo",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "npm run build:esm && npm run build:cjs",
@@ -48,9 +48,11 @@
48
48
  "vitest": "^3.1.4"
49
49
  },
50
50
  "dependencies": {
51
+ "@radix-ui/react-radio-group": "^1.1.3",
51
52
  "@radix-ui/react-slot": "^1.1.0",
52
53
  "@wix/auto_sdk_restaurants_items": "^1.0.48",
53
54
  "@wix/headless-media": "0.0.15",
55
+ "@wix/headless-restaurants-menus": "^0.0.10",
54
56
  "@wix/headless-utils": "^0.0.4",
55
57
  "@wix/redirects": "^1.0.0",
56
58
  "@wix/restaurants": "^1.0.396",