2021-06-30 15:32:10 +02:00
|
|
|
import React, { FunctionComponent, ReactNode } from 'react';
|
|
|
|
import { AbstractPaymentModal, GatewayFormProps } from '../abstract-payment-modal';
|
|
|
|
import { LocalPaymentForm } from './local-payment-form';
|
|
|
|
import { ShoppingCart } from '../../../models/payment';
|
|
|
|
import { PaymentSchedule } from '../../../models/payment-schedule';
|
2022-01-18 16:27:12 +01:00
|
|
|
import { User } from '../../../models/user';
|
2021-06-30 15:32:10 +02:00
|
|
|
import { Invoice } from '../../../models/invoice';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
import { ModalSize } from '../../base/fab-modal';
|
2021-06-30 16:35:25 +02:00
|
|
|
import { Loader } from '../../base/loader';
|
|
|
|
import { react2angular } from 'react2angular';
|
|
|
|
import { IApplication } from '../../../models/application';
|
2021-06-30 15:32:10 +02:00
|
|
|
|
2021-07-01 12:34:10 +02:00
|
|
|
declare const Application: IApplication;
|
2021-06-30 15:32:10 +02:00
|
|
|
|
|
|
|
interface LocalPaymentModalProps {
|
|
|
|
isOpen: boolean,
|
|
|
|
toggleModal: () => void,
|
|
|
|
afterSuccess: (result: Invoice|PaymentSchedule) => void,
|
2021-10-07 16:43:51 +02:00
|
|
|
onError: (message: string) => void,
|
2021-06-30 15:32:10 +02:00
|
|
|
cart: ShoppingCart,
|
2021-10-15 17:31:01 +02:00
|
|
|
updateCart: (cart: ShoppingCart) => void,
|
2021-06-30 15:32:10 +02:00
|
|
|
currentUser: User,
|
|
|
|
schedule?: PaymentSchedule,
|
|
|
|
customer: User
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This component enables a privileged user to confirm a local payments.
|
|
|
|
*/
|
2022-06-20 15:35:38 +02:00
|
|
|
const LocalPaymentModal: React.FC<LocalPaymentModalProps> = ({ isOpen, toggleModal, afterSuccess, onError, cart, updateCart, currentUser, schedule, customer }) => {
|
2021-06-30 15:32:10 +02:00
|
|
|
const { t } = useTranslation('admin');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the logos, shown in the modal footer.
|
|
|
|
*/
|
|
|
|
const logoFooter = (): ReactNode => {
|
|
|
|
return (
|
|
|
|
<div className="local-modal-icons">
|
|
|
|
<i className="fas fa-lock fa-2x" />
|
|
|
|
</div>
|
|
|
|
);
|
2021-07-01 12:34:10 +02:00
|
|
|
};
|
2021-06-30 15:32:10 +02:00
|
|
|
|
2021-10-22 15:43:33 +02:00
|
|
|
/**
|
|
|
|
* Generally, this modal dialog is only shown to admins or to managers when they book for someone else.
|
|
|
|
* If this is not the case, then it is shown to validate a free (or prepaid by wallet) cart.
|
|
|
|
* This function will return `true` in the later case.
|
|
|
|
*/
|
|
|
|
const isFreeOfCharge = (): boolean => {
|
|
|
|
return (customer.id === currentUser.id);
|
|
|
|
};
|
|
|
|
|
2021-06-30 15:32:10 +02:00
|
|
|
/**
|
|
|
|
* Integrates the LocalPaymentForm into the parent AbstractPaymentModal
|
|
|
|
*/
|
2021-10-15 17:31:01 +02:00
|
|
|
const renderForm: FunctionComponent<GatewayFormProps> = ({ onSubmit, onSuccess, onError, operator, className, formId, cart, updateCart, customer, paymentSchedule, children }) => {
|
2021-06-30 15:32:10 +02:00
|
|
|
return (
|
|
|
|
<LocalPaymentForm onSubmit={onSubmit}
|
2021-07-01 12:34:10 +02:00
|
|
|
onSuccess={onSuccess}
|
|
|
|
onError={onError}
|
|
|
|
operator={operator}
|
|
|
|
className={className}
|
|
|
|
formId={formId}
|
|
|
|
cart={cart}
|
2021-10-15 17:31:01 +02:00
|
|
|
updateCart={updateCart}
|
2021-07-01 12:34:10 +02:00
|
|
|
customer={customer}
|
|
|
|
paymentSchedule={paymentSchedule}>
|
2021-06-30 15:32:10 +02:00
|
|
|
{children}
|
|
|
|
</LocalPaymentForm>
|
|
|
|
);
|
2021-07-01 12:34:10 +02:00
|
|
|
};
|
2021-06-30 15:32:10 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<AbstractPaymentModal className="local-payment-modal"
|
2021-07-01 12:34:10 +02:00
|
|
|
isOpen={isOpen}
|
|
|
|
toggleModal={toggleModal}
|
|
|
|
logoFooter={logoFooter()}
|
2022-06-21 12:09:56 +02:00
|
|
|
title={isFreeOfCharge() ? t('app.admin.local_payment_modal.validate_cart') : t('app.admin.local_payment_modal.offline_payment')}
|
2021-07-01 12:34:10 +02:00
|
|
|
formId="local-payment-form"
|
|
|
|
formClassName="local-payment-form"
|
|
|
|
currentUser={currentUser}
|
|
|
|
cart={cart}
|
2021-10-15 17:31:01 +02:00
|
|
|
updateCart={updateCart}
|
2021-07-01 12:34:10 +02:00
|
|
|
customer={customer}
|
|
|
|
afterSuccess={afterSuccess}
|
2021-10-07 16:43:51 +02:00
|
|
|
onError={onError}
|
2021-07-01 12:34:10 +02:00
|
|
|
schedule={schedule}
|
|
|
|
GatewayForm={renderForm}
|
|
|
|
modalSize={schedule ? ModalSize.large : ModalSize.medium}
|
|
|
|
preventCgv
|
|
|
|
preventScheduleInfo />
|
2021-06-30 15:32:10 +02:00
|
|
|
);
|
2021-07-01 12:34:10 +02:00
|
|
|
};
|
2021-06-30 16:35:25 +02:00
|
|
|
|
2022-06-20 15:35:38 +02:00
|
|
|
const LocalPaymentModalWrapper: React.FC<LocalPaymentModalProps> = (props) => {
|
2021-06-30 16:35:25 +02:00
|
|
|
return (
|
|
|
|
<Loader>
|
2022-06-20 15:35:38 +02:00
|
|
|
<LocalPaymentModal {...props} />
|
2021-06-30 16:35:25 +02:00
|
|
|
</Loader>
|
|
|
|
);
|
2021-07-01 12:34:10 +02:00
|
|
|
};
|
2021-06-30 16:35:25 +02:00
|
|
|
|
2022-06-20 15:35:38 +02:00
|
|
|
export { LocalPaymentModalWrapper as LocalPaymentModal };
|
|
|
|
|
|
|
|
Application.Components.component('localPaymentModal', react2angular(LocalPaymentModalWrapper, ['isOpen', 'toggleModal', 'afterSuccess', 'onError', 'currentUser', 'schedule', 'cart', 'updateCart', 'customer']));
|