Skip to content

Commit 6472285

Browse files
authored
Merge pull request #2992 from Shopify/njo/order-api-examples
Add order-api examples
2 parents ef2def4 + bdcaf98 commit 6472285

File tree

5 files changed

+155
-0
lines changed

5 files changed

+155
-0
lines changed

packages/ui-extensions/docs/surfaces/point-of-sale/reference/apis/order-api.doc.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs';
2+
import {generateCodeBlock} from '../helpers/generateCodeBlock';
23
import {ExtensionTargetType, TargetLink} from '../types/ExtensionTargetType';
34

5+
const generateCodeBlockForOrderApi = (title: string, fileName: string) =>
6+
generateCodeBlock(title, 'order-api', fileName);
7+
48
const data: ReferenceEntityTemplateSchema = {
59
name: 'Order API',
610
description: `
@@ -25,6 +29,23 @@ The Order API provides an extension with data about the current order.
2529
],
2630
category: 'APIs',
2731
related: [],
32+
examples: {
33+
description: 'Examples of using the Order API',
34+
examples: [
35+
{
36+
codeblock: generateCodeBlockForOrderApi(
37+
'Basic usage of the Order API in an action',
38+
'basic-usage',
39+
),
40+
},
41+
{
42+
codeblock: generateCodeBlockForOrderApi(
43+
'Display order details in a block',
44+
'display-in-block',
45+
),
46+
},
47+
],
48+
},
2849
};
2950

3051
export default data;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import {
2+
extension,
3+
Screen,
4+
ScrollView,
5+
Text,
6+
} from '@shopify/ui-extensions/point-of-sale';
7+
8+
export default extension('pos.purchase.post.action.render', (root, api) => {
9+
const order = api.order;
10+
11+
const screen = root.createComponent(Screen, {
12+
name: 'PostPurchaseAction',
13+
title: 'Post Purchase Action',
14+
});
15+
16+
const scrollView = root.createComponent(ScrollView, {});
17+
18+
const orderName = root.createComponent(Text, {}, `Order Name: ${order.name}`);
19+
const orderId = root.createComponent(Text, {}, `Order ID: ${order.id}`);
20+
const orderCustomerId = root.createComponent(
21+
Text,
22+
{},
23+
`Order Customer ID: ${order.customerId}`,
24+
);
25+
26+
scrollView.append(orderName);
27+
scrollView.append(orderId);
28+
scrollView.append(orderCustomerId);
29+
30+
screen.append(scrollView);
31+
32+
root.append(screen);
33+
34+
root.mount();
35+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react';
2+
import {
3+
reactExtension,
4+
Screen,
5+
Navigator,
6+
ScrollView,
7+
Text,
8+
Section,
9+
useApi,
10+
} from '@shopify/ui-extensions-react/point-of-sale';
11+
12+
const PostPurchaseAction = () => {
13+
const api = useApi<'pos.purchase.post.action.render'>();
14+
const order = api.order;
15+
16+
return (
17+
<Navigator>
18+
<Screen name="PostPurchaseAction" title="Post Purchase Action">
19+
<ScrollView>
20+
<Section title="Order Information">
21+
<Text>Order ID: {order.id}</Text>
22+
<Text>Order Name: {order.name}</Text>
23+
{order.customerId && <Text>Order Customer ID: {order.customerId}</Text>}
24+
</Section>
25+
</ScrollView>
26+
</Screen>
27+
</Navigator>
28+
);
29+
};
30+
31+
export default reactExtension('pos.purchase.post.action.render', () => (
32+
<PostPurchaseAction />
33+
));
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {
2+
extension,
3+
Screen,
4+
Navigator,
5+
ScrollView,
6+
Text,
7+
Section,
8+
} from '@shopify/ui-extensions/point-of-sale';
9+
10+
export default extension('pos.purchase.post.action.render', (root, api) => {
11+
const order = api.order;
12+
13+
const screen = root.createComponent(Screen, {
14+
name: 'PostPurchaseAction',
15+
title: 'Post Purchase Action',
16+
});
17+
18+
const scrollView = root.createComponent(ScrollView, {});
19+
20+
const orderName = root.createComponent(Text, {}, `Order Name: ${order.name}`);
21+
const orderId = root.createComponent(Text, {}, `Order ID: ${order.id}`);
22+
const orderCustomerId = root.createComponent(
23+
Text,
24+
{},
25+
`Order Customer ID: ${order.customerId}`,
26+
);
27+
28+
scrollView.append(orderName);
29+
scrollView.append(orderId);
30+
scrollView.append(orderCustomerId);
31+
32+
screen.append(scrollView);
33+
34+
root.append(screen);
35+
36+
root.mount();
37+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import {
3+
reactExtension,
4+
POSBlock,
5+
POSBlockRow,
6+
useApi,
7+
Text,
8+
} from '@shopify/ui-extensions-react/point-of-sale';
9+
10+
const OrderDetailsBlock = () => {
11+
const api = useApi<'pos.purchase.post.action.render'>();
12+
const order = api.order;
13+
14+
return (
15+
<POSBlock>
16+
<POSBlockRow>
17+
<Text>Order Name: {order.name}</Text>
18+
<Text>Order ID {order.id.toString()}</Text>
19+
{order.customerId && (
20+
<Text>Order Customer ID {order.customerId.toString()}</Text>
21+
)}
22+
</POSBlockRow>
23+
</POSBlock>
24+
);
25+
};
26+
27+
export default reactExtension('pos.purchase.post.block.render', () => (
28+
<OrderDetailsBlock />
29+
));

0 commit comments

Comments
 (0)