disabled editing of archived tournaments

This commit is contained in:
Kristoffer Longva Eriksen 2022-04-21 10:34:57 +02:00
parent 3f1b13cc16
commit a283ae90b0
1 changed files with 28 additions and 1 deletions

View File

@ -176,6 +176,33 @@ function BracketViewer(props) {
); );
} }
function RemovableBar(props) {
const [endTime, setendTime] = React.useState(null);
React.useEffect(() => {
fetch(process.env.REACT_APP_API_URL + `/tournament/${props.tournamentId}`)
.then(res => res.json())
.then(data => {
if (data.status !== "OK") {
// Do your error thing
console.error(data);
return;
}
let endTime = data.data.endTime;
setendTime(endTime);
})
.catch(err => showError(err));
})
let today = new Date()
let yesterday = today.setDate(today.getDate() - 1)
let isComplete = new Date(endTime) < yesterday
if (isComplete) {
return (null)
} else {
return (<TournamentBar pageTitle="View Tournament" />)
}
}
function showError(error) { function showError(error) {
alert("Something went wrong. \n" + error); alert("Something went wrong. \n" + error);
console.error(error); console.error(error);
@ -187,7 +214,7 @@ export default function TournamentOverview(props) {
return ( return (
<> <>
<Appbar pageTitle="View Tournament" /> <Appbar pageTitle="View Tournament" />
<TournamentBar pageTitle="View Tournament" /> <RemovableBar tournamentId={tournamentId} />
<BracketViewer tournamentId={tournamentId} className="bracketViewer" /> <BracketViewer tournamentId={tournamentId} className="bracketViewer" />
</> </>
); );