fixed dates for this branch

This commit is contained in:
Kristoffer Juelsenn 2022-04-20 18:59:55 +02:00
parent 9e17129c6b
commit 340beb9aa4
2 changed files with 25 additions and 62 deletions

View File

@ -17,11 +17,11 @@ function postTournament(showError, tournamentName, tournamentDescription, tourna
showError("Tournament description cannot be empty"); showError("Tournament description cannot be empty");
return; return;
} }
if (!tournamentStartDate || tournamentStartDate === "") { if (!tournamentStartDate || tournamentStartDate === "" || tournamentStartDate === 0) {
showError("Tournament start date cannot be empty"); showError("Tournament start date cannot be empty");
return; return;
} }
if (!tournamentEndDate || tournamentEndDate === "") { if (!tournamentEndDate || tournamentEndDate === "" || tournamentEndDate === 0) {
showError("Tournament end date cannot be empty"); showError("Tournament end date cannot be empty");
return; return;
} }
@ -75,15 +75,14 @@ function TournamentForm(props) {
setMaxTeamsExponent(event.target.value); setMaxTeamsExponent(event.target.value);
} }
const [startTime, setStartTime] = React.useState([new Date(), new Date()]); const [startTime, setStartTime] = React.useState(new Date());
const [endTime, setEndTime] = React.useState([new Date(), new Date()]); const [endTime, setEndTime] = React.useState(new Date());
function submitTournament(event) { function submitTournament(event) {
event.preventDefault(); event.preventDefault();
console.log(maxTeamsExponent)
let maxTeams = Math.pow(2, maxTeamsExponent); let maxTeams = Math.pow(2, maxTeamsExponent);
let tournamentStart = new Date(startTime).toUTCString(); let tournamentStart = new Date(startTime).valueOf() - new Date().getTimezoneOffset() * 60000;
let tournamentEnd = new Date(endTime).toUTCString(); let tournamentEnd = new Date(endTime).valueOf() - new Date().getTimezoneOffset() * 60000;
postTournament( postTournament(
props.showError, props.showError,
document.getElementById("nameInput").value, document.getElementById("nameInput").value,
@ -92,7 +91,6 @@ function TournamentForm(props) {
tournamentEnd, tournamentEnd,
maxTeams maxTeams
); );
console.log(tournamentStart, tournamentEnd);
} }
const marks = [ const marks = [
@ -116,10 +114,7 @@ function TournamentForm(props) {
<Grid item xs={4}> <Grid item xs={4}>
<LocalizationProvider dateAdapter={AdapterDateFns}> <LocalizationProvider dateAdapter={AdapterDateFns}>
<DateTimePicker label={"Start Time"} inputVariant="outlined" ampm={false} mask="____-__-__ __:__" format="yyyy-MM-dd HH:mm" inputFormat="yyyy-MM-dd HH:mm" value={startTime} <DateTimePicker label={"Start Time"} inputVariant="outlined" ampm={false} mask="____-__-__ __:__" format="yyyy-MM-dd HH:mm" inputFormat="yyyy-MM-dd HH:mm" value={startTime}
onChange={(newValue) => { onChange={setStartTime}
setStartTime(newValue);
// console.log(new Date(newValue).toUTCString());
}}
renderInput={(params) => <TextField id="startDatePicker" {...params} sx={{margin: "0 2.5%"}} />} renderInput={(params) => <TextField id="startDatePicker" {...params} sx={{margin: "0 2.5%"}} />}
/> />
</LocalizationProvider> </LocalizationProvider>
@ -128,10 +123,7 @@ function TournamentForm(props) {
<LocalizationProvider dateAdapter={AdapterDateFns}> <LocalizationProvider dateAdapter={AdapterDateFns}>
<DateTimePicker label={"End Time"} inputVariant="outlined" ampm={false} mask="____-__-__ __:__" format="yyyy-MM-dd HH:mm" inputFormat="yyyy-MM-dd HH:mm" value={endTime} <DateTimePicker label={"End Time"} inputVariant="outlined" ampm={false} mask="____-__-__ __:__" format="yyyy-MM-dd HH:mm" inputFormat="yyyy-MM-dd HH:mm" value={endTime}
onChange={(newValue) => { onChange={setEndTime}
setEndTime(newValue);
// console.log(new Date(newValue).toUTCString());
}}
renderInput={(params) => <TextField id="endDatePicker" {...params} sx={{margin: "0 2.5%"}} />} renderInput={(params) => <TextField id="endDatePicker" {...params} sx={{margin: "0 2.5%"}} />}
/> />
</LocalizationProvider> </LocalizationProvider>

View File

@ -5,7 +5,7 @@ import AppBar from "./components/AsuraBar";
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";
import { Snackbar, IconButton, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle } from "@mui/material"; import { Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle } from "@mui/material";
import CloseIcon from '@mui/icons-material/Close'; import CloseIcon from '@mui/icons-material/Close';
import DeleteIcon from '@mui/icons-material/Delete'; import DeleteIcon from '@mui/icons-material/Delete';
import DateTimePicker from '@mui/lab/DateTimePicker'; import DateTimePicker from '@mui/lab/DateTimePicker';
@ -49,14 +49,13 @@ let submitChanges = curryTournamentId => event => {
return; return;
} }
tournamentStartDate = new Date(tournamentStartDate).toUTCString(); tournamentStartDate = new Date(tournamentStartDate).valueOf() - new Date().getTimezoneOffset() * 60 * 1000;
tournamentEndDate = new Date(tournamentEndDate).toUTCString(); tournamentEndDate = new Date(tournamentEndDate).valueOf() - new Date().getTimezoneOffset() * 60 * 1000;
let formData = new FormData(); let formData = new FormData();
formData.append("name", tournamentName); formData.append("name", tournamentName);
formData.append("description", tournamentDescription); formData.append("description", tournamentDescription);
// formData.append("image", tournamentImageFile);
formData.append("startDate", tournamentStartDate); formData.append("startDate", tournamentStartDate);
formData.append("endDate", tournamentEndDate); formData.append("endDate", tournamentEndDate);
// formData.append("teamLimit", tournamentMaxTeams); // formData.append("teamLimit", tournamentMaxTeams);
@ -104,8 +103,8 @@ let deleteTournament = tournamentId => event => {
function ManageTournament(props) { function ManageTournament(props) {
const [startTime, setStartTime] = React.useState([null,null]); const [startTime, setStartTime] = React.useState(new Date());
const [endTime, setEndTime] = React.useState([null,null]); const [endTime, setEndTime] = React.useState(new Date());
React.useEffect(() => { React.useEffect(() => {
fetch( fetch(
@ -119,11 +118,18 @@ function ManageTournament(props) {
document.getElementById("editName").value = data.data.name; document.getElementById("editName").value = data.data.name;
document.getElementById("editDesc").value = data.data.description; document.getElementById("editDesc").value = data.data.description;
// setStartTime(data.data.startTime.slice(0, 16)); // Get the time from the server, add the local timezone offset and set the input fields
// setEndTime(data.data.endTime.slice(0, 16)); let startDate = new Date(data.data.startTime.slice(0, 16));
let endDate = new Date(data.data.endTime.slice(0, 16));
let localTimeOffset = new Date().getTimezoneOffset() * 60*1000; // Minutes -> Milliseconds
startDate = new Date(startDate.getTime() - localTimeOffset);
endDate = new Date(endDate.getTime() - localTimeOffset);
setStartTime(startDate);
setEndTime(endDate);
}) })
.catch((err) => showError(err)); .catch((err) => showError(err));
}, [endTime, props.tournamentId, startTime]); }, [props.tournamentId]);
return ( return (
<> <>
@ -136,10 +142,7 @@ function ManageTournament(props) {
<Grid item xs={4}> <Grid item xs={4}>
<LocalizationProvider dateAdapter={AdapterDateFns}> <LocalizationProvider dateAdapter={AdapterDateFns}>
<DateTimePicker label={"Start Time"} inputVariant="outlined" ampm={false} mask="____-__-__ __:__" format="yyyy-MM-dd HH:mm" inputFormat="yyyy-MM-dd HH:mm" value={startTime} <DateTimePicker label={"Start Time"} inputVariant="outlined" ampm={false} mask="____-__-__ __:__" format="yyyy-MM-dd HH:mm" inputFormat="yyyy-MM-dd HH:mm" value={startTime}
onChange={(newValue) => { onChange={setStartTime}
setStartTime(newValue);
console.log(new Date(newValue).toUTCString());
}}
renderInput={(params) => <TextField id="editStartDate" {...params} />} renderInput={(params) => <TextField id="editStartDate" {...params} />}
/> />
</LocalizationProvider> </LocalizationProvider>
@ -147,19 +150,13 @@ function ManageTournament(props) {
<Grid item xs={4}> <Grid item xs={4}>
<LocalizationProvider dateAdapter={AdapterDateFns}> <LocalizationProvider dateAdapter={AdapterDateFns}>
<DateTimePicker label={"End Time"} inputVariant="outlined" ampm={false} mask="____-__-__ __:__" format="yyyy-MM-dd HH:mm:" inputFormat="yyyy-MM-dd HH:mm" value={endTime} <DateTimePicker label={"End Time"} inputVariant="outlined" ampm={false} mask="____-__-__ __:__" format="yyyy-MM-dd HH:mm:" inputFormat="yyyy-MM-dd HH:mm" value={endTime}
onChange={(newValue) => { onChange={setEndTime}
setEndTime(newValue);
console.log(new Date(newValue).toUTCString());
}}
renderInput={(params) => <TextField id="editEndDate" {...params} />} renderInput={(params) => <TextField id="editEndDate" {...params} />}
/> />
</LocalizationProvider> </LocalizationProvider>
</Grid> </Grid>
</Grid> </Grid>
</Box> </Box>
{/* <TextField type="datetime-local" id="editStartDate" label="Edit Start Time" InputLabelProps={{shrink: true,}}/>
<TextField type="datetime-local" id="editEndDate" label="Edit End Time" InputLabelProps={{shrink: true}}/> */}
<Button type="submit" variant="contained" onClick={submitChanges(props.tournamentId)} color="primary" > <Button type="submit" variant="contained" onClick={submitChanges(props.tournamentId)} color="primary" >
Save Tournament Details Save Tournament Details
</Button> </Button>
@ -175,30 +172,6 @@ function showError(error) {
console.error(error); console.error(error);
} }
function ClipboardButton(props) {
const [open, setOpen] = React.useState(false);
function copyString() {
navigator.clipboard.writeText(props.clipboardContent || "");
setOpen(true);
}
const handleClose = (event, reason) => {
if (reason === 'clickaway') { return }
setOpen(false);
};
const closeAction = <>
<IconButton size="small" aria-label="close" color="inherit" onClick={handleClose}>
<CloseIcon fontSize="small" />
</IconButton>
</>
return (
<>
<Button onClick={copyString} variant="outlined" color="primary" sx={{margin: "auto 5px"}} >Copy {props.name}</Button>
<Snackbar open={open} autoHideDuration={1500} onClose={handleClose} message={props.name + " copied to clipboard"} action={closeAction} />
</>
);
}
export default function TournamentManager(props) { export default function TournamentManager(props) {
const { tournamentId } = useParams(); const { tournamentId } = useParams();
@ -221,8 +194,6 @@ export default function TournamentManager(props) {
<Button variant="contained" color="error" onClick={deleteTournament(tournamentId)} sx={{margin: "auto 5px"}} endIcon={<DeleteIcon />}> <Button variant="contained" color="error" onClick={deleteTournament(tournamentId)} sx={{margin: "auto 5px"}} endIcon={<DeleteIcon />}>
Delete Tournament Delete Tournament
</Button> </Button>
<ClipboardButton clipboardContent={"https://discord.gg/asura"} name="Discord Invite Link" />
<ClipboardButton clipboardContent={"https://asura.feal.no/tournament/" + tournamentId} name="Tournament Link" />
</Box> </Box>
</Paper> </Paper>