BOD-62 Added new job calculations on import + supplement.
This commit is contained in:
@@ -1,23 +1,35 @@
|
||||
import { useMutation, useQuery } from "@apollo/react-hooks";
|
||||
import { notification } from "antd";
|
||||
import React, { useState } from "react";
|
||||
import { useMutation, useQuery } from "@apollo/react-hooks";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { withRouter } from "react-router-dom";
|
||||
import { DELETE_ALL_AVAILABLE_NEW_JOBS, QUERY_AVAILABLE_NEW_JOBS } from "../../graphql/available-jobs.queries";
|
||||
import { connect } from "react-redux";
|
||||
import { useHistory } from "react-router-dom";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { CalculateJob } from "../../components/job-totals-table/job-totals.utility";
|
||||
import {
|
||||
DELETE_ALL_AVAILABLE_NEW_JOBS,
|
||||
QUERY_AVAILABLE_NEW_JOBS,
|
||||
} from "../../graphql/available-jobs.queries";
|
||||
import { INSERT_NEW_JOB } from "../../graphql/jobs.queries";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import AlertComponent from "../alert/alert.component";
|
||||
import LoadingSpinner from "../loading-spinner/loading-spinner.component";
|
||||
import JobsAvailableComponent from "./jobs-available-new.component";
|
||||
|
||||
export default withRouter(function JobsAvailableContainer({
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
});
|
||||
|
||||
export function JobsAvailableContainer({
|
||||
deleteJob,
|
||||
estDataLazyLoad,
|
||||
history
|
||||
bodyshop,
|
||||
}) {
|
||||
const { loading, error, data, refetch } = useQuery(QUERY_AVAILABLE_NEW_JOBS, {
|
||||
fetchPolicy: "network-only"
|
||||
fetchPolicy: "network-only",
|
||||
});
|
||||
|
||||
const history = useHistory();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [modalVisible, setModalVisible] = useState(false);
|
||||
@@ -41,22 +53,38 @@ export default withRouter(function JobsAvailableContainer({
|
||||
//We don't have the right data. Error!
|
||||
setInsertLoading(false);
|
||||
notification["error"]({
|
||||
message: t("jobs.errors.creating", { error: "No job data present." })
|
||||
message: t("jobs.errors.creating", { error: "No job data present." }),
|
||||
});
|
||||
} else {
|
||||
const newTotals = CalculateJob(
|
||||
{
|
||||
...estData.data.available_jobs_by_pk.est_data,
|
||||
joblines: estData.data.available_jobs_by_pk.est_data.joblines.data,
|
||||
},
|
||||
bodyshop.shoprates
|
||||
);
|
||||
|
||||
const newJob = {
|
||||
...estData.data.available_jobs_by_pk.est_data,
|
||||
clm_total: newTotals.totals.total_repairs,
|
||||
owner_owing: newTotals.custPayable.total,
|
||||
job_totals: newTotals,
|
||||
};
|
||||
|
||||
console.log("newTotals", newTotals);
|
||||
insertNewJob({
|
||||
variables: {
|
||||
job: selectedOwner
|
||||
? Object.assign(
|
||||
{},
|
||||
estData.data.available_jobs_by_pk.est_data,
|
||||
newJob,
|
||||
{ owner: null },
|
||||
{ ownerid: selectedOwner }
|
||||
)
|
||||
: estData.data.available_jobs_by_pk.est_data
|
||||
}
|
||||
: newJob,
|
||||
},
|
||||
})
|
||||
.then(r => {
|
||||
.then((r) => {
|
||||
notification["success"]({
|
||||
message: t("jobs.successes.created"),
|
||||
onClick: () => {
|
||||
@@ -64,20 +92,21 @@ export default withRouter(function JobsAvailableContainer({
|
||||
history.push(
|
||||
`/manage/jobs/${r.data.insert_jobs.returning[0].id}`
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
//Job has been inserted. Clean up the available jobs record.
|
||||
|
||||
deleteJob({
|
||||
variables: { id: estData.data.available_jobs_by_pk.id }
|
||||
}).then(r => {
|
||||
variables: { id: estData.data.available_jobs_by_pk.id },
|
||||
}).then((r) => {
|
||||
refetch();
|
||||
setInsertLoading(false);
|
||||
});
|
||||
})
|
||||
.catch(r => {
|
||||
.catch((r) => {
|
||||
//error while inserting
|
||||
notification["error"]({
|
||||
message: t("jobs.errors.creating", { error: r.message })
|
||||
message: t("jobs.errors.creating", { error: r.message }),
|
||||
});
|
||||
refetch();
|
||||
setInsertLoading(false);
|
||||
@@ -115,4 +144,5 @@ export default withRouter(function JobsAvailableContainer({
|
||||
/>
|
||||
</LoadingSpinner>
|
||||
);
|
||||
});
|
||||
}
|
||||
export default connect(mapStateToProps, null)(JobsAvailableContainer);
|
||||
|
||||
Reference in New Issue
Block a user