import React, { Component } from 'react'; import { Redirect } from 'react-router-dom'; import swal from 'sweetalert'; import ModalRole from "../Modal/ModalRole"; import { PulseLoader } from 'react-spinners'; import Pagination from "react-js-pagination"; import $ from 'jquery'; import { HOST } from '../../config/index'; import Store from '../../store'; class Role extends Component { constructor(props) { super(props); this.state = { modalRole: false, listRole: [], listStaff: [], crrDatas: [], activePage: 1, offset: 0, crrRole: { name: "", description: "" }, dataRole: Store.getState().role.role, }; Store.subscribe(() => { this.setState({ dataRole: Store.getState().role.role, }, () => { }); }); this.itemsPerPage = 10; } componentDidMount() { this.getData(); } getData = () => { this.getRole() } getRole = () => { fetch(`${HOST}/api/levels/company/1`, { method: 'GET', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', // 'Authorization': token 'Authorization': Store.getState().isLogin.access_token, }, }).then((response) => { return response.json() }).then((data) => { if (data.status === 10000) { this.setState({ listRole: data.data }); this.FilterRole(this.state.activePage) } }) } FilterRole(activePage) { const { listRole } = this.state; const offset = (activePage - 1) * this.itemsPerPage; const crrDatas = listRole.slice(offset, offset + this.itemsPerPage); console.log(crrDatas) this.setState({ crrDatas, offset: offset }) } handlePageChange = (pageNumber) => { this.setState({ ...this.state, activePage: pageNumber }) this.FilterRole(pageNumber); } DeleteRole = async (Role) => { let data = await fetch(`${HOST}/api/levels/${Role._id}`, { method: 'DELETE', headers: { 'Content-Type': 'application/json', 'Authorization': Store.getState().isLogin.access_token, // 'Authorization': token, }, }).then((response) => { return response.json() }); if (data.status === 10000) { swal("Thành công", "Bạn đã xóa thành công!", "success", { buttons: false, timer: 1500, }); this.getRole(); } else { swal("Lỗi", "Xóa thất bại!", "error"); } } modalClose = () => { this.setState({ modalRole: false, }); this.getRole(); } render() { if (this.state.isLogin === false) { return ( ) } let bulletedRole = this.state.crrDatas.map((e, i) => { console.log(e) var is_default = "" if (e.is_default === 1) { is_default = " (Default)" } return ( {(i + this.state.offset + 1)} {e.name} {/* { e.active === 0 ? Inactive {is_default} : Active {is_default} } */} {(this.state.dataRole?.indexOf('level:edit') === -1 && this.state.dataRole?.indexOf('level:delete') === -1) ? "" : {this.state.dataRole?.indexOf('level:edit') !== -1 ? : "" } {/* {language[this.props.indexLanguage].tooltip.open_edit} */} {this.state.dataRole?.indexOf('level:delete') !== -1 ? : "" } {/* {language[this.props.indexLanguage].tooltip.open_delete} */} } ) }); var pageRangeDisplayed = 1; if ($(window).width() < 768) { pageRangeDisplayed = 3 } else { pageRangeDisplayed = 5 } return (

Thiết lập quyền

{this.state.dataRole?.indexOf('level:edit') !== -1 ?
: "" }
{/* */} {(this.state.dataRole?.indexOf('level:edit') === -1 && this.state.dataRole?.indexOf('level:delete') === -1) ? "" : } {bulletedRole}
STT TênTrạng tháiThao tác
{/* */}
{/* Showing {this.state.showFirst} to {this.state.showLast} of {this.state.totalLength} entries */}
); } } export default Role;