import react, { useState, useEffect, } from "react"; import { useParams, useHistory } from "react-router-dom/cjs/react-router-dom.min"; import { getGames } from "./GameManager"; import { putEvents } from "./EventManager"; import { getEvents, getEventById } from "./EventManager"; // getGames is imported to allow the select to display a list of games export const UpdateEvent = (props) => { const [ gameList, setGameList] = useState([]) const [ eventList, setEventList] = useState([]) const [ eventToEdit, setEventToEdit ] = useState({}) let { id } = useParams() const history = useHistory() useEffect(() => { getGames().then(data => setGameList(data)) getEvents().then(data => setEventList(data)) getEventById(id).then(data => { setEventToEdit(data) } ) }, [] ) // Still need to write out this form and figure out controlled/uncontrolled input for it. Event pk value needs to be passed to the form as props if I'm understanding this correctly const eventupdateform = () => { return( <>

Update Event

{ const copy = {...eventToEdit} copy.description = e.target.value setEventToEdit(copy) } } > { const copy = {...eventToEdit} copy.date = e.target.value setEventToEdit(copy) } } > { const copy = {...eventToEdit} copy.time = e.target.value setEventToEdit(copy)} } > { e.preventDefault() putEvents(eventToEdit) history.push("/") } } >
) } return( eventupdateform() ) }