From 6de9007c3a1486c6cd12c5497b7f1ecaf0f753e9 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Mon, 21 Jun 2021 09:36:03 -0700 Subject: [PATCH] IO-1213 Recalc totals on jobline insert. --- .../error-boundary.component.jsx | 1 - .../job-lines-upsert-modal.container.jsx | 66 ++++++++++--------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/client/src/components/error-boundary/error-boundary.component.jsx b/client/src/components/error-boundary/error-boundary.component.jsx index 327a2b7de..3f6643e1e 100644 --- a/client/src/components/error-boundary/error-boundary.component.jsx +++ b/client/src/components/error-boundary/error-boundary.component.jsx @@ -73,7 +73,6 @@ class ErrorBoundary extends React.Component { }; render() { - console.log("this.props :>> ", this.props); const { t } = this.props; const { error, info } = this.state; if (this.state.hasErrored === true) { diff --git a/client/src/components/job-lines-upsert-modal/job-lines-upsert-modal.container.jsx b/client/src/components/job-lines-upsert-modal/job-lines-upsert-modal.container.jsx index 3e2ac88ef..89b9c406e 100644 --- a/client/src/components/job-lines-upsert-modal/job-lines-upsert-modal.container.jsx +++ b/client/src/components/job-lines-upsert-modal/job-lines-upsert-modal.container.jsx @@ -12,7 +12,7 @@ import { toggleModalVisible } from "../../redux/modals/modals.actions"; import { selectJobLineEditModal } from "../../redux/modals/modals.selectors"; import UndefinedToNull from "../../utils/undefinedtonull"; import JobLinesUpdsertModal from "./job-lines-upsert-modal.component"; - +import Axios from "axios"; const mapStateToProps = createStructuredSelector({ jobLineEditModal: selectJobLineEditModal, }); @@ -29,10 +29,10 @@ function JobLinesUpsertModalContainer({ const [updateJobLine] = useMutation(UPDATE_JOB_LINE); const [loading, setLoading] = useState(false); - const handleFinish = (values) => { + const handleFinish = async (values) => { setLoading(true); if (!jobLineEditModal.context.id) { - insertJobLine({ + const r = await insertJobLine({ variables: { lineInput: [ { @@ -44,42 +44,44 @@ function JobLinesUpsertModalContainer({ }, ], }, - }) - .then((r) => { - if (jobLineEditModal.actions.refetch) - jobLineEditModal.actions.refetch(); - //Need to recalcuate totals. - toggleModalVisible(); - notification["success"]({ - message: t("joblines.successes.created"), - }); - }) - .catch((error) => { - notification["error"]({ - message: t("joblines.errors.creating", { - message: error.message, - }), - }); + }); + if (!r.errors) { + await Axios.post("/job/totalsssu", { + id: jobLineEditModal.context.jobid, }); + if (jobLineEditModal.actions.refetch) + jobLineEditModal.actions.refetch(); + //Need to recalcuate totals. + toggleModalVisible(); + notification["success"]({ + message: t("joblines.successes.created"), + }); + } else { + notification["error"]({ + message: t("joblines.errors.creating", { + message: JSON.stringify(r.errors.message), + }), + }); + } } else { - updateJobLine({ + const r = await updateJobLine({ variables: { lineId: jobLineEditModal.context.id, line: values, }, - }) - .then((r) => { - notification["success"]({ - message: t("joblines.successes.updated"), - }); - }) - .catch((error) => { - notification["success"]({ - message: t("joblines.errors.updating", { - message: error.message, - }), - }); + }); + if (!r.errors) { + notification["success"]({ + message: t("joblines.successes.updated"), }); + } else { + notification["success"]({ + message: t("joblines.errors.updating", { + message: JSON.stringify(r.errors.message), + }), + }); + } + if (jobLineEditModal.actions.submit) { jobLineEditModal.actions.submit(); } else {