Skip to content

Commit 71e1b03

Browse files
authored
Fix order routing location rule extension template (#282)
### Background This PR put back support for different React, and vanilla JS in the OrderRoutingLocationRule template. ### Testing 1. Run `shopify app generate extension --clone-url https://github.com/Shopify/extensions-templates#Fix_Order_Routing_Location_Rule_extension_template` 1. Verify you can generate an "Order routing location rule - UI Extension" ### Checklist - [x] I have 🎩'd these changes - [x] I have squashed my commits into chunks of work with meaningful commit messages
2 parents 297e000 + 9ca0859 commit 71e1b03

File tree

5 files changed

+148
-16
lines changed

5 files changed

+148
-16
lines changed

order-routing-location-rule/package.json.liquid

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,24 @@
33
"private": true,
44
"version": "1.0.0",
55
"license": "UNLICENSED",
6+
{%- if flavor contains "preact" %}
67
"dependencies": {
78
"preact": "^10.10.x",
9+
"@shopify/ui-extensions": "~2025.10.0-rc"
10+
}
11+
{%- elsif flavor contains "react" %}
12+
"dependencies": {
13+
"react": "^18.0.0",
14+
"@shopify/ui-extensions": "2025.4.x",
15+
"@shopify/ui-extensions-react": "2025.4.x",
16+
"react-reconciler": "0.29.0"
17+
},
18+
"devDependencies": {
19+
"@types/react": "^18.0.0"
20+
}
21+
{%- else %}
22+
"dependencies": {
823
"@shopify/ui-extensions": "2025.4.x"
924
}
25+
{%- endif %}
1026
}

order-routing-location-rule/shopify.extension.toml.liquid

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
{%- if flavor contains "preact" -%}
2+
api_version = "2025-10"
3+
{% else %}
14
api_version = "2025-04"
5+
{% endif -%}
26

37
[[extensions]]
48
# Change the merchant-facing name of the extension in locales/en.default.json

order-routing-location-rule/src/OrderRoutingLocationRule.liquid

Lines changed: 105 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{%- if flavor contains "preact" -%}
12
import {render} from 'preact';
23

34
export default async () => {
@@ -12,11 +13,7 @@ function Extension() {
1213
const handleSubmit = () => {
1314
console.log('submit');
1415

15-
{% if flavor contains "typescript" %}
16-
// const metafields: Parameters<typeof applyMetafieldsChange>[0] = [
17-
{% else %}
1816
// const metafields = [
19-
{% endif %}
2017
// {
2118
// namespace: 'ns',
2219
// key: 'config-1',
@@ -47,3 +44,107 @@ function Extension() {
4744
</s-form>
4845
);
4946
}
47+
48+
{%- elseif flavor contains "react" -%}
49+
import {
50+
reactExtension,
51+
useApi,
52+
Text,
53+
Box,
54+
Form,
55+
} from '@shopify/ui-extensions-react/admin';
56+
57+
// The target used here must match the target used in the extension's toml file (./shopify.extension.toml)
58+
const TARGET = 'admin.settings.order-routing-rule.render';
59+
60+
export default reactExtension(TARGET, () => <App />);
61+
62+
function App() {
63+
// The useApi hook provides access to several useful APIs like i18n, data and saveMetafields.
64+
const {data, applyMetafieldsChange, i18n} = useApi(TARGET);
65+
66+
// Transform your state into metafields and send them back to the admin to batch the
67+
// changes together with the rest of merchant updates to the routing strategy
68+
const handleSubmit = () => {
69+
console.log('submit');
70+
71+
{% if flavor contains "typescript" %}
72+
// const metafields: Parameters<typeof applyMetafieldsChange>[0] = [
73+
{% else %}
74+
// const metafields = [
75+
{% endif %}
76+
// {
77+
// namespace: 'ns',
78+
// key: 'config-1',
79+
// type: 'updateMetafield',
80+
// value: '{value: test}',
81+
// valueType: 'json',
82+
// }
83+
// ];
84+
85+
// applyMetafieldsChange(metafields);
86+
};
87+
88+
// Reset your state to the default values
89+
const handleOnReset = () => {
90+
console.log('reset');
91+
};
92+
93+
return (
94+
<Form onSubmit={handleSubmit} onReset={handleOnReset}>
95+
<Box padding="base">
96+
<Text fontWeight="bold">
97+
{i18n.translate('helpText')}
98+
</Text>
99+
</Box>
100+
<Box padding="base">
101+
{/* Create a UI to allow merchants to provide configuration values for your location rule function */}
102+
</Box>
103+
</Form>
104+
);
105+
}
106+
107+
{%- else -%}
108+
import { extension, Box, Form, Text } from "@shopify/ui-extensions/admin";
109+
110+
// Transform your state into metafields and send them back to the admin to batch the
111+
// changes together with the rest of merchant updates to the routing strategy
112+
const handleSubmit = () => {
113+
console.log('submit');
114+
115+
{% if flavor contains "typescript" %}
116+
// const metafields: Parameters<typeof applyMetafieldsChange>[0] = [
117+
{% else %}
118+
// const metafields = [
119+
{% endif %}
120+
// {
121+
// namespace: 'ns',
122+
// key: 'config-1',
123+
// type: 'updateMetafield',
124+
// value: '{value: test}',
125+
// valueType: 'json',
126+
// }
127+
// ];
128+
129+
// applyMetafieldsChange(metafields);
130+
};
131+
132+
// Reset your state to the default values
133+
const handleOnReset = () => {
134+
console.log('reset');
135+
};
136+
137+
// The target used here must match the target used in the extension's toml file (./shopify.extension.toml)
138+
export default extension("admin.settings.order-routing-rule.render", (root, { extension: {target}, i18n, data, applyMetafieldsChange }) => {
139+
console.log({data});
140+
root.appendChild(
141+
root.createComponent(
142+
Form,
143+
{ onSubmit: handleSubmit, onReset: handleOnReset },
144+
root.createComponent(Box, {padding: 'base'},
145+
root.createComponent(Text, { fontWeight: "bold" }, i18n.translate('helpText'))
146+
)
147+
)
148+
);
149+
});
150+
{%- endif -%}

order-routing-location-rule/tsconfig.json

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{%- if flavor contains "preact" -%}
2+
{
3+
"compilerOptions": {
4+
"jsx": "react-jsx",
5+
"jsxImportSource": "preact",
6+
"target": "ES2020",
7+
"checkJs": true,
8+
"allowJs": true,
9+
"moduleResolution": "node",
10+
"esModuleInterop": true,
11+
}
12+
}
13+
{%- else -%}
14+
{
15+
// This tsconfig.json file is only needed to inform the IDE
16+
// About the `react-jsx` tsconfig option, so IDE doesn't complain about missing react import
17+
// Changing options here won't affect the build of your extension
18+
"compilerOptions": {
19+
"jsx": "react-jsx"
20+
},
21+
"include": ["./src"]
22+
}
23+
{%- endif -%}

0 commit comments

Comments
 (0)