IO-710 Export Log page & insert actions on export

This commit is contained in:
Patrick Fic
2021-04-21 14:31:40 -07:00
parent 6d9576b9a4
commit 09e1ab7f83
38 changed files with 653 additions and 180 deletions

View File

@@ -6,15 +6,21 @@ import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { auth, logImEXEvent } from "../../firebase/firebase.utils";
import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries";
import { UPDATE_PAYMENTS } from "../../graphql/payments.queries";
import { selectBodyshop } from "../../redux/user/user.selectors";
import {
selectBodyshop,
selectCurrentUser,
} from "../../redux/user/user.selectors";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
currentUser: selectCurrentUser,
});
export function PaymentExportButton({
bodyshop,
currentUser,
paymentId,
disabled,
loadingCallback,
@@ -22,6 +28,7 @@ export function PaymentExportButton({
const { t } = useTranslation();
const [updatePayment] = useMutation(UPDATE_PAYMENTS);
const [loading, setLoading] = useState(false);
const [insertExportLog] = useMutation(INSERT_EXPORT_LOG);
const handleQbxml = async () => {
logImEXEvent("accounting_payment_export");
@@ -83,7 +90,36 @@ export function PaymentExportButton({
}),
})
);
await insertExportLog({
variables: {
logs: [
{
bodyshopid: bodyshop.id,
paymentid: paymentId,
successful: false,
message: JSON.stringify(
failedTransactions.map((ft) => ft.errorMessage)
),
useremail: currentUser.email,
},
],
},
});
} else {
await insertExportLog({
variables: {
logs: [
{
bodyshopid: bodyshop.id,
paymentid: paymentId,
successful: true,
useremail: currentUser.email,
},
],
},
});
const paymentUpdateResponse = await updatePayment({
variables: {
paymentIdList: [paymentId],
@@ -93,7 +129,9 @@ export function PaymentExportButton({
},
});
if (!!!paymentUpdateResponse.errors) {
notification["success"]({
notification.open({
type: "success",
key: "paymentsuccessexport",
message: t("payments.successes.exported"),
});
} else {