Created export payables screen + basic invoice exporting BOD-139
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
import { useMutation } from "@apollo/react-hooks";
|
||||
import { Button, notification } from "antd";
|
||||
import axios from "axios";
|
||||
import React, { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { auth } from "../../firebase/firebase.utils";
|
||||
import { UPDATE_INVOICE } from "../../graphql/invoices.queries";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
});
|
||||
|
||||
export function InvoiceExportButton({ bodyshop, invoiceId, disabled }) {
|
||||
const { t } = useTranslation();
|
||||
const [updateInvoice] = useMutation(UPDATE_INVOICE);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const handleQbxml = async () => {
|
||||
setLoading(true);
|
||||
let QbXmlResponse;
|
||||
try {
|
||||
QbXmlResponse = await axios.post(
|
||||
"/accounting/qbxml/payables",
|
||||
{ invoices: [invoiceId] },
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${await auth.currentUser.getIdToken(true)}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
console.log("handle -> XML", QbXmlResponse);
|
||||
} catch (error) {
|
||||
console.log("Error getting QBXML from Server.", error);
|
||||
notification["error"]({
|
||||
message: t("invoices.errors.exporting", {
|
||||
error: "Unable to retrieve QBXML. " + JSON.stringify(error.message),
|
||||
}),
|
||||
});
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
let PartnerResponse;
|
||||
try {
|
||||
PartnerResponse = await axios.post(
|
||||
"http://e9c5a8ed9079.ngrok.io/qb/receivables",
|
||||
QbXmlResponse.data
|
||||
);
|
||||
} catch (error) {
|
||||
console.log("Error connecting to quickbooks or partner.", error);
|
||||
notification["error"]({
|
||||
message: t("invoices.errors.exporting-partner"),
|
||||
});
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("PartnerResponse", PartnerResponse);
|
||||
// const invoiceUpdateResponse = await updateInvoice({
|
||||
// variables: {
|
||||
// invoiceId: invoiceId,
|
||||
// invoice: {
|
||||
// exported: true,
|
||||
// exported_at: new Date(),
|
||||
// },
|
||||
// },
|
||||
// });
|
||||
|
||||
// if (!!!invoiceUpdateResponse.errors) {
|
||||
// notification["success"]({
|
||||
// message: t("jobs.successes.exported"),
|
||||
// });
|
||||
// } else {
|
||||
// notification["error"]({
|
||||
// message: t("jobs.errors.exporting", {
|
||||
// error: JSON.stringify(invoiceUpdateResponse.error),
|
||||
// }),
|
||||
// });
|
||||
// }
|
||||
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Button
|
||||
onClick={handleQbxml}
|
||||
loading={loading}
|
||||
disabled={disabled}
|
||||
type="dashed"
|
||||
>
|
||||
{t("jobs.actions.export")}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, null)(InvoiceExportButton);
|
||||
Reference in New Issue
Block a user