From 88a71dd647c7d1415f66511d8511e4859111a4a0 Mon Sep 17 00:00:00 2001 From: Allan Carr Date: Mon, 8 Apr 2024 12:23:04 -0700 Subject: [PATCH] IO-2731 Payment Edit Signed-off-by: Allan Carr --- .../payment-mark-export-button-component.jsx | 19 ++++++++--- .../payment-modal/payment-modal.container.jsx | 17 ++++++---- .../payment-reexport-button.component.jsx | 33 +++++++++++++++---- .../payment-list-paginated.component.jsx | 7 ++-- client/src/translations/en_us/common.json | 1 + client/src/translations/es/common.json | 1 + client/src/translations/fr/common.json | 1 + 7 files changed, 59 insertions(+), 20 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 5f8cb395a..5ffdc58ee 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 @@ -7,10 +7,12 @@ import { createStructuredSelector } from "reselect"; import { INSERT_EXPORT_LOG } from "../../graphql/accounting.queries"; import { UPDATE_PAYMENT } from "../../graphql/payments.queries"; import { setModalContext } from "../../redux/modals/modals.actions"; +import { selectPayment } from "../../redux/modals/modals.selectors"; import { selectCurrentUser } from "../../redux/user/user.selectors"; const mapStateToProps = createStructuredSelector({ currentUser: selectCurrentUser, + paymentModal: selectPayment, }); const mapDispatchToProps = (dispatch) => ({ @@ -24,6 +26,7 @@ const PaymentMarkForExportButton = ({ refetch, setPaymentContext, currentUser, + paymentModal, }) => { const { t } = useTranslation(); const [insertExportLog, { loading: exportLogLoading }] = @@ -65,16 +68,22 @@ const PaymentMarkForExportButton = ({ refetch, }, context: { + ...paymentModal.context, ...payment, 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 e53894920..11666914d 100644 --- a/client/src/components/payment-modal/payment-modal.container.jsx +++ b/client/src/components/payment-modal/payment-modal.container.jsx @@ -97,16 +97,21 @@ function PaymentModalContainer({ }); if (!!!updatedPayment.errors) { - notification["success"]({ message: t("payments.successes.payment") }); + notification["success"]({ message: t("payments.successes.paymentupdate") }); } else { - notification["error"]({ message: t("payments.errors.payment") }); + notification["error"]({ message: t("payments.errors.paymentupdate") }); } } - 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"]); 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 a7434e76d..fa6063d67 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 @@ -3,15 +3,25 @@ import { Button, notification } from "antd"; import React from "react"; import { useTranslation } from "react-i18next"; import { connect } from "react-redux"; +import { createStructuredSelector } from "reselect"; import { UPDATE_PAYMENT } from "../../graphql/payments.queries"; import { setModalContext } from "../../redux/modals/modals.actions"; +import { selectPayment } from "../../redux/modals/modals.selectors"; +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); @@ -35,15 +45,21 @@ 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 (paymentModal.context.refetchRequiresContext) { + refetch( + paymentUpdateResponse && + paymentUpdateResponse.data.update_payments.returning[0] + ); + } else { + refetch(); + } + } } else { notification["error"]({ message: t("payments.errors.exporting", { @@ -64,4 +80,7 @@ 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 86ad50cb8..6fdfd108a 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 @@ -14,11 +14,11 @@ import { selectBodyshop } from "../../redux/user/user.selectors"; import CurrencyFormatter from "../../utils/CurrencyFormatter"; import { DateFormatter, DateTimeFormatter } from "../../utils/DateFormatter"; import { TemplateList } from "../../utils/TemplateConstants"; +import { pageLimit } from "../../utils/config"; import { alphaSort } from "../../utils/sorters"; import CaBcEtfTableModalContainer from "../ca-bc-etf-table-modal/ca-bc-etf-table-modal.container"; import OwnerNameDisplay from "../owner-name-display/owner-name-display.component"; import PrintWrapperComponent from "../print-wrapper/print-wrapper.component"; -import {pageLimit} from "../../utils/config"; const mapStateToProps = createStructuredSelector({ //currentUser: selectCurrentUser @@ -184,7 +184,10 @@ export function PaymentsListPaginated({ } : refetch, }, - context: apolloResults ? apolloResults : record, + context: { + ...(apolloResults ? apolloResults : record), + refetchRequiresContext: true, + }, }); }} > diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index 210f04c0f..d54e65c1a 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -2332,6 +2332,7 @@ "markexported": "Payment(s) marked exported.", "markreexported": "Payment marked for re-export successfully", "payment": "Payment created successfully. ", + "paymentupdate": "Payment updated successfully. ", "stripe": "Credit card transaction charged successfully." } }, diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index d1a760146..30ab017ba 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -2331,6 +2331,7 @@ "markexported": "", "markreexported": "", "payment": "", + "paymentupdate": "", "stripe": "" } }, diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 87253cf17..8a77e2231 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -2331,6 +2331,7 @@ "markexported": "", "markreexported": "", "payment": "", + "paymentupdate": "", "stripe": "" } },