From 9a8e07d2e5a061f7ec83296e55d0f4b66bdac967 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Fri, 5 Mar 2021 11:20:03 -0800 Subject: [PATCH] Resolve non-updated form on bill enter. IO-739 --- .../bill-enter-modal.container.jsx | 44 +++--- .../bill-form/bill-form.lines.component.jsx | 135 +++++++++--------- .../bill-line-search-select.component.jsx | 28 ++-- .../time-ticket-modal.component.jsx | 1 - .../vendor-search-select.component.jsx | 33 ++--- .../pages/manage/manage.page.component.jsx | 2 - 6 files changed, 116 insertions(+), 127 deletions(-) diff --git a/client/src/components/bill-enter-modal/bill-enter-modal.container.jsx b/client/src/components/bill-enter-modal/bill-enter-modal.container.jsx index 333695f5c..3683b1796 100644 --- a/client/src/components/bill-enter-modal/bill-enter-modal.container.jsx +++ b/client/src/components/bill-enter-modal/bill-enter-modal.container.jsx @@ -1,7 +1,7 @@ import { useApolloClient, useMutation } from "@apollo/client"; import { Button, Form, Modal, notification } from "antd"; import _ from "lodash"; -import React, { useEffect, useState } from "react"; +import React, { useEffect, useState, useMemo } from "react"; import { useTranslation } from "react-i18next"; import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; @@ -197,9 +197,28 @@ function BillEnterModalContainer({ if (enterAgain) form.submit(); }, [enterAgain, form]); + const formValues = useMemo(() => { + return { + ...billEnterModal.context.bill, + jobid: + (billEnterModal.context.job && billEnterModal.context.job.id) || null, + federal_tax_rate: + (bodyshop.bill_tax_rates && bodyshop.bill_tax_rates.federal_tax_rate) || + 0, + state_tax_rate: + (bodyshop.bill_tax_rates && bodyshop.bill_tax_rates.state_tax_rate) || + 0, + local_tax_rate: + (bodyshop.bill_tax_rates && bodyshop.bill_tax_rates.local_tax_rate) || + 0, + }; + }, [billEnterModal, bodyshop]); + useEffect(() => { - if (billEnterModal.visible) form.resetFields(); - }, [billEnterModal.visible, form]); + if (billEnterModal.visible) { + form.setFieldsValue(formValues); + } + }, [billEnterModal.visible, form, formValues]); return ( { setEnterAgain(false); }} - initialValues={{ - ...billEnterModal.context.bill, - jobid: - (billEnterModal.context.job && billEnterModal.context.job.id) || - null, - federal_tax_rate: - (bodyshop.bill_tax_rates && - bodyshop.bill_tax_rates.federal_tax_rate) || - 0, - state_tax_rate: - (bodyshop.bill_tax_rates && - bodyshop.bill_tax_rates.state_tax_rate) || - 0, - local_tax_rate: - (bodyshop.bill_tax_rates && - bodyshop.bill_tax_rates.local_tax_rate) || - 0, - }} + initialValues={formValues} > - - - - - {() => { - const line = getFieldsValue(["billlines"]).billlines[ - index - ]; - if (!!!line) return null; - const lineDiscount = ( - 1 - - Math.round( - (line.actual_cost / line.actual_price) * 100 - ) / - 100 - ).toPrecision(2); +
+ + + + + {() => { + const line = getFieldsValue(["billlines"]) + .billlines[index]; + if (!!!line) return null; + const lineDiscount = ( + 1 - + Math.round( + (line.actual_cost / line.actual_price) * 100 + ) / + 100 + ).toPrecision(2); - if (lineDiscount - discount === 0) return
; - return ; - }} - + if (lineDiscount - discount === 0) return
; + return ; + }} + +
+ + + + + + + + + + + - - - - - - - + ; }} - - - - - {item.line_desc} - - {item.oem_partno ? ( - {item.oem_partno} - ) : null} - - - {item.act_price ? ( - - - {item.act_price || 0} - - - ) : null} - - +
+
{item.line_desc}
+ {item.oem_partno ? ( + {item.oem_partno} + ) : null} + {item.act_price ? ( + + {item.act_price || 0} + + ) : null} +
)) : null} diff --git a/client/src/components/time-ticket-modal/time-ticket-modal.component.jsx b/client/src/components/time-ticket-modal/time-ticket-modal.component.jsx index cb5859a54..dce0e0456 100644 --- a/client/src/components/time-ticket-modal/time-ticket-modal.component.jsx +++ b/client/src/components/time-ticket-modal/time-ticket-modal.component.jsx @@ -146,7 +146,6 @@ export default function TimeTicketModalComponent({ } function LaborAllocationContainer({ jobid }) { - console.log("jobid", jobid); const { loading, data: lineTicketData } = useQuery(GET_LINE_TICKET_BY_PK, { variables: { id: jobid }, skip: !jobid, diff --git a/client/src/components/vendor-search-select/vendor-search-select.component.jsx b/client/src/components/vendor-search-select/vendor-search-select.component.jsx index d6a524d23..0e881e62e 100644 --- a/client/src/components/vendor-search-select/vendor-search-select.component.jsx +++ b/client/src/components/vendor-search-select/vendor-search-select.component.jsx @@ -1,6 +1,6 @@ -import { Col, Row, Select, Tag } from "antd"; -import React, { useEffect, useState, forwardRef } from "react"; import { HeartOutlined } from "@ant-design/icons"; +import { Select, Tag } from "antd"; +import React, { forwardRef, useEffect, useState } from "react"; const { Option } = Select; //To be used as a form element only. @@ -45,31 +45,22 @@ const VendorSearchSelect = ( name={o.name} discount={o.discount} > - - {o.name} - - - - {o.discount && ( - - {`${o.discount * 100}%`} - - )} - +
+
{o.name}
+ + {`${o.discount * 100}%`} +
)) : null} {options ? options.map((o) => ( )) : null} diff --git a/client/src/pages/manage/manage.page.component.jsx b/client/src/pages/manage/manage.page.component.jsx index 8ee35d749..53dd1808a 100644 --- a/client/src/pages/manage/manage.page.component.jsx +++ b/client/src/pages/manage/manage.page.component.jsx @@ -153,8 +153,6 @@ const { Content, Header } = Layout; const stripePromise = new Promise((resolve, reject) => { client.query({ query: QUERY_STRIPE_ID }).then((resp) => { - console.log(resp); - resolve( loadStripe(process.env.REACT_APP_STRIPE_PUBLIC_KEY, { stripeAccount: