etalon_frontend/src/pages/Structure.js

142 lines
3.8 KiB
JavaScript

// IMPORT MODULES
import React, { useEffect } from "react";
// IMPORT COMPONENTS
import Breadcrumb from "../components/Global/Breadcrumb";
// IMPORT IMAGES
import StructureImg from "../img/structureImg.jpg";
// const Structure = () => {
// useEffect(() => {
// window.scrollTo(0, 0);
// }, []);
class Structure extends React.Component {
constructor(props) {
super(props);
this.state = {
items: [],
DataisLoaded: false,
error: null
};
}
componentDidMount() {
this._mounted = true
this.makeRemoteRequest();
}
componentWillUnmount() {
this._mounted = false
}
makeRemoteRequest = () => {
const url = `http://127.0.0.1:8000/api/v1/struktura_sentra`
if (this._mounted) {
this.setState({ DataisLoaded: true });
}
setTimeout(() => {
fetch(url, {
method: 'GET',
})
.then(res => res.json())
.then(res => {
if (this._mounted) {
this.setState({
items: res.data,
error: res.message || null,
DataisLoaded: true,
})
console.log(res.data)
}
})
.catch(error => {
if (this._mounted) {
this.setState({ error, DataisLoaded: false});
}
});
}, 1500);
};
render() {
// const [pageIndex, setPageIndex] = useState(1);
var {DataisLoaded, items} = this.state;
if(!DataisLoaded){
return <div>Loading ....</div>
}else{
return (
<section className="structure">
<Breadcrumb
path_1="Структура Государственного эталонного центра"
currentUrl="/structure"
/>
<div className="container">
<div className="structure-inner">
<div className="tab-header">
<h4 className="tab-header-text" id="tab-header-text">
Структура Государственного эталонного центра
</h4>
<div className="tab-header-line"></div>
</div>
<div className="structure-main-page">
<img src={StructureImg} alt="Structure" />
</div>
<div className="structure-employees">
<table className="structure-table">
<tbody>
<tr className="table-head">
<th>
<span className="name-head">Фамилия, имя, отчество</span>
</th>
<th>
<span className="position-head">Занимаемая должность</span>
</th>
<th>
<span className="tel-head">Рабочий телефон</span>
</th>
</tr>
{items.map(item=>(
<tr>
<td>
<span className="name">
{item.name}
</span>
</td>
<td>
<span className="position">
{item.position_held}
</span>
</td>
<td>
<span className="tel">Teл: {item.phone}</span>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
</section>
);
}
}
};
export default Structure;