diff --git a/components/Paybutton/LoadingSpinner.tsx b/components/Paybutton/LoadingSpinner.tsx new file mode 100644 index 000000000..7cab2d91c --- /dev/null +++ b/components/Paybutton/LoadingSpinner.tsx @@ -0,0 +1,9 @@ +import style from './paybutton.module.css' + +export default (): JSX.Element => { + return ( +
+
+
+ ) +} diff --git a/components/Paybutton/PaybuttonForm.tsx b/components/Paybutton/PaybuttonForm.tsx index 7f6ba5afa..f4b3d9ce7 100644 --- a/components/Paybutton/PaybuttonForm.tsx +++ b/components/Paybutton/PaybuttonForm.tsx @@ -5,9 +5,10 @@ import { WalletWithAddressesWithPaybuttons } from 'services/walletService' import Image from 'next/image' import style from './paybutton.module.css' import Plus from 'assets/plus.png' +import LoadingSpinner from './LoadingSpinner' interface IProps { - onSubmit: Function + onSubmit: (data: PaybuttonPOSTParameters) => Promise paybuttons: [] wallets: WalletWithAddressesWithPaybuttons[] error: String @@ -16,6 +17,7 @@ interface IProps { export default function PaybuttonForm ({ onSubmit, paybuttons, wallets, error }: IProps): ReactElement { const { register, handleSubmit, reset } = useForm() const [modal, setModal] = useState(false) + const [loading, setLoading] = useState(false) useEffect(() => { setModal(false) @@ -28,6 +30,16 @@ export default function PaybuttonForm ({ onSubmit, paybuttons, wallets, error }: label: wallet.name } }) + + const handleFormSubmit = async (data: PaybuttonPOSTParameters): Promise => { + setLoading(true) + try { + await onSubmit(data) + } finally { + setLoading(false) + } + } + return ( <>
@@ -42,7 +54,13 @@ export default function PaybuttonForm ({ onSubmit, paybuttons, wallets, error }:

Create Button

-
{ void handleSubmit(onSubmit)(e) }} method='post'> + { + e.preventDefault() + void handleSubmit(handleFormSubmit)() + }} + method="post" + > @@ -69,8 +87,8 @@ export default function PaybuttonForm ({ onSubmit, paybuttons, wallets, error }: