import { Button, Form, Input, Select, Space, Statistic, Switch, Typography, Upload, } from "antd"; import React, { useEffect, useState } from "react"; import { useApolloClient } from "react-apollo"; import { useTranslation } from "react-i18next"; import { connect } from "react-redux"; import { createStructuredSelector } from "reselect"; import { CHECK_BILL_INVOICE_NUMBER } from "../../graphql/bills.queries"; import { selectBodyshop } from "../../redux/user/user.selectors"; import AlertComponent from "../alert/alert.component"; import FormDatePicker from "../form-date-picker/form-date-picker.component"; import CurrencyInput from "../form-items-formatted/currency-form-item.component"; import JobSearchSelect from "../job-search-select/job-search-select.component"; import LayoutFormRow from "../layout-form-row/layout-form-row.component"; import VendorSearchSelect from "../vendor-search-select/vendor-search-select.component"; import BillFormLines from "./bill-form.lines.component"; import { CalculateBillTotal } from "./bill-form.totals.utility"; import FormFieldsChanged from "../form-fields-changed-alert/form-fields-changed-alert.component"; const mapStateToProps = createStructuredSelector({ bodyshop: selectBodyshop, }); const mapDispatchToProps = (dispatch) => ({}); export function BillFormComponent({ bodyshop, disabled, form, vendorAutoCompleteOptions, lineData, responsibilityCenters, loadLines, billEdit, disableInvNumber, }) { const { t } = useTranslation(); const client = useApolloClient(); const [discount, setDiscount] = useState(0); const handleVendorSelect = (props, opt) => { setDiscount(opt.discount); }; useEffect(() => { if (form.getFieldValue("vendorid") && vendorAutoCompleteOptions) { const vendorId = form.getFieldValue("vendorid"); const matchingVendors = vendorAutoCompleteOptions.filter( (v) => v.id === vendorId ); if (matchingVendors.length === 1) { setDiscount(matchingVendors[0].discount); } } if (form.getFieldValue("jobid")) { loadLines({ variables: { id: form.getFieldValue("jobid") } }); } }, [form, setDiscount, vendorAutoCompleteOptions, loadLines]); return (