feat(insc): add frontend
This commit is contained in:
parent
df33d49cff
commit
3f1fddccd1
@ -1,6 +1,7 @@
|
||||
package fr.titionfire.ffsaf.data.model;
|
||||
|
||||
import fr.titionfire.ffsaf.utils.CompetitionSystem;
|
||||
import fr.titionfire.ffsaf.utils.RegisterEmbeddable;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -37,12 +38,9 @@ public class CompetitionModel {
|
||||
|
||||
Date date;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name = "register",
|
||||
uniqueConstraints = @UniqueConstraint(columnNames = {"id_competition", "id_membre"}),
|
||||
joinColumns = @JoinColumn(name = "id_competition"),
|
||||
inverseJoinColumns = @JoinColumn(name = "id_membre"))
|
||||
List<MembreModel> insc;
|
||||
@ElementCollection(fetch = FetchType.LAZY)
|
||||
@CollectionTable(name = "register", joinColumns = @JoinColumn(name = "id_competition"))
|
||||
List<RegisterEmbeddable> insc;
|
||||
|
||||
String owner;
|
||||
}
|
||||
|
||||
@ -1,26 +1,31 @@
|
||||
package fr.titionfire.ffsaf.domain.service;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.CompetitionModel;
|
||||
import fr.titionfire.ffsaf.data.repository.ClubRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.CompetitionRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.MatchRepository;
|
||||
import fr.titionfire.ffsaf.data.repository.PouleRepository;
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import fr.titionfire.ffsaf.data.repository.*;
|
||||
import fr.titionfire.ffsaf.net2.ServerCustom;
|
||||
import fr.titionfire.ffsaf.net2.data.SimpleCompet;
|
||||
import fr.titionfire.ffsaf.net2.request.SReqCompet;
|
||||
import fr.titionfire.ffsaf.rest.data.CompetitionData;
|
||||
import fr.titionfire.ffsaf.rest.data.RegisterRequestData;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleCompetData;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleRegisterComb;
|
||||
import fr.titionfire.ffsaf.rest.exception.DBadRequestException;
|
||||
import fr.titionfire.ffsaf.rest.exception.DForbiddenException;
|
||||
import fr.titionfire.ffsaf.utils.CompetitionSystem;
|
||||
import fr.titionfire.ffsaf.utils.RegisterEmbeddable;
|
||||
import fr.titionfire.ffsaf.utils.SecurityCtx;
|
||||
import io.quarkus.cache.Cache;
|
||||
import io.quarkus.cache.CacheName;
|
||||
import io.quarkus.hibernate.reactive.panache.Panache;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||
import io.smallrye.mutiny.Multi;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import io.smallrye.mutiny.unchecked.Unchecked;
|
||||
import io.vertx.mutiny.core.Vertx;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.hibernate.reactive.mutiny.Mutiny;
|
||||
import org.keycloak.representations.idm.UserRepresentation;
|
||||
|
||||
import java.util.*;
|
||||
@ -42,6 +47,9 @@ public class CompetitionService {
|
||||
@Inject
|
||||
KeycloakService keycloakService;
|
||||
|
||||
@Inject
|
||||
CombRepository combRepository;
|
||||
|
||||
@Inject
|
||||
ServerCustom serverCustom;
|
||||
|
||||
@ -51,6 +59,14 @@ public class CompetitionService {
|
||||
@Inject
|
||||
Vertx vertx;
|
||||
|
||||
@Inject
|
||||
@CacheName("safca-config")
|
||||
Cache cache;
|
||||
|
||||
@Inject
|
||||
@CacheName("safca-have-access")
|
||||
Cache cacheAccess;
|
||||
|
||||
public Uni<CompetitionData> getById(SecurityCtx securityCtx, Long id) {
|
||||
if (id == 0) {
|
||||
return Uni.createFrom()
|
||||
@ -138,7 +154,7 @@ public class CompetitionService {
|
||||
|
||||
return Panache.withTransaction(() -> repository.persist(model));
|
||||
}).map(CompetitionData::fromModel)
|
||||
.call(__ -> permService.cacheAccess.invalidate(securityCtx.getSubject()));
|
||||
.call(__ -> cacheAccess.invalidate(securityCtx.getSubject()));
|
||||
} else {
|
||||
return permService.hasEditPerm(securityCtx, data.getId())
|
||||
.chain(model -> {
|
||||
@ -160,10 +176,71 @@ public class CompetitionService {
|
||||
}))
|
||||
.chain(__ -> Panache.withTransaction(() -> repository.persist(model)));
|
||||
}).map(CompetitionData::fromModel)
|
||||
.call(__ -> permService.cacheAccess.invalidate(securityCtx.getSubject()));
|
||||
.call(__ -> cacheAccess.invalidate(securityCtx.getSubject()));
|
||||
}
|
||||
}
|
||||
|
||||
public Uni<List<SimpleRegisterComb>> getRegister(SecurityCtx securityCtx, Long id) {
|
||||
return permService.hasEditPerm(securityCtx, id)
|
||||
.chain(c -> Mutiny.fetch(c.getInsc()))
|
||||
.onItem().transformToMulti(Multi.createFrom()::iterable)
|
||||
.onItem().call(combModel -> Mutiny.fetch(combModel.getMembre().getLicences()))
|
||||
.map(combModel -> SimpleRegisterComb.fromModel(combModel, combModel.getMembre().getLicences()))
|
||||
.collect().asList();
|
||||
}
|
||||
|
||||
public Uni<SimpleRegisterComb> addRegisterComb(SecurityCtx securityCtx, Long id, RegisterRequestData data) {
|
||||
return permService.hasEditPerm(securityCtx, id)
|
||||
.chain(c -> findComb(data.getLicence(), data.getFname(), data.getLname())
|
||||
.chain(combModel -> Mutiny.fetch(c.getInsc())
|
||||
.chain(Unchecked.function(insc -> {
|
||||
Optional<RegisterEmbeddable> opt = insc.stream()
|
||||
.filter(m -> m.getMembre().equals(combModel)).findAny();
|
||||
|
||||
RegisterEmbeddable r;
|
||||
if (opt.isPresent()) {
|
||||
r = opt.get();
|
||||
r.setWeight(data.getWeight());
|
||||
r.setOverCategory(data.getOverCategory());
|
||||
} else {
|
||||
r = new RegisterEmbeddable(combModel, data.getWeight(), data.getOverCategory());
|
||||
insc.add(r);
|
||||
}
|
||||
return Panache.withTransaction(() -> repository.persist(c)).map(__ -> r);
|
||||
}))))
|
||||
.chain(r -> Mutiny.fetch(r.getMembre().getLicences())
|
||||
.map(licences -> SimpleRegisterComb.fromModel(r, licences)));
|
||||
}
|
||||
|
||||
private Uni<MembreModel> findComb(Long licence, String fname, String lname) {
|
||||
if (licence != null && licence != 0) {
|
||||
return combRepository.find("licence = ?1", licence).firstResult()
|
||||
.invoke(Unchecked.consumer(combModel -> {
|
||||
if (combModel == null)
|
||||
throw new DForbiddenException("Licence " + licence + " non trouvé");
|
||||
}));
|
||||
} else {
|
||||
if (fname == null || lname == null)
|
||||
return Uni.createFrom().failure(new DBadRequestException("Nom et prénom requis"));
|
||||
return combRepository.find("LOWER(lname) LIKE LOWER(?1) OR LOWER(fname) LIKE LOWER(?2)", lname,
|
||||
fname).firstResult()
|
||||
.invoke(Unchecked.consumer(combModel -> {
|
||||
if (combModel == null)
|
||||
throw new DForbiddenException("Combattant " + fname + " " + lname + " non trouvé");
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public Uni<Void> removeRegisterComb(SecurityCtx securityCtx, Long id, Long combId) {
|
||||
return permService.hasEditPerm(securityCtx, id)
|
||||
.chain(c -> Mutiny.fetch(c.getInsc())
|
||||
.chain(Unchecked.function(insc -> {
|
||||
if (insc.removeIf(m -> m.getMembre().getId().equals(combId)))
|
||||
return Panache.withTransaction(() -> repository.persist(c)).map(__ -> null);
|
||||
throw new DBadRequestException("Combattant non inscrit");
|
||||
})));
|
||||
}
|
||||
|
||||
public Uni<?> delete(SecurityCtx securityCtx, Long id) {
|
||||
return repository.findById(id).invoke(Unchecked.consumer(c -> {
|
||||
if (!securityCtx.getSubject().equals(c.getOwner()) || securityCtx.roleHas("federation_admin"))
|
||||
@ -180,7 +257,7 @@ public class CompetitionService {
|
||||
() -> pouleRepository.delete("compet = ?1", competitionModel)))
|
||||
.chain(model -> Panache.withTransaction(() -> repository.delete("id", model.getId())))
|
||||
.invoke(o -> SReqCompet.rmCompet(serverCustom.clients, id))
|
||||
.call(__ -> permService.cache.invalidate(id));
|
||||
.call(__ -> cache.invalidate(id));
|
||||
}
|
||||
|
||||
public Uni<SimpleCompetData> getSafcaData(SecurityCtx securityCtx, Long id) {
|
||||
@ -234,15 +311,20 @@ public class CompetitionService {
|
||||
}))
|
||||
.invoke(simpleCompet -> SReqCompet.sendUpdate(serverCustom.clients, simpleCompet))
|
||||
.call(simpleCompet -> permService.getSafcaConfig(data.getId())
|
||||
.call(c -> Uni.join().all(Stream.concat(
|
||||
Stream.concat(
|
||||
c.admin().stream().filter(uuid -> !simpleCompet.admin().contains(uuid)),
|
||||
simpleCompet.admin().stream().filter(uuid -> !c.admin().contains(uuid))),
|
||||
Stream.concat(
|
||||
c.table().stream().filter(uuid -> !simpleCompet.table().contains(uuid)),
|
||||
simpleCompet.table().stream().filter(uuid -> !c.table().contains(uuid))))
|
||||
.map(uuid -> permService.cacheAccess.invalidate(uuid.toString())).toList())
|
||||
.andCollectFailures()))
|
||||
.call(__ -> permService.cache.invalidate(data.getId()));
|
||||
.call(c -> {
|
||||
List<Uni<Void>> list = Stream.concat(
|
||||
Stream.concat(
|
||||
c.admin().stream().filter(uuid -> !simpleCompet.admin().contains(uuid)),
|
||||
simpleCompet.admin().stream().filter(uuid -> !c.admin().contains(uuid))),
|
||||
Stream.concat(
|
||||
c.table().stream().filter(uuid -> !simpleCompet.table().contains(uuid)),
|
||||
simpleCompet.table().stream().filter(uuid -> !c.table().contains(uuid)))
|
||||
).map(uuid -> cacheAccess.invalidate(uuid.toString())).toList();
|
||||
|
||||
if (list.isEmpty())
|
||||
return Uni.createFrom().nullItem();
|
||||
return Uni.join().all(list).andCollectFailures();
|
||||
}))
|
||||
.call(__ -> cache.invalidate(data.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,9 @@ package fr.titionfire.ffsaf.rest;
|
||||
|
||||
import fr.titionfire.ffsaf.domain.service.CompetitionService;
|
||||
import fr.titionfire.ffsaf.rest.data.CompetitionData;
|
||||
import fr.titionfire.ffsaf.rest.data.RegisterRequestData;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleCompetData;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleRegisterComb;
|
||||
import fr.titionfire.ffsaf.utils.CompetitionSystem;
|
||||
import fr.titionfire.ffsaf.utils.SecurityCtx;
|
||||
import io.quarkus.security.Authenticated;
|
||||
@ -10,6 +12,7 @@ import io.smallrye.mutiny.Uni;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import org.eclipse.microprofile.openapi.annotations.Operation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -30,6 +33,32 @@ public class CompetitionEndpoints {
|
||||
return service.getById(securityCtx, id);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}/register")
|
||||
@Authenticated
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Uni<List<SimpleRegisterComb>> getRegister(@PathParam("id") Long id) {
|
||||
return service.getRegister(securityCtx, id);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("{id}/register")
|
||||
@Authenticated
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Operation(hidden = true)
|
||||
public Uni<SimpleRegisterComb> addRegisterComb(@PathParam("id") Long id, RegisterRequestData data) {
|
||||
return service.addRegisterComb(securityCtx, id, data);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{id}/register/{comb_id}")
|
||||
@Authenticated
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Operation(hidden = true)
|
||||
public Uni<Void> removeRegisterComb(@PathParam("id") Long id, @PathParam("comb_id") Long combId) {
|
||||
return service.removeRegisterComb(securityCtx, id, combId);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}/safcaData")
|
||||
@Authenticated
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
package fr.titionfire.ffsaf.rest.data;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@RegisterForReflection
|
||||
public class RegisterRequestData {
|
||||
private Long licence;
|
||||
private String fname;
|
||||
private String lname;
|
||||
|
||||
private Integer weight;
|
||||
private int overCategory;
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package fr.titionfire.ffsaf.rest.data;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.LicenceModel;
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import fr.titionfire.ffsaf.net2.data.SimpleClubModel;
|
||||
import fr.titionfire.ffsaf.utils.RegisterEmbeddable;
|
||||
import fr.titionfire.ffsaf.utils.Utils;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@RegisterForReflection
|
||||
public class SimpleRegisterComb {
|
||||
private long id;
|
||||
private String fname;
|
||||
private String lname;
|
||||
private String categorie;
|
||||
private SimpleClubModel club;
|
||||
private Integer licence;
|
||||
private Integer weight;
|
||||
private int overCategory;
|
||||
private boolean hasLicenceActive;
|
||||
|
||||
public static SimpleRegisterComb fromModel(RegisterEmbeddable register, List<LicenceModel> licences) {
|
||||
MembreModel membreModel = register.getMembre();
|
||||
return new SimpleRegisterComb(membreModel.getId(), membreModel.getFname(), membreModel.getLname(),
|
||||
(membreModel.getCategorie() == null) ? "Catégorie inconnue" : membreModel.getCategorie().getName(),
|
||||
SimpleClubModel.fromModel(membreModel.getClub()), membreModel.getLicence(), register.getWeight(),
|
||||
register.getOverCategory(),
|
||||
licences.stream().anyMatch(l -> l.isValidate() && l.getSaison() == Utils.getSaison()));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package fr.titionfire.ffsaf.utils;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import jakarta.persistence.Embeddable;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@RegisterForReflection
|
||||
|
||||
@Embeddable
|
||||
public class RegisterEmbeddable {
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "id_membre")
|
||||
MembreModel membre;
|
||||
|
||||
Integer weight;
|
||||
int overCategory = 0;
|
||||
}
|
||||
@ -43,8 +43,12 @@ export function CompetitionEdit() {
|
||||
<div>
|
||||
{data
|
||||
? <div className="">
|
||||
|
||||
<Content data={data} refresh={refresh}/>
|
||||
|
||||
{data.id !== null && <button style={{marginBottom: "1.5em", width: "100%"}} className="btn btn-primary"
|
||||
onClick={_ => navigate(`/competition/${data.id}/register`)}>Voir/Modifier les participants</button>}
|
||||
|
||||
{data.id !== null && <ContentSAFCA data2={data}/>}
|
||||
|
||||
{data.id !== null && <>
|
||||
@ -74,14 +78,14 @@ function ContentSAFCA({data2}) {
|
||||
useEffect(() => {
|
||||
if (data === null)
|
||||
return
|
||||
if (data.admin !== null){
|
||||
if (data.admin !== null) {
|
||||
let index = 0
|
||||
for (const d of data.admin) {
|
||||
dispatch({type: 'UPDATE_OR_ADD', payload: {id: index, data: d}})
|
||||
index++
|
||||
}
|
||||
}
|
||||
if (data.table !== null){
|
||||
if (data.table !== null) {
|
||||
let index = 0
|
||||
for (const d of data.table) {
|
||||
dispatch2({type: 'UPDATE_OR_ADD', payload: {id: index, data: d}})
|
||||
@ -232,7 +236,8 @@ function Content({data}) {
|
||||
},
|
||||
}
|
||||
).then(data => {
|
||||
navigate("/competition/" + data.id)
|
||||
if (data.id !== undefined)
|
||||
navigate("/competition/" + data.id)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,289 @@
|
||||
import {useNavigate, useParams} from "react-router-dom";
|
||||
import {useLoadingSwitcher} from "../../hooks/useLoading.jsx";
|
||||
import {useFetch} from "../../hooks/useFetch.js";
|
||||
import {AxiosError} from "../../components/AxiosError.jsx";
|
||||
import {ThreeDots} from "react-loader-spinner";
|
||||
import {useEffect, useReducer, useState} from "react";
|
||||
import {apiAxios} from "../../utils/Tools.js";
|
||||
import {toast} from "react-toastify";
|
||||
import {SimpleReducer} from "../../utils/SimpleReducer.jsx";
|
||||
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
||||
import {faTrashCan} from "@fortawesome/free-solid-svg-icons";
|
||||
|
||||
export function CompetitionRegisterAdmin() {
|
||||
const {id} = useParams()
|
||||
const navigate = useNavigate()
|
||||
const [state, dispatch] = useReducer(SimpleReducer, [])
|
||||
const [clubFilter, setClubFilter] = useState("")
|
||||
const [catFilter, setCatFilter] = useState("")
|
||||
const [modalState, setModalState] = useState({})
|
||||
|
||||
const setLoading = useLoadingSwitcher()
|
||||
const {data, error} = useFetch(`/competition/${id}/register`, setLoading, 1)
|
||||
|
||||
useEffect(() => {
|
||||
if (!data)
|
||||
return;
|
||||
data.forEach((d, index) => {
|
||||
dispatch({type: 'UPDATE_OR_ADD', payload: {id: index, data: d}})
|
||||
})
|
||||
}, [data, clubFilter, catFilter]);
|
||||
|
||||
const sendRegister = (event, new_state) => {
|
||||
event.preventDefault();
|
||||
|
||||
console.log(new_state)
|
||||
|
||||
toast.promise(apiAxios.post(`/competition/${id}/register`, new_state), {
|
||||
pending: "Recherche en cours",
|
||||
success: "Combattant trouvé et ajouté/mis à jour",
|
||||
error: {
|
||||
render({data}) {
|
||||
return data.response.data || "Combattant non trouvé"
|
||||
}
|
||||
}
|
||||
}).then((response) => {
|
||||
if (response.data.error) {
|
||||
return
|
||||
}
|
||||
|
||||
let maxId = 0;
|
||||
if (new_state.id) {
|
||||
maxId = new_state.id - 1
|
||||
} else {
|
||||
state.forEach((d) => {
|
||||
if (d.id > maxId)
|
||||
maxId = d.id;
|
||||
})
|
||||
}
|
||||
dispatch({type: 'UPDATE_OR_ADD', payload: {id: maxId + 1, data: response.data}})
|
||||
document.getElementById("closeModal").click();
|
||||
})
|
||||
}
|
||||
|
||||
return <div>
|
||||
<h2>Combattants inscrits</h2>
|
||||
<button type="button" className="btn btn-link" onClick={() => navigate("/competition/" + id)}>
|
||||
« retour
|
||||
</button>
|
||||
|
||||
<div className="row">
|
||||
<div className="col-lg-9">
|
||||
{data
|
||||
? <div className="">
|
||||
<MakeCentralPanel
|
||||
data={state.filter(s => (clubFilter.length === 0 || s.data.club.name === clubFilter) && (catFilter.length === 0 || s.data.categorie === catFilter))}
|
||||
dispatch={dispatch} id={id} setModalState={setModalState}/>
|
||||
</div>
|
||||
: error
|
||||
? <AxiosError error={error}/>
|
||||
: <Def/>
|
||||
}
|
||||
</div>
|
||||
<div className="col-lg-3">
|
||||
<div className="mb-4">
|
||||
<button type="button" className="btn btn-primary" data-bs-toggle="modal" data-bs-target="#registerModal"
|
||||
onClick={() => setModalState({})}>Ajouter un combattant
|
||||
</button>
|
||||
</div>
|
||||
<div className="card mb-4">
|
||||
<div className="card-header">Filtre</div>
|
||||
<div className="card-body">
|
||||
<FiltreBar data={data} clubFilter={clubFilter} setClubFilter={setClubFilter} catFilter={catFilter}
|
||||
setCatFilter={setCatFilter}/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Modal sendRegister={sendRegister} modalState={modalState} setModalState={setModalState}/>
|
||||
</div>
|
||||
}
|
||||
|
||||
function Modal({sendRegister, modalState, setModalState}) {
|
||||
const [licence, setLicence] = useState("")
|
||||
const [fname, setFname] = useState("")
|
||||
const [lname, setLname] = useState("")
|
||||
const [weight, setWeight] = useState("")
|
||||
const [cat, setCat] = useState(0)
|
||||
const [editMode, setEditMode] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (!modalState) {
|
||||
setLicence("")
|
||||
setFname("")
|
||||
setLname("")
|
||||
setWeight("")
|
||||
setCat(0)
|
||||
setEditMode(false)
|
||||
} else {
|
||||
setLicence(modalState.licence ? modalState.licence : "")
|
||||
setFname(modalState.fname ? modalState.fname : "")
|
||||
setLname(modalState.lname ? modalState.lname : "")
|
||||
setWeight(modalState.weight ? modalState.weight : "")
|
||||
setCat(modalState.overCategory ? modalState.overCategory : 0)
|
||||
setEditMode(modalState.licence || (modalState.fname && modalState.lname))
|
||||
}
|
||||
}, [modalState]);
|
||||
|
||||
return <div className="modal fade" id="registerModal" tabIndex="-1" aria-labelledby="registerLabel"
|
||||
aria-hidden="true">
|
||||
<div className="modal-dialog">
|
||||
<div className="modal-content">
|
||||
<form onSubmit={e => {
|
||||
const new_state = {
|
||||
licence: licence,
|
||||
fname: fname,
|
||||
lname: lname,
|
||||
weight: weight,
|
||||
overCategory: cat,
|
||||
id: modalState.id
|
||||
}
|
||||
setModalState(new_state)
|
||||
sendRegister(e, new_state)
|
||||
}}>
|
||||
<div className="modal-header">
|
||||
<h1 className="modal-title fs-5" id="registerLabel">Ajouter un combattant</h1>
|
||||
<button type="button" className="btn-close" data-bs-dismiss="modal"
|
||||
aria-label="Close"></button>
|
||||
</div>
|
||||
<div className="modal-body">
|
||||
<div className="card" style={{marginBottom: "1em"}}>
|
||||
<div className="card-header">Recherche*</div>
|
||||
<div className="card-body">
|
||||
<div className="row">
|
||||
<div className="col">
|
||||
<input type="number" min={0} step={1} className="form-control" placeholder="N° de licence" name="licence"
|
||||
value={licence} onChange={e => setLicence(e.target.value)} disabled={editMode}/>
|
||||
</div>
|
||||
</div>
|
||||
<h5 style={{textAlign: "center", marginTop: "0.25em"}}>Ou</h5>
|
||||
<div className="row">
|
||||
<div className="col">
|
||||
<input type="text" className="form-control" placeholder="Prénom" name="fname" disabled={editMode}
|
||||
value={fname} onChange={e => setFname(e.target.value)}/>
|
||||
</div>
|
||||
<div className="col">
|
||||
<input type="text" className="form-control" placeholder="Nom" name="lname" disabled={editMode}
|
||||
value={lname} onChange={e => setLname(e.target.value)}/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="input-group mb-3">
|
||||
<span className="input-group-text" id="weight">Poids (en kg)</span>
|
||||
<input type="number" min={1} step={1} className="form-control" placeholder="42" aria-label="weight"
|
||||
name="weight" aria-describedby="weight" value={weight} onChange={e => setWeight(e.target.value)}/>
|
||||
</div>
|
||||
|
||||
<div className="input-group mb-3">
|
||||
<span className="input-group-text" id="categorie">Surclassement</span>
|
||||
<select className="form-select" aria-label="categorie" name="categorie" value={cat}
|
||||
onChange={e => setCat(Number(e.target.value))}>
|
||||
<option value={0}>Aucun</option>
|
||||
<option value={1}>+1 catégorie</option>
|
||||
<option value={2}>+2 catégorie</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div className="modal-footer">
|
||||
<button type="submit" className="btn btn-primary">Ajouter</button>
|
||||
<button type="reset" className="btn btn-secondary" data-bs-dismiss="modal" id="closeModal">Annuler</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
let allClub = []
|
||||
let allCat = []
|
||||
|
||||
function FiltreBar({data, clubFilter, setClubFilter, catFilter, setCatFilter}) {
|
||||
useEffect(() => {
|
||||
if (!data)
|
||||
return;
|
||||
allClub.push(...data.map((e) => e.club?.name))
|
||||
allClub = allClub.filter((value, index, self) => self.indexOf(value) === index).filter(value => value != null).sort()
|
||||
allCat.push(...data.map((e) => e.categorie))
|
||||
allCat = allCat.filter((value, index, self) => self.indexOf(value) === index).filter(value => value != null).sort()
|
||||
}, [data]);
|
||||
|
||||
return <div>
|
||||
<div className="mb-3">
|
||||
<select className="form-select" value={clubFilter} onChange={event => setClubFilter(event.target.value)}>
|
||||
<option value="">--- tout les clubs ---</option>
|
||||
{allClub && allClub.map((value, index) => {
|
||||
return <option key={index} value={value}>{value}</option>
|
||||
})
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<select className="form-select" value={catFilter} onChange={event => setCatFilter(event.target.value)}>
|
||||
<option value="">--- toute les catégories ---</option>
|
||||
{allCat && allCat.map((value, index) => {
|
||||
return <option key={index} value={value}>{value}</option>
|
||||
})
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
function MakeCentralPanel({data, dispatch, id, setModalState}) {
|
||||
return <>
|
||||
<div className="mb-4">
|
||||
<div className="list-group">
|
||||
{data.map((req, index) => (
|
||||
<div key={index} className="list-group-item d-flex justify-content-between align-items-start list-group-item-action"
|
||||
data-bs-toggle="modal" data-bs-target="#registerModal" onClick={() => setModalState({...req.data, id: req.id})}>
|
||||
<div className="row">
|
||||
<span className="col-auto">{req.data.licence ? String(req.data.licence).padStart(5, '0') : "-------"}</span>
|
||||
<div className="ms-2 col-auto">
|
||||
<div className="fw-bold">{req.data.fname} {req.data.lname}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="row">
|
||||
<div className="col-auto" style={{textAlign: "right"}}>
|
||||
<small>{req.data.club?.name || "Sans club"}<br/>{req.data.categorie}</small>
|
||||
</div>
|
||||
<div className="col-auto">
|
||||
<button className="btn btn-danger" type="button"
|
||||
onClick={e => {
|
||||
e.preventDefault()
|
||||
toast.promise(apiAxios.delete(`/competition/${id}/register/${req.data.id}`), {
|
||||
pending: "Désinscription en cours",
|
||||
success: "Combattant désinscrit",
|
||||
error: {
|
||||
render({data}) {
|
||||
return data.response.data || "Erreur"
|
||||
}
|
||||
}
|
||||
}).finally(() => {
|
||||
dispatch({type: 'REMOVE', payload: req.id})
|
||||
setTimeout(() => document.getElementById("closeModal").click(), 500);
|
||||
})
|
||||
}
|
||||
}>
|
||||
<FontAwesomeIcon icon={faTrashCan}/>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
|
||||
function Def() {
|
||||
return <div className="list-group">
|
||||
<li className="list-group-item"><ThreeDots/></li>
|
||||
<li className="list-group-item"><ThreeDots/></li>
|
||||
<li className="list-group-item"><ThreeDots/></li>
|
||||
<li className="list-group-item"><ThreeDots/></li>
|
||||
<li className="list-group-item"><ThreeDots/></li>
|
||||
</div>
|
||||
}
|
||||
@ -2,6 +2,7 @@ import {LoadingProvider} from "../../hooks/useLoading.jsx";
|
||||
import {Outlet} from "react-router-dom";
|
||||
import {CompetitionList} from "./CompetitionList.jsx";
|
||||
import {CompetitionEdit} from "./CompetitionEdit.jsx";
|
||||
import {CompetitionRegisterAdmin} from "./CompetitionRegisterAdmin.jsx";
|
||||
|
||||
export function CompetitionRoot() {
|
||||
return <>
|
||||
@ -21,6 +22,10 @@ export function getCompetitionChildren() {
|
||||
{
|
||||
path: ':id',
|
||||
element: <CompetitionEdit/>
|
||||
},
|
||||
{
|
||||
path: ':id/register',
|
||||
element: <CompetitionRegisterAdmin/>
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user