diff --git a/client/src/App.js b/client/src/App.js index 754d6ca..c0841b5 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -12,6 +12,8 @@ import 'react-toastify/dist/ReactToastify.css'; import { EditScreen } from './Screens/EditScreen' import { AddMatchScreen } from './Screens/AddMatchScreen' import { FixtureScreen } from './Screens/FixtureScreen' +import {EditFixtureScreen} from './Screens/EditFixtureScreen' +import {EditMatchScreen} from './Screens/EditMatchScreen' function App() { const[user,setUser] = useState(null); @@ -28,6 +30,8 @@ function App() { } /> } /> } /> + } /> + } /> diff --git a/client/src/Screens/AdminScreen.js b/client/src/Screens/AdminScreen.js index 54905be..82b3286 100644 --- a/client/src/Screens/AdminScreen.js +++ b/client/src/Screens/AdminScreen.js @@ -18,6 +18,7 @@ export const AdminScreen = () => { return ( Add Match + Edit Fixture ); } diff --git a/client/src/Screens/EditFixtureScreen.js b/client/src/Screens/EditFixtureScreen.js new file mode 100644 index 0000000..765ecb8 --- /dev/null +++ b/client/src/Screens/EditFixtureScreen.js @@ -0,0 +1,51 @@ +import React, { useState, useEffect } from 'react' +import axios from 'axios' +import { Link } from 'react-router-dom' +import '../fixture.css' +import Button from 'react-bootstrap/Button'; + + + + + +export const EditFixtureScreen = ({}) => { + + const [matches, setMatches] = useState([ ]) + + + useEffect(() => { + axios.get('http://localhost:5000/matches') + .then(response => setMatches(response.data)) + }, []) + + + + return ( +
+
    + {matches.map(match => { + return ( +
  • + + {match.homeTeam} Vs {match.awayTeam} + {match.referee} + {match.date} + +
    + {match.homeTeam} + {match.score} + {match.awayTeam} +
    + EDIT +
  • + ) + })} +
+
+ ) +} + + + + +export default EditFixtureScreen; \ No newline at end of file diff --git a/client/src/Screens/EditMatchScreen.js b/client/src/Screens/EditMatchScreen.js new file mode 100644 index 0000000..2401cbd --- /dev/null +++ b/client/src/Screens/EditMatchScreen.js @@ -0,0 +1,51 @@ +import React, { useState } from 'react' +import axios from 'axios'; +import Button from 'react-bootstrap/Button'; +import { useEffect } from 'react'; +import { useParams } from 'react-router-dom'; + +export const EditMatchScreen = () => { + + const {id} = useParams(); + + const [newmatch, setMatch] = useState({ + score: "", + }) + + useEffect(() => { + axios.get(`http://localhost:5000/matches/editfixture/${id}`) + .then(response => setMatch(response.data)) + }, []) + + const matchUpdate = () => { + axios.put(`http://localhost:5000/matches/editfixture/${id}`, newmatch) + .then((match) => console.log(match)) + } + + const matchDelete = () => { + axios.delete(`http://localhost:5000/matches/editfixture/${id}`) + .then((res) => console.log(res.status)) + } + + const handleChange = (e) => { + const { name, value } = e.target + setMatch(oldMatch => { + return { + ...oldMatch, + [name]: value + } + }) + } + return ( +
+ +
+ + + + +
+ ); +} + +export default EditMatchScreen; \ No newline at end of file diff --git a/server/routers/matchRouter.js b/server/routers/matchRouter.js index fcb72f7..af63902 100644 --- a/server/routers/matchRouter.js +++ b/server/routers/matchRouter.js @@ -13,5 +13,23 @@ router.get('/', (req, res) => { .catch(err => res.status(400).json('Error: '+err)) }) +router.get('/editfixture/:id', (req, res) => { + Match.findById(req.params.id) + .then(matches => res.json(matches)) + .catch(err => res.json('Error: +err')) +}) + +router.delete("/editfixture/:id", async (req,res) => { + Match.findByIdAndDelete(req.params.id).then(() => res.json('Match deleted')) + .catch((err=>res.status(400).json("Error: "+err))) +}) + +//update user +router.put("/editfixture/:id", async(req,res)=>{ + Match.findByIdAndUpdate(req.params.id,{$set:req.body}) + .then(() => res.json('Match updated')) + .catch(err=>res.status(400).json('Error: '+err)) +}) + export default router; \ No newline at end of file