Changed from alert to snackbar most places, unstable version
This commit is contained in:
parent
53f44ed5a0
commit
539f31ea96
|
@ -2,6 +2,7 @@ import * as React from "react";
|
||||||
import { BrowserRouter as Router, Link, Route, Routes } from "react-router-dom";
|
import { BrowserRouter as Router, Link, Route, Routes } from "react-router-dom";
|
||||||
// import { AlertContainer, alert } from "react-custom-alert";
|
// import { AlertContainer, alert } from "react-custom-alert";
|
||||||
import AppBar from "./components/AsuraBar";
|
import AppBar from "./components/AsuraBar";
|
||||||
|
import ErrorSnackbar from "./components/ErrorSnackbar";
|
||||||
import TournamentBar from "./components/TournamentBar";
|
import TournamentBar from "./components/TournamentBar";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { Button, TextField, Grid, Box, Container, Paper, Stack } from "@mui/material";
|
import { Button, TextField, Grid, Box, Container, Paper, Stack } from "@mui/material";
|
||||||
|
@ -16,37 +17,38 @@ import PropTypes from 'prop-types'
|
||||||
let submitChanges = curryTournamentId => event => {
|
let submitChanges = curryTournamentId => event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
let tournamentId = curryTournamentId;
|
let tournamentId = curryTournamentId;
|
||||||
//TODO use refs to get values
|
//TODO: use refs to get values
|
||||||
let tournamentName = document.getElementById("editName").value;
|
let tournamentName = document.getElementById("editName").value;
|
||||||
let tournamentDescription = document.getElementById("editDesc").value;
|
let tournamentDescription = document.getElementById("editDesc").value;
|
||||||
// let tournamentImageFile = document.getElementById("editImage").files[0];
|
// let tournamentImageFile = document.getElementById("editImage").files[0];
|
||||||
let tournamentStartDate = document.getElementById("editStartDate").value;
|
let tournamentStartDate = document.getElementById("editStartDate").value;
|
||||||
let tournamentEndDate = document.getElementById("editEndDate").value;
|
let tournamentEndDate = document.getElementById("editEndDate").value;
|
||||||
|
let showError;
|
||||||
|
|
||||||
if (!tournamentName || tournamentName === "") {
|
if (!tournamentName || tournamentName === "") {
|
||||||
alert("Tournament name cannot be empty");
|
showError("Tournament name cannot be empty");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!tournamentDescription || tournamentDescription === "") {
|
if (!tournamentDescription || tournamentDescription === "") {
|
||||||
alert("Tournament description cannot be empty");
|
showError("Tournament description cannot be empty");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!tournamentStartDate || tournamentStartDate === "") {
|
if (!tournamentStartDate || tournamentStartDate === "") {
|
||||||
alert("Tournament start date cannot be empty");
|
showError("Tournament start date cannot be empty");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!tournamentEndDate || tournamentEndDate === "") {
|
if (!tournamentEndDate || tournamentEndDate === "") {
|
||||||
alert("Tournament end date cannot be empty");
|
showError("Tournament end date cannot be empty");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tournamentStartDate > tournamentEndDate) {
|
if (tournamentStartDate > tournamentEndDate) {
|
||||||
alert("Tournament start date cannot be after end date");
|
showError("Tournament start date cannot be after end date");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let today = new Date();
|
let today = new Date();
|
||||||
if (tournamentStartDate < today || tournamentEndDate < today) {
|
if (tournamentStartDate < today || tournamentEndDate < today) {
|
||||||
alert("Tournament start and end date must be after today");
|
showError("Tournament start and end date must be after today");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +79,7 @@ let submitChanges = curryTournamentId => event => {
|
||||||
})
|
})
|
||||||
.catch((error) => showError(error));
|
.catch((error) => showError(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
let deleteTournament = tournamentId => event => {
|
let deleteTournament = tournamentId => event => {
|
||||||
console.log(tournamentId);
|
console.log(tournamentId);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -163,10 +166,10 @@ function ManageTournament(props) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function showError(error) {
|
// function showError(error) {
|
||||||
alert("Something went wrong. \n" + error);
|
// alert("Something went wrong. \n" + error);
|
||||||
console.error(error);
|
// console.error(error);
|
||||||
}
|
// }
|
||||||
|
|
||||||
function ConfirmationDialogRaw(props) {
|
function ConfirmationDialogRaw(props) {
|
||||||
const { tournamentId } = useParams();
|
const { tournamentId } = useParams();
|
||||||
|
@ -220,17 +223,25 @@ export default function TournamentManager(props) {
|
||||||
const handleClickListItem = () => {
|
const handleClickListItem = () => {
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [openError, setOpenError] = React.useState(false);
|
||||||
|
const [errorMessage, setErrorMessage] = React.useState("");
|
||||||
|
function showError(message) {
|
||||||
|
setOpenError(false);
|
||||||
|
setErrorMessage(message);
|
||||||
|
setOpenError(true);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
<>
|
<>
|
||||||
<AppBar pageTitle="Edit Tournament" />
|
<AppBar pageTitle="Edit Tournament" />
|
||||||
<TournamentBar pageTitle="Edit Tournament"/>
|
<TournamentBar pageTitle="Edit Tournament"/>
|
||||||
<Paper sx={{minHeight: "30vh", width: "90vw", margin: "20px auto", padding: "20px 0"}} component={Container} direction="column" align="center">
|
<Paper sx={{minHeight: "30vh", width: "90vw", margin: "20px auto", padding: "20px 0"}} component={Container} direction="column" align="center">
|
||||||
<ManageTournament tournamentId={tournamentId} />
|
<ManageTournament tournamentId={tournamentId} showError={showError} />
|
||||||
{/* <AnnounceButton /> */}
|
{/* <AnnounceButton /> */}
|
||||||
<Box sx={{width: "100%"}}>
|
<Box sx={{width: "100%"}}>
|
||||||
<Button variant="contained" color="error" onClick={handleClickListItem} sx={{margin: "auto 5px"}} endIcon={<DeleteIcon />}>
|
<Button variant="contained" color="error" onClick={handleClickListItem} sx={{margin: "auto 5px"}} endIcon={<DeleteIcon />}>
|
||||||
|
@ -246,6 +257,7 @@ export default function TournamentManager(props) {
|
||||||
</Box>
|
</Box>
|
||||||
</Paper>
|
</Paper>
|
||||||
|
|
||||||
|
<ErrorSnackbar message={errorMessage} open={openError} setOpen={setOpenError} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue