import React, { useEffect, useState } from 'react'; import AddIcon from '@mui/icons-material/Add'; import IconButton from '@mui/material/IconButton'; import TextField from '@mui/material/TextField'; import Stack from '@mui/material/Stack'; import Button from '@mui/material/Button'; import { DateTimePicker } from '@mui/x-date-pickers'; import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns'; import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; import GameAdder from './GameAdder'; import { post_gamenight, unpack_api_result} from '../api/Api'; function AddGameNight(props) { const [expanded, setExpanded] = useState(false); const [gameName, setGameName] = useState(""); const [date, setDate] = useState(Date.now()); const [gameList, setGameList] = useState([]); const handleNameChange = (event) => { setGameName(event.target.value); }; const onDateChange = (date) => { setDate(date); }; const onGamesListChange = (gameList) => { setGameList(gameList); } useEffect(() => { if(!expanded) { setGameName(""); setDate(null); } }, [expanded]); const handleAddGamenight = (event) => { event.preventDefault(); if (props.user !== null) { let input = { name: gameName, datetime: date, game_list: gameList, } unpack_api_result(post_gamenight(input, props.user.jwt), props.setFlash) .then(result => { setExpanded(false); setGameName(""); setDate(null); }) .then(() => props.refetchGamenights()) } }; if(expanded) { return (
{ e.preventDefault(); }}>
Gamenight }/>
); } else { return ( setExpanded(true)}> ); } } export default AddGameNight