diff --git a/src/views/Master/MasterBroadcast/DialogForm.js b/src/views/Master/MasterBroadcast/DialogForm.js index 7ce2d67..6f264dd 100644 --- a/src/views/Master/MasterBroadcast/DialogForm.js +++ b/src/views/Master/MasterBroadcast/DialogForm.js @@ -3,7 +3,7 @@ import React, { Component } from 'react'; import { Button, Form, FormFeedback, FormGroup, Input, Label, Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap'; import Select from 'react-select'; import axios from 'axios'; -import { BASE_URL_GEOHR_API2, ROLE_SEARCH, USER_WASPANG, USER_LIST } from '../../../const/ApiConst'; +import { BASE_URL_GEOHR_API2, ROLE_SEARCH, USER_WASPANG, USER_LIST, USER_SEARCH } from '../../../const/ApiConst'; import { Transfer } from 'antd'; import { withTranslation } from 'react-i18next'; @@ -51,13 +51,18 @@ class DialogForm extends Component { allEmployeeId: [], idEmployeeDivision: [], idOrganization: [], - disableTransfer: true + disableTransfer: true, + listCompany: [], + company_id: this.props.company_id, + role_name: '' } } async componentDidMount() { - this.getDataUsers(); - this.getDataRole(); + if (this.props.company_id !== null) { + this.getDataRole(); + this.getDataUsers(); + } this.props.showDialog(this.showDialog); } @@ -69,14 +74,16 @@ class DialogForm extends Component { id: dataEdit.id, title: dataEdit.title_notif, description: dataEdit.description, - message: dataEdit.message_notif + message: dataEdit.message_notif, + company_id: dataEdit.company_id }) } else { this.setState({ id: 0, title: "", description: "", - message: "" + message: "", + company_id: 0 }) } this.setState({ isParentClick: false }); @@ -128,9 +135,12 @@ class DialogForm extends Component { title, description, message, - penerima - } = this.state + penerima, + } = this.state + let { + company_id + } = this.state let idSend = []; let send_to_type = "all"; if (penerima === "all") { @@ -151,15 +161,17 @@ class DialogForm extends Component { } else { idSend = idSend; } - + if (this.props.role_name !== 'Super Admin') { + company_id = parseInt(this.props.company_id) + } const data = { title, description, message, send_to_type, - id: idSend + id: idSend, + company_id: company_id } - if (param === 'registered' || param === 'send') { this.props.handleSaveBroadcast(param, data) } @@ -201,7 +213,18 @@ class DialogForm extends Component { getDataRole = async () => { const payload = { - + "paging": { + "start": 0, + "length": -1 + }, + "columns": [ + { + "name": "company_id", + "logic_operator": "=", + "value": this.state.company_id, + "operator": "AND" + } + ], "orders": { "columns": ["id"], "ascending": false } } @@ -231,20 +254,11 @@ class DialogForm extends Component { } getDataUsers = async () => { - - const payload = { "paging": { "start": 0, - "length": 10 + "length": -1 }, - "filter_columns": [ - { - "name": "name", - "value": "", - "table_name": "m_users" - } - ], "columns": [ { "name": "name", @@ -254,34 +268,10 @@ class DialogForm extends Component { "table_name": "m_users" }, { - "name": "id", + "name": "company_id", "logic_operator": "=", - "value": "3", - "operator": "AND", - "table_name": "m_roles" - } - ], - "joins": [ - { - "name": "m_users", - "column_join": "user_id", - "column_results": [ - "username", - "name", - "email", - "gender", - "phone_number", - "address", - "birth_place", - "birth_date" - ] - }, - { - "name": "m_roles", - "column_join": "role_id", - "column_results": [ - "name" - ] + "value": this.state.company_id, + "operator": "AND" } ], "orders": { @@ -293,7 +283,7 @@ class DialogForm extends Component { } //TODO should use search instead const result = await axios - .get(USER_LIST, config) + .post(USER_SEARCH, payload, config) .then(res => res) .catch((error) => error.response); @@ -330,11 +320,29 @@ class DialogForm extends Component { }; + handleSelectCompany = (selectedOption) => { + const selectedCompanyId = selectedOption.value; + this.setState({ company_id: selectedCompanyId }, () => { + this.getDataRole(); + this.getDataUsers(); + }); + } + renderForm = () => { const t = this.props const { errorTitle, errorMessage } = this.state return (
+ ) } handleCloseDialog = () => { diff --git a/src/views/Master/ProjectPhase/DialogForm.js b/src/views/Master/ProjectPhase/DialogForm.js index db5b010..05d02be 100644 --- a/src/views/Master/ProjectPhase/DialogForm.js +++ b/src/views/Master/ProjectPhase/DialogForm.js @@ -8,17 +8,20 @@ import InputColor from "./InputColor"; import "./styles.css"; import "rc-color-picker/assets/index.css"; import { useTranslation } from 'react-i18next'; -const company_id = localStorage.getItem("company_id") -const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit }) => { +import { Select } from 'antd'; +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 [color, setColor] = useState('') + const [selectedCompany, setSelectedCompany] = useState(null) const { t } = useTranslation(); useEffect(() => { if (typeDialog === "Edit") { setId(dataEdit.id) setProjectType(dataEdit.name) setColor(dataEdit.color) + setSelectedCompany(dataEdit.company_id) } else { setId(0) setColor('') @@ -29,18 +32,24 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi const handleSave = () => { let data = ''; if (typeDialog === "Save") { + if (role_name === 'Super Admin') { + company_id = selectedCompany + } data = { name: projectType, color, - company_id + company_id: company_id } closeDialog('save', data); } else { + if (role_name === 'Super Admin') { + company_id = selectedCompany + } data = { id, name: projectType, color, - company_id + company_id: company_id } closeDialog('edit', data); } @@ -52,6 +61,10 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi setId(0) } + const onChangeCompany = (val) => { + setSelectedCompany(val); + }; + const renderForm = () => { return ( ) } diff --git a/src/views/SimproV2/ChecklistK3/DialogForm.js b/src/views/SimproV2/ChecklistK3/DialogForm.js index 459638c..07a4ab2 100644 --- a/src/views/SimproV2/ChecklistK3/DialogForm.js +++ b/src/views/SimproV2/ChecklistK3/DialogForm.js @@ -5,20 +5,22 @@ import { } from 'reactstrap'; import 'antd/dist/antd.css'; import { useTranslation } from 'react-i18next'; +import { Select } from 'antd'; +const { Option } = Select; - -const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit, company_id }) => { +const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit, company_id, listCompany, role_name }) => { const [id, setId] = useState(0) const [name, setName] = useState('') const [description, setDescription] = useState('') + const [selectedCompany, setSelectedCompany] = useState(null) const { t } = useTranslation() - useEffect(() => { if (typeDialog === "Edit") { setId(dataEdit.id) setDescription(dataEdit.description) setName(dataEdit.name) + setSelectedCompany(dataEdit.company_id); } else { handleClearData() @@ -27,20 +29,26 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi const handleSave = () => { let data = ''; + if (role_name === 'Super Admin') { + company_id = selectedCompany + } + if (typeDialog === "Save") { data = { name: name, - description, - company_id + description: description, + company_id: parseInt(company_id), } - closeDialog('save', data); } else { + if (role_name === 'Super Admin') { + company_id = selectedCompany + } data = { id, name: name, - description, - company_id + description: description, + company_id: company_id, } closeDialog('edit', data); } @@ -56,8 +64,13 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi setId(0) setName('') setDescription('') + setSelectedCompany(null) } + const onChangeCompany = (val) => { + setSelectedCompany(val); + }; + const renderForm = () => { return ( ) } diff --git a/src/views/SimproV2/Divisi/DialogForm.js b/src/views/SimproV2/Divisi/DialogForm.js index ee43a37..3c59e8a 100644 --- a/src/views/SimproV2/Divisi/DialogForm.js +++ b/src/views/SimproV2/Divisi/DialogForm.js @@ -10,12 +10,13 @@ import InputColor from "./InputColor"; import "./styles.css"; import "rc-color-picker/assets/index.css"; const { Option } = Select -const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit, dataDivisions, company_id }) => { +const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit, dataDivisions, company_id, role_name, listCompany }) => { const [id, setId] = useState(0) const [name, setName] = useState('') const [parent, setParent] = useState(null) const [description, setDescription] = useState('') const [color, setColor] = useState('') + const [selectedCompany, setSelectedCompany] = useState(null) const { t } = useTranslation() const onChangeParent = (val) => { @@ -29,6 +30,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi setName(dataEdit.name) setParent(dataEdit.parent) setColor(dataEdit.color) + setSelectedCompany(dataEdit.company_id); } else { setId(0) setColor('') @@ -47,22 +49,28 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi if (!err) { if (typeDialog === "Save") { + if (role_name === 'Super Admin') { + company_id = selectedCompany + } data = { name, description, parent, color, - company_id + company_id: company_id } closeDialog('save', data); } else { + if (role_name === 'Super Admin') { + company_id = selectedCompany + } data = { id, name, description, parent, color, - company_id + company_id: company_id } closeDialog('edit', data); } @@ -71,6 +79,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi setName('') setParent(null) setColor('') + setSelectedCompany(null) } } const handleCancel = () => { @@ -79,8 +88,13 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi setDescription('') setName('') setParent(null) + setSelectedCompany(null) } + const onChangeCompany = (val) => { + setSelectedCompany(val); + }; + const renderForm = () => { return ( ) } diff --git a/src/views/SimproV2/ProjectType/DialogForm.js b/src/views/SimproV2/ProjectType/DialogForm.js index afe4058..6619f40 100644 --- a/src/views/SimproV2/ProjectType/DialogForm.js +++ b/src/views/SimproV2/ProjectType/DialogForm.js @@ -3,20 +3,19 @@ import { Modal, ModalHeader, ModalBody, ModalFooter, Button, Form, FormGroup, Label, Input, Col, Row } from 'reactstrap'; -import { DatePicker, Tooltip, Select } from 'antd'; -import { formatRupiah, formatNumber } from '../../../const/CustomFunc' +import { Select } from 'antd'; import moment from 'moment'; import 'antd/dist/antd.css'; import { useTranslation } from 'react-i18next'; const { Option } = Select -const company_id = window.localStorage.getItem('company_id'); -const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit }) => { +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(); @@ -28,7 +27,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi setUnitPrice(dataEdit.unit_price) setUom(dataEdit.uom) setProjectType(dataEdit.name) - + setSelectedCompany(dataEdit.company_id) } else { setId(0) } @@ -37,39 +36,43 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi const handleSave = () => { let data = ''; if (typeDialog === "Save") { + if (role_name === 'Super Admin') { + company_id = selectedCompany + } data = { name: projectType, description, - company_id + 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: 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 ( @@ -88,6 +91,33 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi + {role_name === 'Super Admin' && +