IO-1926 Add export log to mark as exported.

This commit is contained in:
Patrick Fic
2022-06-07 12:39:59 -07:00
parent d32fd9e697
commit a1472cd9ff
3 changed files with 73 additions and 14 deletions

View File

@@ -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) {