import React, { ReactNode, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { FabModal } from '../../base/fab-modal'; import { PaymentSchedule } from '../../../models/payment-schedule'; import { User } from '../../../models/user'; import mastercardLogo from '../../../../../images/mastercard.png'; import visaLogo from '../../../../../images/visa.png'; import payzenLogo from '../../../../../images/payzen-secure.png'; import { PayzenForm } from './payzen-form'; interface PayzenCardUpdateModalProps { isOpen: boolean, toggleModal: () => void, onSuccess: () => void, schedule: PaymentSchedule, operator: User } /** * Modal dialog to allow the member to update his payment card for a payment schedule, when the PayZen gateway is used */ export const PayzenCardUpdateModal: React.FC = ({ isOpen, toggleModal, onSuccess, schedule, operator }) => { const { t } = useTranslation('shared'); // prevent submitting the form to update the card details, until the user has filled correctly all required fields const [canSubmitUpdateCard, setCanSubmitUpdateCard] = useState(true); // we save errors here, if any, for display purposes. const [errors, setErrors] = useState(null); // the unique identifier of the html form const formId = 'payzen-card'; /** * Return the logos, shown in the modal footer. */ const logoFooter = (): ReactNode => { return (
powered by PayZen mastercard visa
); }; /** * When the user clicks the submit button, we disable it to prevent double form submission */ const handleCardUpdateSubmit = (): void => { setCanSubmitUpdateCard(false); }; /** * When the card was not updated, show the error */ const handleCardUpdateError = (error): void => { setErrors(error); setCanSubmitUpdateCard(true); }; return ( {schedule && {errors &&
{errors}
}
}
{canSubmitUpdateCard && } {!canSubmitUpdateCard &&
}
); };