From 1cf5a1fba8ea9a8c80344c0e73e60bbb328bd71a Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Tue, 24 May 2022 16:44:10 -0700 Subject: [PATCH] IO-1864 Mark bills as exported in bulk. --- .../accounting-payables-table.component.jsx | 31 +++++--- ...yable-mark-selected-exported.component.jsx | 79 +++++++++++++++++++ 2 files changed, 100 insertions(+), 10 deletions(-) create mode 100644 client/src/components/payable-mark-selected-exported/payable-mark-selected-exported.component.jsx diff --git a/client/src/components/accounting-payables-table/accounting-payables-table.component.jsx b/client/src/components/accounting-payables-table/accounting-payables-table.component.jsx index 71939895e..fcdcca0b6 100644 --- a/client/src/components/accounting-payables-table/accounting-payables-table.component.jsx +++ b/client/src/components/accounting-payables-table/accounting-payables-table.component.jsx @@ -14,6 +14,7 @@ import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; import { selectBodyshop } from "../../redux/user/user.selectors"; import ExportLogsCountDisplay from "../export-logs-count-display/export-logs-count-display.component"; +import BillMarkSelectedExported from "../payable-mark-selected-exported/payable-mark-selected-exported.component"; const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, @@ -28,7 +29,12 @@ export default connect( mapDispatchToProps )(AccountingPayablesTableComponent); -export function AccountingPayablesTableComponent({ bodyshop, loading, bills, refetch }) { +export function AccountingPayablesTableComponent({ + bodyshop, + loading, + bills, + refetch, +}) { const { t } = useTranslation(); const [selectedBills, setSelectedBills] = useState([]); const [transInProgress, setTransInProgress] = useState(false); @@ -143,15 +149,13 @@ export function AccountingPayablesTableComponent({ bodyshop, loading, bills, ref sorter: (a, b) => a.clm_total - b.clm_total, render: (text, record) => ( -
- -
+ ), }, ]; @@ -177,6 +181,13 @@ export function AccountingPayablesTableComponent({ bodyshop, loading, bills, ref + ({ + //setUserLanguage: language => dispatch(setUserLanguage(language)) +}); + +export default connect( + mapStateToProps, + mapDispatchToProps +)(BillMarkSelectedExported); + +export function BillMarkSelectedExported({ + billids, + disabled, + loadingCallback, + completedCallback, + refetch, +}) { + const { t } = useTranslation(); + const [loading, setLoading] = useState(false); + + const [updateBill] = useMutation(gql` + mutation UPDATE_BILL($billIds: [uuid!]!) { + update_bills(where: { id: { _in: $billIds } }, _set: { exported: true }) { + returning { + id + exported + exported_at + } + } + } + `); + + const handleUpdate = async () => { + setLoading(true); + loadingCallback(true); + const result = await updateBill({ + variables: { billIds: billids }, + update(cache){ + + } + }); + + if (!result.errors) { + notification["success"]({ + message: t("bills.successes.markexported"), + }); + } else { + notification["error"]({ + message: t("bills.errors.saving", { + error: JSON.stringify(result.errors), + }), + }); + } + loadingCallback(false); + completedCallback && completedCallback([]); + setLoading(false); + refetch && refetch(); + }; + + return ( + + ); +}