Skip to content

Commit 86d76f2

Browse files
authored
Add returned types for event targets (#2694)
* fix versions link. * update BaseTransactionComplete to use existing type. * update docs and examples for event targets. * add changeset
1 parent 45597bb commit 86d76f2

20 files changed

+124
-42
lines changed

.changeset/clean-keys-move.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/ui-extensions': patch
3+
---
4+
5+
Update `BaseTransactionComplete.customer` to use existing type. Update examples and screenshots.

packages/ui-extensions/docs/surfaces/point-of-sale/reference/components/POSReceiptBlock.doc.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,30 @@ const data: ReferenceEntityTemplateSchema = {
1313
> This component only accepts \`Text\` and \`QRCode\` components as children.`,
1414
isVisualComponent: true,
1515
type: 'component',
16-
// eslint-disable-next-line no-warning-comments
17-
// TODO: add images (and update description, examples, types, related) after determining what child components are allowed.
18-
// thumbnail: 'pos-receipt-block-thumbnail.png',
19-
// definitions: [
20-
// {
21-
// title: 'POSReceiptBlock',
22-
// description: '',
23-
// type: 'POSReceiptBlockProps',
24-
// },
25-
// ],
16+
thumbnail: 'pos-receipt-block-thumbnail.png',
2617
category: 'Components',
2718
related: [
2819
{
2920
name: 'Text',
21+
subtitle: 'Acceptable child components',
22+
type: 'apps',
3023
url: '/docs/api/pos-ui-extensions/components/text',
3124
},
3225
{
3326
name: 'QRCode',
27+
subtitle: 'Acceptable child components',
28+
type: 'apps',
3429
url: '/docs/api/pos-ui-extensions/components/qrcode',
3530
},
31+
{
32+
name: 'pos.receipt-footer.block.render',
33+
subtitle: 'Target',
34+
type: 'blocks',
35+
url: '/docs/api/pos-ui-extensions/targets/receipts/pos-receipt-footer-block-render',
36+
},
3637
],
3738
defaultExample: {
38-
// image: 'pos-receipt-block-default.png',
39+
image: 'pos-receipt-block-default.png',
3940
codeblock: generateCodeBlockForPOSReceiptBlock(
4041
'Render a POSReceiptBlock in POS receipts',
4142
'default.example',

packages/ui-extensions/docs/surfaces/point-of-sale/reference/components/QRCode.doc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const data: ReferenceEntityTemplateSchema = {
2525
{
2626
name: 'POSReceiptBlock',
2727
subtitle: 'Required parent wrapper component',
28+
type: 'apps',
2829
url: '/docs/api/pos-ui-extensions/components/posreceiptblock',
2930
},
3031
],

packages/ui-extensions/docs/surfaces/point-of-sale/reference/examples/pos-receipt-block/default.example.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ import {
77

88
export default extension(
99
'pos.receipt-footer.block.render',
10-
(root) => {
10+
(root, api) => {
1111
const block = root.createComponent(
1212
POSReceiptBlock,
1313
);
1414
const text = root.createComponent(
1515
Text,
1616
{},
17-
'Submission ID: acde070d-8c2c-b0b0-9d8a-162843c10333',
17+
'Custom receipt text',
1818
);
1919
const qrCode = root.createComponent(QRCode, {
20-
value: 'https://www.shopify.com',
20+
value: `https://www.shopify.com/?example=${encodeURIComponent(
21+
api.transaction.orderId ?? '',
22+
)}`,
2123
});
2224

2325
block.append(text);

packages/ui-extensions/docs/surfaces/point-of-sale/reference/examples/pos-receipt-block/default.example.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@ import {
44
QRCode,
55
Text,
66
reactExtension,
7+
useApi,
78
} from '@shopify/ui-extensions-react/point-of-sale';
89

9-
const ReceiptFooterBlock = () => (
10-
<POSReceiptBlock>
11-
<Text>
12-
Submission ID:
13-
acde070d-8c2c-b0b0-9d8a-162843c10333
14-
</Text>
15-
<QRCode value="https://www.shopify.com" />
16-
</POSReceiptBlock>
17-
);
10+
const ReceiptFooterBlock = () => {
11+
const api = useApi(
12+
'pos.receipt-footer.block.render',
13+
);
14+
15+
return (
16+
<POSReceiptBlock>
17+
<Text>Custom receipt text</Text>
18+
<QRCode
19+
value={`https://www.shopify.com/?example=${encodeURIComponent(
20+
api.transaction.orderId ?? '',
21+
)}`}
22+
/>
23+
</POSReceiptBlock>
24+
);
25+
};
1826

1927
export default reactExtension(
2028
'pos.receipt-footer.block.render',

packages/ui-extensions/docs/surfaces/point-of-sale/reference/examples/qrcode/default.example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default extension(
1111
POSReceiptBlock,
1212
);
1313
const qrCode = root.createComponent(QRCode, {
14-
value: `https://example.com?id=${encodeURIComponent(
14+
value: `https://shopify.com?example=${encodeURIComponent(
1515
api.transaction.orderId ?? '',
1616
)}`,
1717
});

packages/ui-extensions/docs/surfaces/point-of-sale/reference/examples/qrcode/default.example.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const ReceiptFooterWithQRCodeBlock = () => {
1414
return (
1515
<POSReceiptBlock>
1616
<QRCode
17-
value={`https://example.com?id=${encodeURIComponent(
17+
value={`https://shopify.com?example=${encodeURIComponent(
1818
api.transaction.orderId ?? '',
1919
)}`}
2020
/>
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
11
import {
2+
extension,
23
POSReceiptBlock,
4+
QRCode,
35
Text,
4-
extension,
56
} from '@shopify/ui-extensions/point-of-sale';
67

78
export default extension('pos.receipt-footer.block.render', (root, api) => {
89
const block = root.createComponent(POSReceiptBlock);
9-
const text = root.createComponent(Text, {}, `Order ID: ${api.order.id}`);
10+
const textTransactionType = root.createComponent(
11+
Text,
12+
{},
13+
`Transaction type: ${api.transaction.transactionType}`,
14+
);
15+
const textTaxTotal = root.createComponent(
16+
Text,
17+
{},
18+
`Total tax: ${api.transaction.taxTotal}`,
19+
);
20+
const qrCodeValue =
21+
api.transaction.transactionType === 'Exchange'
22+
? `exampleExchange=${encodeURIComponent(
23+
api.transaction.exchangeId ?? '',
24+
)}`
25+
: `exampleOrder=${encodeURIComponent(api.transaction.orderId ?? '')}`;
26+
27+
const qrCode = root.createComponent(QRCode, {
28+
value: `https://www.shopify.com?${qrCodeValue}`,
29+
});
1030

11-
block.append(text);
31+
block.append(textTransactionType);
32+
block.append(textTaxTotal);
33+
block.append(qrCode);
1234
root.append(block);
1335
});

packages/ui-extensions/docs/surfaces/point-of-sale/reference/examples/targets/pos-receipt-footer-block-render.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
import React from 'react';
22

33
import {
4-
Text,
5-
useApi,
64
reactExtension,
5+
useApi,
76
POSReceiptBlock,
7+
QRCode,
8+
Text,
89
} from '@shopify/ui-extensions-react/point-of-sale';
910

1011
const Block = () => {
11-
const api = useApi<'pos.receipt-footer.block.render'>();
12+
const {transaction} = useApi<'pos.receipt-footer.block.render'>();
13+
const qrCodeValue =
14+
transaction.transactionType === 'Exchange'
15+
? `exampleExchange=${encodeURIComponent(transaction.exchangeId ?? '')}`
16+
: `exampleOrder=${encodeURIComponent(transaction.orderId ?? '')}`;
17+
1218
return (
1319
<POSReceiptBlock>
14-
<Text>{`Order ID: ${api.order.id}`}</Text>
20+
<Text>{`Transaction type: ${transaction.transactionType}`}</Text>
21+
<Text>{`Total tax: ${transaction.taxTotal}`}</Text>
22+
<QRCode value={`https://www.shopify.com?${qrCodeValue}`} />
1523
</POSReceiptBlock>
1624
);
1725
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// for use with `definitions` in a reference entity schema.
2+
export const CUSTOM_DATA = (type: string, title?: string) => ({
3+
title: title ?? type,
4+
description: 'The data object provided to this extension target.',
5+
// exact type name auto-populates the properties.
6+
type,
7+
});
8+
9+
export const TRANSACTION_COMPLETE_DEFINITION = {
10+
definitions: [CUSTOM_DATA('TransactionCompleteData')],
11+
};

0 commit comments

Comments
 (0)