Skip to content

Commit 316b82e

Browse files
authored
Unstable Release from checkout-web (#2717)
* all unstable release changes * remove remote-dom related api changes mean for next rc release * reintroduce payment method export until next rc release * still using yarn * remove extra line for cleaner diff * remove everything within components meant for next rc release * remove shared code changes within components * conform to public package's linting rules * add line back for cleaner diff * remove reference for orderStatusApiEmpty that moved to customer accounts * add new code changes and doc examples from newer monorepo changes * add changesets to PR
1 parent 2c9bea2 commit 316b82e

File tree

18 files changed

+248
-26
lines changed

18 files changed

+248
-26
lines changed

.changeset/chilled-planes-itch.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@shopify/ui-extensions-react': minor
3+
'@shopify/ui-extensions': minor
4+
---
5+
6+
addition of removeAttribute type to applyAttributeChange api in checkout surface

.changeset/dry-needles-knock.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@shopify/ui-extensions-react': patch
3+
'@shopify/ui-extensions': patch
4+
---
5+
6+
addition of isFirstOrder to the orderConfirmation api and ordersCount to the standard api in checkout surface

packages/ui-extensions-react/src/surfaces/checkout/hooks/buyer-journey.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ export function useBuyerJourneyCompleted<
4242
*
4343
* If you do, then you're expected to inform the buyer why navigation was blocked,
4444
* either by passing validation errors to the checkout UI or rendering the errors in your extension.
45+
*
46+
* `useBuyerJourneyIntercept()` should be called at the top level of the extension,
47+
* not within an embedded or child component, to avoid errors should the child component get destroyed.
4548
*/
4649
export function useBuyerJourneyIntercept<
4750
Target extends RenderExtensionTarget = RenderExtensionTarget,

packages/ui-extensions/docs/surfaces/checkout/reference/apis/attributes.doc.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
CHECKOUT_API_PROPERTIES_DESCRIPTION,
66
getLinksByTag,
77
getHookExample,
8+
getExample,
89
} from '../helper.docs';
910

1011
const data: ReferenceEntityTemplateSchema = {
@@ -42,7 +43,11 @@ const data: ReferenceEntityTemplateSchema = {
4243
type: 'UseAttributeValuesGeneratedType',
4344
},
4445
],
45-
defaultExample: getHookExample('attribute-values'),
46+
defaultExample: getExample('attribute-values', ['jsx', 'js']),
47+
examples: {
48+
description: '',
49+
examples: [getExample('attributes/attribute-change', ['jsx', 'js'])],
50+
},
4651
related: getLinksByTag('apis'),
4752
};
4853

packages/ui-extensions/docs/surfaces/checkout/reference/apis/buyer-journey.doc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const data: ReferenceEntityTemplateSchema = {
3838
Installs a function for intercepting and preventing progress on checkout.
3939
To block checkout progress, you must set the [block_progress](/docs/api/checkout-ui-extensions/configuration#block-progress) capability in your extension's configuration.
4040
If you do, then you're expected to inform the buyer why navigation was blocked, either by passing validation errors to the checkout UI or rendering the errors in your extension.
41+
\`useBuyerJourneyIntercept()\` should be called at the top level of the extension, not within an embedded or child component, to avoid errors should the child component get destroyed.
4142
`,
4243
type: 'UseBuyerJourneyInterceptGeneratedType',
4344
},

packages/ui-extensions/docs/surfaces/checkout/reference/apis/localized-fields.doc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const data: ReferenceEntityTemplateSchema = {
2929
{
3030
title: 'useLocalizedField',
3131
description:
32-
'Returns the requested localized field and re-renders your component if the value changes.',
32+
'Returns the current localized fields and re-renders your component if the values change.',
3333
type: 'UseLocalizedFieldGeneratedType',
3434
},
3535
],

packages/ui-extensions/docs/surfaces/checkout/reference/apis/order.doc.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ import {
44
getLinksByTag,
55
ORDER_CONFIRMATION_API_PROPERTIES_DESCRIPTION,
66
getExample,
7-
ORDER_STATUS_API_PROPERTIES_DESCRIPTION,
87
} from '../helper.docs';
98

10-
// added temporarily to keep a note that the order status api docs have been moved to customer accounts
11-
// can be removed from 2025-01 on
12-
interface OrderStatusApiEmpty {}
13-
149
const data: ReferenceEntityTemplateSchema = {
1510
name: 'Order',
1611
description:
@@ -25,11 +20,6 @@ const data: ReferenceEntityTemplateSchema = {
2520
description: ORDER_CONFIRMATION_API_PROPERTIES_DESCRIPTION,
2621
type: 'OrderConfirmationApi',
2722
},
28-
{
29-
title: 'OrderStatusApi',
30-
description: ORDER_STATUS_API_PROPERTIES_DESCRIPTION,
31-
type: 'OrderStatusApiEmpty',
32-
},
3323
],
3424
related: getLinksByTag('apis'),
3525
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {
2+
extension,
3+
Text,
4+
} from '@shopify/ui-extensions/checkout';
5+
6+
export default extension(
7+
'purchase.checkout.block.render',
8+
(root, {attributes}) => {
9+
attributes.subscribe(() => {
10+
renderUI();
11+
});
12+
13+
function renderUI() {
14+
const buyerSelectedFreeTShirt =
15+
attributes.current?.find(
16+
(attr) =>
17+
attr.key ===
18+
'buyerSelectedFreeTShirt',
19+
)?.value;
20+
21+
const tshirtSize = attributes.current?.find(
22+
(attr) => attr.key === 'tshirtSize',
23+
)?.value;
24+
25+
if (
26+
Boolean(buyerSelectedFreeTShirt) === true
27+
) {
28+
root.replaceChildren(
29+
root.createComponent(
30+
Text,
31+
undefined,
32+
`You selected a free t-shirt, size: ${tshirtSize}`,
33+
),
34+
);
35+
} else {
36+
root.replaceChildren();
37+
}
38+
}
39+
40+
renderUI();
41+
},
42+
);
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import {
2+
extension,
3+
BlockStack,
4+
Button,
5+
Text,
6+
} from '@shopify/ui-extensions/checkout';
7+
8+
export default extension(
9+
'purchase.checkout.block.render',
10+
(
11+
root,
12+
{
13+
attributes,
14+
instructions,
15+
applyAttributeChange,
16+
},
17+
) => {
18+
let giftWrap = false;
19+
const text = root.createComponent(Text);
20+
const button = root.createComponent(Button, {
21+
onPress: async () => {
22+
const result = giftWrap
23+
? await applyAttributeChange({
24+
type: 'removeAttribute',
25+
key: 'giftWrap',
26+
})
27+
: await applyAttributeChange({
28+
type: 'updateAttribute',
29+
key: 'giftWrap',
30+
value: 'true',
31+
});
32+
if (result.type === 'error') {
33+
console.error(result.message);
34+
}
35+
},
36+
});
37+
const blockStack = root.createComponent(
38+
BlockStack,
39+
{
40+
spacing: 'tight',
41+
},
42+
[text, button],
43+
);
44+
45+
attributes.subscribe(updateUI);
46+
instructions.subscribe(updateUI);
47+
48+
function updateUI() {
49+
giftWrap = Boolean(
50+
attributes.current?.find(
51+
(attr) => attr.key === 'giftWrap',
52+
)?.value,
53+
);
54+
55+
text.replaceChildren(
56+
`Gift wrapping: ${giftWrap ? 'Added' : 'Not set'}`,
57+
);
58+
button.updateProps({
59+
disabled:
60+
!instructions.current?.attributes
61+
?.canUpdateAttributes,
62+
});
63+
button.replaceChildren(
64+
giftWrap
65+
? 'Remove gift wrap'
66+
: 'Add gift wrap',
67+
);
68+
}
69+
updateUI();
70+
71+
root.append(blockstack);
72+
},
73+
);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import {
2+
reactExtension,
3+
BlockStack,
4+
Button,
5+
Text,
6+
useAttributeValues,
7+
useApplyAttributeChange,
8+
useInstructions,
9+
} from '@shopify/ui-extensions-react/checkout';
10+
11+
export default reactExtension(
12+
'purchase.checkout.block.render',
13+
() => <Extension />,
14+
);
15+
16+
function Extension() {
17+
const [giftWrapValue] = useAttributeValues([
18+
'giftWrap',
19+
]);
20+
const giftWrap = Boolean(giftWrapValue);
21+
const applyAttributeChange =
22+
useApplyAttributeChange();
23+
const instructions = useInstructions();
24+
25+
async function toggleGiftWrap() {
26+
const result = giftWrap
27+
? await applyAttributeChange({
28+
type: 'removeAttribute',
29+
key: 'giftWrap',
30+
})
31+
: await applyAttributeChange({
32+
type: 'updateAttribute',
33+
key: 'giftWrap',
34+
value: 'true',
35+
});
36+
if (result.type === 'error') {
37+
console.error(result.message);
38+
}
39+
}
40+
41+
return (
42+
<BlockStack spacing="tight">
43+
<Text>
44+
Gift wrapping:{' '}
45+
{giftWrap ? 'Added' : 'Not set'}
46+
</Text>
47+
<Button
48+
onPress={toggleGiftWrap}
49+
disabled={
50+
!instructions.attributes
51+
.canUpdateAttributes
52+
}
53+
>
54+
{giftWrap
55+
? 'Remove gift wrap'
56+
: 'Add gift wrap'}
57+
</Button>
58+
</BlockStack>
59+
);
60+
}

0 commit comments

Comments
 (0)