Restricted invoice export to 1 at a time BOD-139
This commit is contained in:
@@ -12,13 +12,20 @@ const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
});
|
||||
|
||||
export function InvoiceExportButton({ bodyshop, invoiceId, disabled }) {
|
||||
export function InvoiceExportButton({
|
||||
bodyshop,
|
||||
invoiceId,
|
||||
disabled,
|
||||
loadingCallback,
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [updateInvoice] = useMutation(UPDATE_INVOICE);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const handleQbxml = async () => {
|
||||
setLoading(true);
|
||||
if (!!loadingCallback) loadingCallback(true);
|
||||
|
||||
let QbXmlResponse;
|
||||
try {
|
||||
QbXmlResponse = await axios.post(
|
||||
@@ -38,6 +45,7 @@ export function InvoiceExportButton({ bodyshop, invoiceId, disabled }) {
|
||||
error: "Unable to retrieve QBXML. " + JSON.stringify(error.message),
|
||||
}),
|
||||
});
|
||||
if (loadingCallback) loadingCallback(false);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
@@ -45,7 +53,7 @@ export function InvoiceExportButton({ bodyshop, invoiceId, disabled }) {
|
||||
let PartnerResponse;
|
||||
try {
|
||||
PartnerResponse = await axios.post(
|
||||
"http://e9c5a8ed9079.ngrok.io/qb/receivables",
|
||||
"http://e9c5a8ed9079.ngrok.io/qb/",
|
||||
QbXmlResponse.data
|
||||
);
|
||||
} catch (error) {
|
||||
@@ -53,33 +61,34 @@ export function InvoiceExportButton({ bodyshop, invoiceId, disabled }) {
|
||||
notification["error"]({
|
||||
message: t("invoices.errors.exporting-partner"),
|
||||
});
|
||||
if (!!loadingCallback) loadingCallback(false);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("PartnerResponse", PartnerResponse);
|
||||
// const invoiceUpdateResponse = await updateInvoice({
|
||||
// variables: {
|
||||
// invoiceId: invoiceId,
|
||||
// invoice: {
|
||||
// exported: true,
|
||||
// exported_at: new Date(),
|
||||
// },
|
||||
// },
|
||||
// });
|
||||
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),
|
||||
// }),
|
||||
// });
|
||||
// }
|
||||
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);
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user