Browse Source

update menu by company_id

pull/2/head
farhantock 1 year ago
parent
commit
a7828bc998
  1. 54
      src/views/Master/MasterRoles/DialogForm.js
  2. 63
      src/views/Master/MasterRoles/DialogMenuRoles.js
  3. 5
      src/views/Master/MasterRoles/index.js

54
src/views/Master/MasterRoles/DialogForm.js

@ -5,7 +5,7 @@ import 'antd/dist/antd.css';
import { withTranslation } from 'react-i18next'; import { withTranslation } from 'react-i18next';
import axios from 'axios'; import axios from 'axios';
import { Select } from 'antd'; import { Select } from 'antd';
import { MENU_SEARCH } from '../../../const/ApiConst.js'; import { MENU_COMPANY_SEARCH, MENU_SEARCH } from '../../../const/ApiConst.js';
const { Option } = Select const { Option } = Select
const token = window.localStorage.getItem('token'); const token = window.localStorage.getItem('token');
@ -18,6 +18,7 @@ const config = {
} }
}; };
class DialogForm extends Component { class DialogForm extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
@ -61,12 +62,49 @@ class DialogForm extends Component {
} }
getAllMenu = async () => { getAllMenu = async () => {
const { companyID } = this.props;
const { roleName } = this.props;
if (roleName !== "Super Admin") {
const payload = {
"paging": {
"start": 0,
"length": -1
},
"columns": [{
"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 }
}
const result = await axios
.post(MENU_COMPANY_SEARCH, payload, config)
.then(res => res)
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
this.setState({ menu: result.data.data });
}
} else {
const payload = { const payload = {
"paging": { "start": 0, "length": -1 }, "paging": {
"columns": [ "start": 0,
{ "name": "name", "logic_operator": "ilike", "value": "", "operator": "AND" } "length": -1
], },
"joins": [], "columns": [{
"name": "name",
"logic_operator": "ilike",
"value": "",
"operator": "AND"
}],
"orders": { "columns": ["id"], "ascending": false } "orders": { "columns": ["id"], "ascending": false }
} }
const result = await axios const result = await axios
@ -78,6 +116,8 @@ class DialogForm extends Component {
} }
} }
}
showDialog = () => { showDialog = () => {
this.setState({ isParentClick: true }); this.setState({ isParentClick: true });
} }
@ -166,7 +206,7 @@ class DialogForm extends Component {
}}> }}>
{this.state.menu.map((item) => ( {this.state.menu.map((item) => (
<option key={item.id} value={item.id}> <option key={item.id} value={item.id}>
{item.name} {item.name ?? item.join_first_name}
</option> </option>
))} ))}
</Input> </Input>

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

@ -3,9 +3,8 @@ 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_SEARCH } from '../../../const/ApiConst.js'; import { MENU_COMPANY_SEARCH, 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');
@ -52,30 +51,64 @@ 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": { "start": 0, "length": -1 }, "paging": {
"columns": [ "start": 0,
{ "name": "name", "logic_operator": "ilike", "value": "", "operator": "AND" } "length": -1
], },
"joins": [], "columns": [{
"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_SEARCH, payload, config) .post(MENU_COMPANY_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) {
console.log('data Menu Role :', result.data.data);
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 => {
@ -155,7 +188,7 @@ class DialogMenuRoles extends Component {
menu.map((val, index) => { menu.map((val, index) => {
return ( return (
<tr key={index}> <tr key={index}>
<td>{val.name}</td> <td>{val.join_first_name ?? 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>
) )

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

@ -426,6 +426,9 @@ class index extends Component {
dataEdit={this.state.dataEdit} dataEdit={this.state.dataEdit}
showDialog={showDialog => this.showChildDialog = showDialog} showDialog={showDialog => this.showChildDialog = showDialog}
dataHs={this.state.dataIdHo} dataHs={this.state.dataIdHo}
companyID={this.state.company_id}
roleName={this.state.role_name}
/> />
<DialogMenuRoles <DialogMenuRoles
openDialog={dialogMenuForm} openDialog={dialogMenuForm}
@ -433,6 +436,8 @@ class index extends Component {
idRoles={this.state.idRoles} idRoles={this.state.idRoles}
showDialog={showDialog => this.showMenuRolesDialog = showDialog} showDialog={showDialog => this.showMenuRolesDialog = showDialog}
menuRoles={this.state.menuRoles} menuRoles={this.state.menuRoles}
companyID={this.state.company_id}
roleName={this.state.role_name}
/> />
<Card> <Card>
<CardHeader style={{ display: "flex", justifyContent: "space-between" }}> <CardHeader style={{ display: "flex", justifyContent: "space-between" }}>

Loading…
Cancel
Save