|
|
@ -1,7 +1,7 @@ |
|
|
|
import React, { useEffect, useState } from 'react' |
|
|
|
import React, { useEffect, useState } from 'react' |
|
|
|
import { |
|
|
|
import { |
|
|
|
Modal, ModalHeader, ModalBody, ModalFooter, |
|
|
|
Modal, ModalHeader, ModalBody, ModalFooter, |
|
|
|
Button, Form, FormGroup, Label, Input, Col, Row |
|
|
|
Button, Form, FormGroup, Label, Input, Col, Row, CustomInput |
|
|
|
} from 'reactstrap'; |
|
|
|
} from 'reactstrap'; |
|
|
|
import { Select } from 'antd'; |
|
|
|
import { Select } from 'antd'; |
|
|
|
import moment from 'moment'; |
|
|
|
import moment from 'moment'; |
|
|
@ -16,9 +16,12 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi |
|
|
|
const [description, setDescription] = useState('') |
|
|
|
const [description, setDescription] = useState('') |
|
|
|
const [unitPrice, setUnitPrice] = useState() |
|
|
|
const [unitPrice, setUnitPrice] = useState() |
|
|
|
const [selectedCompany, setSelectedCompany] = useState(null) |
|
|
|
const [selectedCompany, setSelectedCompany] = useState(null) |
|
|
|
|
|
|
|
const [isMultiLocation, setIsMultiLocation] = useState(false); |
|
|
|
const { t } = useTranslation(); |
|
|
|
const { t } = useTranslation(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleIsMultiLocationChange = () => { |
|
|
|
|
|
|
|
setIsMultiLocation(!isMultiLocation); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (typeDialog === "Edit") { |
|
|
|
if (typeDialog === "Edit") { |
|
|
@ -28,46 +31,51 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi |
|
|
|
setUom(dataEdit.uom) |
|
|
|
setUom(dataEdit.uom) |
|
|
|
setProjectType(dataEdit.name) |
|
|
|
setProjectType(dataEdit.name) |
|
|
|
setSelectedCompany(dataEdit.company_id) |
|
|
|
setSelectedCompany(dataEdit.company_id) |
|
|
|
|
|
|
|
setIsMultiLocation(dataEdit.is_multiLocation) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
setId(0) |
|
|
|
handleClear() |
|
|
|
} |
|
|
|
} |
|
|
|
}, [dataEdit, openDialog]) |
|
|
|
}, [dataEdit, openDialog]) |
|
|
|
|
|
|
|
|
|
|
|
const handleSave = () => { |
|
|
|
const handleSave = () => { |
|
|
|
let data = ''; |
|
|
|
let data = ''; |
|
|
|
if (typeDialog === "Save") { |
|
|
|
|
|
|
|
if (role_name === 'Super Admin') { |
|
|
|
if (role_name === 'Super Admin') { |
|
|
|
company_id = selectedCompany |
|
|
|
company_id = selectedCompany |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (typeDialog === "Save") { |
|
|
|
data = { |
|
|
|
data = { |
|
|
|
name: projectType, |
|
|
|
name: projectType, |
|
|
|
description, |
|
|
|
description, |
|
|
|
company_id: company_id |
|
|
|
company_id: parseInt(company_id), |
|
|
|
|
|
|
|
is_multiLocation: isMultiLocation |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
closeDialog('save', data); |
|
|
|
closeDialog('save', data); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (role_name === 'Super Admin') { |
|
|
|
|
|
|
|
company_id = selectedCompany |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
data = { |
|
|
|
data = { |
|
|
|
id, |
|
|
|
id, |
|
|
|
name: projectType, |
|
|
|
name: projectType, |
|
|
|
description, |
|
|
|
description, |
|
|
|
company_id: company_id |
|
|
|
company_id: parseInt(company_id), |
|
|
|
|
|
|
|
is_multiLocation: isMultiLocation |
|
|
|
} |
|
|
|
} |
|
|
|
closeDialog('edit', data); |
|
|
|
closeDialog('edit', data); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
handleClear(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleClear = () => { |
|
|
|
setId(0) |
|
|
|
setId(0) |
|
|
|
|
|
|
|
setProjectType('') |
|
|
|
setDescription('') |
|
|
|
setDescription('') |
|
|
|
setSelectedCompany(null) |
|
|
|
setSelectedCompany(null) |
|
|
|
|
|
|
|
setIsMultiLocation(false) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const handleCancel = () => { |
|
|
|
const handleCancel = () => { |
|
|
|
closeDialog('cancel', 'none') |
|
|
|
closeDialog('cancel', 'none'); |
|
|
|
setId(0) |
|
|
|
handleClear(); |
|
|
|
setDescription('') |
|
|
|
|
|
|
|
setSelectedCompany(null) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const onChangeCompany = (val) => { |
|
|
|
const onChangeCompany = (val) => { |
|
|
@ -91,8 +99,17 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi |
|
|
|
</FormGroup> |
|
|
|
</FormGroup> |
|
|
|
</Col> |
|
|
|
</Col> |
|
|
|
</Row> |
|
|
|
</Row> |
|
|
|
{role_name === 'Super Admin' && |
|
|
|
|
|
|
|
<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}> |
|
|
|
<Col md={6}> |
|
|
|
<FormGroup> |
|
|
|
<FormGroup> |
|
|
|
<Label className="capitalize"> |
|
|
|
<Label className="capitalize"> |
|
|
@ -116,8 +133,9 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi |
|
|
|
</Select> |
|
|
|
</Select> |
|
|
|
</FormGroup> |
|
|
|
</FormGroup> |
|
|
|
</Col> |
|
|
|
</Col> |
|
|
|
</Row> |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
</Row> |
|
|
|
</Form> |
|
|
|
</Form> |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|