diff --git a/client/src/components/invoice-enter-modal/invoice-enter-modal.container.jsx b/client/src/components/invoice-enter-modal/invoice-enter-modal.container.jsx index 5078a0029..56f30fbc0 100644 --- a/client/src/components/invoice-enter-modal/invoice-enter-modal.container.jsx +++ b/client/src/components/invoice-enter-modal/invoice-enter-modal.container.jsx @@ -45,12 +45,14 @@ function InvoiceEnterModalContainer({ invoice: [ Object.assign({}, remainingValues, { invoicelines: { - data: remainingValues.invoicelines.map((i) => { - return { - ...i, - joblineid: i.joblineid === "noline" ? null : i.joblineid, - }; - }), + data: + remainingValues.invoicelines && + remainingValues.invoicelines.map((i) => { + return { + ...i, + joblineid: i.joblineid === "noline" ? null : i.joblineid, + }; + }), }, }), ], diff --git a/client/src/components/invoice-form/invoice-form.component.jsx b/client/src/components/invoice-form/invoice-form.component.jsx index b57764fda..02bf469fb 100644 --- a/client/src/components/invoice-form/invoice-form.component.jsx +++ b/client/src/components/invoice-form/invoice-form.component.jsx @@ -12,7 +12,6 @@ import { CalculateInvoiceTotal } from "./invoice-form.totals.utility"; export default function InvoiceFormComponent({ form, - roAutoCompleteOptions, vendorAutoCompleteOptions, lineData, responsibilityCenters, @@ -57,7 +56,6 @@ export default function InvoiceFormComponent({ ]} > { if (form.getFieldValue("jobid") !== null) { diff --git a/client/src/components/invoice-form/invoice-form.container.jsx b/client/src/components/invoice-form/invoice-form.container.jsx index 0743ed8d0..e13a22caf 100644 --- a/client/src/components/invoice-form/invoice-form.container.jsx +++ b/client/src/components/invoice-form/invoice-form.container.jsx @@ -3,7 +3,6 @@ import React from "react"; import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; import { GET_JOB_LINES_TO_ENTER_INVOICE } from "../../graphql/jobs-lines.queries"; -import { ACTIVE_JOBS_FOR_AUTOCOMPLETE } from "../../graphql/jobs.queries"; import { SEARCH_VENDOR_AUTOCOMPLETE } from "../../graphql/vendors.queries"; import { selectBodyshop } from "../../redux/user/user.selectors"; import InvoiceFormComponent from "./invoice-form.component"; @@ -13,10 +12,6 @@ const mapStateToProps = createStructuredSelector({ }); export function InvoiceFormContainer({ bodyshop, form, invoiceEdit }) { - const { data: RoAutoCompleteData } = useQuery(ACTIVE_JOBS_FOR_AUTOCOMPLETE, { - variables: { statuses: bodyshop.md_ro_statuses.open_statuses || ["Open"] }, - }); - const { data: VendorAutoCompleteData } = useQuery(SEARCH_VENDOR_AUTOCOMPLETE); const [loadLines, { data: lineData }] = useLazyQuery( @@ -28,7 +23,6 @@ export function InvoiceFormContainer({ bodyshop, form, invoiceEdit }) { { + const [callSearch, { loading, error, data }] = useLazyQuery( + SEARCH_JOBS_FOR_AUTOCOMPLETE + ); + const [ + callIdSearch, + { loading: idLoading, error: idError, data: idData }, + ] = useLazyQuery(SEARCH_JOBS_BY_ID_FOR_AUTOCOMPLETE); + + const executeSearch = (v) => { + callSearch(v); + }; + const debouncedExecuteSearch = _.debounce(executeSearch, 800); + + const handleSearch = (value) => { + debouncedExecuteSearch({ variables: { search: value } }); + }; -const JobSearchSelect = ( - { value, onChange, options, onBlur, disabled, loading }, - ref -) => { const [option, setOption] = useState(value); useEffect(() => { + if (value === option) { + console.log("Job ID Provided, searching..."); + callIdSearch({ variables: { id: value } }); + } + }, [value, option, callIdSearch]); + + // useEffect(() => { + // if (value !== option && onChange) { + // onChange(option); + // } + // }, [value, option, onChange]); + + const handleSelect = (value) => { + setOption(value); if (value !== option && onChange) { onChange(option); } - }, [value, option, onChange]); + }; + + const theOptions = [ + ...(idData && idData.jobs_by_pk ? [idData.jobs_by_pk] : []), + ...(data && data.search_jobs ? data.search_jobs : []), + ]; return ( - +
+ + {idLoading || loading ? : null} +
); }; export default forwardRef(JobSearchSelect); diff --git a/client/src/components/jobs-close-allocation-button/jobs-close-allocation-button.component.jsx b/client/src/components/jobs-close-allocation-button/jobs-close-allocation-button.component.jsx index d43fa84ef..d1cbe1280 100644 --- a/client/src/components/jobs-close-allocation-button/jobs-close-allocation-button.component.jsx +++ b/client/src/components/jobs-close-allocation-button/jobs-close-allocation-button.component.jsx @@ -61,7 +61,7 @@ export function JobsCloseLabmatAllocationButton({ setState({ center: "", amount: 0 }); }; - const showAllocation = allocation.total.getAmount() > 0; + const showAllocation = Dinero(allocation.total).getAmount() > 0; useEffect(() => { if (remainingAmount === 0) setVisible(false); }, [remainingAmount, setVisible]); @@ -73,7 +73,8 @@ export function JobsCloseLabmatAllocationButton({