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'; class Role extends Component { constructor(props) { super(props); this.state = { modalRole: false, listRole: [], listStaff: [], crrDatas: [], activePage: 1, offset: 0, crrRole: { name: "", description: "" }, }; 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 }, }).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) => { if (Role.is_default === 1) { swal("Cảnh báo", "Bạn không được xóa quyền mặc định", "warning"); return; } let data = await fetch(`${HOST}/api/role/delete`, { method: 'POST', headers: { 'Content-Type': 'application/json', // 'Authorization': token, }, body: JSON.stringify({ 'id': Role.id }) }).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} } {/* {language[this.props.indexLanguage].tooltip.open_edit} */} {/* {language[this.props.indexLanguage].tooltip.open_delete} */} ) }); var pageRangeDisplayed = 1; if ($(window).width() < 768) { pageRangeDisplayed = 3 } else { pageRangeDisplayed = 5 } return (

Quyền

{bulletedRole}
STT Tên Trạng thái Thao tác
{/* */}
{/* Showing {this.state.showFirst} to {this.state.showLast} of {this.state.totalLength} entries */}
); } } export default Role;