Browse Source

add select company by super admin

pull/1/head
farhantock 11 months ago
parent
commit
0aecd61415
  1. 110
      src/views/Master/MasterBroadcast/DialogForm.js
  2. 48
      src/views/Master/ProjectPhase/DialogForm.js
  3. 56
      src/views/SimproV2/ChecklistK3/DialogForm.js
  4. 47
      src/views/SimproV2/Divisi/DialogForm.js
  5. 58
      src/views/SimproV2/ProjectType/DialogForm.js
  6. 60
      src/views/SimproV2/Satuan/DialogForm.js

110
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 (
<Form>
{this.props.role_name === 'Super Admin' && (
<FormGroup>
<Label>{this.props.t('company')}</Label>
<Select
options={this.props.listCompany.map(company => ({ value: company.id, label: company.company_name }))}
onChange={this.handleSelectCompany}
value={this.state.company_id}
/>
</FormGroup>
)}
<FormGroup>
<Label>{this.props.t('receiver')}</Label>
<Input type="select" value={this.state.penerima} onChange={(e) => this.handleChangePenerima(e.target.value)}>
@ -395,7 +403,7 @@ class DialogForm extends Component {
<Label>{this.props.t('broadcastDescription')}</Label>
<Input style={{ minHeight: "100px" }} type="textarea" value={this.state.description} onChange={(e) => this.setState({ description: e.target.value })} placeholder={this.props.t('inputDescription')} />
</FormGroup>
</Form>
</Form >
)
}
handleCloseDialog = () => {

48
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 (
<Form>
@ -69,6 +82,33 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
</FormGroup>
</Col>
</Row>
{role_name === 'Super Admin' &&
<Row>
<Col md={6}>
<FormGroup>
<Label className="capitalize">
{t('company')}<span style={{ color: "red" }}>*</span>
</Label>
<Select
showSearch
filterOption={(inputValue, option) =>
option.children.toLowerCase().includes(inputValue.toLowerCase())
}
value={selectedCompany}
defaultValue={selectedCompany}
onChange={onChangeCompany}
style={{ width: "100%" }}
>
{listCompany.map((res) => (
<Option key={res.id} value={res.id}>
{res.company_name}
</Option>
))}
</Select>
</FormGroup>
</Col>
</Row>
}
</Form>
)
}

56
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 (
<Form>
@ -75,6 +88,33 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
</FormGroup>
</Col>
</Row>
{role_name === 'Super Admin' &&
<Row>
<Col md={6}>
<FormGroup>
<Label className="capitalize">
{t('company')}<span style={{ color: "red" }}>*</span>
</Label>
<Select
showSearch
filterOption={(inputValue, option) =>
option.children.toLowerCase().includes(inputValue.toLowerCase())
}
value={selectedCompany}
defaultValue={selectedCompany}
onChange={onChangeCompany}
style={{ width: "100%" }}
>
{listCompany.map((res) => (
<Option key={res.id} value={res.id}>
{res.company_name}
</Option>
))}
</Select>
</FormGroup>
</Col>
</Row>
}
</Form>
)
}

47
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 (
<Form>
@ -133,6 +147,33 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
</FormGroup>
</Col>
</Row>
{role_name === 'Super Admin' &&
<Row>
<Col md={6}>
<FormGroup>
<Label className="capitalize">
{t('company')}<span style={{ color: "red" }}>*</span>
</Label>
<Select
showSearch
filterOption={(inputValue, option) =>
option.children.toLowerCase().includes(inputValue.toLowerCase())
}
value={selectedCompany}
defaultValue={selectedCompany}
onChange={onChangeCompany}
style={{ width: "100%" }}
>
{listCompany.map((res) => (
<Option key={res.id} value={res.id}>
{res.company_name}
</Option>
))}
</Select>
</FormGroup>
</Col>
</Row>
}
</Form>
)
}

58
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
</FormGroup>
</Col>
</Row>
{role_name === 'Super Admin' &&
<Row>
<Col md={6}>
<FormGroup>
<Label className="capitalize">
{t('company')}<span style={{ color: "red" }}>*</span>
</Label>
<Select
showSearch
filterOption={(inputValue, option) =>
option.children.toLowerCase().includes(inputValue.toLowerCase())
}
value={selectedCompany}
defaultValue={selectedCompany}
onChange={onChangeCompany}
style={{ width: "100%" }}
>
{listCompany.map((res) => (
<Option key={res.id} value={res.id}>
{res.company_name}
</Option>
))}
</Select>
</FormGroup>
</Col>
</Row>
}
</Form>
)
}

60
src/views/SimproV2/Satuan/DialogForm.js

@ -3,15 +3,16 @@ import {
Modal, ModalHeader, ModalBody, ModalFooter,
Button, Form, FormGroup, Label, Input, Col, Row
} from 'reactstrap';
import { Select } from 'antd';
import 'antd/dist/antd.css';
import { useTranslation } from 'react-i18next';
const { Option } = Select;
const company_id = 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 [name, setName] = useState('')
const [description, setDescription] = useState('')
const [selectedCompany, setSelectedCompany] = useState(null)
const { t } = useTranslation()
@ -20,7 +21,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
setId(dataEdit.id)
setDescription(dataEdit.description)
setName(dataEdit.name)
setSelectedCompany(dataEdit.company_id);
} else {
setId(0)
}
@ -29,34 +30,46 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
const handleSave = () => {
let data = '';
if (typeDialog === "Save") {
if (role_name === 'Super Admin') {
company_id = selectedCompany
}
data = {
name: name,
description,
company_id
description: description,
company_id: 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);
}
setId(0)
setDescription('')
setSelectedCompany(null)
}
const handleCancel = () => {
closeDialog('cancel', 'none')
setId(0)
setDescription('')
setSelectedCompany(null)
}
const onChangeCompany = (val) => {
setSelectedCompany(val);
};
const renderForm = () => {
return (
<Form>
@ -74,6 +87,33 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
</FormGroup>
</Col>
</Row>
{role_name === 'Super Admin' &&
<Row>
<Col md={6}>
<FormGroup>
<Label className="capitalize">
{t('company')}<span style={{ color: "red" }}>*</span>
</Label>
<Select
showSearch
filterOption={(inputValue, option) =>
option.children.toLowerCase().includes(inputValue.toLowerCase())
}
value={selectedCompany}
defaultValue={selectedCompany}
onChange={onChangeCompany}
style={{ width: "100%" }}
>
{listCompany.map((res) => (
<Option key={res.id} value={res.id}>
{res.company_name}
</Option>
))}
</Select>
</FormGroup>
</Col>
</Row>
}
</Form>
)
}

Loading…
Cancel
Save