|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
import "../style/team_panel.css"
|
|
|
|
|
import {BASE} from "../Constants"
|
|
|
|
|
import {Member, MemberRole, Team, TeamInfo} from "../model/Team"
|
|
|
|
|
import {useNavigate, useParams} from "react-router-dom"
|
|
|
|
|
import {useAppFetcher, useUser} from "../App.tsx";
|
|
|
|
@ -29,7 +28,6 @@ export default function TeamPanelPage() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isCoach = team.members.some(m=>m.user.id === user!.id && m.role === MemberRole.COACH)
|
|
|
|
|
console.log(isCoach,team,user)
|
|
|
|
|
return (
|
|
|
|
|
<TeamPanel
|
|
|
|
|
team={{ info: team.info, members: team.members }}
|
|
|
|
@ -50,14 +48,9 @@ function TeamPanel({
|
|
|
|
|
}) {
|
|
|
|
|
return (
|
|
|
|
|
<div id="main-div">
|
|
|
|
|
<header>
|
|
|
|
|
<h1>
|
|
|
|
|
<a href={BASE + "/"}>IQBall</a>
|
|
|
|
|
</h1>
|
|
|
|
|
</header>
|
|
|
|
|
<TeamDisplay team={team.info} />
|
|
|
|
|
|
|
|
|
|
{isCoach && <CoachOptions id={team.info.id} />}
|
|
|
|
|
{isCoach && <CoachOptions id={team.info.id} userId={currentUserId} />}
|
|
|
|
|
|
|
|
|
|
<MembersDisplay
|
|
|
|
|
members={team.members}
|
|
|
|
@ -94,25 +87,27 @@ function ColorDisplay({ color }: { color: string }) {
|
|
|
|
|
return <div className="square" style={{ backgroundColor: color }} />
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CoachOptions({ id }: { id: number }) {
|
|
|
|
|
function CoachOptions({ id,userId }: { id: number,userId:number }) {
|
|
|
|
|
const navigate = useNavigate()
|
|
|
|
|
const fetcher = useAppFetcher()
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<button
|
|
|
|
|
id="delete"
|
|
|
|
|
onClick={() =>
|
|
|
|
|
confirm("Êtes-vous sûr de supprimer cette équipe?")
|
|
|
|
|
? (window.location.href = `${BASE}/team/${id}/delete`)
|
|
|
|
|
: {}
|
|
|
|
|
onClick={async () => {
|
|
|
|
|
const res = confirm("Êtes-vous sûr de supprimer cette équipe?")
|
|
|
|
|
if (res) {
|
|
|
|
|
await fetcher.fetchAPI(
|
|
|
|
|
"team/" + id + "/members/" + userId,
|
|
|
|
|
{},
|
|
|
|
|
"DELETE"
|
|
|
|
|
)
|
|
|
|
|
navigate("/")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}>
|
|
|
|
|
Supprimer
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
id="edit"
|
|
|
|
|
onClick={() =>
|
|
|
|
|
(window.location.href = `${BASE}/team/${id}/edit`)
|
|
|
|
|
}>
|
|
|
|
|
Modifier
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
@ -145,7 +140,7 @@ function MembersDisplay({
|
|
|
|
|
<button
|
|
|
|
|
id="add-member"
|
|
|
|
|
onClick={() =>
|
|
|
|
|
navigate("team/"+idTeam+"addMember")
|
|
|
|
|
navigate("/team/"+idTeam+"/addMember")
|
|
|
|
|
}>
|
|
|
|
|
+
|
|
|
|
|
</button>
|
|
|
|
@ -167,6 +162,9 @@ function MemberDisplay({
|
|
|
|
|
idTeam: number
|
|
|
|
|
currentUserId: number
|
|
|
|
|
}) {
|
|
|
|
|
const fetcher = useAppFetcher()
|
|
|
|
|
const navigate = useNavigate()
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="member">
|
|
|
|
|
<img
|
|
|
|
@ -181,10 +179,13 @@ function MemberDisplay({
|
|
|
|
|
<button
|
|
|
|
|
id="delete"
|
|
|
|
|
onClick={() =>
|
|
|
|
|
confirm(
|
|
|
|
|
"Êtes-vous sûr de retirer ce membre de l'équipe?",
|
|
|
|
|
)
|
|
|
|
|
? (window.location.href = `${BASE}/team/${idTeam}/remove/${member.user.id}`)
|
|
|
|
|
confirm("Êtes-vous sûr de quitter cette équipe?")
|
|
|
|
|
? (fetcher.fetchAPI(
|
|
|
|
|
"team/"+idTeam+"/members/"+member.user.id,
|
|
|
|
|
{},
|
|
|
|
|
"DELETE"
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
: {}
|
|
|
|
|
}>
|
|
|
|
|
Retirer
|
|
|
|
@ -193,10 +194,20 @@ function MemberDisplay({
|
|
|
|
|
{isCoach && currentUserId == member.user.id && (
|
|
|
|
|
<button
|
|
|
|
|
id="delete"
|
|
|
|
|
onClick={() =>
|
|
|
|
|
confirm("Êtes-vous sûr de quitter cette équipe?")
|
|
|
|
|
? (window.location.href = `${BASE}/team/${idTeam}/remove/${member.user.id}`)
|
|
|
|
|
: {}
|
|
|
|
|
onClick={async () => {
|
|
|
|
|
|
|
|
|
|
const res = confirm(
|
|
|
|
|
"Êtes-vous sûr de retirer ce membre de l'équipe?"
|
|
|
|
|
)
|
|
|
|
|
if (res) {
|
|
|
|
|
await fetcher.fetchAPI(
|
|
|
|
|
"team/" + idTeam + "/members/" + member.user.id,
|
|
|
|
|
{},
|
|
|
|
|
"DELETE"
|
|
|
|
|
)
|
|
|
|
|
navigate("/")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}>
|
|
|
|
|
Quitter
|
|
|
|
|
</button>
|
|
|
|
|