|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
import React, { useEffect, useState } from 'react' |
|
|
|
|
import { |
|
|
|
|
Modal, ModalHeader, ModalBody, ModalFooter, |
|
|
|
|
Button, Form, FormGroup, Label, Input, Col, Row |
|
|
|
|
Button, Form, FormGroup, Label, Input, Col, Row, CustomInput |
|
|
|
|
} from 'reactstrap'; |
|
|
|
|
import { Select } from 'antd'; |
|
|
|
|
import moment from 'moment'; |
|
|
|
@ -16,9 +16,12 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
|
|
|
|
|
const [description, setDescription] = useState('') |
|
|
|
|
const [unitPrice, setUnitPrice] = useState() |
|
|
|
|
const [selectedCompany, setSelectedCompany] = useState(null) |
|
|
|
|
const [isMultiLocation, setIsMultiLocation] = useState(false); |
|
|
|
|
const { t } = useTranslation(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleIsMultiLocationChange = () => { |
|
|
|
|
setIsMultiLocation(!isMultiLocation); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (typeDialog === "Edit") { |
|
|
|
@ -28,46 +31,51 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
|
|
|
|
|
setUom(dataEdit.uom) |
|
|
|
|
setProjectType(dataEdit.name) |
|
|
|
|
setSelectedCompany(dataEdit.company_id) |
|
|
|
|
setIsMultiLocation(dataEdit.is_multiLocation) |
|
|
|
|
} else { |
|
|
|
|
setId(0) |
|
|
|
|
handleClear() |
|
|
|
|
} |
|
|
|
|
}, [dataEdit, openDialog]) |
|
|
|
|
|
|
|
|
|
const handleSave = () => { |
|
|
|
|
let data = ''; |
|
|
|
|
if (role_name === 'Super Admin') { |
|
|
|
|
company_id = selectedCompany |
|
|
|
|
} |
|
|
|
|
if (typeDialog === "Save") { |
|
|
|
|
if (role_name === 'Super Admin') { |
|
|
|
|
company_id = selectedCompany |
|
|
|
|
} |
|
|
|
|
data = { |
|
|
|
|
name: projectType, |
|
|
|
|
description, |
|
|
|
|
company_id: company_id |
|
|
|
|
company_id: parseInt(company_id), |
|
|
|
|
is_multiLocation: isMultiLocation |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
closeDialog('save', data); |
|
|
|
|
} else { |
|
|
|
|
if (role_name === 'Super Admin') { |
|
|
|
|
company_id = selectedCompany |
|
|
|
|
} |
|
|
|
|
data = { |
|
|
|
|
id, |
|
|
|
|
name: projectType, |
|
|
|
|
description, |
|
|
|
|
company_id: company_id |
|
|
|
|
company_id: parseInt(company_id), |
|
|
|
|
is_multiLocation: isMultiLocation |
|
|
|
|
} |
|
|
|
|
closeDialog('edit', data); |
|
|
|
|
} |
|
|
|
|
handleClear(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleClear = () => { |
|
|
|
|
setId(0) |
|
|
|
|
setProjectType('') |
|
|
|
|
setDescription('') |
|
|
|
|
setSelectedCompany(null) |
|
|
|
|
setIsMultiLocation(false) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleCancel = () => { |
|
|
|
|
closeDialog('cancel', 'none') |
|
|
|
|
setId(0) |
|
|
|
|
setDescription('') |
|
|
|
|
setSelectedCompany(null) |
|
|
|
|
closeDialog('cancel', 'none'); |
|
|
|
|
handleClear(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const onChangeCompany = (val) => { |
|
|
|
@ -91,33 +99,43 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
|
|
|
|
|
</FormGroup> |
|
|
|
|
</Col> |
|
|
|
|
</Row> |
|
|
|
|
{role_name === 'Super Admin' && |
|
|
|
|
<Row> |
|
|
|
|
<Col md={6}> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize"> |
|
|
|
|
{t('company')}<span style={{ color: "red" }}>*</span> |
|
|
|
|
</Label> |
|
|
|
|
<Select |
|
|
|
|
showSearch |
|
|
|
|
filterOption={(inputValue, option) => |
|
|
|
|
option.children.toLowerCase().includes(inputValue.toLowerCase()) |
|
|
|
|
} |
|
|
|
|
value={selectedCompany} |
|
|
|
|
defaultValue={selectedCompany} |
|
|
|
|
onChange={onChangeCompany} |
|
|
|
|
style={{ width: "100%" }} |
|
|
|
|
> |
|
|
|
|
{listCompany.map((res) => ( |
|
|
|
|
<Option key={res.id} value={res.id}> |
|
|
|
|
{res.company_name} |
|
|
|
|
</Option> |
|
|
|
|
))} |
|
|
|
|
</Select> |
|
|
|
|
</FormGroup> |
|
|
|
|
</Col> |
|
|
|
|
</Row> |
|
|
|
|
} |
|
|
|
|
<Row> |
|
|
|
|
<Col md={6}> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize">Is Multi Location</Label> |
|
|
|
|
<div> |
|
|
|
|
<CustomInput type="switch" id="isMultiLocationSwitch" name="isMultiLocationSwitch" checked={isMultiLocation} onChange={handleIsMultiLocationChange} /> |
|
|
|
|
</div> |
|
|
|
|
</FormGroup> |
|
|
|
|
</Col> |
|
|
|
|
{ |
|
|
|
|
role_name === 'Super Admin' && ( |
|
|
|
|
<Col md={6}> |
|
|
|
|
<FormGroup> |
|
|
|
|
<Label className="capitalize"> |
|
|
|
|
{t('company')}<span style={{ color: "red" }}>*</span> |
|
|
|
|
</Label> |
|
|
|
|
<Select |
|
|
|
|
showSearch |
|
|
|
|
filterOption={(inputValue, option) => |
|
|
|
|
option.children.toLowerCase().includes(inputValue.toLowerCase()) |
|
|
|
|
} |
|
|
|
|
value={selectedCompany} |
|
|
|
|
defaultValue={selectedCompany} |
|
|
|
|
onChange={onChangeCompany} |
|
|
|
|
style={{ width: "100%" }} |
|
|
|
|
> |
|
|
|
|
{listCompany.map((res) => ( |
|
|
|
|
<Option key={res.id} value={res.id}> |
|
|
|
|
{res.company_name} |
|
|
|
|
</Option> |
|
|
|
|
))} |
|
|
|
|
</Select> |
|
|
|
|
</FormGroup> |
|
|
|
|
</Col> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
</Row> |
|
|
|
|
</Form> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|