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 (
STT | Tên | Trạng thái | Thao tác |
---|