From a2a7c1c58cc48ef571de7d0a8caa0833bfd5d33b Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Mon, 8 Apr 2024 09:48:39 -0700 Subject: [PATCH] Add contextRefect to payment export buttons. --- .../payment-mark-export-button-component.jsx | 12 ++++++---- .../payment-reexport-button.component.jsx | 24 +++++++++++++------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/client/src/components/payment-mark-export-button/payment-mark-export-button-component.jsx b/client/src/components/payment-mark-export-button/payment-mark-export-button-component.jsx index 59819e03c..fc6aab627 100644 --- a/client/src/components/payment-mark-export-button/payment-mark-export-button-component.jsx +++ b/client/src/components/payment-mark-export-button/payment-mark-export-button-component.jsx @@ -61,11 +61,13 @@ const PaymentMarkForExportButton = ({ bodyshop, payment, refetch, setPaymentCont } }); - if (refetch) - refetch( - paymentUpdateResponse && - paymentUpdateResponse.data.update_payments.returning[0] - ); + if (refetch) { + if (context.refetchRequiresContext) { + refetch(paymentUpdateResponse && paymentUpdateResponse.data.update_payments.returning[0]); + } else { + refetch(); + } + } } else { notification["error"]({ message: t("payments.errors.exporting", { diff --git a/client/src/components/payment-reexport-button/payment-reexport-button.component.jsx b/client/src/components/payment-reexport-button/payment-reexport-button.component.jsx index 5325231e4..39621a2a1 100644 --- a/client/src/components/payment-reexport-button/payment-reexport-button.component.jsx +++ b/client/src/components/payment-reexport-button/payment-reexport-button.component.jsx @@ -5,12 +5,18 @@ import { useTranslation } from "react-i18next"; import { connect } from "react-redux"; import { UPDATE_PAYMENT } from "../../graphql/payments.queries"; import { setModalContext } from "../../redux/modals/modals.actions"; +import { selectPayment } from "../../redux/modals/modals.selectors"; +import { createStructuredSelector } from "reselect"; + +const mapStateToProps = createStructuredSelector({ + paymentModal: selectPayment +}); const mapDispatchToProps = (dispatch) => ({ setPaymentContext: (context) => dispatch(setModalContext({ context: context, modal: "payment" })) }); -const PaymentReexportButton = ({ payment, refetch, setPaymentContext }) => { +const PaymentReexportButton = ({ paymentModal, payment, refetch, setPaymentContext }) => { const { t } = useTranslation(); const [updatePayment, { loading }] = useMutation(UPDATE_PAYMENT); @@ -34,15 +40,19 @@ const PaymentReexportButton = ({ payment, refetch, setPaymentContext }) => { refetch }, context: { + ...paymentModal.context, ...payment, exportedat: null } }); - if (refetch) - refetch( - paymentUpdateResponse && - paymentUpdateResponse.data.update_payments.returning[0] - ); + + if (refetch) { + if (context.refetchRequiresContext) { + refetch(paymentUpdateResponse && paymentUpdateResponse.data.update_payments.returning[0]); + } else { + refetch(); + } + } } else { notification["error"]({ message: t("payments.errors.exporting", { @@ -59,4 +69,4 @@ const PaymentReexportButton = ({ payment, refetch, setPaymentContext }) => { ); }; -export default connect(null, mapDispatchToProps)(PaymentReexportButton); +export default connect(mapStateToProps, mapDispatchToProps)(PaymentReexportButton);