|
|
|
@ -11,28 +11,33 @@ import { Pagination, Tooltip, Table } from 'antd';
|
|
|
|
|
import { ROLE_ADD, ROLE_SEARCH, ROLE_EDIT, ROLE_DELETE, ROLEMENU_ADD, ROLEMENU_SEARCH, ROLEMENU_DELETE_ROLE } from '../../../const/ApiConst.js'; |
|
|
|
|
import { withTranslation } from 'react-i18next'; |
|
|
|
|
|
|
|
|
|
const token = window.localStorage.getItem('token'); |
|
|
|
|
const company_id = window.localStorage.getItem('company_id'); |
|
|
|
|
const role_name = window.localStorage.getItem('role_name'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const BASE_URL = "http://siopas.co.id/custom-php/api/geohr/"; |
|
|
|
|
|
|
|
|
|
const config = { |
|
|
|
|
headers: |
|
|
|
|
{ |
|
|
|
|
Authorization: `Bearer ${token}`, |
|
|
|
|
"Content-type": `application/json` |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const momentFormat = 'HH:mm'; |
|
|
|
|
|
|
|
|
|
const LENGTH_DATA = 10 |
|
|
|
|
|
|
|
|
|
class index extends Component { |
|
|
|
|
constructor(props) { |
|
|
|
|
let role_id = '', user_id = '', isLogin = '', token = '', company_id = 0, role_name = ''; |
|
|
|
|
if (props.location.state && props.location.state.role_id && props.location.state.user_id) { |
|
|
|
|
role_id = props.location.state.role_id; |
|
|
|
|
user_id = props.location.state.user_id; |
|
|
|
|
token = props.location.state.token; |
|
|
|
|
isLogin = props.location.state.isLogin; |
|
|
|
|
company_id = props.location.state.company_id; |
|
|
|
|
role_name = props.location.state.role_name; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
token = window.localStorage.getItem('token'); |
|
|
|
|
role_name = window.localStorage.getItem('role_name'); |
|
|
|
|
company_id = window.localStorage.getItem('company_id'); |
|
|
|
|
} |
|
|
|
|
super(props) |
|
|
|
|
this.config = { |
|
|
|
|
headers: { |
|
|
|
|
Authorization: `Bearer ${token}`, |
|
|
|
|
"Content-type": "application/json" |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
this.state = { |
|
|
|
|
alertDelete: false, |
|
|
|
|
alertNotDelete: false, |
|
|
|
@ -58,9 +63,9 @@ class index extends Component {
|
|
|
|
|
tooltipTambah: false, |
|
|
|
|
totalPage: 0, |
|
|
|
|
typeDialog: 'Save', |
|
|
|
|
company_id: company_id |
|
|
|
|
company_id: company_id, |
|
|
|
|
role_name: role_name |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.columns = [ |
|
|
|
|
{ |
|
|
|
|
title: this.props.t('action'), |
|
|
|
@ -117,7 +122,7 @@ class index extends Component {
|
|
|
|
|
"joins": [], |
|
|
|
|
"orders": { "columns": ["id"], "ascending": false } |
|
|
|
|
} |
|
|
|
|
if (role_name !== "Super Admin") { |
|
|
|
|
if (this.state.role_name !== "Super Admin") { |
|
|
|
|
formData.columns.push( |
|
|
|
|
{ "name": "company_id", "logic_operator": "=", "value": this.state.company_id, "operator": "AND" }, |
|
|
|
|
) |
|
|
|
@ -127,7 +132,7 @@ class index extends Component {
|
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
const result = await axios |
|
|
|
|
.post(ROLE_SEARCH, formData, config) |
|
|
|
|
.post(ROLE_SEARCH, formData, this.config) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
@ -172,7 +177,7 @@ class index extends Component {
|
|
|
|
|
const { idDelete } = this.state |
|
|
|
|
const url = ROLE_DELETE(idDelete) |
|
|
|
|
|
|
|
|
|
const result = await axios.delete(url, config) |
|
|
|
|
const result = await axios.delete(url, this.config) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
@ -193,10 +198,10 @@ class index extends Component {
|
|
|
|
|
name: data.name, |
|
|
|
|
description: data.description, |
|
|
|
|
default_page: data.selectedMenu, |
|
|
|
|
company_id: company_id |
|
|
|
|
company_id: this.company_id |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const result = await axios.post(ROLE_ADD, formData, config) |
|
|
|
|
const result = await axios.post(ROLE_ADD, formData, this.config) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
@ -216,7 +221,7 @@ class index extends Component {
|
|
|
|
|
default_page: data.selectedMenu |
|
|
|
|
} |
|
|
|
|
const url = ROLE_EDIT(data.id) |
|
|
|
|
const result = await axios.put(url, formData, config) |
|
|
|
|
const result = await axios.put(url, formData, this.config) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
@ -285,7 +290,7 @@ class index extends Component {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const result = await axios |
|
|
|
|
.post(ROLEMENU_SEARCH, formData, config) |
|
|
|
|
.post(ROLEMENU_SEARCH, formData, this.config) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
@ -309,7 +314,7 @@ class index extends Component {
|
|
|
|
|
menu_id: val.menu_id, |
|
|
|
|
role_id: val.roles_id |
|
|
|
|
} |
|
|
|
|
promises.push(axios.post(ROLEMENU_ADD, formData, config) |
|
|
|
|
promises.push(axios.post(ROLEMENU_ADD, formData, this.config) |
|
|
|
|
.then(res => result.push(res))) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
@ -329,7 +334,7 @@ class index extends Component {
|
|
|
|
|
|
|
|
|
|
deleteCurrentRoleMenu = async (id) => { |
|
|
|
|
let urlDel = ROLEMENU_DELETE_ROLE(id) |
|
|
|
|
const result = await axios.delete(urlDel, config) |
|
|
|
|
const result = await axios.delete(urlDel, this.config) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
if (result && result.data && result.data.code === 200) { |
|
|
|
@ -352,7 +357,7 @@ class index extends Component {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const result = await axios |
|
|
|
|
.post(ROLE_SEARCH, formData, config) |
|
|
|
|
.post(ROLE_SEARCH, formData, this.config) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
|