Browse Source

feat(project type): add form multi location

pull/1/head
Watiah11 6 months ago
parent
commit
a2d7c837cc
  1. 102
      src/views/SimproV2/ProjectType/DialogForm.js

102
src/views/SimproV2/ProjectType/DialogForm.js

@ -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 (role_name === 'Super Admin') {
company_id = selectedCompany
}
if (typeDialog === "Save") { if (typeDialog === "Save") {
if (role_name === 'Super Admin') {
company_id = selectedCompany
}
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,33 +99,43 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
</FormGroup> </FormGroup>
</Col> </Col>
</Row> </Row>
{role_name === 'Super Admin' && <Row>
<Row> <Col md={6}>
<Col md={6}> <FormGroup>
<FormGroup> <Label className="capitalize">Is Multi Location</Label>
<Label className="capitalize"> <div>
{t('company')}<span style={{ color: "red" }}>*</span> <CustomInput type="switch" id="isMultiLocationSwitch" name="isMultiLocationSwitch" checked={isMultiLocation} onChange={handleIsMultiLocationChange} />
</Label> </div>
<Select </FormGroup>
showSearch </Col>
filterOption={(inputValue, option) => {
option.children.toLowerCase().includes(inputValue.toLowerCase()) role_name === 'Super Admin' && (
} <Col md={6}>
value={selectedCompany} <FormGroup>
defaultValue={selectedCompany} <Label className="capitalize">
onChange={onChangeCompany} {t('company')}<span style={{ color: "red" }}>*</span>
style={{ width: "100%" }} </Label>
> <Select
{listCompany.map((res) => ( showSearch
<Option key={res.id} value={res.id}> filterOption={(inputValue, option) =>
{res.company_name} option.children.toLowerCase().includes(inputValue.toLowerCase())
</Option> }
))} value={selectedCompany}
</Select> defaultValue={selectedCompany}
</FormGroup> onChange={onChangeCompany}
</Col> style={{ width: "100%" }}
</Row> >
} {listCompany.map((res) => (
<Option key={res.id} value={res.id}>
{res.company_name}
</Option>
))}
</Select>
</FormGroup>
</Col>
)
}
</Row>
</Form> </Form>
) )
} }

Loading…
Cancel
Save