diff --git a/src/views/SimproV2/ProjectType/DialogForm.js b/src/views/SimproV2/ProjectType/DialogForm.js index 6619f40..0238082 100644 --- a/src/views/SimproV2/ProjectType/DialogForm.js +++ b/src/views/SimproV2/ProjectType/DialogForm.js @@ -1,154 +1,172 @@ -import React, { useEffect, useState } from 'react' -import { - Modal, ModalHeader, ModalBody, ModalFooter, - Button, Form, FormGroup, Label, Input, Col, Row -} from 'reactstrap'; -import { Select } from 'antd'; -import moment from 'moment'; -import 'antd/dist/antd.css'; -import { useTranslation } from 'react-i18next'; -const { Option } = Select - -const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit, company_id, listCompany, role_name }) => { - const [id, setId] = useState(0) - const [projectType, setProjectType] = useState('') - const [uom, setUom] = useState('') - const [description, setDescription] = useState('') - const [unitPrice, setUnitPrice] = useState() - const [selectedCompany, setSelectedCompany] = useState(null) - const { t } = useTranslation(); - - - - useEffect(() => { - if (typeDialog === "Edit") { - setId(dataEdit.id) - setDescription(dataEdit.description) - setUnitPrice(dataEdit.unit_price) - setUom(dataEdit.uom) - setProjectType(dataEdit.name) - setSelectedCompany(dataEdit.company_id) - } else { - setId(0) - } - }, [dataEdit, openDialog]) - - const handleSave = () => { - let data = ''; - if (typeDialog === "Save") { - if (role_name === 'Super Admin') { - company_id = selectedCompany - } - data = { - name: projectType, - description, - company_id: company_id - } - - closeDialog('save', data); - } else { - if (role_name === 'Super Admin') { - company_id = selectedCompany - } - data = { - id, - name: projectType, - description, - company_id: company_id - } - closeDialog('edit', data); - } - setId(0) - setDescription('') - setSelectedCompany(null) - } - - const handleCancel = () => { - closeDialog('cancel', 'none') - setId(0) - setDescription('') - setSelectedCompany(null) - } - - const onChangeCompany = (val) => { - setSelectedCompany(val); - }; - - const renderForm = () => { - return ( -
- - - - - setProjectType(e.target.value)} placeholder={t('inputName')} /> - - - - - - setDescription(e.target.value)} placeholder={t('inputDescription')} /> - - - - {role_name === 'Super Admin' && - - - - - - - - - } -
- ) - } - - - return ( - <> - - {typeDialog == "Save" ? `Add` : "Edit"} Resource - - {renderForm()} - - - {' '} - - - - - {/* toggleMapDialog} - dataEdit={dataEdit} - workArea_={workArea} - lat_={lat} - lon_={lon} - radius_={radius} - /> */} - - ) - -} - -export default DialogForm; \ No newline at end of file +import React, { useEffect, useState } from 'react' +import { + Modal, ModalHeader, ModalBody, ModalFooter, + Button, Form, FormGroup, Label, Input, Col, Row, CustomInput +} from 'reactstrap'; +import { Select } from 'antd'; +import moment from 'moment'; +import 'antd/dist/antd.css'; +import { useTranslation } from 'react-i18next'; +const { Option } = Select + +const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit, company_id, listCompany, role_name }) => { + const [id, setId] = useState(0) + const [projectType, setProjectType] = useState('') + const [uom, setUom] = useState('') + 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") { + setId(dataEdit.id) + setDescription(dataEdit.description) + setUnitPrice(dataEdit.unit_price) + setUom(dataEdit.uom) + setProjectType(dataEdit.name) + setSelectedCompany(dataEdit.company_id) + setIsMultiLocation(dataEdit.is_multiLocation) + } else { + handleClear() + } + }, [dataEdit, openDialog]) + + const handleSave = () => { + let data = ''; + if (role_name === 'Super Admin') { + company_id = selectedCompany + } + if (typeDialog === "Save") { + data = { + name: projectType, + description, + company_id: parseInt(company_id), + is_multiLocation: isMultiLocation + } + + closeDialog('save', data); + } else { + data = { + id, + name: projectType, + description, + 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'); + handleClear(); + } + + const onChangeCompany = (val) => { + setSelectedCompany(val); + }; + + const renderForm = () => { + return ( +
+ + + + + setProjectType(e.target.value)} placeholder={t('inputName')} /> + + + + + + setDescription(e.target.value)} placeholder={t('inputDescription')} /> + + + + + + + +
+ +
+
+ + { + role_name === 'Super Admin' && ( + + + + + + + ) + } +
+
+ ) + } + + + return ( + <> + + {typeDialog == "Save" ? `Add` : "Edit"} Resource + + {renderForm()} + + + {' '} + + + + + {/* toggleMapDialog} + dataEdit={dataEdit} + workArea_={workArea} + lat_={lat} + lon_={lon} + radius_={radius} + /> */} + + ) + +} + +export default DialogForm;