From 680a66b1567ce279810326aa59bf9b34f80fb927 Mon Sep 17 00:00:00 2001 From: Allan Carr Date: Tue, 20 Aug 2024 10:00:52 -0700 Subject: [PATCH] IO-2887 Returnfrombill Parts Drawer Info Signed-off-by: Allan Carr --- ...arts-order-list-table-drawer.component.jsx | 106 +++++++----------- 1 file changed, 41 insertions(+), 65 deletions(-) diff --git a/client/src/components/parts-order-list-table/parts-order-list-table-drawer.component.jsx b/client/src/components/parts-order-list-table/parts-order-list-table-drawer.component.jsx index f4c5976b6..5dde61a72 100644 --- a/client/src/components/parts-order-list-table/parts-order-list-table-drawer.component.jsx +++ b/client/src/components/parts-order-list-table/parts-order-list-table-drawer.component.jsx @@ -1,8 +1,7 @@ -import { DeleteFilled, EyeFilled } from "@ant-design/icons"; +import { DeleteFilled } from "@ant-design/icons"; import { PageHeader } from "@ant-design/pro-layout"; import { useLazyQuery, useMutation } from "@apollo/client"; import { Button, Drawer, Grid, Popconfirm, Space, Table } from "antd"; - import queryString from "query-string"; import React, { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; @@ -83,47 +82,34 @@ export function PartsOrderListTableDrawerComponent({ sortedInfo: {} }); - const [returnfrombill, setReturnFromBill] = useState(); - const [billData, setBillData] = useState(); + const [billData, setBillData] = useState(null); const search = queryString.parse(useLocation().search); const selectedpartsorder = search.partsorderid; - const [billQuery] = useLazyQuery(QUERY_BILL_BY_PK); const [deletePartsOrder] = useMutation(DELETE_PARTS_ORDER); const parts_orders = billsQuery.data ? billsQuery.data.parts_orders : []; const { refetch } = billsQuery; + const [billQuery] = useLazyQuery(QUERY_BILL_BY_PK); + const selectedPartsOrderRecord = parts_orders.find((r) => r.id === selectedpartsorder); useEffect(() => { - if (returnfrombill === null) { - setBillData(null); - } else { - const fetchData = async () => { - const result = await billQuery({ - variables: { billid: returnfrombill } - }); - setBillData(result.data); - }; - fetchData(); - } - }, [returnfrombill, billQuery]); + const fetchData = async () => { + if (selectedPartsOrderRecord?.returnfrombill) { + try { + const { data } = await billQuery({ + variables: { billid: selectedPartsOrderRecord.returnfrombill } + }); + setBillData(data); + } catch (error) { + console.error("Error fetching bill data:", error); + } + } + }; + fetchData(); + }, [selectedPartsOrderRecord, billQuery]); - const recordActions = (record, showView = false) => ( + const recordActions = (record) => ( - {showView && ( - - )} -