|
|
@ -1,32 +1,32 @@
|
|
|
|
import {FormEvent, useState} from "react"
|
|
|
|
import {FormEvent, useState} from "react"
|
|
|
|
import { fetchAPI } from "../Fetcher.ts"
|
|
|
|
|
|
|
|
import { Failure } from "../api/failure.ts"
|
|
|
|
|
|
|
|
import "../style/form.css"
|
|
|
|
import "../style/form.css"
|
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
import { useNavigate } from "react-router-dom"
|
|
|
|
import {useNavigate, useParams} from "react-router-dom"
|
|
|
|
import {useAppFetcher} from "../App.tsx";
|
|
|
|
import {useAppFetcher} from "../App.tsx";
|
|
|
|
|
|
|
|
import {Failure} from "../app/Failure.ts";
|
|
|
|
export default function AddMemberPage() {
|
|
|
|
export default function AddMemberPage() {
|
|
|
|
|
|
|
|
|
|
|
|
const [errors, setErrors] = useState<Failure[]>([])
|
|
|
|
const [errors, setErrors] = useState<Failure[]>([])
|
|
|
|
const fetcher = useAppFetcher()
|
|
|
|
const fetcher = useAppFetcher()
|
|
|
|
const navigate = useNavigate()
|
|
|
|
const navigate = useNavigate()
|
|
|
|
|
|
|
|
const { teamId } = useParams()
|
|
|
|
|
|
|
|
|
|
|
|
async function handleSubmit(e : FormEvent){
|
|
|
|
async function handleSubmit(e : FormEvent){
|
|
|
|
e.preventDefault()
|
|
|
|
e.preventDefault()
|
|
|
|
|
|
|
|
|
|
|
|
const { name, mainColor,secondColor,picture } = Object.fromEntries(
|
|
|
|
const { email,role} = Object.fromEntries(
|
|
|
|
new FormData(e.target as HTMLFormElement),
|
|
|
|
new FormData(e.target as HTMLFormElement),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
console.log(email,role)
|
|
|
|
const response = await fetcher.fetchAPI(
|
|
|
|
const response = await fetcher.fetchAPI(
|
|
|
|
"teams",
|
|
|
|
"teams/"+teamId+"/members",
|
|
|
|
{name,mainColor,secondColor,picture},
|
|
|
|
{email,role},
|
|
|
|
"POST"
|
|
|
|
"POST"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if(response.ok){
|
|
|
|
if(response.ok){
|
|
|
|
const teamId = await response.json()
|
|
|
|
const teamId = await response.json()
|
|
|
|
navigate("/team/"+teamId+"/members")
|
|
|
|
navigate("/team/"+teamId)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -51,7 +51,7 @@ export default function AddMemberPage() {
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className="container">
|
|
|
|
<div className="container">
|
|
|
|
<h2>Créer une équipe</h2>
|
|
|
|
<h2>Ajouter un membre à votre équipe</h2>
|
|
|
|
|
|
|
|
|
|
|
|
{errors.map(({ type, messages }) =>
|
|
|
|
{errors.map(({ type, messages }) =>
|
|
|
|
messages.map((message) => (
|
|
|
|
messages.map((message) => (
|
|
|
@ -63,46 +63,28 @@ export default function AddMemberPage() {
|
|
|
|
|
|
|
|
|
|
|
|
<form onSubmit={handleSubmit}>
|
|
|
|
<form onSubmit={handleSubmit}>
|
|
|
|
<div className="form-group">
|
|
|
|
<div className="form-group">
|
|
|
|
<label htmlFor="name">Nom de l'équipe :</label>
|
|
|
|
<label htmlFor="email">Email du membre :</label>
|
|
|
|
<input
|
|
|
|
<input type="text" id="email" name="email" required/>
|
|
|
|
className="text-input"
|
|
|
|
|
|
|
|
type="text"
|
|
|
|
<fieldset className="role">
|
|
|
|
id="email"
|
|
|
|
<legend>Rôle du membre dans l'équipe :</legend>
|
|
|
|
name="email"
|
|
|
|
<div className="radio">
|
|
|
|
required
|
|
|
|
<label htmlFor="P">Joueur</label>
|
|
|
|
/>
|
|
|
|
<input type="radio" id="P" name="role" value="PLAYER" checked />
|
|
|
|
<label htmlFor="picture">Logo :</label>
|
|
|
|
</div>
|
|
|
|
<input
|
|
|
|
<div className="radio">
|
|
|
|
className="text-input"
|
|
|
|
<label htmlFor="C">Coach</label>
|
|
|
|
type="text"
|
|
|
|
<input type="radio" id="C" name="role" value="COACH" />
|
|
|
|
id="picture"
|
|
|
|
</div>
|
|
|
|
name="picture"
|
|
|
|
</fieldset>
|
|
|
|
required
|
|
|
|
|
|
|
|
/>
|
|
|
|
<div id="buttons">
|
|
|
|
<label htmlFor="mainColor">Couleur principale :</label>
|
|
|
|
<input
|
|
|
|
<input
|
|
|
|
className="button"
|
|
|
|
className="color-input"
|
|
|
|
type="submit"
|
|
|
|
type="color"
|
|
|
|
value="Confirmer"
|
|
|
|
id="main_color"
|
|
|
|
/>
|
|
|
|
name="main_color"
|
|
|
|
</div>
|
|
|
|
value="#ffffff"
|
|
|
|
|
|
|
|
required
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
<label htmlFor="secondColor">Couleur secondaire :</label>
|
|
|
|
|
|
|
|
<input
|
|
|
|
|
|
|
|
className="color-input"
|
|
|
|
|
|
|
|
type="color"
|
|
|
|
|
|
|
|
id="second_color"
|
|
|
|
|
|
|
|
name="second_color"
|
|
|
|
|
|
|
|
required
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
<div id="buttons">
|
|
|
|
|
|
|
|
<input
|
|
|
|
|
|
|
|
className="button"
|
|
|
|
|
|
|
|
type="submit"
|
|
|
|
|
|
|
|
value="Confirmer"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
|
|