Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce CartLineItem APIs and targets #2682

Draft
wants to merge 1 commit into
base: unstable
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {Tile, extension} from '@shopify/ui-extensions/point-of-sale';

export default extension('pos.home.tile.render', (root, api) => {
const tile = root.createComponent(Tile, {
title: 'My App',
subtitle: 'Call cart function',
enabled: true,
onPress: () => {
api.cart.getLineItem('aa-1234567');
},
});

root.append(tile);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

import React from 'react';
import {
reactExtension,
useApi,
Tile
} from '@shopify/ui-extensions-react/point-of-sale';

const SmartGridTile = () => {
const api = useApi<'pos.home.tile.render'>();

return (
<Tile
title='My App'
subtitle='Call cart function'
enabled
onPress={() => api.cart.getLineItem('aa-1234567')}
/>
);
};

export default reactExtension(
'pos.home.tile.render',
() => <SmartGridTile />
);
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
CartUpdateInput,
Customer,
CustomSale,
LineItem,
SetLineItemDiscountInput,
SetLineItemPropertiesInput,
} from '../../../types/cart';
Expand Down Expand Up @@ -87,6 +88,11 @@ export interface CartApiContent {
*/
removeLineItem(uuid: string): Promise<void>;

/** Get the line item at this uuid from the cart
* @param uuid the uuid of the line item that should be retrieved
*/
getLineItem(uuid: string): Promise<LineItem | undefined>;

/** Adds custom properties to the cart
* @param properties the custom key to value object to attribute to the cart
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface CartLineItemApi {
cartLineItem: CartLineItemApiContent;
}

export interface CartLineItemApiContent {
/**
* The unique identifier for the cart line item.
*/
uuid: string;
}
25 changes: 25 additions & 0 deletions packages/ui-extensions/src/surfaces/point-of-sale/targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {ActionApi} from './render/api/action-api/action-api';
import {ProductApi} from './render/api/product-api/product-api';
import {ActionTargetApi} from './render/api/action-target-api/action-target-api';
import {DraftOrderApi} from './render/api/draft-order-api/draft-order-api';
import {CartLineItemApi} from './render/api/cart-line-item-api/cart-line-item-api';

type SmartGridComponents = AnyComponentBuilder<Pick<Components, 'Tile'>>;
type ActionComponents = AnyComponentBuilder<Pick<Components, 'Button'>>;
Expand Down Expand Up @@ -134,6 +135,30 @@ export interface ExtensionTargets {
StandardApi<'pos.receipt-footer.block.render'> & OrderApi,
ReceiptComponents
>;
// New targets for manage line items
'pos.manage-line.action.render': RenderExtension<
ActionTargetApi<'pos.manage-line.action.render'> &
CartApi &
ActionApi &
ProductApi &
CartLineItemApi,
BasicComponents
>;
'pos.manage-line.block.render': RenderExtension<
StandardApi<'pos.manage-line.block.render'> &
CartApi &
ProductApi &
CartLineItemApi,
BlockComponents
>;
'pos.manage-line.action.menu-item.render': RenderExtension<
StandardApi<'pos.manage-line.action.menu-item.render'> &
ActionApi &
CartApi &
ProductApi &
CartLineItemApi,
ActionComponents
>;
}

export type ExtensionTarget = keyof ExtensionTargets;
Expand Down