diff --git a/client/src/components/bill-detail-edit/bill-detail-edit.container.jsx b/client/src/components/bill-detail-edit/bill-detail-edit.container.jsx index aad7403df..d16ba9ecc 100644 --- a/client/src/components/bill-detail-edit/bill-detail-edit.container.jsx +++ b/client/src/components/bill-detail-edit/bill-detail-edit.container.jsx @@ -14,6 +14,7 @@ import React, { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { useLocation, useHistory } from "react-router-dom"; import { + DELETE_BILL_LINE, INSERT_NEW_BILL_LINES, UPDATE_BILL_LINE, } from "../../graphql/bill-lines.queries"; @@ -58,6 +59,7 @@ export function BillDetailEditcontainer({ const [update_bill] = useMutation(UPDATE_BILL); const [insertBillLine] = useMutation(INSERT_NEW_BILL_LINES); const [updateBillLine] = useMutation(UPDATE_BILL_LINE); + const [deleteBillLine] = useMutation(DELETE_BILL_LINE); const selectedBreakpoint = Object.entries(Grid.useBreakpoint()) .filter((screen) => !!screen[1]) @@ -107,6 +109,20 @@ export function BillDetailEditcontainer({ }) ); + //Find bill lines that were deleted. + const deletedJobLines = []; + + data.bills_by_pk.billlines.forEach((a) => { + const matchingRecord = billlines.find((b) => b.id === a.id); + if (!matchingRecord) { + deletedJobLines.push(a); + } + }); + + deletedJobLines.forEach((d) => { + updates.push(deleteBillLine({ variables: { id: d.id } })); + }); + billlines.forEach((billline) => { const { deductedfromlbr, jobline, ...il } = billline; delete il.__typename; @@ -142,6 +158,7 @@ export function BillDetailEditcontainer({ ); } }); + await Promise.all(updates); insertAuditTrail({ @@ -160,6 +177,8 @@ export function BillDetailEditcontainer({ useEffect(() => { if (search.billid && data) { form.resetFields(); + form.resetFields(); + form.setFieldsValue(transformData(data)); } }, [form, search.billid, data]); diff --git a/client/src/components/job-detail-lines/job-lines.component.jsx b/client/src/components/job-detail-lines/job-lines.component.jsx index e5f09ab2b..e6bff1185 100644 --- a/client/src/components/job-detail-lines/job-lines.component.jsx +++ b/client/src/components/job-detail-lines/job-lines.component.jsx @@ -81,11 +81,6 @@ export function JobLinesComponent({ (c) => c.name === job.ins_co_nm )?.private; - console.log( - "🚀 ~ file: job-lines.component.jsx ~ line 81 ~ jobIsPrivate", - jobIsPrivate - ); - const columns = [ { title: "#", diff --git a/client/src/graphql/bill-lines.queries.js b/client/src/graphql/bill-lines.queries.js index 1b49812c7..b237aa0d0 100644 --- a/client/src/graphql/bill-lines.queries.js +++ b/client/src/graphql/bill-lines.queries.js @@ -12,6 +12,13 @@ export const UPDATE_BILL_LINE = gql` } } `; +export const DELETE_BILL_LINE = gql` + mutation DELETE_BILL_LINE($id: uuid!) { + delete_billlines_by_pk(id: $id) { + id + } + } +`; export const INSERT_NEW_BILL_LINES = gql` mutation INSERT_NEW_BILL_LINES($billLines: [billlines_insert_input!]!) {