Skip to content

Commit 3237128

Browse files
committed
UI tutorial completed state
1 parent 1274bdb commit 3237128

File tree

2 files changed

+20
-5
lines changed
  • sample-apps/discounts

2 files changed

+20
-5
lines changed

sample-apps/discounts/extensions/product-discount/input.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ query Input {
1111
}
1212
}
1313
discountNode {
14-
metafield(namespace: "discounts-tutorial", key: "function-configuration") {
14+
metafield(namespace: "$app:discounts-tutorial", key: "function-configuration") {
1515
value
1616
}
1717
}

sample-apps/discounts/web/frontend/pages/volume/[functionId]/new.jsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import { data } from "@shopify/app-bridge/actions/Modal";
2929
import { useAuthenticatedFetch } from "../../../hooks";
3030

3131
const todaysDate = new Date();
32-
const METAFIELD_NAMESPACE = "discounts-tutorial";
33-
const METAFIELD_CONFIGURATION_KEY = "volume-config";
32+
const METAFIELD_NAMESPACE = "$app:discounts-tutorial";
33+
const METAFIELD_CONFIGURATION_KEY = "function-configuration";
3434

3535
export default function VolumeNew() {
3636
// Read the function ID from the URL
@@ -79,7 +79,10 @@ export default function VolumeNew() {
7979
usageOncePerCustomer: useField(false),
8080
startDate: useField(todaysDate),
8181
endDate: useField(null),
82-
configuration: {},
82+
configuration: { // Add quantity and percentage configuration to form data
83+
quantity: useField('1'),
84+
percentage: useField('0'),
85+
},
8386
},
8487
onSubmit: async (form) => {
8588
const discount = {
@@ -92,7 +95,10 @@ export default function VolumeNew() {
9295
namespace: METAFIELD_NAMESPACE,
9396
key: METAFIELD_CONFIGURATION_KEY,
9497
type: "json",
95-
value: JSON.stringify({}),
98+
value: JSON.stringify({ // Populate metafield from form data
99+
quantity: parseInt(form.configuration.quantity),
100+
percentage: parseFloat(form.configuration.percentage),
101+
}),
96102
},
97103
],
98104
};
@@ -174,6 +180,15 @@ export default function VolumeNew() {
174180
discountCode={discountCode}
175181
discountMethod={discountMethod}
176182
/>
183+
{ /* Collect data for the configuration metafield. */ }
184+
<Card title="Volume">
185+
<Card.Section>
186+
<Stack>
187+
<TextField label="Minimum quantity" {...configuration.quantity} />
188+
<TextField label="Discount percentage" {...configuration.percentage} suffix="%" />
189+
</Stack>
190+
</Card.Section>
191+
</Card>
177192
{discountMethod.value === DiscountMethod.Code && (
178193
<UsageLimitsCard
179194
totalUsageLimit={usageTotalLimit}

0 commit comments

Comments
 (0)