Skip to content

Commit

Permalink
disable button while loading and also loading should show as soon as …
Browse files Browse the repository at this point in the history
…button is clicked (#14321)
  • Loading branch information
abhigyanghosh30 authored Sep 23, 2024
1 parent 2ca10a6 commit 5fdf89e
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const BuyButton = ({ setError, products, action, coupon }: Props) => {
}, [values.country]);

const onPayClick = async () => {
setIsLoading(true);
confirmNavigateListener.set();
validateForm().then((errors) => {
const possibleErrors = Object.keys(errors);
Expand All @@ -86,11 +87,13 @@ const BuyButton = ({ setError, products, action, coupon }: Props) => {
if (!(possibleErrors.length === 0)) {
setError(<>Please make sure all fields are filled in correctly.</>);
document.querySelector("h1")?.scrollIntoView();
setIsLoading(false);
return;
}
});

if (!(Object.keys(errors).length === 0)) {
setIsLoading(false);
return;
}

Expand Down Expand Up @@ -386,6 +389,7 @@ const BuyButton = ({ setError, products, action, coupon }: Props) => {
style={{ marginTop: "calc(.5rem - 1.5px)" }}
onClick={onPayClick}
loading={isLoading}
disabled={isLoading}
>
Buy now
</ActionButton>
Expand Down

0 comments on commit 5fdf89e

Please sign in to comment.