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 (
STT | Tên | {/*Trạng thái | */} {(this.state.dataRole?.indexOf('level:edit') === -1 && this.state.dataRole?.indexOf('level:delete') === -1) ? "" :Thao tác | }
---|