Browse Source

fix: fixed role menu

pull/1/head
Watiah11 8 months ago
parent
commit
cf01b2be23
  1. 28
      src/views/Master/MasterRoles/DialogMenuRoles.js
  2. 121
      src/views/Master/MasterRoles/index.js

28
src/views/Master/MasterRoles/DialogMenuRoles.js

@ -1,6 +1,6 @@
import React, { Component } from 'react'
import { Modal, ModalHeader, ModalBody, ModalFooter, Row, Col, Table } from 'reactstrap';
import { Button, Form, FormGroup, Label, Input } from 'reactstrap';
import { Modal, ModalHeader, ModalBody, ModalFooter, Table } from 'reactstrap';
import { Button, Form } from 'reactstrap';
import 'antd/dist/antd.css';
import axios from 'axios';
import { MENU_COMPANY_SEARCH } from '../../../const/ApiConst.js';
@ -34,13 +34,11 @@ export default class DialogMenuRoles extends Component {
stateUpdateAll: false,
stateDeleteAll: false,
allChecked: true,
company_id: props.company_id || null,
}
}
async componentDidMount() {
this.props.showDialog(this.showDialog);
this.getAllMenu();
}
async componentDidUpdate(prevProps, prevState) {
@ -51,10 +49,8 @@ export default class DialogMenuRoles extends Component {
this.setStateUpdate(true);
this.setStateCreate(true);
this.setStateDelete(true);
this.getAllMenu();
this.setState({ isParentClick: false, id: idRoles });
// if (prevState.menu == this.state.menu) {
// await this.setStateReadAfterRender();
// }
}
}
@ -72,11 +68,9 @@ export default class DialogMenuRoles extends Component {
],
"orders": { "columns": ["id"], "ascending": false }
}
if (this.state.role_name !== "Super Admin") {
payload.columns.push(
{ "name": "company_id", "logic_operator": "=", "value": this.state.company_id, "operator": "AND" }
)
}
payload.columns.push(
{ "name": "company_id", "logic_operator": "=", "value": this.props.company_id, "operator": "AND" }
)
const result = await axios
.post(MENU_COMPANY_SEARCH, payload, config)
.then(res => res)
@ -116,14 +110,6 @@ export default class DialogMenuRoles extends Component {
})
}
// setStateReadAfterRender = async () => {
// await new Promise((resolve) => {
// this.setState({}, resolve);
// });
// // Now you have access to the rendered elements and can update state based on it
// this.setStateRead(true);
// }
setStateCreate = edit => {
const stateCreate = [];
this.state.menu.map((val) => {
@ -484,7 +470,7 @@ export default class DialogMenuRoles extends Component {
};
const renderMenu = (parentId, depth = 0) => {
const children = getChildren(parentId);
return children.map((menuItem, index) => {
return children.map((menuItem) => {
const currentIndex = menuIdx;
menuIdxList[currentIndex] = menuItem.menu_id;
menuIdx++

121
src/views/Master/MasterRoles/index.js

@ -43,7 +43,6 @@ class index extends Component {
tooltipTambah: false,
totalPage: 0,
typeDialog: 'Save',
company_id: props.company_id || 0,
role_name: props.role_name || '',
role_id: props.role_id || 0,
user_id: props.user_id || 0,
@ -68,29 +67,27 @@ class index extends Component {
render: (text, record) => <>
<Tooltip title={this.props.t('menuRoles')}>
{
checkActMenup('/roles', 'update') ?
<i className="cil-menu fa-lg" style={{ color: 'green', marginRight: 10, cursor: "pointer" }} onClick={() => this.handleMenuRoles(text.id)}></i>
:
null
}
checkActMenup('/roles', 'update') ?
<i className="cil-menu fa-lg" style={{ color: 'green', marginRight: 10, cursor: "pointer" }} onClick={() => this.handleMenuRoles(text)}></i>
:
null
}
</Tooltip>
<Tooltip title={this.props.t('delete')}>
{
checkActMenup('/roles', 'delete') ?
<i className="fa fa-trash" style={{ color: 'red', marginRight: 10, cursor: "pointer" }} onClick={() => this.handleDelete(text.id)}></i>
:
null
}
checkActMenup('/roles', 'delete') ?
<i className="fa fa-trash" style={{ color: 'red', marginRight: 10, cursor: "pointer" }} onClick={() => this.handleDelete(text)}></i>
:
null
}
</Tooltip>
<Tooltip title={this.props.t('edit')}>
{
checkActMenup('/roles', 'update') ?
<i className="fa fa-edit" style={{ color: 'green', cursor: "pointer" }} onClick={() => this.handleEdit(text)}></i>
:
null
}
checkActMenup('/roles', 'update') ?
<i className="fa fa-edit" style={{ color: 'green', cursor: "pointer" }} onClick={() => this.handleEdit(text)}></i>
:
null
}
</Tooltip>
</>,
},
@ -133,7 +130,6 @@ class index extends Component {
if (this.state.currentPage !== 1 && this.state.currentPage > 1) {
start = (this.state.currentPage * this.state.rowsPerPage) - this.state.rowsPerPage
}
const formData = {
"paging": { "start": start, "length": this.state.rowsPerPage },
"columns": [],
@ -153,12 +149,9 @@ class index extends Component {
}
if (this.state.role_name !== "Super Admin") {
formData.columns.push(
{ "name": "company_id", "logic_operator": "=", "value": this.state.company_id, "operator": "AND" },
{ "name": "company_id", "logic_operator": "=", "value": this.props.company_id, "operator": "AND" },
)
} else {
// formData.columns.push(
// { "name": "company_id", "logic_operator": "is null", "value": "", "operator": "AND" },
// )
formData.joins.push(
{ "name": "m_company", "column_join": "company_id", "column_results": ["company_name"] }
)
@ -228,7 +221,6 @@ class index extends Component {
}
saveRole = async (data) => {
const formData = {
name: data.name,
description: data.description,
@ -247,7 +239,6 @@ class index extends Component {
} else {
NotificationManager.error(`Data role gagal ditambahkan`, 'Failed!!');
}
}
editRole = async (data) => {
@ -272,13 +263,13 @@ class index extends Component {
}
handleEdit = (data) => {
this.setState({ dataEdit: data });
this.setState({ dataEdit: data, company_id: data.company_id });
this.handleOpenDialog('Edit');
}
handleDelete = (id) => {
id == '1' ? this.setState({ alertNotDelete: true }) :
this.setState({ alertDelete: true, idDelete: id });
handleDelete = (data) => {
data.id == '1' ? this.setState({ alertNotDelete: true }) :
this.setState({ alertDelete: true, idDelete: data.id });
}
onShowSizeChange = (current, pageSize) => {
@ -317,29 +308,24 @@ class index extends Component {
}
}
handleMenuRoles = async (id) => {
handleMenuRoles = async (data) => {
const formData = {
"paging": { "start": 0, "length": -1 },
"columns": [],
"joins": [{ "name": "m_menu", "column_join": "menu_id", "column_results": ["parent_id", "name"] }],
"orders": { "columns": ["id"], "ascending": false }
}
if (this.state.role_name !== "Super Admin") {
formData.columns.push(
{ "name": "role_id", "logic_operator": "=", "value": `${id}`, "operator": "AND" }
)
}
formData.columns.push(
{ "name": "role_id", "logic_operator": "=", "value": parseInt(data.id), "operator": "AND" }
)
const result = await axios
.post(ROLEMENU_SEARCH, formData, this.state.config)
.then(res => res)
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
this.setState({ menuRoles: result.data.data, idRoles: id }, () => {
this.setState({ menuRoles: result.data.data, idRoles: data.id, company_id: data.company_id }, () => {
this.handleOpenDialogMr();
});
} else {
}
}
@ -348,8 +334,7 @@ class index extends Component {
if (payloadArray.length > 0) {
await this.deleteCurrentRoleMenu(payloadArray[0].roles_id)
}
let promises = []
let result = []
let dataArr = []
dataArray.map((val, index) => {
if (val.read === true) {
const formData = {
@ -359,24 +344,22 @@ class index extends Component {
read: val.read,
update: val.update,
delete: val.delete
}
promises.push(axios.post(ROLEMENU_ADD, formData, this.state.config)
.then(res => result.push(res)))
dataArr.push(formData);
}
})
await Promise.all(promises);
if (result) {
if (result.length > 0) {
if (result[0].data.code === 200) {
this.getDataRoles();
NotificationManager.success('Data roles berhasil ditambahkan!!', 'Success!!');
} else {
NotificationManager.error(`${result[0].data.message}`, 'Failed!!');
}
}
}
});
const result = await axios
.post(ROLEMENU_ADD, dataArr, this.state.config)
.then((res) => res)
.catch((err) => err.response);
if (result && result.data && result.data.code == 200) {
this.getDataRoles();
NotificationManager.success('Data roles berhasil ditambahkan!!', 'Success!!');
} else {
NotificationManager.error(`${result.data.message}`, 'Failed!!');
}
}
deleteCurrentRoleMenu = async (id) => {
@ -413,12 +396,9 @@ class index extends Component {
if (this.state.role_name !== "Super Admin") {
formData.columns.push(
{ "name": "company_id", "logic_operator": "=", "value": this.state.company_id, "operator": "AND" },
{ "name": "company_id", "logic_operator": "=", "value": this.props.company_id, "operator": "AND" },
)
} else {
// formData.columns.push(
// { "name": "company_id", "logic_operator": "is null", "value": "", "operator": "AND" },
// )
formData.joins.push(
{ "name": "m_company", "column_join": "company_id", "column_results": ["company_name"] }
)
@ -462,9 +442,7 @@ class index extends Component {
}
render() {
const { t } = this.props;
const { tooltipTambah, tooltipExport, dialogMenuForm, dataTable, openDialog, currentPage, rowsPerPage, totalPage, search, tooltipEdit, tooltipDelete, tooltipMenu } = this.state
let noSeq = 0;
const { dialogMenuForm, dataTable, openDialog, currentPage, rowsPerPage, totalPage, search } = this.state
return (
<div>
<NotificationContainer />
@ -524,16 +502,15 @@ class index extends Component {
<Col>
<Tooltip title={this.props.t('rolesAdd')}>
{
checkActMenup('/roles', 'create') ?
<Button Button id="TooltipTambah" color="success" onClick={() => this.handleOpenDialog('Save')}><i className="fa fa-plus"></i>
</Button>
:
null
}
checkActMenup('/roles', 'create') ?
<Button Button id="TooltipTambah" color="success" onClick={() => this.handleOpenDialog('Save')}><i className="fa fa-plus"></i>
</Button>
:
null
}
</Tooltip>
<Tooltip title={this.props.t('exportExcel')}>
<Button style={{ marginLeft: "5px" }} id="TooltipExport" color="primary" onClick={() => this.handleExportExcel()}><i className="fa fa-print"></i></Button>
<Button style={{ marginLeft: "5px" }} id="TooltipExport" color="primary" onClick={() => this.handleExportExcel()}><i className="fa fa-print"></i></Button>
</Tooltip>
</Col>
</Row>

Loading…
Cancel
Save