Skip to content

Commit

Permalink
tournament details connect
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislawMalinski committed May 29, 2024
1 parent 1b7acae commit bbb14fc
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions src/Tournaments/TournamentDetails.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,53 @@
import './TournamentDetails.scss'
import { getListOfTournaments } from './getListOfTournaments';
import { TournamentService } from '../services/TournamentService';
import { useParams } from 'react-router-dom';
import { useEffect, useState } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
import { login, logout } from '../User/store';
function TournamentDetails({isAuthenticated, user, login, logout }) {

const { tournamentId } = useParams();
const tournament = getListOfTournaments().find(t => t.id === parseInt(tournamentId));
const [tournament, setTournament] = useState(null);

if (!tournament) {
return <div>Tournament not found</div>;
}

useEffect(() => {
TournamentService.getTournament(tournamentId)
.then((response) => {
setTournament(response.data.data);
console.log(response.data.data);
})
.catch((error) => {
console.error(error);
});
}, [tournamentId]);

console.log(tournamentId)
// alert(tournament)

return (
<div className="tournamentWrapper">
return (<>{(!tournament || Object.keys(tournament).length === 0) ? <div>Tournament not found</div> :
(<div className="tournamentWrapper">
<p>Szczegóły Turnieju</p>
<div className="tournamentDetails">
<div className="details">
<p>Nazwa: {tournament.name}</p>
<p>Liczba uczestników: {tournament.participantsAmount}</p>
<p>Max liczba uczestników: {tournament.maxParticipants}</p>
<p>Data: {tournament.date}</p>
<p>Title: {tournament.tournamentTitle}</p>
<p>Creator: {tournament.creatorName}</p>
<p>Player limit: {tournament.playersLimit}</p>
<p>Planned on: {tournament.tournamentsDate}</p>
<p>Ograniczenia: {tournament.limitations}</p>
<p>Status: {tournament.state}</p>
<p>Status: {tournament.status}</p>
</div>
{/* <img className="tournamentImage" src="" alt=""></img> */}
<div className="tournamentImage"></div>
</div>
<p className="tournamentDescription">Opis: {tournament.description}</p>
<p className="tournamentDescription">Description: {tournament.description}</p>
{isAuthenticated ? (
<button className="btn"><Link to={`/tournaments/edit/${tournament.id}`}>Edit Tournament</Link></button>
) : null}
</div>
</div>)}
</>
);
}

const mapStateToProps = (state) => ({
isAuthenticated: state.isAuthenticated,
user: state.user,
Expand Down

0 comments on commit bbb14fc

Please sign in to comment.