Skip to content

Commit 26de751

Browse files
committed
Add string syntax example to intents docs
1 parent 4a8c631 commit 26de751

File tree

3 files changed

+52
-25
lines changed

3 files changed

+52
-25
lines changed

packages/ui-extensions/docs/surfaces/customer-account/reference/apis/intents.doc.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const data: ReferenceEntityTemplateSchema = {
1111
defaultExample: {
1212
description: '',
1313
codeblock: {
14-
title: 'Replace payment method',
14+
title: 'Replace payment method with object syntax',
1515
tabs: [
1616
{
1717
code: '../examples/apis/intents.example.jsx',
@@ -46,7 +46,6 @@ Where:
4646
title: 'IntentAction',
4747
description: `Supported actions that can be performed on resources.
4848
- \`create\`: Opens a creation workflow for a new resource
49-
- \`edit\`: Opens an editing workflow for an existing resource (requires \`value\` parameter)
5049
- \`open\`: Opens a workflow for an existing resource (requires \`value\` parameter)`,
5150
type: 'IntentAction',
5251
},
@@ -73,24 +72,19 @@ Where:
7372
],
7473
examples: {
7574
description: 'Intents for each Shopify resource type',
76-
exampleGroups: [
75+
examples: [
7776
{
78-
title: 'Subscription Contract',
79-
examples: [
80-
{
81-
description:
82-
'Replace the payment method on an active subscription contract. Opens a modal with vaulted cards.',
83-
codeblock: {
84-
title: 'Replace payment method',
85-
tabs: [
86-
{
87-
code: '../examples/apis/intents.example.jsx',
88-
language: 'jsx',
89-
},
90-
],
77+
description:
78+
'Replace the payment method on an active subscription contract. Opens a modal with vaulted cards.',
79+
codeblock: {
80+
title: 'Replace payment method with string syntax',
81+
tabs: [
82+
{
83+
code: '../examples/apis/intents.string.example.jsx',
84+
language: 'jsx',
9185
},
92-
},
93-
],
86+
],
87+
},
9488
},
9589
],
9690
},

packages/ui-extensions/docs/surfaces/customer-account/reference/examples/apis/intents.example.jsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ export default async () => {
77

88
function Extension() {
99
async function handleReplacePaymentMethod() {
10-
const activity = await intents.invoke({
11-
action: 'open',
12-
type: 'shopify/SubscriptionContract',
13-
value:
14-
'gid://shopify/SubscriptionContract/123',
15-
data: {field: 'paymentMethod'},
16-
});
10+
const activity = await shopify.intents.invoke(
11+
{
12+
action: 'open',
13+
type: 'shopify/SubscriptionContract',
14+
value:
15+
'gid://shopify/SubscriptionContract/123',
16+
data: {field: 'paymentMethod'},
17+
},
18+
);
1719

1820
const response = await activity.complete;
1921

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import '@shopify/ui-extensions/preact';
2+
import {render} from 'preact';
3+
4+
export default async () => {
5+
render(<Extension />, document.body);
6+
};
7+
8+
function Extension() {
9+
async function handleReplacePaymentMethod() {
10+
const activity = await shopify.intents.invoke(
11+
'open:shopify/SubscriptionContract,gid://shopify/SubscriptionContract/123?field=paymentMethod',
12+
);
13+
14+
const response = await activity.complete;
15+
16+
if (response.code === 'ok') {
17+
console.log(
18+
'Intent completed successfully',
19+
response.data,
20+
);
21+
}
22+
}
23+
24+
return (
25+
<s-button
26+
onClick={handleReplacePaymentMethod}
27+
>
28+
Edit subscription payment method
29+
</s-button>
30+
);
31+
}

0 commit comments

Comments
 (0)