|
|
@ -3,8 +3,9 @@ import { Modal, ModalHeader, ModalBody, ModalFooter, Row, Col, Table } from 'rea |
|
|
|
import { Button, Form, FormGroup, Label, Input } from 'reactstrap'; |
|
|
|
import { Button, Form, FormGroup, Label, Input } from 'reactstrap'; |
|
|
|
import 'antd/dist/antd.css'; |
|
|
|
import 'antd/dist/antd.css'; |
|
|
|
import axios from 'axios'; |
|
|
|
import axios from 'axios'; |
|
|
|
import { MENU_COMPANY_SEARCH, MENU_SEARCH } from '../../../const/ApiConst.js'; |
|
|
|
import { MENU_SEARCH } from '../../../const/ApiConst.js'; |
|
|
|
import { withTranslation, WithTranslation } from 'react-i18next'; |
|
|
|
import { withTranslation, WithTranslation } from 'react-i18next'; |
|
|
|
|
|
|
|
const BASE_URL = "http://siopas.co.id/custom-php/api/geohr/"; |
|
|
|
|
|
|
|
|
|
|
|
const token = window.localStorage.getItem('token'); |
|
|
|
const token = window.localStorage.getItem('token'); |
|
|
|
|
|
|
|
|
|
|
@ -51,61 +52,30 @@ class DialogMenuRoles extends Component { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getAllMenu = async () => { |
|
|
|
getAllMenu = async () => { |
|
|
|
const { companyID } = this.props; |
|
|
|
|
|
|
|
const { roleName } = this.props; |
|
|
|
|
|
|
|
if (roleName !== "Super Admin") { |
|
|
|
|
|
|
|
const payload = { |
|
|
|
const payload = { |
|
|
|
"paging": { |
|
|
|
"paging": { "start": 0, "length": -1 }, |
|
|
|
"start": 0, |
|
|
|
"columns": [ |
|
|
|
"length": -1 |
|
|
|
{ "name": "name", "logic_operator": "ilike", "value": "", "operator": "AND" } |
|
|
|
}, |
|
|
|
], |
|
|
|
"columns": [{ |
|
|
|
"joins": [], |
|
|
|
"name": "company_id", |
|
|
|
|
|
|
|
"logic_operator": "=", |
|
|
|
|
|
|
|
"value": companyID, |
|
|
|
|
|
|
|
"operator": "AND" |
|
|
|
|
|
|
|
}], |
|
|
|
|
|
|
|
"joins": [{ |
|
|
|
|
|
|
|
"name": "m_menu", |
|
|
|
|
|
|
|
"column_join": "menu_id", |
|
|
|
|
|
|
|
"column_results": [ |
|
|
|
|
|
|
|
"name" |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}], |
|
|
|
|
|
|
|
"orders": { "columns": ["id"], "ascending": false } |
|
|
|
"orders": { "columns": ["id"], "ascending": false } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const result = await axios |
|
|
|
const result = await axios |
|
|
|
.post(MENU_COMPANY_SEARCH, payload, config) |
|
|
|
.post(MENU_SEARCH, payload, config) |
|
|
|
.then(res => res) |
|
|
|
.then(res => res) |
|
|
|
.catch((error) => error.response); |
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
this.setState({ menu: result.data.data }, () => { |
|
|
|
this.setState({ menu: result.data.data }, () => { |
|
|
|
this.setStateMenu(false); |
|
|
|
this.setStateMenu(false); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
const payload = { |
|
|
|
|
|
|
|
"paging": { |
|
|
|
|
|
|
|
"start": 0, |
|
|
|
|
|
|
|
"length": -1 |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
"columns": [{ |
|
|
|
|
|
|
|
"name": "name", |
|
|
|
|
|
|
|
"logic_operator": "ilike", |
|
|
|
|
|
|
|
"value": "", |
|
|
|
|
|
|
|
"operator": "AND" |
|
|
|
|
|
|
|
}], |
|
|
|
|
|
|
|
"orders": { "columns": ["id"], "ascending": false } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const result = await axios |
|
|
|
|
|
|
|
.post(MENU_SEARCH, payload, config) |
|
|
|
|
|
|
|
.then(res => res) |
|
|
|
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
|
|
|
|
this.setState({ menu: result.data.data }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setStateMenu = edit => { |
|
|
|
setStateMenu = edit => { |
|
|
@ -126,14 +96,13 @@ class DialogMenuRoles extends Component { |
|
|
|
let copyStateMenu = [...this.state.stateMenu]; |
|
|
|
let copyStateMenu = [...this.state.stateMenu]; |
|
|
|
this.props.menuRoles.map((val, indexMenu) => { |
|
|
|
this.props.menuRoles.map((val, indexMenu) => { |
|
|
|
let index = this.getIndexDataMenu(val.menu_id); |
|
|
|
let index = this.getIndexDataMenu(val.menu_id); |
|
|
|
console.log('index true', index); |
|
|
|
console.log("index true", val.menu_id); |
|
|
|
if (index >= 0) { |
|
|
|
if (index >= 0) { |
|
|
|
copyStateMenu[index] = true; |
|
|
|
copyStateMenu[index] = true; |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
this.setState({ stateMenu: [] }, () => { |
|
|
|
this.setState({ stateMenu: [] }, () => { |
|
|
|
let check = copyStateMenu.some(this.checkArray); |
|
|
|
let check = copyStateMenu.some(this.checkArray); |
|
|
|
console.log('icheck', check); |
|
|
|
|
|
|
|
if (check === false) { |
|
|
|
if (check === false) { |
|
|
|
this.setState({ allChecked: true, stateMenu: copyStateMenu }) |
|
|
|
this.setState({ allChecked: true, stateMenu: copyStateMenu }) |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -182,12 +151,11 @@ class DialogMenuRoles extends Component { |
|
|
|
|
|
|
|
|
|
|
|
renderForm = () => { |
|
|
|
renderForm = () => { |
|
|
|
const { menu, stateMenu } = this.state |
|
|
|
const { menu, stateMenu } = this.state |
|
|
|
console.log('stateMenu', stateMenu); |
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
menu.map((val, index) => { |
|
|
|
menu.map((val, index) => { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<tr key={index}> |
|
|
|
<tr key={index}> |
|
|
|
<td>{val.join_first_name ?? val.name}</td> |
|
|
|
<td>{val.name}</td> |
|
|
|
<td><input type="checkbox" onClick={(e) => this.handleChangeCheckbox(e.target.checked, index)} defaultChecked={stateMenu[index]} /></td> |
|
|
|
<td><input type="checkbox" onClick={(e) => this.handleChangeCheckbox(e.target.checked, index)} defaultChecked={stateMenu[index]} /></td> |
|
|
|
</tr> |
|
|
|
</tr> |
|
|
|
) |
|
|
|
) |
|
|
|