Browse Source

feat(project type): add form multi location

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

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

@ -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 (typeDialog === "Save") {
if (role_name === 'Super Admin') {
company_id = selectedCompany
}
if (typeDialog === "Save") {
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,8 +99,17 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
</FormGroup>
</Col>
</Row>
{role_name === 'Super Admin' &&
<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">
@ -116,8 +133,9 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
</Select>
</FormGroup>
</Col>
</Row>
)
}
</Row>
</Form>
)
}

Loading…
Cancel
Save