From a3557bbc86a78d08516f6d3d5bda463beb1896e6 Mon Sep 17 00:00:00 2001 From: Allan Carr Date: Fri, 5 May 2023 13:10:07 -0700 Subject: [PATCH] IO-2261 Add Delete function, Correct Payment edit, add Totals to Bills handler --- .../bill-delete-button.component.jsx | 4 ++- .../payment-list-paginated.component.jsx | 17 ++++++++-- client/src/graphql/payments.queries.js | 34 +++++++++++++++++++ .../src/pages/bills/bills.page.component.jsx | 10 +++++- os-loader.js | 1 + server/opensearch/os-handler.js | 2 ++ 6 files changed, 64 insertions(+), 4 deletions(-) diff --git a/client/src/components/bill-delete-button/bill-delete-button.component.jsx b/client/src/components/bill-delete-button/bill-delete-button.component.jsx index b6cb19992..5d2d154f6 100644 --- a/client/src/components/bill-delete-button/bill-delete-button.component.jsx +++ b/client/src/components/bill-delete-button/bill-delete-button.component.jsx @@ -6,7 +6,7 @@ import { useTranslation } from "react-i18next"; import { DELETE_BILL } from "../../graphql/bills.queries"; import RbacWrapper from "../rbac-wrapper/rbac-wrapper.component"; -export default function BillDeleteButton({ bill }) { +export default function BillDeleteButton({ bill, callback }) { const [loading, setLoading] = useState(false); const { t } = useTranslation(); const [deleteBill] = useMutation(DELETE_BILL); @@ -36,6 +36,8 @@ export default function BillDeleteButton({ bill }) { if (!!!result.errors) { notification["success"]({ message: t("bills.successes.deleted") }); + + if (callback && typeof callback === "function") callback(bill.id); } else { //Check if it's an fkey violation. const error = JSON.stringify(result.errors); 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 718d056e8..d1d806b29 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 @@ -1,4 +1,5 @@ import { EditFilled, SyncOutlined } from "@ant-design/icons"; +import { useApolloClient } from "@apollo/client"; import { Button, Card, Input, Space, Table, Typography } from "antd"; import axios from "axios"; import queryString from "query-string"; @@ -7,6 +8,7 @@ import { useTranslation } from "react-i18next"; import { connect } from "react-redux"; import { Link, useHistory, useLocation } from "react-router-dom"; import { createStructuredSelector } from "reselect"; +import { QUERY_PAYMENT_BY_ID } from "../../graphql/payments.queries"; import { setModalContext } from "../../redux/modals/modals.actions"; import { selectBodyshop } from "../../redux/user/user.selectors"; import CurrencyFormatter from "../../utils/CurrencyFormatter"; @@ -43,6 +45,7 @@ export function PaymentsListPaginated({ const [openSearchResults, setOpenSearchResults] = useState([]); const [searchLoading, setSearchLoading] = useState(false); const { page, sortcolumn, sortorder } = search; + const client = useApolloClient(); const history = useHistory(); const [state, setState] = useState({ sortedInfo: {}, @@ -154,10 +157,20 @@ export function PaymentsListPaginated({ } - + { + //Filter out the state and set it again. + setOpenSearchResults((currentResults) => + currentResults.filter((bill) => bill.id !== deletedBillid) + ); + }} + /> {record.isinhouse && (