IO-2298 added export buttons on payments

This commit is contained in:
swtmply
2023-05-25 01:28:22 +08:00
parent 8f91416623
commit 209245187f
5 changed files with 79 additions and 4 deletions

View File

@@ -0,0 +1,49 @@
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";
const PaymentReexportButton = ({ payment, refetch }) => {
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();
} 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 PaymentReexportButton;