Skip to content

Commit

Permalink
feat: show loading spinner when coming back from amazon
Browse files Browse the repository at this point in the history
  • Loading branch information
amihajlovski committed Nov 7, 2023
1 parent 4f6884b commit 05799f1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 7 additions & 2 deletions adyen/components/AdyenCheckout.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import '@adyen/adyen-web/dist/adyen.css'
import {useAdyenCheckout} from '../context/adyen-checkout-context'

const AdyenCheckoutComponent = (props) => {
const {adyenPaymentMethods, getPaymentMethodsConfiguration, setAdyenStateData} =
useAdyenCheckout()
const {
adyenPaymentMethods,
getPaymentMethodsConfiguration,
setAdyenStateData,
setAdyenPaymentInProgress
} = useAdyenCheckout()
const paymentContainer = useRef(null)

useEffect(() => {
Expand Down Expand Up @@ -37,6 +41,7 @@ const AdyenCheckoutComponent = (props) => {
if (redirectResult) {
checkout.submitDetails({data: {details: {redirectResult}}})
} else if (amazonCheckoutSessionId) {
setAdyenPaymentInProgress(true)
const amazonPay = checkout
.create('amazonpay', {
amazonCheckoutSessionId,
Expand Down
3 changes: 3 additions & 0 deletions adyen/context/adyen-checkout-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const AdyenCheckoutProvider = ({children}) => {
const [fetchingPaymentMethods, setFetchingPaymentMethods] = useState(false)
const [adyenPaymentMethods, setAdyenPaymentMethods] = useState()
const [adyenStateData, setAdyenStateData] = useState()
const [adyenPaymentInProgress, setAdyenPaymentInProgress] = useState()

useEffect(() => {
const fetchPaymentMethods = async () => {
Expand Down Expand Up @@ -93,6 +94,8 @@ export const AdyenCheckoutProvider = ({children}) => {
const value = {
adyenPaymentMethods,
adyenStateData,
adyenPaymentInProgress,
setAdyenPaymentInProgress: (data) => setAdyenPaymentInProgress(data),
setAdyenStateData: (data) => setAdyenStateData(data),
getPaymentMethodsConfiguration
}
Expand Down
3 changes: 2 additions & 1 deletion overrides/app/pages/checkout/partials/payment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const Payment = () => {
}

const {step, STEPS, goToStep, goToNextStep} = useCheckout()
const {adyenPaymentMethods, adyenStateData} = useAdyenCheckout()
const {adyenPaymentMethods, adyenStateData, adyenPaymentInProgress} = useAdyenCheckout()
const [isSubmittingPayment, setIsSubmittingPayment] = useState(false)

const billingAddressForm = useForm({
Expand Down Expand Up @@ -134,6 +134,7 @@ const Payment = () => {
editing={step === STEPS.PAYMENT}
isLoading={
!adyenPaymentMethods ||
adyenPaymentInProgress ||
billingAddressForm.formState.isSubmitting ||
isSubmittingPayment
}
Expand Down

0 comments on commit 05799f1

Please sign in to comment.