@@ -29,8 +29,8 @@ import { data } from "@shopify/app-bridge/actions/Modal";
29
29
import { useAuthenticatedFetch } from "../../../hooks" ;
30
30
31
31
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 " ;
34
34
35
35
export default function VolumeNew ( ) {
36
36
// Read the function ID from the URL
@@ -79,7 +79,10 @@ export default function VolumeNew() {
79
79
usageOncePerCustomer : useField ( false ) ,
80
80
startDate : useField ( todaysDate ) ,
81
81
endDate : useField ( null ) ,
82
- configuration : { } ,
82
+ configuration : { // Add quantity and percentage configuration to form data
83
+ quantity : useField ( '1' ) ,
84
+ percentage : useField ( '0' ) ,
85
+ } ,
83
86
} ,
84
87
onSubmit : async ( form ) => {
85
88
const discount = {
@@ -92,7 +95,10 @@ export default function VolumeNew() {
92
95
namespace : METAFIELD_NAMESPACE ,
93
96
key : METAFIELD_CONFIGURATION_KEY ,
94
97
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
+ } ) ,
96
102
} ,
97
103
] ,
98
104
} ;
@@ -174,6 +180,15 @@ export default function VolumeNew() {
174
180
discountCode = { discountCode }
175
181
discountMethod = { discountMethod }
176
182
/>
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 >
177
192
{ discountMethod . value === DiscountMethod . Code && (
178
193
< UsageLimitsCard
179
194
totalUsageLimit = { usageTotalLimit }
0 commit comments