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 788584a08..e10617466 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 @@ -8,16 +8,18 @@ import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries"; import { UPDATE_PAYMENT } from "../../graphql/payments.queries"; import { setModalContext } from "../../redux/modals/modals.actions"; import { selectCurrentUser } from "../../redux/user/user.selectors"; +import { selectPayment } from "../../redux/modals/modals.selectors"; const mapStateToProps = createStructuredSelector({ - currentUser: selectCurrentUser + currentUser: selectCurrentUser, + paymentModal: selectPayment }); const mapDispatchToProps = (dispatch) => ({ setPaymentContext: (context) => dispatch(setModalContext({ context: context, modal: "payment" })) }); -const PaymentMarkForExportButton = ({ bodyshop, payment, refetch, setPaymentContext, currentUser }) => { +const PaymentMarkForExportButton = ({ bodyshop, payment, refetch, setPaymentContext, currentUser, paymentModal }) => { const { t } = useTranslation(); const [insertExportLog, { loading: exportLogLoading }] = useMutation(INSERT_EXPORT_LOG); const [updatePayment, { loading: updatePaymentLoading }] = useMutation(UPDATE_PAYMENT); @@ -56,17 +58,20 @@ const PaymentMarkForExportButton = ({ bodyshop, payment, refetch, setPaymentCont refetch }, context: { + ...paymentModal.context, ...payment, smartRefetch: true, exportedat: today } }); - if (refetch) - refetch( - paymentUpdateResponse && - paymentUpdateResponse.data.update_payments.returning[0] - ); + if (refetch) { + if (paymentModal.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-modal/payment-modal.container.jsx b/client/src/components/payment-modal/payment-modal.container.jsx index b7e2eaf9c..fecb0c746 100644 --- a/client/src/components/payment-modal/payment-modal.container.jsx +++ b/client/src/components/payment-modal/payment-modal.container.jsx @@ -89,10 +89,13 @@ function PaymentModalContainer({paymentModal, toggleModalVisible, bodyshop }) { } if (actions.refetch) { - const updatedData = smartRefetch && updatedPayment ? updatedPayment.data.update_payments.returning[0] : undefined; - actions.refetch(updatedData); + if (context.refetchRequiresContext) { + actions.refetch(updatedPayment && updatedPayment.data.update_payments.returning[0]); + } else { + actions.refetch(); + } } - + if (enterAgain) { const prev = form.getFieldsValue(["date"]); @@ -166,13 +169,7 @@ function PaymentModalContainer({paymentModal, toggleModalVisible, bodyshop }) { )} -
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 d85cb14d3..434377e86 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,16 +40,19 @@ const PaymentReexportButton = ({ payment, refetch, setPaymentContext }) => { refetch }, context: { - smartRefetch: true, + ...paymentModal.context, ...payment, exportedat: null } }); - if (refetch) - refetch( - paymentUpdateResponse && - paymentUpdateResponse.data.update_payments.returning[0] - ); + + if (refetch) { + if (paymentModal.context.refetchRequiresContext) { + refetch(paymentUpdateResponse && paymentUpdateResponse.data.update_payments.returning[0]); + } else { + refetch(); + } + } } else { notification["error"]({ message: t("payments.errors.exporting", { @@ -60,4 +69,4 @@ const PaymentReexportButton = ({ payment, refetch, setPaymentContext }) => { ); }; -export default connect(null, mapDispatchToProps)(PaymentReexportButton); +export default connect(mapStateToProps, mapDispatchToProps)(PaymentReexportButton); diff --git a/client/src/components/payments-list-paginated/payment-list-paginated.component.jsx b/client/src/components/payments-list-paginated/payment-list-paginated.component.jsx index e9e96057f..e6f0d9822 100644 --- a/client/src/components/payments-list-paginated/payment-list-paginated.component.jsx +++ b/client/src/components/payments-list-paginated/payment-list-paginated.component.jsx @@ -171,7 +171,7 @@ export function PaymentsListPaginated({ } : refetch }, - context: apolloResults ? { smartRefetch: true, ...apolloResults} : {smartRefetch: true, ...record} + context: { ...(apolloResults ? apolloResults : record), refetchRequiresContext: true } }); }} >