Make the tournament page correctly handle status codes from the backend

This commit is contained in:
JP1998 2019-04-08 11:41:48 +02:00
parent a8fec087b7
commit fb93feed45
3 changed files with 25 additions and 25 deletions

View File

@ -26,7 +26,7 @@ export class ErrorPageComponent extends React.Component {
}
}
function ErrorPage(props){
export function ErrorPage(props){
return (
<Container className="mb-5">
<div className="row mb-5">

View File

@ -34,7 +34,7 @@ class EditTournamentPage extends React.Component {
super(props);
this.state = {
validCode: true
validCode: false
};
}

View File

@ -18,6 +18,7 @@ import {
Row,
Table
} from 'reactstrap';
import { ErrorPageComponent } from '../js/components/ErrorComponents.js';
import 'bootstrap/dist/css/bootstrap.min.css';
import {BigImage, Footer, TurniereNavigation} from '../js/CommonComponents.js';
import '../static/everypage.css';
@ -88,16 +89,6 @@ function getLevelName(levelNumber) {
}
}
function TournamentContainer(props) {
const { tournament } = props.data;
if (tournament === null) {
return <Container>null</Container>;
} else {
return <TournamentPage tournament={tournament}/>;
}
}
function Stage(props) {
return (<div>
<Container className='py-5'>
@ -393,25 +384,34 @@ class Main extends React.Component {
getRequest(getState(), '/tournaments/' + code)
.then(response => {
this.setState({tournament: convertTournament(response.data)});
this.setState({ status : response.status, tournament : convertTournament(response.data)});
})
.catch(() => { /* TODO: Show some kind of error or smth */ });
.catch((err) => {
this.setState({ status : err.response.status });
});
}
render() {
const tournamentName = this.state.tournament === null ? 'Turnier' : this.state.tournament.name;
return (
<div>
<Head>
<title>{tournamentName}: turnie.re</title>
</Head>
<TurniereNavigation/>
<BigImage text={tournamentName}/>
<TournamentContainer data={this.state}/>
<Footer/>
</div>
);
const { status, tournament } = this.state;
if (status == 200) {
return (
<div>
<Head>
<title>{tournamentName}: turnie.re</title>
</Head>
<TurniereNavigation/>
<BigImage text={tournamentName}/>
<TournamentPage tournament={tournament}/>
<Footer/>
</div>
);
} else {
return <ErrorPageComponent code={status}/>;
}
}
}