import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { react2angular } from 'react2angular'; import '../../lib/i18n'; import { Loader } from '../base/loader'; import { FabModal } from '../base/fab-modal'; import { PaymentSchedule } from '../../models/payment-schedule'; import { IApplication } from '../../models/application'; import FormatLib from '../../lib/format'; declare const Application: IApplication; interface PaymentScheduleSummaryProps { schedule: PaymentSchedule } /** * This component displays a summary of the monthly payment schedule for the current cart, with a subscription */ export const PaymentScheduleSummary: React.FC = ({ schedule }) => { const { t } = useTranslation('shared'); // is open, the modal dialog showing the full details of the payment schedule? const [modal, setModal] = useState(false); /** * Test if all payment deadlines have the same amount */ const hasEqualDeadlines = (): boolean => { const prices = schedule.items.map(i => i.amount); return prices.every(p => p === prices[0]); }; /** * Open or closes the modal dialog showing the full payment schedule */ const toggleFullScheduleModal = (): void => { setModal(!modal); }; return (

{ t('app.shared.payment_schedule_summary.your_payment_schedule') }

{hasEqualDeadlines() &&
  • {t('app.shared.payment_schedule_summary.NUMBER_monthly_payment_of_AMOUNT', { NUMBER: schedule.items.length, AMOUNT: FormatLib.price(schedule.items[0].amount) })} {t('app.shared.payment_schedule_summary.first_debit')}
} {!hasEqualDeadlines() &&
  • {t('app.shared.payment_schedule_summary.monthly_payment_NUMBER', { NUMBER: 1 })} {FormatLib.price(schedule.items[0].amount)} {t('app.shared.payment_schedule_summary.debit')}
  • {t('app.shared.payment_schedule_summary.NUMBER_monthly_payment_of_AMOUNT', { NUMBER: schedule.items.length - 1, AMOUNT: FormatLib.price(schedule.items[1].amount) })}
}
    {schedule.items.map(item => (
  • {FormatLib.date(item.due_date)} {FormatLib.price(item.amount)}
  • ))}
); }; const PaymentScheduleSummaryWrapper: React.FC = ({ schedule }) => { return ( ); }; Application.Components.component('paymentScheduleSummary', react2angular(PaymentScheduleSummaryWrapper, ['schedule']));