From 8be8ad0ed9b96f84eda3daac8ef2d802b2f29f01 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Wed, 20 May 2020 17:02:54 -0700 Subject: [PATCH] Added saving of basic invoicing data for job BOD-131 --- bodyshop_translations.babel | 126 ++++++++++++++++++ .../jobs-close-save-button.component.jsx | 65 +++++++++ .../pages/jobs-close/jobs-close.component.jsx | 11 ++ client/src/translations/en_us/common.json | 6 + client/src/translations/es/common.json | 6 + client/src/translations/fr/common.json | 6 + 6 files changed, 220 insertions(+) create mode 100644 client/src/components/jobs-close-save-button/jobs-close-save-button.component.jsx diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index 18694dcff..19bcce99c 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -1151,6 +1151,27 @@ + + federal_tax + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + lab false @@ -1340,6 +1361,27 @@ + + local_tax + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + mapa false @@ -1571,6 +1613,27 @@ + + state_tax + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + tow false @@ -4426,6 +4489,27 @@ + + close + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + create false @@ -6981,6 +7065,27 @@ + + invoicing + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + noaccess false @@ -10954,6 +11059,27 @@ + + invoiced + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + save false diff --git a/client/src/components/jobs-close-save-button/jobs-close-save-button.component.jsx b/client/src/components/jobs-close-save-button/jobs-close-save-button.component.jsx new file mode 100644 index 000000000..553c9492d --- /dev/null +++ b/client/src/components/jobs-close-save-button/jobs-close-save-button.component.jsx @@ -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 ( + + ); +} + +export default connect(mapStateToProps, null)(JobsCloseSaveButton); diff --git a/client/src/pages/jobs-close/jobs-close.component.jsx b/client/src/pages/jobs-close/jobs-close.component.jsx index b72cf3c30..443a355e9 100644 --- a/client/src/pages/jobs-close/jobs-close.component.jsx +++ b/client/src/pages/jobs-close/jobs-close.component.jsx @@ -7,6 +7,7 @@ import JobsClosePartsAllocation from "../../components/jobs-close-parts-allocati import Dinero from "dinero.js"; import JobsCloseTotals from "../../components/jobs-close-totals/jobs-close-totals.component"; import JobsCloseAutoAllocate from "../../components/jobs-close-auto-allocate/jobs-close-auto-allocate.component"; +import JobsCloseSaveButton from "../../components/jobs-close-save-button/jobs-close-save-button.component"; const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, @@ -58,6 +59,16 @@ export function JobsCloseComponent({ job, bodyshop, jobTotals }) { return (
+