11import { useState , useEffect } from "react" ;
2- import { Form , useActionData , useNavigation , useSubmit , useLoaderData } from "react-router" ;
2+ import { useActionData , useNavigation , useSubmit , useLoaderData } from "react-router" ;
33import { boundary } from "@shopify/shopify-app-react-router/server" ;
44
55import { authenticate } from "../shopify.server" ;
@@ -144,42 +144,44 @@ export default function PaymentCustomization() {
144144 const isLoading = navigation . state === "submitting" ;
145145
146146 const errorBanner = actionData ?. errors . length ? (
147- < s-section >
148- < s-banner
149- title = "There was an error creating the customization."
150- status = "critical"
151- >
152- < ul >
153- { actionData ?. errors . map ( ( error , index ) => {
154- return < li key = { `${ index } ` } > { error . message } </ li > ;
155- } ) }
156- </ ul >
157- </ s-banner >
158- </ s-section >
147+ < s-banner tone = "critical" heading = "There was an error creating the customization." >
148+ < ul >
149+ { actionData ?. errors . map ( ( error , index ) => {
150+ return < li key = { `${ index } ` } > { error . message } </ li > ;
151+ } ) }
152+ </ ul >
153+ </ s-banner >
159154 ) : null ;
160155
161- const handleSubmit = ( ) => {
156+ const handleSubmit = ( event ) => {
157+ event . preventDefault ( ) ;
162158 submit ( { paymentMethodName, cartTotal } , { method : "post" } ) ;
163159 } ;
164160
161+ const handleReset = ( ) => {
162+ setPaymentMethodName ( loaderData . paymentMethodName ) ;
163+ setCartTotal ( loaderData . cartTotal ) ;
164+ } ;
165+
165166 useEffect ( ( ) => {
166167 if ( actionData ?. errors . length === 0 ) {
167168 open ( "shopify:admin/settings/payments/customizations" , "_top" ) ;
168169 }
169170 } , [ actionData ?. errors ] ) ;
170171
171172 return (
172- < s-page inlineSize = "base" >
173- < ui-title-bar title = "Hide payment method" >
174- < button onClick = { ( ) => open ( "shopify:admin/settings/payments/customizations" , "_top" ) } slot = "navigation" >
175- Payment customizations
176- </ button >
177- < button onClick = { handleSubmit } variant = "primary" { ...( isLoading && { loading : true } ) } slot = "primary-action" > Save</ button >
178- </ ui-title-bar >
179- { errorBanner }
180- < s-section >
181- < Form method = "post" id = "payment-form" >
182- < s-grid gridTemplateColumns = "repeat(2, 1fr)" gap = "large" >
173+ < form data-save-bar onSubmit = { handleSubmit } onReset = { handleReset } >
174+ < s-page >
175+ < ui-title-bar title = "Hide payment method" >
176+ < button variant = "breadcrumb" href = "shopify:admin/settings/payments/customizations" >
177+ Payment customizations
178+ </ button >
179+ </ ui-title-bar >
180+
181+ { errorBanner }
182+
183+ < s-section >
184+ < s-grid gap = "base" >
183185 < s-text-field
184186 name = "paymentMethodName"
185187 type = "text"
@@ -189,7 +191,8 @@ export default function PaymentCustomization() {
189191 disabled = { isLoading }
190192 autoComplete = "on"
191193 required
192- />
194+ > </ s-text-field >
195+
193196 < s-number-field
194197 name = "cartTotal"
195198 label = "Cart total"
@@ -199,10 +202,10 @@ export default function PaymentCustomization() {
199202 min = "0"
200203 step = "0.01"
201204 required
202- / >
205+ > </ s-number-field >
203206 </ s-grid >
204- </ Form >
205- </ s-section >
206- </ s-page >
207+ </ s-section >
208+ </ s-page >
209+ </ form >
207210 ) ;
208211}
0 commit comments