From 1469960643baefdfb9ababda36d0e493c9f2f837 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Fri, 5 Apr 2024 12:52:26 -0700 Subject: [PATCH 1/3] Resolve payment refetch. --- .../payment-modal/payment-modal.container.jsx | 16 ++++++++-------- .../payment-list-paginated.component.jsx | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/client/src/components/payment-modal/payment-modal.container.jsx b/client/src/components/payment-modal/payment-modal.container.jsx index f993c13b8..eb1c6ff59 100644 --- a/client/src/components/payment-modal/payment-modal.container.jsx +++ b/client/src/components/payment-modal/payment-modal.container.jsx @@ -90,7 +90,13 @@ function PaymentModalContainer({ paymentModal, toggleModalVisible, bodyshop, cur } } - if (actions.refetch) actions.refetch(updatedPayment && updatedPayment.data.update_payments.returning[0]); + if (actions.refetch) { + if (context.refetchRequiresContext) { + actions.refetch(updatedPayment && updatedPayment.data.update_payments.returning[0]); + } else { + actions.refetch(); + } + } if (enterAgain) { const prev = form.getFieldsValue(["date"]); @@ -165,13 +171,7 @@ function PaymentModalContainer({ paymentModal, toggleModalVisible, bodyshop, cur )} -
+ 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 1a5dd6774..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 ? apolloResults : record + context: { ...(apolloResults ? apolloResults : record), refetchRequiresContext: true } }); }} > From a2a7c1c58cc48ef571de7d0a8caa0833bfd5d33b Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Mon, 8 Apr 2024 09:48:39 -0700 Subject: [PATCH 2/3] 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); From b8e4520366cc3c8e1de9e9a8ec33f2444928fe59 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Mon, 8 Apr 2024 11:05:12 -0700 Subject: [PATCH 3/3] Resolve ES Lint error. --- .../payment-mark-export-button-component.jsx | 9 ++++++--- .../payment-reexport-button.component.jsx | 2 +- 2 files changed, 7 insertions(+), 4 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 fc6aab627..8511b7506 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,13 +58,14 @@ const PaymentMarkForExportButton = ({ bodyshop, payment, refetch, setPaymentCont refetch }, context: { + ...paymentModal.context, ...payment, exportedat: today } }); if (refetch) { - if (context.refetchRequiresContext) { + if (paymentModal.context.refetchRequiresContext) { refetch(paymentUpdateResponse && paymentUpdateResponse.data.update_payments.returning[0]); } else { refetch(); 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 39621a2a1..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 @@ -47,7 +47,7 @@ const PaymentReexportButton = ({ paymentModal, payment, refetch, setPaymentConte }); if (refetch) { - if (context.refetchRequiresContext) { + if (paymentModal.context.refetchRequiresContext) { refetch(paymentUpdateResponse && paymentUpdateResponse.data.update_payments.returning[0]); } else { refetch();