diff --git a/src/components/game/GameManager.js b/src/components/game/GameManager.js index 3d81c95..e26aed1 100644 --- a/src/components/game/GameManager.js +++ b/src/components/game/GameManager.js @@ -32,4 +32,18 @@ export const getGameTypes = () => { } }) .then(response => response.json()) +} + +export const putGames = (editedGame) => { + return fetch(`http://localhost:8000/games/${editedGame.id}`, { + method: "PUT", + body: JSON.stringify( + editedGame + ), + headers:{ + "Authorization": `Token ${localStorage.getItem("lu_token")}`, + "Content-Type": "Application/json" + } + } + ) } \ No newline at end of file diff --git a/src/components/game/UpdateGame.js b/src/components/game/UpdateGame.js index cc5a740..749870b 100644 --- a/src/components/game/UpdateGame.js +++ b/src/components/game/UpdateGame.js @@ -1,16 +1,12 @@ import react, { useState, useEffect, } from "react"; import { useParams, useHistory } from "react-router-dom/cjs/react-router-dom.min"; -import { getEvents } from "./EventManager"; -import { putGames } from "./GameManager"; -import { getGames, getGameById } from "./GameManager"; +import { getGames, getGameById, getGameTypes, putGames } from "./GameManager"; // getGames is imported to allow the select to display a list of games export const UpdateGame = (props) => { const [ gameList, setGameList] = useState([]) - const [ eventList, setEventList] = useState([]) - const [ gameToEdit, setGamegameToEdit ] = useState({}) - - + const [ gameToEdit, setGameToEdit ] = useState({}) + const [gametypes, setGameTypes ] = useState([]) let { id } = useParams() const history = useHistory() @@ -19,10 +15,11 @@ export const UpdateGame = (props) => { useEffect(() => { getGames().then(data => setGameList(data)) - getEvents().then(data => setEventList(data)) + getGameTypes().then(data=> setGameTypes(data)) getGameById(id).then(data => { - setGamegameToEdit(data) + data.game_type = data.game_type.id + setGameToEdit(data) } ) @@ -35,75 +32,79 @@ useEffect(() => { const gameupdateform = () => { return( <> -