File tree Expand file tree Collapse file tree 10 files changed +268
-0
lines changed
ui-extensions-react/src/surfaces/point-of-sale/hooks
ui-extensions/docs/surfaces/point-of-sale/reference Expand file tree Collapse file tree 10 files changed +268
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ export {
14
14
useStatefulSubscribableLocale ,
15
15
destroyStatefulSubscribableLocale ,
16
16
} from './locale-api' ;
17
+ export { useOrder } from './order-api' ;
17
18
18
19
export {
19
20
useScannerDataSubscription ,
Original file line number Diff line number Diff line change 1
1
import { ReferenceEntityTemplateSchema } from '@shopify/generate-docs' ;
2
+ import { generateCodeBlock } from '../helpers/generateCodeBlock' ;
2
3
import { ExtensionTargetType , TargetLink } from '../types/ExtensionTargetType' ;
3
4
5
+ const generateCodeBlockForOrderApi = ( title : string , fileName : string ) =>
6
+ generateCodeBlock ( title , 'order-api' , fileName ) ;
7
+
4
8
const data : ReferenceEntityTemplateSchema = {
5
9
name : 'Order API' ,
6
10
description : `
@@ -25,6 +29,35 @@ The Order API provides an extension with data about the current order.
25
29
] ,
26
30
category : 'APIs' ,
27
31
related : [ ] ,
32
+ examples : {
33
+ description : 'Examples of using the Order API' ,
34
+ examples : [
35
+ {
36
+ codeblock : generateCodeBlockForOrderApi (
37
+ 'Basic usage of the Order API with useOrder hook' ,
38
+ 'basic-usage' ,
39
+ ) ,
40
+ } ,
41
+ {
42
+ codeblock : generateCodeBlockForOrderApi (
43
+ 'Display order details in a custom block' ,
44
+ 'display-in-block' ,
45
+ ) ,
46
+ } ,
47
+ {
48
+ codeblock : generateCodeBlockForOrderApi (
49
+ 'Use Order API with navigation' ,
50
+ 'with-navigation' ,
51
+ ) ,
52
+ } ,
53
+ {
54
+ codeblock : generateCodeBlockForOrderApi (
55
+ 'Simple useOrder hook example' ,
56
+ 'use-order-hook' ,
57
+ ) ,
58
+ } ,
59
+ ] ,
60
+ } ,
28
61
} ;
29
62
30
63
export default data ;
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.block.render' , ( root , api ) => {
11
+ // Access order information from the API
12
+ const order = api . order ;
13
+
14
+ const navigator = root . createComponent ( Navigator , { } ) ;
15
+ const screen = navigator . createComponent ( Screen , {
16
+ name : 'OrderDetails' ,
17
+ title : 'Order Details' ,
18
+ } ) ;
19
+ const scrollView = screen . createComponent ( ScrollView , { } ) ;
20
+ const section = scrollView . createComponent ( Section , {
21
+ title : 'Order Information' ,
22
+ } ) ;
23
+
24
+ section . createComponent ( Text , { } , `Order ID: ${ order . id } ` ) ;
25
+ section . createComponent ( Text , { } , `Order Name: ${ order . name } ` ) ;
26
+
27
+ if ( order . customerId ) {
28
+ section . createComponent ( Text , { } , `Customer ID: ${ order . customerId } ` ) ;
29
+ }
30
+
31
+ root . mount ( ) ;
32
+ } ) ;
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
+ useOrder ,
10
+ } from '@shopify/ui-extensions-react/point-of-sale' ;
11
+
12
+ const SmartGridModal = ( ) => {
13
+ // Use the useOrder hook to access order information
14
+ const order = useOrder ( ) ;
15
+
16
+ return (
17
+ < Navigator >
18
+ < Screen name = "OrderDetails" title = "Order Details" >
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 > Customer ID: { order . customerId } </ Text > }
24
+ </ Section >
25
+ </ ScrollView >
26
+ </ Screen >
27
+ </ Navigator >
28
+ ) ;
29
+ } ;
30
+
31
+ export default reactExtension ( 'pos.purchase.post.block.render' , ( ) => (
32
+ < SmartGridModal />
33
+ ) ) ;
Original file line number Diff line number Diff line change
1
+ import {
2
+ extension ,
3
+ POSBlock ,
4
+ POSBlockRow ,
5
+ } from '@shopify/ui-extensions/point-of-sale' ;
6
+
7
+ export default extension ( 'pos.order-details.block.render' , ( root , api ) => {
8
+ const order = api . order ;
9
+
10
+ const posBlock = root . createComponent ( POSBlock , { } ) ;
11
+
12
+ posBlock . createComponent ( POSBlockRow , {
13
+ label : 'Order' ,
14
+ value : order . name ,
15
+ } ) ;
16
+
17
+ posBlock . createComponent ( POSBlockRow , {
18
+ label : 'Order ID' ,
19
+ value : order . id . toString ( ) ,
20
+ } ) ;
21
+
22
+ if ( order . customerId ) {
23
+ posBlock . createComponent ( POSBlockRow , {
24
+ label : 'Customer ID' ,
25
+ value : order . customerId . toString ( ) ,
26
+ } ) ;
27
+ }
28
+
29
+ root . mount ( ) ;
30
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import {
3
+ reactExtension ,
4
+ POSBlock ,
5
+ POSBlockRow ,
6
+ useOrder ,
7
+ } from '@shopify/ui-extensions-react/point-of-sale' ;
8
+
9
+ const OrderDetailsBlock = ( ) => {
10
+ // Use the useOrder hook directly
11
+ const order = useOrder ( ) ;
12
+
13
+ return (
14
+ < POSBlock >
15
+ < POSBlockRow label = "Order" value = { order . name } />
16
+ < POSBlockRow label = "Order ID" value = { order . id . toString ( ) } />
17
+ { order . customerId && (
18
+ < POSBlockRow label = "Customer ID" value = { order . customerId . toString ( ) } />
19
+ ) }
20
+ </ POSBlock >
21
+ ) ;
22
+ } ;
23
+
24
+ export default reactExtension ( 'pos.order-details.block.render' , ( ) => (
25
+ < OrderDetailsBlock />
26
+ ) ) ;
Original file line number Diff line number Diff line change
1
+ import { extension , Text , Stack } from '@shopify/ui-extensions/point-of-sale' ;
2
+
3
+ export default extension ( 'pos.order-details.block.render' , ( root , api ) => {
4
+ // Access order data directly from the API
5
+ const order = api . order ;
6
+
7
+ const stack = root . createComponent ( Stack , { } ) ;
8
+
9
+ stack . createComponent ( Text , { } , `Order #${ order . name } ` ) ;
10
+ stack . createComponent ( Text , { } , `ID: ${ order . id } ` ) ;
11
+
12
+ if ( order . customerId ) {
13
+ stack . createComponent ( Text , { } , `Customer ID: ${ order . customerId } ` ) ;
14
+ }
15
+
16
+ root . mount ( ) ;
17
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import {
3
+ reactExtension ,
4
+ Text ,
5
+ Stack ,
6
+ useOrder ,
7
+ } from '@shopify/ui-extensions-react/point-of-sale' ;
8
+
9
+ const OrderInfo = ( ) => {
10
+ // The useOrder hook provides direct access to order data
11
+ const order = useOrder ( ) ;
12
+
13
+ return (
14
+ < Stack >
15
+ < Text > Order #{ order . name } </ Text >
16
+ < Text > ID: { order . id } </ Text >
17
+ { order . customerId && < Text > Customer ID: { order . customerId } </ Text > }
18
+ </ Stack >
19
+ ) ;
20
+ } ;
21
+
22
+ export default reactExtension ( 'pos.order-details.block.render' , ( ) => (
23
+ < OrderInfo />
24
+ ) ) ;
Original file line number Diff line number Diff line change
1
+ import {
2
+ extension ,
3
+ Navigator ,
4
+ Screen ,
5
+ Text ,
6
+ Button ,
7
+ } from '@shopify/ui-extensions/point-of-sale' ;
8
+
9
+ export default extension ( 'pos.purchase.post.action.render' , ( root , api ) => {
10
+ const order = api . order ;
11
+ const navigation = api . navigation ;
12
+
13
+ const navigator = root . createComponent ( Navigator , { } ) ;
14
+ const screen = navigator . createComponent ( Screen , {
15
+ name : 'OrderActions' ,
16
+ title : 'Order Actions' ,
17
+ } ) ;
18
+
19
+ screen . createComponent ( Text , { } , `Processing order: ${ order . name } ` ) ;
20
+
21
+ if ( order . customerId ) {
22
+ screen . createComponent ( Button , {
23
+ title : 'View Customer' ,
24
+ onPress : ( ) => {
25
+ navigation . navigate ( 'CustomerDetails' , {
26
+ customerId : order . customerId ,
27
+ } ) ;
28
+ } ,
29
+ } ) ;
30
+ }
31
+
32
+ root . mount ( ) ;
33
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import {
3
+ reactExtension ,
4
+ Navigator ,
5
+ Screen ,
6
+ Text ,
7
+ Button ,
8
+ useOrder ,
9
+ useApi ,
10
+ } from '@shopify/ui-extensions-react/point-of-sale' ;
11
+
12
+ const OrderActionModal = ( ) => {
13
+ const order = useOrder ( ) ;
14
+ const { navigation} = useApi ( ) ;
15
+
16
+ const handleViewCustomer = ( ) => {
17
+ if ( order . customerId ) {
18
+ // Navigate to customer details
19
+ navigation . navigate ( 'CustomerDetails' , {
20
+ customerId : order . customerId ,
21
+ } ) ;
22
+ }
23
+ } ;
24
+
25
+ return (
26
+ < Navigator >
27
+ < Screen name = "OrderActions" title = "Order Actions" >
28
+ < Text > Processing order: { order . name } </ Text >
29
+ { order . customerId && (
30
+ < Button title = "View Customer" onPress = { handleViewCustomer } />
31
+ ) }
32
+ </ Screen >
33
+ </ Navigator >
34
+ ) ;
35
+ } ;
36
+
37
+ export default reactExtension ( 'pos.purchase.post.action.render' , ( ) => (
38
+ < OrderActionModal />
39
+ ) ) ;
You can’t perform that action at this time.
0 commit comments