From a1472cd9ff59e622e01b3b48698b44136bfb587b Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Tue, 7 Jun 2022 12:39:59 -0700 Subject: [PATCH] IO-1926 Add export log to mark as exported. --- .../bill-mark-exported-button.component.jsx | 31 +++++++++++++++---- .../jobs-admin-mark-reexport.component.jsx | 29 +++++++++++++++-- ...yable-mark-selected-exported.component.jsx | 27 ++++++++++++---- 3 files changed, 73 insertions(+), 14 deletions(-) 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 index d81244098..80fa1ae44 100644 --- 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 @@ -9,11 +9,14 @@ import { createStructuredSelector } from "reselect"; import { selectAuthLevel, selectBodyshop, + selectCurrentUser, } from "../../redux/user/user.selectors"; import { HasRbacAccess } from "../rbac-wrapper/rbac-wrapper.component"; +import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries"; const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, authLevel: selectAuthLevel, + currentUser: selectCurrentUser, }); const mapDispatchToProps = (dispatch) => ({ //setUserLanguage: language => dispatch(setUserLanguage(language)) @@ -24,9 +27,15 @@ export default connect( mapDispatchToProps )(BillMarkExportedButton); -export function BillMarkExportedButton({ bodyshop, authLevel, bill }) { +export function BillMarkExportedButton({ + currentUser, + bodyshop, + authLevel, + bill, +}) { const { t } = useTranslation(); const [loading, setLoading] = useState(false); + const [insertExportLog] = useMutation(INSERT_EXPORT_LOG); const [updateBill] = useMutation(gql` mutation UPDATE_BILL($billId: uuid!) { @@ -46,6 +55,20 @@ export function BillMarkExportedButton({ bodyshop, authLevel, bill }) { variables: { billId: bill.id }, }); + await insertExportLog({ + variables: { + logs: [ + { + bodyshopid: bodyshop.id, + billid: bill.id, + successful: true, + message: t("general.labels.markedexported"), + useremail: currentUser.email, + }, + ], + }, + }); + if (!result.errors) { notification["success"]({ message: t("bills.successes.markexported"), @@ -69,11 +92,7 @@ export function BillMarkExportedButton({ bodyshop, authLevel, bill }) { if (hasAccess) return ( - ); diff --git a/client/src/components/jobs-admin-mark-reexport/jobs-admin-mark-reexport.component.jsx b/client/src/components/jobs-admin-mark-reexport/jobs-admin-mark-reexport.component.jsx index 929c7f6d5..70dbf0a31 100644 --- a/client/src/components/jobs-admin-mark-reexport/jobs-admin-mark-reexport.component.jsx +++ b/client/src/components/jobs-admin-mark-reexport/jobs-admin-mark-reexport.component.jsx @@ -6,12 +6,17 @@ import { useTranslation } from "react-i18next"; import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; -import { selectBodyshop } from "../../redux/user/user.selectors"; +import { + selectBodyshop, + selectCurrentUser, +} from "../../redux/user/user.selectors"; import moment from "moment"; import AuditTrailMapping from "../../utils/AuditTrailMappings"; import { insertAuditTrail } from "../../redux/application/application.actions"; +import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries"; const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, + currentUser: selectCurrentUser, }); const mapDispatchToProps = (dispatch) => ({ insertAuditTrail: ({ jobid, operation }) => @@ -22,9 +27,15 @@ export default connect( mapDispatchToProps )(JobAdminMarkReexport); -export function JobAdminMarkReexport({ insertAuditTrail, bodyshop, job }) { +export function JobAdminMarkReexport({ + insertAuditTrail, + bodyshop, + currentUser, + job, +}) { const { t } = useTranslation(); const [loading, setLoading] = useState(false); + const [insertExportLog] = useMutation(INSERT_EXPORT_LOG); const [markJobForReexport] = useMutation(gql` mutation MARK_JOB_FOR_REEXPORT($jobId: uuid!) { update_jobs_by_pk( @@ -101,6 +112,20 @@ export function JobAdminMarkReexport({ insertAuditTrail, bodyshop, job }) { variables: { jobId: job.id, date_exported: moment() }, }); + await insertExportLog({ + variables: { + logs: [ + { + bodyshopid: bodyshop.id, + jobid: job.id, + successful: true, + message: t("general.labels.markedexported"), + useremail: currentUser.email, + }, + ], + }, + }); + if (!result.errors) { notification["success"]({ message: t("jobs.successes.save") }); insertAuditTrail({ diff --git a/client/src/components/payable-mark-selected-exported/payable-mark-selected-exported.component.jsx b/client/src/components/payable-mark-selected-exported/payable-mark-selected-exported.component.jsx index a18c370df..8032e03a5 100644 --- a/client/src/components/payable-mark-selected-exported/payable-mark-selected-exported.component.jsx +++ b/client/src/components/payable-mark-selected-exported/payable-mark-selected-exported.component.jsx @@ -4,14 +4,15 @@ import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; +import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries"; import { - selectAuthLevel, selectBodyshop, + selectCurrentUser, } from "../../redux/user/user.selectors"; const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, - authLevel: selectAuthLevel, + currentUser: selectCurrentUser, }); const mapDispatchToProps = (dispatch) => ({ //setUserLanguage: language => dispatch(setUserLanguage(language)) @@ -23,6 +24,8 @@ export default connect( )(BillMarkSelectedExported); export function BillMarkSelectedExported({ + bodyshop, + currentUser, billids, disabled, loadingCallback, @@ -31,7 +34,7 @@ export function BillMarkSelectedExported({ }) { const { t } = useTranslation(); const [loading, setLoading] = useState(false); - + const [insertExportLog] = useMutation(INSERT_EXPORT_LOG); const [updateBill] = useMutation(gql` mutation UPDATE_BILL($billIds: [uuid!]!) { update_bills(where: { id: { _in: $billIds } }, _set: { exported: true }) { @@ -49,9 +52,21 @@ export function BillMarkSelectedExported({ loadingCallback(true); const result = await updateBill({ variables: { billIds: billids }, - update(cache){ - - } + update(cache) {}, + }); + + await insertExportLog({ + variables: { + logs: billids.map((id) => { + return { + bodyshopid: bodyshop.id, + billid: id, + successful: true, + message: t("general.labels.markedexported"), + useremail: currentUser.email, + }; + }), + }, }); if (!result.errors) {