File tree Expand file tree Collapse file tree 5 files changed +155
-0
lines changed
packages/ui-extensions/docs/surfaces/point-of-sale/reference Expand file tree Collapse file tree 5 files changed +155
-0
lines changed Original file line number Diff line number Diff line change 11import { ReferenceEntityTemplateSchema } from '@shopify/generate-docs' ;
2+ import { generateCodeBlock } from '../helpers/generateCodeBlock' ;
23import { ExtensionTargetType , TargetLink } from '../types/ExtensionTargetType' ;
34
5+ const generateCodeBlockForOrderApi = ( title : string , fileName : string ) =>
6+ generateCodeBlock ( title , 'order-api' , fileName ) ;
7+
48const 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
3051export default data ;
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 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+ ) ) ;
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 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+ ) ) ;
You can’t perform that action at this time.
0 commit comments