1+ {%- if flavor contains "preact" -%}
12import {render} from 'preact';
23
34export 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 -%}
0 commit comments