@@ -7,7 +7,7 @@ import style from './paybutton.module.css'
77import Plus from 'assets/plus.png'
88
99interface IProps {
10- onSubmit : Function
10+ onSubmit : ( data : PaybuttonPOSTParameters ) => Promise < void >
1111 paybuttons : [ ]
1212 wallets : WalletWithAddressesWithPaybuttons [ ]
1313 error : String
@@ -16,6 +16,7 @@ interface IProps {
1616export default function PaybuttonForm ( { onSubmit, paybuttons, wallets, error } : IProps ) : ReactElement {
1717 const { register, handleSubmit, reset } = useForm < PaybuttonPOSTParameters > ( )
1818 const [ modal , setModal ] = useState ( false )
19+ const [ loading , setLoading ] = useState ( false )
1920
2021 useEffect ( ( ) => {
2122 setModal ( false )
@@ -28,6 +29,16 @@ export default function PaybuttonForm ({ onSubmit, paybuttons, wallets, error }:
2829 label : wallet . name
2930 }
3031 } )
32+
33+ const handleFormSubmit = async ( data : PaybuttonPOSTParameters ) : Promise < void > => {
34+ setLoading ( true )
35+ try {
36+ await onSubmit ( data )
37+ } finally {
38+ setLoading ( false )
39+ }
40+ }
41+
3142 return (
3243 < >
3344 < div className = { style . create_button_ctn } >
@@ -42,7 +53,13 @@ export default function PaybuttonForm ({ onSubmit, paybuttons, wallets, error }:
4253 < div className = { style . form_ctn_inner } >
4354 < h4 > Create Button</ h4 >
4455 < div className = { style . form_ctn } >
45- < form onSubmit = { ( e ) => { void handleSubmit ( onSubmit ) ( e ) } } method = 'post' >
56+ < form
57+ onSubmit = { ( e ) => {
58+ e . preventDefault ( )
59+ void handleSubmit ( handleFormSubmit ) ( )
60+ } }
61+ method = "post"
62+ >
4663 < label htmlFor = 'name' > Name*</ label >
4764 < input { ...register ( 'name' ) } type = 'text' id = 'name' name = 'name' placeholder = "The unique name of your button" required />
4865 < label htmlFor = 'wallet' > Wallet*</ label >
@@ -69,7 +86,7 @@ export default function PaybuttonForm ({ onSubmit, paybuttons, wallets, error }:
6986 < textarea { ...register ( 'description' ) } id = 'description' name = 'description' placeholder = "More information about your button (optional)" />
7087 < div className = { style . btn_row } >
7188 { error !== '' && < div className = { style . error_message } > { error } </ div > }
72- < button type = 'submit' className = 'button_main' > Submit</ button >
89+ < button type = 'submit' className = 'button_main' disabled = { loading } > { loading ? 'Loading...' : ' Submit' } </ button >
7390 < button onClick = { ( ) => { setModal ( false ) ; reset ( ) } } className = 'button_outline' > Cancel</ button >
7491 </ div >
7592 </ form >
0 commit comments