Refactored communication with partner app to use custom objects + error handling BOD-83 BOD-138 BOD-139

This commit is contained in:
Patrick Fic
2020-06-02 17:46:51 -07:00
parent 6060def9f4
commit 59f21b95b1
12 changed files with 176 additions and 55 deletions

View File

@@ -1,4 +1,4 @@
import { Input, Table } from "antd";
import { Input, Table, Button } from "antd";
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { Link } from "react-router-dom";
@@ -123,13 +123,14 @@ export default function AccountingReceivablesTableComponent({ loading, jobs }) {
sorter: (a, b) => a.clm_total - b.clm_total,
render: (text, record) => (
<div>
<div style={{ display: "flex" }}>
<JobExportButton
jobId={record.id}
disabled={!!record.date_exported}
/>
{JSON.stringify(record.date_exported)}
<Link to={`/manage/jobs/${record.id}/close`}>
<Button>{t("jobs.labels.viewallocations")}</Button>
</Link>
</div>
),
},

View File

@@ -229,6 +229,11 @@ function Header({
{t("menus.header.accounting-receivables")}
</Link>
</Menu.Item>
<Menu.Item key="payables">
<Link to="/manage/accounting/payables">
{t("menus.header.accounting-payables")}
</Link>
</Menu.Item>
</Menu.SubMenu>
<Menu.SubMenu title={t("menus.header.shop")}>

View File

@@ -6,7 +6,7 @@ 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 { UPDATE_INVOICES } from "../../graphql/invoices.queries";
import { selectBodyshop } from "../../redux/user/user.selectors";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
@@ -19,7 +19,7 @@ export function InvoiceExportButton({
loadingCallback,
}) {
const { t } = useTranslation();
const [updateInvoice] = useMutation(UPDATE_INVOICE);
const [updateInvoice] = useMutation(UPDATE_INVOICES);
const [loading, setLoading] = useState(false);
const handleQbxml = async () => {
@@ -51,6 +51,7 @@ export function InvoiceExportButton({
}
let PartnerResponse;
try {
PartnerResponse = await axios.post(
"http://e9c5a8ed9079.ngrok.io/qb/",
@@ -66,26 +67,42 @@ export function InvoiceExportButton({
return;
}
const invoiceUpdateResponse = await updateInvoice({
variables: {
invoiceId: invoiceId,
invoice: {
exported: true,
exported_at: new Date(),
console.log("handleQbxml -> PartnerResponse", PartnerResponse);
const failedTransactions = PartnerResponse.data.filter((r) => !r.success);
const successfulTransactions = PartnerResponse.data.filter(
(r) => r.success
);
if (failedTransactions.length > 0) {
//Uh oh. At least one was no good.
failedTransactions.map((ft) =>
notification["error"]({
message: t("invoices.errors.exporting", {
error: ft.errorMessage || "",
}),
})
);
}
if (successfulTransactions.length > 0) {
const invoiceUpdateResponse = await updateInvoice({
variables: {
invoiceIdList: successfulTransactions.map((st) => st.id),
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),
}),
});
if (!!!invoiceUpdateResponse.errors) {
notification["success"]({
message: t("jobs.successes.exported"),
});
} else {
notification["error"]({
message: t("jobs.errors.exporting", {
error: JSON.stringify(invoiceUpdateResponse.error),
}),
});
}
}
if (!!loadingCallback) loadingCallback(false);

View File

@@ -44,7 +44,7 @@ export function JobsCloseExportButton({ bodyshop, jobId, disabled }) {
let PartnerResponse;
try {
PartnerResponse = await axios.post(
"http://localhost:1337/qb/",
"http://e9c5a8ed9079.ngrok.io/qb/",
QbXmlResponse.data,
{
headers: {
@@ -62,26 +62,40 @@ export function JobsCloseExportButton({ bodyshop, jobId, disabled }) {
}
console.log("PartnerResponse", PartnerResponse);
const jobUpdateResponse = await updateJob({
variables: {
jobId: jobId,
job: {
status: bodyshop.md_ro_statuses.default_exported || "Exported*",
date_exported: new Date(),
},
},
});
if (!!!jobUpdateResponse.errors) {
notification["success"]({
message: t("jobs.successes.exported"),
});
//Check to see if any of them failed. If they didn't don't execute the update.
const failedTransactions = PartnerResponse.data.filter((r) => !r.success);
if (failedTransactions.length > 0) {
//Uh oh. At least one was no good.
failedTransactions.map((ft) =>
notification["error"]({
message: t("jobs.errors.exporting", {
error: ft.errorMessage || "",
}),
})
);
} else {
notification["error"]({
message: t("jobs.errors.exporting", {
error: JSON.stringify(jobUpdateResponse.error),
}),
const jobUpdateResponse = await updateJob({
variables: {
jobId: jobId,
job: {
status: bodyshop.md_ro_statuses.default_exported || "Exported*",
date_exported: new Date(),
},
},
});
if (!!!jobUpdateResponse.errors) {
notification["success"]({
message: t("jobs.successes.exported"),
});
} else {
notification["error"]({
message: t("jobs.errors.exporting", {
error: JSON.stringify(jobUpdateResponse.error),
}),
});
}
}
setLoading(false);