From a2dca6c1a1984f6a57d8fe53156e190a14f342dd Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Tue, 8 Feb 2022 11:11:56 -0800 Subject: [PATCH] IO-1720 Add bill mark as exported. --- bodyshop_translations.babel | 42 ++++++++++ .../bill-detail-edit.container.jsx | 2 + .../bill-mark-exported-button.component.jsx | 82 +++++++++++++++++++ client/src/translations/en_us/common.json | 2 + client/src/translations/es/common.json | 2 + client/src/translations/fr/common.json | 2 + 6 files changed, 132 insertions(+) create mode 100644 client/src/components/bill-mark-exported-button/bill-mark-exported-button.component.jsx diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index 5070b9dad..7427dc5d9 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -2863,6 +2863,27 @@ + + markexported + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + markforreexport false @@ -3120,6 +3141,27 @@ + + markexported + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + reexport false diff --git a/client/src/components/bill-detail-edit/bill-detail-edit.container.jsx b/client/src/components/bill-detail-edit/bill-detail-edit.container.jsx index 4a854497e..b8ac4e8cb 100644 --- a/client/src/components/bill-detail-edit/bill-detail-edit.container.jsx +++ b/client/src/components/bill-detail-edit/bill-detail-edit.container.jsx @@ -28,6 +28,7 @@ import { createStructuredSelector } from "reselect"; import { setModalContext } from "../../redux/modals/modals.actions"; import { insertAuditTrail } from "../../redux/application/application.actions"; import AuditTrailMapping from "../../utils/AuditTrailMappings"; +import BillMarkExportedButton from "../bill-mark-exported-button/bill-mark-exported-button.component"; const mapStateToProps = createStructuredSelector({ //currentUser: selectCurrentUser @@ -234,6 +235,7 @@ export function BillDetailEditcontainer({ + } /> diff --git a/client/src/components/bill-mark-exported-button/bill-mark-exported-button.component.jsx b/client/src/components/bill-mark-exported-button/bill-mark-exported-button.component.jsx new file mode 100644 index 000000000..d81244098 --- /dev/null +++ b/client/src/components/bill-mark-exported-button/bill-mark-exported-button.component.jsx @@ -0,0 +1,82 @@ +import { useMutation } from "@apollo/client"; +import { Button, notification } from "antd"; +import { gql } from "@apollo/client"; +import React, { useState } from "react"; +import { useTranslation } from "react-i18next"; + +import { connect } from "react-redux"; +import { createStructuredSelector } from "reselect"; +import { + selectAuthLevel, + selectBodyshop, +} from "../../redux/user/user.selectors"; +import { HasRbacAccess } from "../rbac-wrapper/rbac-wrapper.component"; +const mapStateToProps = createStructuredSelector({ + bodyshop: selectBodyshop, + authLevel: selectAuthLevel, +}); +const mapDispatchToProps = (dispatch) => ({ + //setUserLanguage: language => dispatch(setUserLanguage(language)) +}); + +export default connect( + mapStateToProps, + mapDispatchToProps +)(BillMarkExportedButton); + +export function BillMarkExportedButton({ bodyshop, authLevel, bill }) { + const { t } = useTranslation(); + const [loading, setLoading] = useState(false); + + const [updateBill] = useMutation(gql` + mutation UPDATE_BILL($billId: uuid!) { + update_bills(where: { id: { _eq: $billId } }, _set: { exported: true }) { + returning { + id + exported + exported_at + } + } + } + `); + + const handleUpdate = async () => { + setLoading(true); + const result = await updateBill({ + variables: { billId: bill.id }, + }); + + if (!result.errors) { + notification["success"]({ + message: t("bills.successes.markexported"), + }); + } else { + notification["error"]({ + message: t("bills.errors.saving", { + error: JSON.stringify(result.errors), + }), + }); + } + setLoading(false); + //Get the owner details, populate it all back into the job. + }; + + const hasAccess = HasRbacAccess({ + bodyshop, + authLevel, + action: "bills:reexport", + }); + + if (hasAccess) + return ( + + ); + + return <>; +} diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index b25f97355..c8a03c46d 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -183,6 +183,7 @@ "federal_tax": "Federal Tax", "iouexists": "An IOU exists that is associated to this RO.", "local_tax": "Local Tax", + "markexported": "Mark Exported", "markforreexport": "Mark for Re-export", "new": "New Bill", "noneselected": "No bill selected.", @@ -197,6 +198,7 @@ "created": "Invoice added successfully.", "deleted": "Bill deleted successfully.", "exported": "Bill(s) exported successfully.", + "markexported": "Bill marked as exported.", "reexport": "Bill marked for re-export." }, "validation": { diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index 29ff8e820..3fa3cf7ec 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -183,6 +183,7 @@ "federal_tax": "", "iouexists": "", "local_tax": "", + "markexported": "", "markforreexport": "", "new": "", "noneselected": "", @@ -197,6 +198,7 @@ "created": "", "deleted": "", "exported": "", + "markexported": "", "reexport": "" }, "validation": { diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 655f3fc02..f6ab1802d 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -183,6 +183,7 @@ "federal_tax": "", "iouexists": "", "local_tax": "", + "markexported": "", "markforreexport": "", "new": "", "noneselected": "", @@ -197,6 +198,7 @@ "created": "", "deleted": "", "exported": "", + "markexported": "", "reexport": "" }, "validation": {