Merged in feature/IO-2298-payment-export (pull request #802)

IO-2298 added export buttons on payments

Approved-by: Patrick Fic
This commit is contained in:
John Allen Delos Reyes
2023-05-25 17:41:54 +00:00
committed by Patrick Fic
5 changed files with 85 additions and 4 deletions

View File

@@ -99,7 +99,7 @@ export function JobPayments({
render: (text, record) => (
<Space wrap>
<Button
disabled={record.exportedat}
// disabled={record.exportedat}
onClick={() => {
setPaymentContext({
actions: { refetch: refetch },

View File

@@ -1,6 +1,6 @@
import { useMutation } from "@apollo/client";
import { Button, Form, Modal, notification } from "antd";
import { Button, Form, Modal, notification, Space } from "antd";
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
@@ -19,6 +19,8 @@ import {
import { GenerateDocument } from "../../utils/RenderTemplate";
import { TemplateList } from "../../utils/TemplateConstants";
import PaymentForm from "../payment-form/payment-form.component";
import PaymentExportButton from "../payment-export-button/payment-export-button.component";
import PaymentReexportButton from "../payment-reexport-button/payment-reexport-button.component";
const mapStateToProps = createStructuredSelector({
paymentModal: selectPayment,
@@ -176,12 +178,22 @@ function PaymentModalContainer({
</span>
}
>
<Space>
<PaymentReexportButton payment={context} refetch={actions.refetch} />
<PaymentExportButton
bodyshop={bodyshop}
paymentId={context.id}
disabled={!!context.exportedat}
refetch={actions.refetch}
/>
</Space>
<Form
onFinish={handleFinish}
autoComplete={"off"}
form={form}
layout="vertical"
initialValues={context || {}}
disabled={context.exportedat}
>
<PaymentForm form={form} />
</Form>

View File

@@ -0,0 +1,66 @@
import React from "react";
import { Button, notification } from "antd";
import { useTranslation } from "react-i18next";
import { UPDATE_PAYMENT } from "../../graphql/payments.queries";
import { useMutation } from "@apollo/client";
import { setModalContext } from "../../redux/modals/modals.actions";
import { connect } from "react-redux";
const mapDispatchToProps = (dispatch) => ({
setPaymentContext: (context) =>
dispatch(setModalContext({ context: context, modal: "payment" })),
});
const PaymentReexportButton = ({ payment, refetch, setPaymentContext }) => {
const { t } = useTranslation();
const [updatePayment, { loading }] = useMutation(UPDATE_PAYMENT);
const handleClick = async () => {
const paymentUpdateResponse = await updatePayment({
variables: {
paymentId: payment.id,
payment: {
exportedat: null,
},
},
});
if (!!!paymentUpdateResponse.errors) {
notification.open({
type: "success",
key: "paymentsuccessexport",
message: t("payments.successes.reexported"),
});
if (refetch) refetch();
setPaymentContext({
actions: {
refetch,
},
context: {
...payment,
exportedat: null,
},
});
} else {
notification["error"]({
message: t("payments.errors.exporting", {
error: JSON.stringify(paymentUpdateResponse.error),
}),
});
}
};
return (
<Button
onClick={handleClick}
loading={loading}
disabled={!payment.exportedat}
>
{t("bills.labels.markforreexport")}
</Button>
);
};
export default connect(null, mapDispatchToProps)(PaymentReexportButton);

View File

@@ -156,7 +156,7 @@ export function PaymentsListPaginated({
render: (text, record) => (
<Space>
<Button
disabled={record.exportedat}
// disabled={record.exportedat}
onClick={async () => {
let apolloResults;
if (search.search) {

View File

@@ -2217,10 +2217,13 @@
"new": "New Payment",
"signup": "Please contact support to sign up for electronic payments.",
"title": "Payments",
"totalpayments": "Total Payments"
"totalpayments": "Total Payments",
"markforexport": "Mark for Export",
"markforreexport": "Mark for Reexport"
},
"successes": {
"exported": "Payment(s) exported successfully.",
"reexported": "Payment Re-exported successfully",
"markexported": "Payment(s) marked exported.",
"payment": "Payment created successfully. ",
"stripe": "Credit card transaction charged successfully."