Added saving of basic invoicing data for job BOD-131
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import React, { useState } from "react";
|
||||
import { Button, notification } from "antd";
|
||||
import { useMutation } from "@apollo/react-hooks";
|
||||
import { UPDATE_JOB } from "../../graphql/jobs.queries";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
});
|
||||
|
||||
export function JobsCloseSaveButton({
|
||||
bodyshop,
|
||||
suspenseAmount,
|
||||
jobId,
|
||||
jobTotals,
|
||||
labMatAllocations,
|
||||
partsAllocations,
|
||||
}) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const { t } = useTranslation();
|
||||
const [updateJob] = useMutation(UPDATE_JOB);
|
||||
|
||||
const handleSave = async () => {
|
||||
setLoading(true);
|
||||
|
||||
const result = await updateJob({
|
||||
variables: {
|
||||
jobId: jobId,
|
||||
job: {
|
||||
date_invoiced: new Date(),
|
||||
status: bodyshop.md_ro_statuses.default_invoiced || "Invoiced*",
|
||||
invoice_allocation: {
|
||||
labMatAllocations,
|
||||
partsAllocations,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!!!result.errors) {
|
||||
notification["success"]({ message: t("jobs.successes.invoiced") });
|
||||
} else {
|
||||
notification["error"]({
|
||||
message: t("jobs.errors.invoicing", {
|
||||
error: JSON.stringify(result.errors),
|
||||
}),
|
||||
});
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
console.log("suspense", suspenseAmount);
|
||||
return (
|
||||
<Button
|
||||
onClick={handleSave}
|
||||
disabled={suspenseAmount > 0}
|
||||
loading={loading}
|
||||
>
|
||||
{t("general.actions.close")}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, null)(JobsCloseSaveButton);
|
||||
Reference in New Issue
Block a user