{"version":3,"sources":["components/SupplierDetails/FormView.jsx","containers/SupplierDetails/FormView.js"],"names":["FormView","React","constructor","props","_this","super","this","state","getItemId","_this$state$item","_this$props$linkTarge","item","id","linkTargetRecord","supplierDetailId","find","Boolean","fetchItem","async","itemId","arguments","length","undefined","isNil","setState","selectProductVisible","_this$props$settingsT","_suppliers$value$data","_suppliers$value","responses","Promise","all","getItem","catch","error","_this$props$onCancel","_this$props","onCancel","call","getSettings","type","settingsType","cloneDeep","value","data","suppliers","getSuppliers","supplierId","supplierIds","fieldSettings","showError","handleSelectProductOk","selectedProduct","productId","description","itemDescription","barcode","_this$props$settingsT2","_responses$2$value$da","newItem","price","saveItem","Error","updateItems","createItem","handleSubmit","createHandleSubmit","searchSuppliers","createSearchSuppliers","componentDidMount","render","_this$state$suppliers","_this$state$suppliers2","_jsxs","_Fragment","children","_jsx","_Spin","Modal","title","t","visible","okText","onOk","okButtonProps","disabled","width","SelectProducts","onSelect","values","filterProps","privateDatabaseOnly","createLabel","createLabelFactory","createFieldDecorator","createFieldFactory","form","readOnly","isReadOnly","_Form","layout","colon","onSubmit","stopEvent","className","ValidationError","errors","validationErrors","Item","label","_Input","TextArea","rows","Select","dropdownRender","createDropdownRender","onSearch","showSearch","items","filter","each","map","Option","getOptionProps","name","InputNumber","min","currency","FormButtons","saveButtonLoading","saveAndCloseButtonLoading","create","createFormViewContainer","actions","extraDispatchToProps","dispatch","params","supplierActions","getOptions","pageIndex","pageSize","active","Component"],"mappings":"6TAoBA,MAAMA,UAAiBC,YAGrBC,YAAYC,GAAQ,IAADC,EACjBC,MAAMF,GAAMC,EAAAE,KAAA,KAHdC,MAAQ,CAAC,EAAC,KAaVC,UAAY,SAAAC,EAAAC,EAAA,MAAM,CAAgB,QAAhBD,EAACH,KAAKC,MAAMI,YAAI,IAAAF,OAAA,EAAfA,EAAiBG,GAA+B,QAA7BF,EAAEJ,KAAKH,MAAMU,wBAAgB,IAAAH,OAAA,EAA3BA,EAA6BI,kBAAkBC,KA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AAQ,OAE9DnD,cAAAuB,IAAMS,KAAI,CAACC,MAAOjB,EAAY,eAAejB,SAC1CmB,EAAqB,cAArBA,CAAoClB,cAAAkC,IAAOC,SAAQ,CAACC,KAAM,UAG/DpC,cAAA,OAAK4B,UAAU,yBAAwB7B,SACrCC,cAACoD,IAAW,CACV/B,SAAUA,EACV5D,SAAU/B,KAAKH,MAAMkC,SACrBiE,SAAUhG,KAAK2D,aACfgE,kBAAmB3H,KAAKC,MAAM0H,kBAC9BC,0BAA2B5H,KAAKC,MAAM2H,gCAKhD,EAGa/B,UAAKgC,QAALhC,CAAcnG,GCxLdoI,sBAAwB,CACrCC,YACAC,qBAAsBA,CAACC,EAAUpI,KAAK,CACpC2C,aAAe0F,GACbD,EACEE,IAAgBC,WAAW,CACzBC,UAAW,EACXC,SAAU,OACPJ,EACHK,OAAQ,eATHT,CAaZU,E","file":"static/js/57.9ff765e8.chunk.js","sourcesContent":["import * as React from 'react'\r\nimport { isNil, cloneDeep } from 'lodash'\r\nimport { Form, Input, Spin } from 'antd'\r\nimport { showError, ValidationError } from 'helpers/errors'\r\nimport {\r\n createDropdownRender,\r\n createSearchSuppliers,\r\n createLabelFactory,\r\n createFieldFactory,\r\n createHandleSubmit,\r\n isReadOnly,\r\n} from 'helpers/formViews'\r\nimport { stopEvent } from 'helpers/events'\r\nimport { t } from 'helpers/i18n'\r\nimport Modal from 'elements/Modal'\r\nimport Select, { Option, getOptionProps } from 'elements/Select'\r\nimport SelectProducts from 'containers/Products/Select'\r\nimport InputNumber from 'elements/InputNumber'\r\nimport FormButtons from 'elements/FormButtons'\r\n\r\nclass FormView extends React.Component {\r\n state = {}\r\n\r\n constructor(props) {\r\n super(props)\r\n\r\n this.handleSubmit = createHandleSubmit(this)\r\n this.searchSuppliers = createSearchSuppliers(this)\r\n }\r\n\r\n componentDidMount() {\r\n this.fetchItem()\r\n }\r\n\r\n getItemId = () => [this.state.item?.id, this.props.linkTargetRecord?.supplierDetailId].find(Boolean)\r\n\r\n fetchItem = async ({ itemId = this.getItemId() } = {}) => {\r\n if (isNil(itemId) && !this.props.linkTargetRecord) {\r\n this.setState({ selectProductVisible: true })\r\n } else {\r\n try {\r\n const responses = await Promise.all([\r\n this.props.getItem(itemId).catch((error) => {\r\n this.props.onCancel?.()\r\n throw error\r\n }),\r\n this.props.getSettings({ type: this.props.settingsType ?? 'supplierDetails' }),\r\n ])\r\n\r\n const item = cloneDeep(responses[0].value.data)\r\n\r\n const suppliers = await this.props.getSuppliers(\r\n item.supplierId ? { supplierIds: [item.supplierId] } : undefined\r\n )\r\n\r\n this.setState({\r\n item,\r\n fieldSettings: responses[1].value.data.fieldSettings,\r\n suppliers: suppliers?.value?.data ?? {},\r\n })\r\n } catch (error) {\r\n showError({ error })\r\n }\r\n }\r\n }\r\n\r\n handleSelectProductOk = async () => {\r\n const { selectedProduct } = this.state\r\n\r\n if (selectedProduct) {\r\n const { productId, description: itemDescription, barcode } = selectedProduct\r\n\r\n this.setState({ selectProductVisible: false })\r\n\r\n try {\r\n const responses = await Promise.all([\r\n this.props.newItem({\r\n productId,\r\n itemDescription,\r\n barcode,\r\n price: 0,\r\n description: '',\r\n }),\r\n this.props.getSettings({ type: this.props.settingsType ?? 'supplierDetails' }),\r\n this.props.getSuppliers(),\r\n ])\r\n\r\n this.setState({\r\n item: responses[0].value.data,\r\n fieldSettings: responses[1].value.data.fieldSettings,\r\n suppliers: responses[2].value.data ?? {},\r\n })\r\n } catch (error) {\r\n showError({ error })\r\n }\r\n }\r\n }\r\n\r\n saveItem = async (item) => {\r\n if (!item) {\r\n throw new Error('item is undefined')\r\n }\r\n\r\n const saved = item.id ? await this.props.updateItems([item]) : await this.props.createItem([item])\r\n\r\n return saved\r\n }\r\n\r\n render() {\r\n const { item, fieldSettings, selectedProduct } = this.state\r\n\r\n if (!item || !fieldSettings) {\r\n return (\r\n <>\r\n <Spin />\r\n <Modal\r\n title={t('selectProduct')}\r\n visible={this.state.selectProductVisible}\r\n okText={t('select')}\r\n onOk={this.handleSelectProductOk}\r\n okButtonProps={{ disabled: !selectedProduct }}\r\n onCancel={this.props.onCancel}\r\n width={992}\r\n >\r\n <SelectProducts\r\n onSelect={(values) => this.setState({ selectedProduct: values[0] })}\r\n filterProps={{ privateDatabaseOnly: true }}\r\n />\r\n </Modal>\r\n </>\r\n )\r\n }\r\n\r\n const createLabel = createLabelFactory(fieldSettings)\r\n const createFieldDecorator = createFieldFactory(this.props.form, item, fieldSettings)\r\n const readOnly = isReadOnly(this)\r\n\r\n return (\r\n <Form layout=\"vertical\" colon={false} onSubmit={readOnly ? stopEvent : this.handleSubmit}>\r\n <div className=\"form-items-container\">\r\n <ValidationError errors={this.state.validationErrors} />\r\n <Form.Item label={createLabel('barcode')}>\r\n {createFieldDecorator('barcode')(<Input disabled />)}\r\n </Form.Item>\r\n <Form.Item label={createLabel('itemDescription')}>\r\n {createFieldDecorator('itemDescription')(<Input.TextArea rows={5} disabled />)}\r\n </Form.Item>\r\n <Form.Item label={createLabel('supplierId')}>\r\n {createFieldDecorator('supplierId')(\r\n <Select\r\n dropdownRender={createDropdownRender(this.state.suppliers)}\r\n onSearch={this.searchSuppliers}\r\n readOnly={readOnly}\r\n showSearch\r\n >\r\n {(this.state.suppliers?.items ?? [])\r\n .filter((each) => each.id)\r\n .map((each) => (\r\n <Option key={each.id} value={each.id}>\r\n <span {...getOptionProps(each)}>{each.name}</span>\r\n </Option>\r\n ))}\r\n </Select>\r\n )}\r\n </Form.Item>\r\n <Form.Item label={createLabel('supplierItemNumber')}>\r\n {createFieldDecorator('supplierItemNumber')(<Input />)}\r\n </Form.Item>\r\n <Form.Item label={createLabel('price')}>\r\n {createFieldDecorator('price')(<InputNumber min={0} currency />)}\r\n </Form.Item>\r\n <Form.Item label={createLabel('description')}>\r\n {createFieldDecorator('description')(<Input.TextArea rows={5} />)}\r\n </Form.Item>\r\n </div>\r\n <div className=\"form-buttons-container\">\r\n <FormButtons\r\n readOnly={readOnly}\r\n onCancel={this.props.onCancel}\r\n onSubmit={this.handleSubmit}\r\n saveButtonLoading={this.state.saveButtonLoading}\r\n saveAndCloseButtonLoading={this.state.saveAndCloseButtonLoading}\r\n />\r\n </div>\r\n </Form>\r\n )\r\n }\r\n}\r\n\r\nexport default Form.create()(FormView)\r\n","import actions from 'actions/supplierDetails'\r\nimport supplierActions from 'actions/suppliers'\r\nimport { createFormViewContainer } from 'factories/FormView'\r\nimport Component from 'components/SupplierDetails/FormView'\r\n\r\nexport default createFormViewContainer({\r\n actions,\r\n extraDispatchToProps: (dispatch, props) => ({\r\n getSuppliers: (params) =>\r\n dispatch(\r\n supplierActions.getOptions({\r\n pageIndex: 1,\r\n pageSize: 100,\r\n ...params,\r\n active: 'Active',\r\n })\r\n ),\r\n }),\r\n})(Component)\r\n"],"sourceRoot":""}