ScoDocMobile/src/ScoDoc/ChoixDept.js

53 lines
1.5 KiB
JavaScript

import React, {Component} from "react";
import {Link} from "react-router-dom";
import './Style.css'
import {getJson} from './Request'
/** Page de choix du département */
class ChoixDept extends Component {
constructor(props) {
super(props);
this.state = {
// Liste des départements disponibles pour l'utilisateur
depts: [],
};
}
componentWillMount() {
this.getData()
}
/**
* Recupère la liste des départements depuis l'API
*/
getData() {
let BASE_URL = window.$api_url
getJson(BASE_URL + 'list_depts?format=json')
.then(res => {
this.setState({ depts: res.data })
});
}
render() {
return (
<div className="wrapper">
<h1 id="pageTitle">Choix du département</h1>
<div className="container">
<div className="row">
{this.state.depts.map((dept, index) => {
return (
<div className="col-sm" key={index} id="wrapDept">
<Link to={`/${dept}/Scolarite`}>
Département {dept}
</Link>
</div>
)
},)}
</div>
</div>
</div>
);
}
}
export default ChoixDept