Refactored to use invoice form for modal + detail edit page. BOD-634
This commit is contained in:
@@ -8,12 +8,10 @@ import { connect } from "react-redux";
|
||||
import { useLocation } from "react-router-dom";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { QUERY_INVOICE_BY_PK } from "../../graphql/invoices.queries";
|
||||
import { GET_JOB_LINES_TO_ENTER_INVOICE } from "../../graphql/jobs-lines.queries";
|
||||
import { ACTIVE_JOBS_FOR_AUTOCOMPLETE } from "../../graphql/jobs.queries";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import AlertComponent from "../alert/alert.component";
|
||||
import InvoiceFormContainer from "../invoice-form/invoice-form.container";
|
||||
import LoadingSkeleton from "../loading-skeleton/loading-skeleton.component";
|
||||
import InvoiceDetailEditComponent from "./invoice-detail-edit.component";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
@@ -29,35 +27,19 @@ export function InvoiceDetailEditContainer({ bodyshop }) {
|
||||
skip: !!!search.invoiceid,
|
||||
});
|
||||
|
||||
const { data: RoAutoCompleteData } = useQuery(ACTIVE_JOBS_FOR_AUTOCOMPLETE, {
|
||||
fetchPolicy: "network-only",
|
||||
variables: { statuses: bodyshop.md_ro_statuses.open_statuses || ["Open"] },
|
||||
});
|
||||
|
||||
const {
|
||||
loading: linesLoading,
|
||||
data: lineData,
|
||||
refetch: loadLines,
|
||||
} = useQuery(GET_JOB_LINES_TO_ENTER_INVOICE, {
|
||||
variables: { id: data && data.invoices_by_pk.jobid },
|
||||
fetchPolicy: "network-only",
|
||||
skip: !!!(data && data.invoices_by_pk.id),
|
||||
});
|
||||
|
||||
const handleFinish = (values) => {
|
||||
console.log("values", values);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// if (data) {
|
||||
// loadLines();
|
||||
// if (lineData) //form.resetFields();
|
||||
// }
|
||||
}, [data, lineData]);
|
||||
if (search.invoiceid) {
|
||||
form.resetFields();
|
||||
}
|
||||
}, [form, search.invoiceid]);
|
||||
|
||||
if (error) return <AlertComponent message={error.message} type="error" />;
|
||||
return (
|
||||
<LoadingSkeleton loading={loading || linesLoading}>
|
||||
<LoadingSkeleton loading={loading}>
|
||||
<Form
|
||||
form={form}
|
||||
onFinish={handleFinish}
|
||||
@@ -78,13 +60,7 @@ export function InvoiceDetailEditContainer({ bodyshop }) {
|
||||
: {}
|
||||
}
|
||||
>
|
||||
<InvoiceDetailEditComponent
|
||||
form={form}
|
||||
roAutoCompleteOptions={RoAutoCompleteData && RoAutoCompleteData.jobs}
|
||||
loadLines={loadLines}
|
||||
lineData={lineData ? lineData.joblines : null}
|
||||
responsibilityCenters={bodyshop.md_responsibility_centers || null}
|
||||
/>
|
||||
<InvoiceFormContainer form={form} hideVendor />
|
||||
</Form>
|
||||
</LoadingSkeleton>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user