commit
e6cc4cbc96
@ -9,6 +9,7 @@ import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@ -54,6 +55,8 @@ public class CompetitionModel {
|
||||
@OneToMany(mappedBy = "competition", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
|
||||
List<RegisterModel> insc;
|
||||
|
||||
List<Long> banMembre = new ArrayList<>();
|
||||
|
||||
String owner;
|
||||
|
||||
String data1;
|
||||
|
||||
@ -0,0 +1,41 @@
|
||||
package fr.titionfire.ffsaf.data.model;
|
||||
|
||||
import fr.titionfire.ffsaf.data.id.RegisterId;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@RegisterForReflection
|
||||
|
||||
@Entity
|
||||
@Table(name = "helloasso_register")
|
||||
public class HelloAssoRegisterModel {
|
||||
@EmbeddedId
|
||||
RegisterId id;
|
||||
|
||||
@MapsId("competitionId")
|
||||
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "id_competition")
|
||||
CompetitionModel competition;
|
||||
|
||||
@MapsId("membreId")
|
||||
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "id_membre")
|
||||
MembreModel membre;
|
||||
|
||||
Integer orderId;
|
||||
|
||||
public HelloAssoRegisterModel(CompetitionModel competition, MembreModel membre, Integer orderId) {
|
||||
this.id = new RegisterId(competition.getId(), membre.getId());
|
||||
this.competition = competition;
|
||||
this.membre = membre;
|
||||
this.orderId = orderId;
|
||||
}
|
||||
}
|
||||
@ -40,6 +40,9 @@ public class RegisterModel {
|
||||
@JoinColumn(name = "club")
|
||||
ClubModel club = null;
|
||||
|
||||
@Column(nullable = false, columnDefinition = "boolean default false")
|
||||
boolean lockEdit = false;
|
||||
|
||||
public RegisterModel(CompetitionModel competition, MembreModel membre, Integer weight, int overCategory,
|
||||
Categorie categorie, ClubModel club) {
|
||||
this.id = new RegisterId(competition.getId(), membre.getId());
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
package fr.titionfire.ffsaf.data.repository;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.HelloAssoRegisterModel;
|
||||
import io.quarkus.hibernate.reactive.panache.PanacheRepositoryBase;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
|
||||
@ApplicationScoped
|
||||
public class HelloAssoRegisterRepository implements PanacheRepositoryBase<HelloAssoRegisterModel, Long> {
|
||||
}
|
||||
@ -10,10 +10,7 @@ import fr.titionfire.ffsaf.data.repository.CombRepository;
|
||||
import fr.titionfire.ffsaf.net2.ServerCustom;
|
||||
import fr.titionfire.ffsaf.net2.data.SimpleClubModel;
|
||||
import fr.titionfire.ffsaf.net2.request.SReqClub;
|
||||
import fr.titionfire.ffsaf.rest.data.ClubMapData;
|
||||
import fr.titionfire.ffsaf.rest.data.DeskMember;
|
||||
import fr.titionfire.ffsaf.rest.data.RenewAffData;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleClubList;
|
||||
import fr.titionfire.ffsaf.rest.data.*;
|
||||
import fr.titionfire.ffsaf.rest.exception.DBadRequestException;
|
||||
import fr.titionfire.ffsaf.rest.exception.DForbiddenException;
|
||||
import fr.titionfire.ffsaf.rest.exception.DNotFoundException;
|
||||
@ -144,6 +141,19 @@ public class ClubService {
|
||||
.toList());
|
||||
}
|
||||
|
||||
public Uni<List<VerySimpleMembre>> getMembers(SecurityCtx securityCtx) {
|
||||
return combRepository.find("userId = ?1", securityCtx.getSubject()).firstResult()
|
||||
.invoke(Unchecked.consumer(m -> {
|
||||
if (m == null || m.getClub() == null)
|
||||
throw new DNotFoundException("Club non trouvé");
|
||||
if (!securityCtx.isInClubGroup(m.getClub().getId()))
|
||||
throw new DForbiddenException();
|
||||
}))
|
||||
.chain(m -> combRepository.list("club = ?1", m.getClub()))
|
||||
.map(membreModels -> membreModels.stream()
|
||||
.map(m -> new VerySimpleMembre(m.getLname(), m.getFname(), m.getLicence())).toList());
|
||||
}
|
||||
|
||||
public Uni<String> updateOfUser(SecurityCtx securityCtx, PartClubForm form) {
|
||||
TypeReference<HashMap<Contact, String>> typeRef = new TypeReference<>() {
|
||||
};
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package fr.titionfire.ffsaf.domain.service;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.CompetitionModel;
|
||||
import fr.titionfire.ffsaf.data.model.HelloAssoRegisterModel;
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import fr.titionfire.ffsaf.data.model.RegisterModel;
|
||||
import fr.titionfire.ffsaf.data.repository.*;
|
||||
@ -8,6 +9,7 @@ import fr.titionfire.ffsaf.net2.ServerCustom;
|
||||
import fr.titionfire.ffsaf.net2.data.SimpleCompet;
|
||||
import fr.titionfire.ffsaf.net2.request.SReqCompet;
|
||||
import fr.titionfire.ffsaf.net2.request.SReqRegister;
|
||||
import fr.titionfire.ffsaf.rest.client.dto.NotificationData;
|
||||
import fr.titionfire.ffsaf.rest.data.CompetitionData;
|
||||
import fr.titionfire.ffsaf.rest.data.RegisterRequestData;
|
||||
import fr.titionfire.ffsaf.rest.data.SimpleCompetData;
|
||||
@ -22,13 +24,18 @@ 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.quarkus.mailer.Mail;
|
||||
import io.quarkus.mailer.reactive.ReactiveMailer;
|
||||
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 jakarta.ws.rs.NotFoundException;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.hibernate.reactive.mutiny.Mutiny;
|
||||
import org.jboss.logging.Logger;
|
||||
import org.keycloak.representations.idm.UserRepresentation;
|
||||
|
||||
import java.util.*;
|
||||
@ -37,6 +44,7 @@ import java.util.stream.Stream;
|
||||
@WithSession
|
||||
@ApplicationScoped
|
||||
public class CompetitionService {
|
||||
private static final Logger LOGGER = Logger.getLogger(CompetitionService.class);
|
||||
|
||||
@Inject
|
||||
CompetitionRepository repository;
|
||||
@ -59,9 +67,19 @@ public class CompetitionService {
|
||||
@Inject
|
||||
ServerCustom serverCustom;
|
||||
|
||||
@Inject
|
||||
MembreService membreService;
|
||||
|
||||
@Inject
|
||||
CompetPermService permService;
|
||||
|
||||
@Inject
|
||||
HelloAssoRegisterRepository helloAssoRepository;
|
||||
|
||||
@SuppressWarnings("CdiInjectionPointsInspection")
|
||||
@Inject
|
||||
ReactiveMailer reactiveMailer;
|
||||
|
||||
@Inject
|
||||
Vertx vertx;
|
||||
|
||||
@ -196,6 +214,9 @@ public class CompetitionService {
|
||||
}
|
||||
|
||||
private void copyData(CompetitionData data, CompetitionModel model) {
|
||||
if (model.getBanMembre() == null)
|
||||
model.setBanMembre(new ArrayList<>());
|
||||
|
||||
model.setName(data.getName());
|
||||
model.setAdresse(data.getAdresse());
|
||||
model.setDescription(data.getDescription());
|
||||
@ -211,55 +232,126 @@ public class CompetitionService {
|
||||
model.setData4(data.getData4());
|
||||
}
|
||||
|
||||
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<List<SimpleRegisterComb>> getRegister(SecurityCtx securityCtx, Long id, String source) {
|
||||
if ("admin".equals(source))
|
||||
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();
|
||||
if ("club".equals(source))
|
||||
return Uni.createFrom().nullItem()
|
||||
.invoke(Unchecked.consumer(__ -> {
|
||||
if (!securityCtx.isClubAdmin())
|
||||
throw new DForbiddenException();
|
||||
}))
|
||||
.chain(__ -> membreService.getByAccountId(securityCtx.getSubject()))
|
||||
.chain(model -> registerRepository.list("competition.id = ?1 AND membre.club = ?2", id,
|
||||
model.getClub()))
|
||||
.onItem().transformToMulti(Multi.createFrom()::iterable)
|
||||
.onItem().call(combModel -> Mutiny.fetch(combModel.getMembre().getLicences()))
|
||||
.map(combModel -> SimpleRegisterComb.fromModel(combModel, combModel.getMembre().getLicences()))
|
||||
.collect().asList();
|
||||
|
||||
return membreService.getByAccountId(securityCtx.getSubject())
|
||||
.chain(model -> registerRepository.find("competition.id = ?1 AND membre = ?2", id, model).firstResult()
|
||||
.map(rm -> rm == null ? List.of() : List.of(SimpleRegisterComb.fromModel(rm, List.of()))));
|
||||
}
|
||||
|
||||
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<RegisterModel> opt = insc.stream()
|
||||
.filter(m -> m.getMembre().equals(combModel)).findAny();
|
||||
public Uni<SimpleRegisterComb> addRegisterComb(SecurityCtx securityCtx, Long id, RegisterRequestData data,
|
||||
String source) {
|
||||
if ("admin".equals(source))
|
||||
return permService.hasEditPerm(securityCtx, id)
|
||||
.chain(c -> findComb(data.getLicence(), data.getFname(), data.getLname())
|
||||
.call(combModel -> {
|
||||
if (c.getBanMembre() == null)
|
||||
c.setBanMembre(new ArrayList<>());
|
||||
c.getBanMembre().remove(combModel.getId());
|
||||
return Panache.withTransaction(() -> repository.persist(c));
|
||||
})
|
||||
.chain(combModel -> updateRegister(data, c, combModel, true)))
|
||||
.chain(r -> Mutiny.fetch(r.getMembre().getLicences())
|
||||
.map(licences -> SimpleRegisterComb.fromModel(r, licences)));
|
||||
if ("club".equals(source))
|
||||
return repository.findById(id)
|
||||
.invoke(Unchecked.consumer(cm -> {
|
||||
if (!(cm.getRegisterMode() == RegisterMode.CLUB_ADMIN || cm.getRegisterMode() == RegisterMode.FREE)
|
||||
|| !securityCtx.isClubAdmin())
|
||||
throw new DForbiddenException();
|
||||
if (new Date().before(cm.getStartRegister()) || new Date().after(cm.getEndRegister()))
|
||||
throw new DBadRequestException("Inscription fermée");
|
||||
}))
|
||||
.chain(c -> findComb(data.getLicence(), data.getFname(), data.getLname())
|
||||
.invoke(Unchecked.consumer(model -> {
|
||||
if (!securityCtx.isInClubGroup(model.getClub().getId()))
|
||||
throw new DForbiddenException();
|
||||
if (c.getBanMembre().contains(model.getId()))
|
||||
throw new DForbiddenException(
|
||||
"Vous n'avez pas le droit d'inscrire ce membre (par décision de l'administrateur de la compétition)");
|
||||
}))
|
||||
.chain(combModel -> updateRegister(data, c, combModel, false)))
|
||||
.chain(r -> Mutiny.fetch(r.getMembre().getLicences())
|
||||
.map(licences -> SimpleRegisterComb.fromModel(r, licences)));
|
||||
|
||||
RegisterModel r;
|
||||
if (opt.isPresent()) {
|
||||
r = opt.get();
|
||||
r.setWeight(data.getWeight());
|
||||
r.setOverCategory(data.getOverCategory());
|
||||
r.setCategorie(
|
||||
(combModel.getBirth_date() == null) ? combModel.getCategorie() :
|
||||
Utils.getCategoryFormBirthDate(combModel.getBirth_date(),
|
||||
c.getDate()));
|
||||
int days = Utils.getDaysBeforeCompetition(c.getDate());
|
||||
if (days > -7) {
|
||||
r.setClub(combModel.getClub());
|
||||
}
|
||||
} else {
|
||||
r = new RegisterModel(c, combModel, data.getWeight(), data.getOverCategory(),
|
||||
(combModel.getBirth_date() == null) ? combModel.getCategorie() :
|
||||
Utils.getCategoryFormBirthDate(combModel.getBirth_date(),
|
||||
c.getDate()),
|
||||
(combModel.getClub() == null) ? null : combModel.getClub());
|
||||
insc.add(r);
|
||||
}
|
||||
return repository.findById(id)
|
||||
.invoke(Unchecked.consumer(cm -> {
|
||||
if (cm.getRegisterMode() != RegisterMode.FREE)
|
||||
throw new DForbiddenException();
|
||||
if (new Date().before(cm.getStartRegister()) || new Date().after(cm.getEndRegister()))
|
||||
throw new DBadRequestException("Inscription fermée");
|
||||
}))
|
||||
.chain(c -> membreService.getByAccountId(securityCtx.getSubject())
|
||||
.invoke(Unchecked.consumer(model -> {
|
||||
if (c.getBanMembre().contains(model.getId()))
|
||||
throw new DForbiddenException(
|
||||
"Vous n'avez pas le droit de vous inscrire (par décision de l'administrateur de la compétition)");
|
||||
}))
|
||||
.chain(combModel -> updateRegister(data, c, combModel, false)))
|
||||
.map(r -> SimpleRegisterComb.fromModel(r, List.of()));
|
||||
}
|
||||
|
||||
if (c.getSystem() == CompetitionSystem.SAFCA) {
|
||||
SReqRegister.sendIfNeed(serverCustom.clients,
|
||||
new CompetitionData.SimpleRegister(r.getMembre().getId(),
|
||||
r.getOverCategory(), r.getWeight(), r.getCategorie(),
|
||||
(r.getClub() == null) ? null : r.getClub().getId()), c.getId());
|
||||
}
|
||||
return Panache.withTransaction(() -> repository.persist(c)).map(__ -> r);
|
||||
}))))
|
||||
.chain(r -> Mutiny.fetch(r.getMembre().getLicences())
|
||||
.map(licences -> SimpleRegisterComb.fromModel(r, licences)));
|
||||
private Uni<RegisterModel> updateRegister(RegisterRequestData data, CompetitionModel c,
|
||||
MembreModel combModel, boolean admin) {
|
||||
return registerRepository.find("competition = ?1 AND membre = ?2", c, combModel).firstResult()
|
||||
.onFailure().recoverWithNull()
|
||||
.map(Unchecked.function(r -> {
|
||||
if (r != null) {
|
||||
if (!admin && r.isLockEdit())
|
||||
throw new DForbiddenException(
|
||||
"Modification bloquée par l'administrateur de la compétition");
|
||||
r.setWeight(data.getWeight());
|
||||
r.setOverCategory(data.getOverCategory());
|
||||
r.setCategorie(
|
||||
(combModel.getBirth_date() == null) ? combModel.getCategorie() :
|
||||
Utils.getCategoryFormBirthDate(combModel.getBirth_date(),
|
||||
c.getDate()));
|
||||
int days = Utils.getDaysBeforeCompetition(c.getDate());
|
||||
if (days > -7)
|
||||
r.setClub(combModel.getClub());
|
||||
if (admin)
|
||||
r.setLockEdit(data.isLockEdit());
|
||||
} else {
|
||||
r = new RegisterModel(c, combModel, data.getWeight(), data.getOverCategory(),
|
||||
(combModel.getBirth_date() == null) ? combModel.getCategorie() :
|
||||
Utils.getCategoryFormBirthDate(combModel.getBirth_date(),
|
||||
c.getDate()),
|
||||
(combModel.getClub() == null) ? null : combModel.getClub());
|
||||
if (admin)
|
||||
r.setLockEdit(data.isLockEdit());
|
||||
else
|
||||
r.setLockEdit(false);
|
||||
}
|
||||
|
||||
if (c.getSystem() == CompetitionSystem.SAFCA) {
|
||||
SReqRegister.sendIfNeed(serverCustom.clients,
|
||||
new CompetitionData.SimpleRegister(r.getMembre().getId(),
|
||||
r.getOverCategory(), r.getWeight(), r.getCategorie(),
|
||||
(r.getClub() == null) ? null : r.getClub().getId()), c.getId());
|
||||
}
|
||||
return r;
|
||||
}))
|
||||
.chain(r -> Panache.withTransaction(() -> registerRepository.persist(r)));
|
||||
}
|
||||
|
||||
private Uni<MembreModel> findComb(Long licence, String fname, String lname) {
|
||||
@ -282,19 +374,56 @@ public class CompetitionService {
|
||||
}
|
||||
}
|
||||
|
||||
public Uni<Void> removeRegisterComb(SecurityCtx securityCtx, Long id, Long combId) {
|
||||
return permService.hasEditPerm(securityCtx, id)
|
||||
.chain(c -> registerRepository.delete("competition = ?1 AND membre.id = ?2", c, combId)
|
||||
.invoke(Unchecked.consumer(l -> {
|
||||
if (l != 0) {
|
||||
if (c.getSystem() == CompetitionSystem.SAFCA) {
|
||||
SReqRegister.sendRmIfNeed(serverCustom.clients, combId, id);
|
||||
}
|
||||
} else {
|
||||
throw new DBadRequestException("Combattant non inscrit");
|
||||
}
|
||||
}))
|
||||
).replaceWithVoid();
|
||||
public Uni<Void> removeRegisterComb(SecurityCtx securityCtx, Long id, Long combId, String source, boolean ban) {
|
||||
if ("admin".equals(source))
|
||||
return permService.hasEditPerm(securityCtx, id)
|
||||
.chain(cm -> {
|
||||
if (cm.getBanMembre() == null)
|
||||
cm.setBanMembre(new ArrayList<>());
|
||||
if (ban) {
|
||||
if (!cm.getBanMembre().contains(combId))
|
||||
cm.getBanMembre().add(combId);
|
||||
} else {
|
||||
cm.getBanMembre().remove(combId);
|
||||
}
|
||||
return Panache.withTransaction(() -> repository.persist(cm));
|
||||
})
|
||||
.chain(c -> deleteRegister(combId, c, true));
|
||||
if ("club".equals(source))
|
||||
return repository.findById(id)
|
||||
.invoke(Unchecked.consumer(cm -> {
|
||||
if (!(cm.getRegisterMode() == RegisterMode.CLUB_ADMIN || cm.getRegisterMode() == RegisterMode.FREE)
|
||||
|| !securityCtx.isClubAdmin())
|
||||
throw new DForbiddenException();
|
||||
if (new Date().before(cm.getStartRegister()) || new Date().after(cm.getEndRegister()))
|
||||
throw new DBadRequestException("Inscription fermée");
|
||||
}))
|
||||
.call(cm -> membreService.getByAccountId(securityCtx.getSubject())
|
||||
.invoke(Unchecked.consumer(model -> {
|
||||
if (!securityCtx.isInClubGroup(model.getClub().getId()))
|
||||
throw new DForbiddenException();
|
||||
})))
|
||||
.chain(c -> deleteRegister(combId, c, false));
|
||||
|
||||
return repository.findById(id)
|
||||
.invoke(Unchecked.consumer(cm -> {
|
||||
if (cm.getRegisterMode() != RegisterMode.FREE)
|
||||
throw new DForbiddenException();
|
||||
if (new Date().before(cm.getStartRegister()) || new Date().after(cm.getEndRegister()))
|
||||
throw new DBadRequestException("Inscription fermée");
|
||||
}))
|
||||
.chain(c -> deleteRegister(combId, c, false));
|
||||
}
|
||||
|
||||
private Uni<Void> deleteRegister(Long combId, CompetitionModel c, boolean admin) {
|
||||
return registerRepository.find("competition = ?1 AND membre.id = ?2", c, combId).firstResult()
|
||||
.onFailure().transform(t -> new DBadRequestException("Combattant non inscrit"))
|
||||
.call(Unchecked.function(registerModel -> {
|
||||
if (!admin && registerModel.isLockEdit())
|
||||
throw new DForbiddenException("Modification bloquée par l'administrateur de la compétition");
|
||||
return Panache.withTransaction(() -> registerRepository.delete(registerModel));
|
||||
}))
|
||||
.replaceWithVoid();
|
||||
}
|
||||
|
||||
public Uni<?> delete(SecurityCtx securityCtx, Long id) {
|
||||
@ -383,4 +512,100 @@ public class CompetitionService {
|
||||
}))
|
||||
.call(__ -> cache.invalidate(data.getId()));
|
||||
}
|
||||
|
||||
public Uni<Response> unregisterHelloAsso(NotificationData data) {
|
||||
if (!data.getState().equals("Refunded"))
|
||||
return Uni.createFrom().item(Response.ok().build());
|
||||
|
||||
return helloAssoRepository.list("orderId = ?1", data.getOrder().getId())
|
||||
.chain(regs -> {
|
||||
Uni<?> uni = Uni.createFrom().nullItem();
|
||||
|
||||
for (HelloAssoRegisterModel reg : regs) {
|
||||
if (reg.getCompetition().getRegisterMode() != RegisterMode.HELLOASSO)
|
||||
continue;
|
||||
if (!data.getOrder().getOrganizationSlug().equalsIgnoreCase(reg.getCompetition().getData1()))
|
||||
continue;
|
||||
|
||||
uni = uni.call(__ -> Panache.withTransaction(
|
||||
() -> registerRepository.delete("competition = ?1 AND membre = ?2",
|
||||
reg.getCompetition(), reg.getMembre())));
|
||||
}
|
||||
|
||||
return uni;
|
||||
})
|
||||
.onFailure().invoke(Throwable::printStackTrace)
|
||||
.map(__ -> Response.ok().build());
|
||||
}
|
||||
|
||||
public Uni<Response> registerHelloAsso(NotificationData data) {
|
||||
String organizationSlug = data.getOrganizationSlug();
|
||||
String formSlug = data.getFormSlug();
|
||||
RegisterRequestData req = new RegisterRequestData(null, "", "", null, 0, false);
|
||||
|
||||
return repository.find("data1 = ?1 AND data2 = ?2", organizationSlug, formSlug).firstResult()
|
||||
.onFailure().recoverWithNull()
|
||||
.chain(cm -> {
|
||||
Uni<?> uni = Uni.createFrom().nullItem();
|
||||
if (cm == null || cm.getRegisterMode() != RegisterMode.HELLOASSO)
|
||||
return uni;
|
||||
|
||||
List<String> place = List.of(cm.getData3().toLowerCase().split(";"));
|
||||
List<String> fail = new ArrayList<>();
|
||||
|
||||
for (NotificationData.Item item : data.getItems()) {
|
||||
if (!place.contains(item.getName().toLowerCase()))
|
||||
continue;
|
||||
if (item.getCustomFields() == null || item.getCustomFields().isEmpty()) {
|
||||
fail.add("%s %s - licence n°???".formatted(item.getUser().getLastName(),
|
||||
item.getUser().getFirstName()));
|
||||
continue;
|
||||
}
|
||||
|
||||
Optional<Long> optional = item.getCustomFields().stream()
|
||||
.filter(cf -> cf.getName().equalsIgnoreCase("Numéro de licence")).findAny().map(
|
||||
NotificationData.CustomField::getAnswer).map(Long::valueOf);
|
||||
|
||||
if (optional.isPresent()) {
|
||||
uni = uni.call(__ -> membreService.getByLicence(optional.get())
|
||||
.invoke(Unchecked.consumer(m -> {
|
||||
if (m == null)
|
||||
throw new NotFoundException();
|
||||
}))
|
||||
.call(m -> Panache.withTransaction(() ->
|
||||
helloAssoRepository.persist(
|
||||
new HelloAssoRegisterModel(cm, m, data.getId()))))
|
||||
.chain(m -> updateRegister(req, cm, m, true)))
|
||||
.onFailure().recoverWithItem(throwable -> {
|
||||
fail.add("%s %s - licence n°%d".formatted(item.getUser().getLastName(),
|
||||
item.getUser().getFirstName(), optional.get()));
|
||||
return null;
|
||||
})
|
||||
.replaceWithVoid();
|
||||
} else {
|
||||
fail.add("%s %s - licence n°???".formatted(item.getUser().getLastName(),
|
||||
item.getUser().getFirstName()));
|
||||
}
|
||||
}
|
||||
|
||||
return uni.call(__ -> fail.isEmpty() ? Uni.createFrom().nullItem() :
|
||||
reactiveMailer.send(
|
||||
Mail.withText(cm.getData4(),
|
||||
"FFSAF - Compétition - Erreur HelloAsso",
|
||||
String.format(
|
||||
"""
|
||||
Bonjour,
|
||||
|
||||
Une erreur a été rencontrée lors de l'enregistrement d'une inscription à votre compétition %s pour les combattants suivants:
|
||||
%s
|
||||
|
||||
Cordialement,
|
||||
L'intranet de la FFSAF
|
||||
""", cm.getName(), String.join("\r\n", fail))
|
||||
).setFrom("FFSAF <no-reply@ffsaf.fr>").setReplyTo("support@ffsaf.fr")
|
||||
).onFailure().invoke(e -> LOGGER.error("Fail to send email", e)));
|
||||
})
|
||||
.onFailure().invoke(Throwable::printStackTrace)
|
||||
.map(__ -> Response.ok().build());
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,13 +13,25 @@ public class WebhookService {
|
||||
@Inject
|
||||
CheckoutService checkoutService;
|
||||
|
||||
@Inject
|
||||
CompetitionService competitionService;
|
||||
|
||||
@ConfigProperty(name = "helloasso.organizationSlug")
|
||||
String organizationSlug;
|
||||
|
||||
public Uni<Response> helloAssoNotification(HelloassoNotification notification) {
|
||||
if (notification.getEventType().equals("Payment")){
|
||||
if (notification.getData().getOrder().getOrganizationSlug().equalsIgnoreCase(organizationSlug)){
|
||||
return checkoutService.paymentStatusChange(notification.getData().getState(), notification.getMetadata());
|
||||
if (notification.getEventType().equals("Payment")) {
|
||||
if (notification.getData().getOrder().getFormType().equals("Checkout")) {
|
||||
if (notification.getData().getOrder().getOrganizationSlug().equalsIgnoreCase(organizationSlug)) {
|
||||
return checkoutService.paymentStatusChange(notification.getData().getState(),
|
||||
notification.getMetadata());
|
||||
}
|
||||
} else if (notification.getData().getOrder().getFormType().equals("Event")) {
|
||||
return competitionService.unregisterHelloAsso(notification.getData());
|
||||
}
|
||||
}else if (notification.getEventType().equals("Order")){
|
||||
if (notification.getData().getFormType().equals("Event")) {
|
||||
return competitionService.registerHelloAsso(notification.getData());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -275,6 +275,23 @@ public class ClubEndpoints {
|
||||
return pdfService.getAffiliationPdf(securityCtx.getSubject());
|
||||
}
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/members")
|
||||
@RolesAllowed({"club_president", "club_secretaire", "club_respo_intra", "club_tresorier"})
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Operation(summary = "Revoie tout les membres de votre club")
|
||||
@APIResponses(value = {
|
||||
@APIResponse(responseCode = "200", description = "List des membres"),
|
||||
@APIResponse(responseCode = "403", description = "Accès refusé"),
|
||||
@APIResponse(responseCode = "404", description = "L'utilisateur n'est pas membre d'un club"),
|
||||
@APIResponse(responseCode = "500", description = "Erreur interne du serveur")
|
||||
})
|
||||
public Uni<List<VerySimpleMembre>> getMembers() {
|
||||
return clubService.getMembers(securityCtx);
|
||||
}
|
||||
|
||||
|
||||
@GET
|
||||
@Path("/renew/{id}")
|
||||
@RolesAllowed({"club_president", "club_secretaire", "club_respo_intra"})
|
||||
|
||||
@ -36,29 +36,31 @@ public class CompetitionEndpoints {
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}/register")
|
||||
@Path("{id}/register/{source}")
|
||||
@Authenticated
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Uni<List<SimpleRegisterComb>> getRegister(@PathParam("id") Long id) {
|
||||
return service.getRegister(securityCtx, id);
|
||||
public Uni<List<SimpleRegisterComb>> getRegister(@PathParam("id") Long id, @PathParam("source") String source) {
|
||||
return service.getRegister(securityCtx, id, source);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("{id}/register")
|
||||
@Path("{id}/register/{source}")
|
||||
@Authenticated
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Operation(hidden = true)
|
||||
public Uni<SimpleRegisterComb> addRegisterComb(@PathParam("id") Long id, RegisterRequestData data) {
|
||||
return service.addRegisterComb(securityCtx, id, data);
|
||||
public Uni<SimpleRegisterComb> addRegisterComb(@PathParam("id") Long id, @PathParam("source") String source,
|
||||
RegisterRequestData data) {
|
||||
return service.addRegisterComb(securityCtx, id, data, source);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{id}/register/{comb_id}")
|
||||
@Path("{id}/register/{comb_id}/{source}")
|
||||
@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);
|
||||
public Uni<Void> removeRegisterComb(@PathParam("id") Long id, @PathParam("comb_id") Long combId,
|
||||
@PathParam("source") String source, @QueryParam("ban") boolean ban) {
|
||||
return service.removeRegisterComb(securityCtx, id, combId, source, ban);
|
||||
}
|
||||
|
||||
@GET
|
||||
|
||||
@ -5,6 +5,8 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@ -12,11 +14,14 @@ import lombok.NoArgsConstructor;
|
||||
public class NotificationData {
|
||||
private Order order;
|
||||
private Integer id;
|
||||
private String formSlug;
|
||||
private String formType;
|
||||
private String organizationSlug;
|
||||
private String checkoutIntentId;
|
||||
private String oldSlugOrganization; // Pour les changements de nom d'association
|
||||
private String newSlugOrganization;
|
||||
private String state; // Pour les formulaires
|
||||
private List<Item> items;
|
||||
|
||||
|
||||
@Data
|
||||
@ -26,5 +31,35 @@ public class NotificationData {
|
||||
public static class Order {
|
||||
private Integer id;
|
||||
private String organizationSlug;
|
||||
private String formSlug;
|
||||
private String formType;
|
||||
}
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@RegisterForReflection
|
||||
public static class Item {
|
||||
private String name;
|
||||
private User user;
|
||||
private List<CustomField> customFields;
|
||||
}
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@RegisterForReflection
|
||||
public static class User {
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
}
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@RegisterForReflection
|
||||
public static class CustomField {
|
||||
private String name;
|
||||
private String answer;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,13 @@
|
||||
package fr.titionfire.ffsaf.rest.data;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@RegisterForReflection
|
||||
public class RegisterRequestData {
|
||||
private Long licence;
|
||||
@ -12,4 +16,5 @@ public class RegisterRequestData {
|
||||
|
||||
private Integer weight;
|
||||
private int overCategory;
|
||||
private boolean lockEdit = false;
|
||||
}
|
||||
|
||||
@ -2,8 +2,8 @@ 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.data.model.RegisterModel;
|
||||
import fr.titionfire.ffsaf.net2.data.SimpleClubModel;
|
||||
import fr.titionfire.ffsaf.utils.Utils;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.AllArgsConstructor;
|
||||
@ -18,19 +18,23 @@ public class SimpleRegisterComb {
|
||||
private long id;
|
||||
private String fname;
|
||||
private String lname;
|
||||
private String genre;
|
||||
private String categorie;
|
||||
private SimpleClubModel club;
|
||||
private Integer licence;
|
||||
private Integer weight;
|
||||
private int overCategory;
|
||||
private boolean hasLicenceActive;
|
||||
private boolean lockEdit;
|
||||
|
||||
public static SimpleRegisterComb fromModel(RegisterModel register, List<LicenceModel> licences) {
|
||||
MembreModel membreModel = register.getMembre();
|
||||
return new SimpleRegisterComb(membreModel.getId(), membreModel.getFname(), membreModel.getLname(),
|
||||
membreModel.getGenre().name(),
|
||||
(register.getCategorie() == null) ? "Catégorie inconnue" : register.getCategorie().getName(),
|
||||
SimpleClubModel.fromModel(register.getClub()), membreModel.getLicence(), register.getWeight(),
|
||||
register.getOverCategory(),
|
||||
licences.stream().anyMatch(l -> l.isValidate() && l.getSaison() == Utils.getSaison()));
|
||||
licences.stream().anyMatch(l -> l.isValidate() && l.getSaison() == Utils.getSaison()),
|
||||
register.isLockEdit());
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
package fr.titionfire.ffsaf.rest.data;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.eclipse.microprofile.openapi.annotations.media.Schema;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@RegisterForReflection
|
||||
public class VerySimpleMembre {
|
||||
@Schema(description = "Le nom du membre.", example = "Dupont")
|
||||
private String lname = "";
|
||||
@Schema(description = "Le prénom du membre.", example = "Jean")
|
||||
private String fname = "";
|
||||
@Schema(description = "Le numéro de licence du membre.", example = "12345")
|
||||
private Integer licence;
|
||||
}
|
||||
@ -200,7 +200,6 @@ function FileOutput() {
|
||||
<small>À utiliser comme template pour mettre à jour les informations</small>
|
||||
</div>
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -23,11 +23,11 @@ export function CompetitionEdit() {
|
||||
toast.promise(
|
||||
apiAxios.delete(`/competition/${id}`),
|
||||
{
|
||||
pending: "Suppression de la competition en cours...",
|
||||
success: "Competition supprimé avec succès 🎉",
|
||||
pending: "Suppression de la compétition en cours...",
|
||||
success: "Compétition supprimé avec succès 🎉",
|
||||
error: {
|
||||
render({data}) {
|
||||
return errFormater(data, "Échec de la suppression de la competition")
|
||||
return errFormater(data, "Échec de la suppression de la compétition")
|
||||
}
|
||||
},
|
||||
}
|
||||
@ -47,18 +47,18 @@ export function CompetitionEdit() {
|
||||
<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>}
|
||||
onClick={_ => navigate(`/competition/${data.id}/register?type=${data.registerMode}`)}>Voir/Modifier les participants</button>}
|
||||
|
||||
{data.id !== null && data.system === "SAFCA" && <ContentSAFCA data2={data}/>}
|
||||
|
||||
{data.id !== null && <>
|
||||
<div className="col" style={{textAlign: 'right', marginTop: '1em'}}>
|
||||
<button className="btn btn-danger btn-sm" data-bs-toggle="modal"
|
||||
data-bs-target="#confirm-delete">Supprimer la competition
|
||||
data-bs-target="#confirm-delete">Supprimer la compétition
|
||||
</button>
|
||||
</div>
|
||||
<ConfirmDialog title="Supprimer la competition"
|
||||
message="Êtes-vous sûr de vouloir supprimer cette competition est tout les resultat associer?"
|
||||
<ConfirmDialog title="Supprimer la compétition"
|
||||
message="Êtes-vous sûr de vouloir supprimer cette compétition est tout les resultat associer?"
|
||||
onConfirm={handleRm}/>
|
||||
</>}
|
||||
</div>
|
||||
@ -301,7 +301,7 @@ function Content({data}) {
|
||||
return <form onSubmit={handleSubmit}>
|
||||
<div className="card mb-4">
|
||||
<input name="id" value={data.id || ""} readOnly hidden/>
|
||||
<div className="card-header">{data.id ? "Edition competition" : "Création competition"}</div>
|
||||
<div className="card-header">{data.id ? "Edition compétition" : "Création compétition"}</div>
|
||||
<div className="card-body text-center">
|
||||
|
||||
<div className="accordion" id="accordionExample">
|
||||
@ -330,7 +330,7 @@ function Content({data}) {
|
||||
<h2 className="accordion-header">
|
||||
<button className="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo"
|
||||
aria-expanded="true" aria-controls="collapseTwo">
|
||||
Informations générales sur la competition
|
||||
Informations générales sur la compétition
|
||||
</button>
|
||||
</h2>
|
||||
<div id="collapseTwo" className="accordion-collapse collapse show" data-bs-parent="#accordionExample">
|
||||
|
||||
@ -31,12 +31,23 @@ function MakeCentralPanel({data, navigate}) {
|
||||
|
||||
return <>
|
||||
{userinfo?.roles?.includes("create_compet") &&
|
||||
<div className="col mb-2" style={{textAlign: 'right', marginTop: '1em'}}>
|
||||
<button type="button" className="btn btn-primary" onClick={() => navigate("/competition/0")}>Nouvelle competition</button>
|
||||
</div> }
|
||||
<div className="col mb-2" style={{textAlign: 'right', marginTop: '1em'}}>
|
||||
<button type="button" className="btn btn-primary" onClick={() => navigate("/competition/0")}>Nouvelle compétition</button>
|
||||
</div>}
|
||||
<div className="mb-4">
|
||||
<h3>Compétition future</h3>
|
||||
<div className="list-group">
|
||||
{data.map(req => (<MakeRow key={req.id} data={req} navigate={navigate}/>))}
|
||||
{data.filter(req => new Date(req.toDate.split('T')[0]) >= new Date()).sort((a, b) => {
|
||||
return new Date(a.date.split('T')[0]) - new Date(b.date.split(')T')[0])
|
||||
}).map(req => (<MakeRow key={req.id} data={req} navigate={navigate}/>))}
|
||||
</div>
|
||||
</div>
|
||||
<div className="mb-4">
|
||||
<h3>Compétition passée</h3>
|
||||
<div className="list-group">
|
||||
{data.filter(req => new Date(req.toDate.split('T')[0]) < new Date()).sort((a, b) => {
|
||||
return new Date(b.date.split('T')[0]) - new Date(a.date.split(')T')[0])
|
||||
}).map(req => (<MakeRow key={req.id} data={req} navigate={navigate}/>))}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
@ -58,7 +69,7 @@ const inscText = (type) => {
|
||||
|
||||
function MakeRow({data, navigate}) {
|
||||
return <div className="list-group-item list-group-item-action"
|
||||
onClick={() => data.canEdit ? navigate("" + data.id) : navigate("view/" + data.id)}>
|
||||
onClick={() => data.canEdit ? navigate("" + data.id) : navigate("" + data.id + "/view")}>
|
||||
<div className="row justify-content-between align-items-start ">
|
||||
<div className="ms-2 col-auto">
|
||||
<div><strong>{data.name}</strong> <small>par {data.clubName}</small></div>
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
.autocomplete-wrapper {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
}
|
||||
|
||||
.suggestions-list2 {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
z-index: 1000;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 1px solid #ced4da;
|
||||
border-top: none;
|
||||
border-radius: 0 0 4px 4px;
|
||||
}
|
||||
|
||||
.suggestions-list {
|
||||
position: absolute;
|
||||
z-index: 1000;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 1px solid #ced4da;
|
||||
border-top: none;
|
||||
border-radius: 0 0 4px 4px;
|
||||
}
|
||||
|
||||
.suggestions-list .list-group-item {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.suggestions-list .list-group-item:hover {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
@ -1,16 +1,19 @@
|
||||
import {useNavigate, useParams} from "react-router-dom";
|
||||
import {useLoadingSwitcher} from "../../hooks/useLoading.jsx";
|
||||
import {useNavigate, useParams, useSearchParams} from "react-router-dom";
|
||||
import {LoadingProvider, 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 {useEffect, useReducer, useRef, useState} from "react";
|
||||
import {apiAxios, errFormater} 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";
|
||||
import {faAdd, faGavel, faTrashCan} from "@fortawesome/free-solid-svg-icons";
|
||||
import "./CompetitionRegisterAdmin.css"
|
||||
import * as XLSX from "xlsx-js-style";
|
||||
import * as Tools from "../../utils/Tools.js";
|
||||
|
||||
export function CompetitionRegisterAdmin() {
|
||||
export function CompetitionRegisterAdmin({source}) {
|
||||
const {id} = useParams()
|
||||
const navigate = useNavigate()
|
||||
const [state, dispatch] = useReducer(SimpleReducer, [])
|
||||
@ -19,32 +22,24 @@ export function CompetitionRegisterAdmin() {
|
||||
const [modalState, setModalState] = useState({})
|
||||
|
||||
const setLoading = useLoadingSwitcher()
|
||||
const {data, error} = useFetch(`/competition/${id}/register`, setLoading, 1)
|
||||
const {data, error} = useFetch(`/competition/${id}/register/${source}`, setLoading, 1)
|
||||
|
||||
const sortName = (a, b) => {
|
||||
if (a.data.fname === b.data.fname)
|
||||
return a.data.lname.localeCompare(b.data.lname);
|
||||
if (a.data.fname === b.data.fname) return a.data.lname.localeCompare(b.data.lname);
|
||||
return a.data.fname.localeCompare(b.data.fname);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!data)
|
||||
return;
|
||||
data.forEach((d, index) => {
|
||||
dispatch({type: 'UPDATE_OR_ADD', payload: {id: index, data: d}})
|
||||
if (!data) return;
|
||||
data.forEach((d) => {
|
||||
dispatch({type: 'UPDATE_OR_ADD', payload: {id: d.id, data: d}})
|
||||
})
|
||||
dispatch({type: 'SORT', payload: sortName})
|
||||
}, [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: {
|
||||
const sendRegister = (new_state) => {
|
||||
toast.promise(apiAxios.post(`/competition/${id}/register/${source}`, new_state), {
|
||||
pending: "Recherche en cours", success: "Combattant trouvé et ajouté/mis à jour", error: {
|
||||
render({data}) {
|
||||
return data.response.data || "Combattant non trouvé"
|
||||
}
|
||||
@ -53,17 +48,7 @@ export function CompetitionRegisterAdmin() {
|
||||
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}})
|
||||
dispatch({type: 'UPDATE_OR_ADD', payload: {id: response.data.id, data: response.data}})
|
||||
dispatch({type: 'SORT', payload: sortName})
|
||||
document.getElementById("closeModal").click();
|
||||
})
|
||||
@ -71,22 +56,18 @@ export function CompetitionRegisterAdmin() {
|
||||
|
||||
return <div>
|
||||
<h2>Combattants inscrits</h2>
|
||||
<button type="button" className="btn btn-link" onClick={() => navigate("/competition/" + id)}>
|
||||
<button type="button" className="btn btn-link"
|
||||
onClick={() => source === "admin" ? navigate("/competition/" + id) : navigate("/competition/" + id + "/view")}>
|
||||
« 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/>
|
||||
}
|
||||
{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} source={source}/>
|
||||
</div> : error ? <AxiosError error={error}/> : <Def/>}
|
||||
</div>
|
||||
<div className="col-lg-3">
|
||||
<div className="mb-4">
|
||||
@ -94,27 +75,214 @@ export function CompetitionRegisterAdmin() {
|
||||
onClick={() => setModalState({})}>Ajouter un combattant
|
||||
</button>
|
||||
</div>
|
||||
<QuickAdd sendRegister={sendRegister} source={source}/>
|
||||
<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}/>
|
||||
setCatFilter={setCatFilter} source={source}/>
|
||||
</div>
|
||||
</div>
|
||||
{source === "admin" && <FileOutput data={data}/>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Modal sendRegister={sendRegister} modalState={modalState} setModalState={setModalState}/>
|
||||
<Modal sendRegister={sendRegister} modalState={modalState} setModalState={setModalState} source={source}/>
|
||||
</div>
|
||||
}
|
||||
|
||||
function Modal({sendRegister, modalState, setModalState}) {
|
||||
function QuickAdd({sendRegister, source}) {
|
||||
|
||||
const handleAdd = (licence) => {
|
||||
console.log("Quick add licence: " + licence)
|
||||
|
||||
sendRegister({
|
||||
licence: licence, fname: "", lname: "", weight: "", overCategory: 0, lockEdit: false, id: null
|
||||
})
|
||||
}
|
||||
|
||||
return <div className="card mb-4">
|
||||
<div className="card-header">Ajout rapide</div>
|
||||
<div className="card-body">
|
||||
<div className="row">
|
||||
<span>N° de licence</span>
|
||||
</div>
|
||||
<div className="input-group">
|
||||
<input type="text" className="form-control" placeholder="12345" id="quickAddLicence"
|
||||
onKeyDown={e => {
|
||||
if (e.key === "Enter") {
|
||||
const licence = e.target.value.trim()
|
||||
if (licence.length === 0) return;
|
||||
e.target.value = ""
|
||||
handleAdd(licence)
|
||||
}
|
||||
}}/>
|
||||
<button className="btn btn-primary" type="button" id="quickAddBtn"
|
||||
onClick={_ => {
|
||||
const licence = document.getElementById("quickAddLicence").value.trim()
|
||||
if (licence.length === 0) return;
|
||||
|
||||
document.getElementById("quickAddLicence").value = ""
|
||||
handleAdd(licence)
|
||||
}}><FontAwesomeIcon icon={faAdd} className="no-modal"/>
|
||||
</button>
|
||||
|
||||
{source === "club" && <LoadingProvider>
|
||||
<SearchMember sendRegister={sendRegister}/>
|
||||
</LoadingProvider>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
function SearchMember({sendRegister}) {
|
||||
const setLoading = useLoadingSwitcher()
|
||||
const {data, error} = useFetch(`/club/members`, setLoading, 1)
|
||||
const [suggestions, setSuggestions] = useState([])
|
||||
|
||||
const handleAdd = (name) => {
|
||||
const member = data.find(m => `${m.fname} ${m.lname}`.trim() === name);
|
||||
console.log("Quick add licence:", member)
|
||||
|
||||
if (!member) {
|
||||
toast.error("Combattant non trouvé");
|
||||
return;
|
||||
}
|
||||
|
||||
sendRegister({
|
||||
licence: member.licence, fname: member.fname, lname: member.lname, weight: "", overCategory: 0, lockEdit: false, id: null
|
||||
})
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!data) return;
|
||||
|
||||
const names = data.map(member => `${member.fname} ${member.lname}`.trim());
|
||||
names.sort((a, b) => a.localeCompare(b));
|
||||
setSuggestions(names);
|
||||
}, []);
|
||||
|
||||
return <>
|
||||
{data ? <div className="row mb-3" style={{marginTop: "0.5em"}}>
|
||||
<span>Prénom et nom</span>
|
||||
<AutoCompleteInput suggestions={suggestions} handleAdd={handleAdd}/>
|
||||
</div> : error ? <AxiosError error={error}/> : <Def/>}
|
||||
</>
|
||||
}
|
||||
|
||||
const AutoCompleteInput = ({suggestions = [], handleAdd}) => {
|
||||
const [inputValue, setInputValue] = useState('');
|
||||
const [filteredSuggestions, setFilteredSuggestions] = useState([]);
|
||||
const [showSuggestions, setShowSuggestions] = useState(false);
|
||||
const [activeSuggestion, setActiveSuggestion] = useState(0);
|
||||
const wrapperRef = useRef(null);
|
||||
|
||||
// Filtre les suggestions
|
||||
useEffect(() => {
|
||||
if (inputValue.trim() === '') {
|
||||
setFilteredSuggestions([]);
|
||||
setShowSuggestions(false);
|
||||
} else {
|
||||
const filtered = suggestions.filter(suggestion => suggestion.toLowerCase().includes(inputValue.toLowerCase()));
|
||||
setFilteredSuggestions(filtered);
|
||||
setShowSuggestions(true);
|
||||
setActiveSuggestion(0); // Réinitialise la sélection active
|
||||
}
|
||||
}, [inputValue, suggestions]);
|
||||
|
||||
// Ferme les suggestions si clic à l'extérieur
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event) => {
|
||||
if (wrapperRef.current && !wrapperRef.current.contains(event.target)) {
|
||||
setShowSuggestions(false);
|
||||
}
|
||||
};
|
||||
document.addEventListener('mousedown', handleClickOutside);
|
||||
return () => document.removeEventListener('mousedown', handleClickOutside);
|
||||
}, []);
|
||||
|
||||
// Gestion du clic sur une suggestion
|
||||
const handleSuggestionClick = (suggestion) => {
|
||||
setInputValue(suggestion);
|
||||
setShowSuggestions(false); // Ferme automatiquement après sélection
|
||||
};
|
||||
|
||||
// Navigation clavier
|
||||
const handleKeyDown = (e) => {
|
||||
// Touches directionnelles
|
||||
if (e.key === 'ArrowDown') {
|
||||
e.preventDefault();
|
||||
setActiveSuggestion(prev => prev < filteredSuggestions.length - 1 ? prev + 1 : prev);
|
||||
} else if (e.key === 'ArrowUp') {
|
||||
e.preventDefault();
|
||||
setActiveSuggestion(prev => (prev > 0 ? prev - 1 : 0));
|
||||
}
|
||||
// Validation avec Entrée
|
||||
else if (e.key === 'Enter' && filteredSuggestions.length > 0) {
|
||||
e.preventDefault();
|
||||
if (inputValue === filteredSuggestions[activeSuggestion]) {
|
||||
handleAdd(inputValue);
|
||||
setInputValue('');
|
||||
} else {
|
||||
setInputValue(filteredSuggestions[activeSuggestion]);
|
||||
}
|
||||
setShowSuggestions(false);
|
||||
}
|
||||
// Fermeture avec Échap
|
||||
else if (e.key === 'Escape') {
|
||||
setShowSuggestions(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (<div className="autocomplete-wrapper" ref={wrapperRef}>
|
||||
<div className="input-group">
|
||||
<input
|
||||
type="text"
|
||||
className="form-control"
|
||||
value={inputValue}
|
||||
onChange={(e) => setInputValue(e.target.value)}
|
||||
onKeyDown={handleKeyDown}
|
||||
onFocus={() => inputValue && setShowSuggestions(true)}
|
||||
placeholder="Rechercher..."
|
||||
aria-autocomplete="list"
|
||||
aria-expanded={showSuggestions}
|
||||
aria-controls="suggestions-list"
|
||||
/>
|
||||
|
||||
<button className="btn btn-primary" type="button" id="quickAddBtn"
|
||||
onClick={_ => {
|
||||
handleAdd(inputValue);
|
||||
setInputValue(''); // Réinitialise le champ après l'ajout
|
||||
}}>
|
||||
<FontAwesomeIcon icon={faAdd} className="no-modal"/>
|
||||
</button>
|
||||
</div>
|
||||
{showSuggestions && filteredSuggestions.length > 0 && (<ul
|
||||
id="suggestions-list"
|
||||
className="suggestions-list list-group"
|
||||
role="listbox"
|
||||
>
|
||||
{filteredSuggestions.map((suggestion, index) => (<li
|
||||
key={index}
|
||||
className={`list-group-item list-group-item-action ${index === activeSuggestion ? 'active' : ''}`}
|
||||
onClick={() => handleSuggestionClick(suggestion)}
|
||||
role="option"
|
||||
aria-selected={index === activeSuggestion}
|
||||
>
|
||||
{suggestion}
|
||||
</li>))}
|
||||
</ul>)}
|
||||
</div>);
|
||||
};
|
||||
|
||||
function Modal({sendRegister, modalState, setModalState, source}) {
|
||||
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)
|
||||
const [lockEdit, setLockEdit] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (!modalState) {
|
||||
@ -124,6 +292,7 @@ function Modal({sendRegister, modalState, setModalState}) {
|
||||
setWeight("")
|
||||
setCat(0)
|
||||
setEditMode(false)
|
||||
setLockEdit(false)
|
||||
} else {
|
||||
setLicence(modalState.licence ? modalState.licence : "")
|
||||
setFname(modalState.fname ? modalState.fname : "")
|
||||
@ -131,6 +300,7 @@ function Modal({sendRegister, modalState, setModalState}) {
|
||||
setWeight(modalState.weight ? modalState.weight : "")
|
||||
setCat(modalState.overCategory ? modalState.overCategory : 0)
|
||||
setEditMode(modalState.licence || (modalState.fname && modalState.lname))
|
||||
setLockEdit(modalState.lockEdit)
|
||||
}
|
||||
}, [modalState]);
|
||||
|
||||
@ -139,21 +309,16 @@ function Modal({sendRegister, modalState, setModalState}) {
|
||||
<div className="modal-dialog">
|
||||
<div className="modal-content">
|
||||
<form onSubmit={e => {
|
||||
e.preventDefault()
|
||||
const new_state = {
|
||||
licence: licence,
|
||||
fname: fname,
|
||||
lname: lname,
|
||||
weight: weight,
|
||||
overCategory: cat,
|
||||
id: modalState.id
|
||||
licence: licence, fname: fname, lname: lname, weight: weight, overCategory: cat, lockEdit: lockEdit, id: modalState.id
|
||||
}
|
||||
setModalState(new_state)
|
||||
sendRegister(e, new_state)
|
||||
sendRegister(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>
|
||||
<h1 className="modal-title fs-5" id="registerLabel">{editMode ? "Modification d'" : "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"}}>
|
||||
@ -194,9 +359,16 @@ function Modal({sendRegister, modalState, setModalState}) {
|
||||
<option value={2}>+2 catégorie</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{editMode && source === "admin" && <div className="form-check form-switch form-check-reverse">
|
||||
<input className="form-check-input" type="checkbox" id="switchCheckReverse" checked={lockEdit}
|
||||
onChange={e => setLockEdit(e.target.checked)}/>
|
||||
<label className="form-check-label" htmlFor="switchCheckReverse">Empêcher les membres/club de modifier cette
|
||||
inscription</label>
|
||||
</div>}
|
||||
</div>
|
||||
<div className="modal-footer">
|
||||
<button type="submit" className="btn btn-primary">{editMode? "Modifier" : "Ajouter"}</button>
|
||||
<button type="submit" className="btn btn-primary">{editMode ? "Modifier" : "Ajouter"}</button>
|
||||
<button type="reset" className="btn btn-secondary" data-bs-dismiss="modal" id="closeModal">Annuler</button>
|
||||
</div>
|
||||
</form>
|
||||
@ -208,10 +380,9 @@ function Modal({sendRegister, modalState, setModalState}) {
|
||||
let allClub = []
|
||||
let allCat = []
|
||||
|
||||
function FiltreBar({data, clubFilter, setClubFilter, catFilter, setCatFilter}) {
|
||||
function FiltreBar({data, clubFilter, setClubFilter, catFilter, setCatFilter, source}) {
|
||||
useEffect(() => {
|
||||
if (!data)
|
||||
return;
|
||||
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))
|
||||
@ -219,76 +390,148 @@ function FiltreBar({data, clubFilter, setClubFilter, catFilter, setCatFilter}) {
|
||||
}, [data]);
|
||||
|
||||
return <div>
|
||||
<div className="mb-3">
|
||||
{source === "admin" && <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>}
|
||||
<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}) {
|
||||
function MakeCentralPanel({data, dispatch, id, setModalState, source}) {
|
||||
const [searchParams] = useSearchParams();
|
||||
const registerType = searchParams.get("type") || "FREE";
|
||||
|
||||
return <>
|
||||
{(registerType === "FREE" || registerType === "CLUB_ADMIN") && source === "admin" &&
|
||||
<span>Tips 1: Il est possible de bannir un combattant, ce qui l'empêchera d'être réinscrit par un autre moyen que par un administrateur de cette compétition.
|
||||
Pour cela, cliquez sur la petite <FontAwesomeIcon icon={faGavel}/> à côté de son nom.<br/>
|
||||
Tips 2: Il est aussi possible de verrouiller les modifications de son inscription depuis sa fiche, ce qui l'empêchera d'être modifié/supprimé par lui-même et/ou un responsable de club.
|
||||
</span>}
|
||||
<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>
|
||||
<small>{req.data.club?.name || "Sans club"}</small>
|
||||
{data.map((req, index) => (<div key={index} className="list-group-item" style={{padding: "0"}}>
|
||||
<div className="row" style={{padding: "0", margin: "0"}}>
|
||||
<div style={{padding: ".5rem 1rem"}}
|
||||
className={"col d-flex justify-content-between align-items-start list-group-item-" + ((req.data.lockEdit && source !== "admin") ? "secondary " : "action")}
|
||||
data-bs-toggle={(req.data.lockEdit && source !== "admin") ? "" : "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><strong>{req.data.fname} {req.data.lname}</strong> <small>{req.data.genre}</small></div>
|
||||
<small>{req.data.club?.name || "Sans club"}</small>
|
||||
</div>
|
||||
</div>
|
||||
<div className="row">
|
||||
<div className="col-auto" style={{textAlign: "right"}}>
|
||||
<small>{req.data.categorie + (req.data.overCategory === 0 ? "" : (" avec " + req.data.overCategory + " de surclassement"))}<br/>
|
||||
{req.data.weight ? req.data.weight : "---"} kg
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="row">
|
||||
<div className="col-auto" style={{textAlign: "right"}}>
|
||||
<small>{req.data.categorie + (req.data.overCategory === 0 ? "" : (" avec " + req.data.overCategory + " de surclassement"))}<br/>
|
||||
{req.data.weight ? req.data.weight : "---"} kg
|
||||
</small>
|
||||
</div>
|
||||
<div className="col-auto">
|
||||
<button className="btn btn-danger" type="button"
|
||||
<div className="col-auto" style={{padding: "0 0.5rem 0 0", alignContent: "center"}}>
|
||||
{(registerType === "FREE" || registerType === "CLUB_ADMIN") && source === "admin" &&
|
||||
<button className="btn btn btn-danger no-modal" type="button" disabled={req.data.lockEdit && source !== "admin"}
|
||||
style={{margin: "0 0.25rem 0 0"}}
|
||||
onClick={e => {
|
||||
e.preventDefault()
|
||||
toast.promise(apiAxios.delete(`/competition/${id}/register/${req.data.id}`), {
|
||||
pending: "Désinscription en cours",
|
||||
success: "Combattant désinscrit",
|
||||
error: {
|
||||
|
||||
if (req.data.lockEdit && source !== "admin") return;
|
||||
if (!window.confirm("Êtes-vous sûr de vouloir désinscrire et bannir ce combattant de la compétition?\n(Vous pouvez le réinscrire plus tard)"))
|
||||
return;
|
||||
|
||||
toast.promise(apiAxios.delete(`/competition/${id}/register/${req.data.id}/${source}?ban=true`), {
|
||||
pending: "Désinscription en cours", success: "Combattant désinscrit et bannie", error: {
|
||||
render({data}) {
|
||||
return data.response.data || "Erreur"
|
||||
}
|
||||
}
|
||||
}).finally(() => {
|
||||
dispatch({type: 'REMOVE', payload: req.id})
|
||||
setTimeout(() => document.getElementById("closeModal").click(), 500);
|
||||
})
|
||||
}}>
|
||||
<FontAwesomeIcon icon={faGavel} className="no-modal"/>
|
||||
</button>}
|
||||
<button className="btn btn-danger no-modal" type="button" disabled={req.data.lockEdit && source !== "admin"}
|
||||
onClick={e => {
|
||||
e.preventDefault()
|
||||
|
||||
if (req.data.lockEdit && source !== "admin") return;
|
||||
if (registerType === "HELLOASSO") {
|
||||
if (!window.confirm("Êtes-vous sûr de vouloir désinscrire ce combattant ?\nCela ne le désinscrira pas de la billetterie HelloAsso et ne le remboursera pas."))
|
||||
return;
|
||||
} else {
|
||||
if (!window.confirm("Êtes-vous sûr de vouloir désinscrire ce combattant ?"))
|
||||
return;
|
||||
}
|
||||
}>
|
||||
<FontAwesomeIcon icon={faTrashCan}/>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
toast.promise(apiAxios.delete(`/competition/${id}/register/${req.data.id}/${source}?ban=false`), {
|
||||
pending: "Désinscription en cours", success: "Combattant désinscrit", error: {
|
||||
render({data}) {
|
||||
return data.response.data || "Erreur"
|
||||
}
|
||||
}
|
||||
}).finally(() => {
|
||||
dispatch({type: 'REMOVE', payload: req.id})
|
||||
})
|
||||
}}>
|
||||
<FontAwesomeIcon icon={faTrashCan} className="no-modal"/>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>))}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
|
||||
function FileOutput({data}) {
|
||||
const handleFileDownload = () => {
|
||||
const dataOut = []
|
||||
for (const e of data) {
|
||||
const tmp = {
|
||||
licence: e.licence,
|
||||
nom: e.lname,
|
||||
prenom: e.fname,
|
||||
genre: e.genre,
|
||||
weight: e.weight,
|
||||
categorie: e.categorie,
|
||||
overCategory: e.overCategory,
|
||||
club: e.club ? e.club.name : '',
|
||||
}
|
||||
dataOut.push(tmp)
|
||||
}
|
||||
|
||||
const wb = XLSX.utils.book_new();
|
||||
const ws = XLSX.utils.json_to_sheet(dataOut);
|
||||
XLSX.utils.sheet_add_aoa(ws, [["Licence", "Nom", "Prénom", "Genre", "Poids", "Catégorie normalizer", "Surclassement", "Club"]], {origin: 'A1'});
|
||||
|
||||
ws["!cols"] = [{wch: 7}, {wch: 16}, {wch: 16}, {wch: 6}, {wch: 6}, {wch: 10}, {wch: 10}, {wch: 60}]
|
||||
|
||||
XLSX.utils.book_append_sheet(wb, ws, "Feuille 1");
|
||||
XLSX.writeFile(wb, "output.xlsx");
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button className="btn btn-primary" onClick={handleFileDownload}>Exporter les inscription</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Def() {
|
||||
return <div className="list-group">
|
||||
<li className="list-group-item"><ThreeDots/></li>
|
||||
@ -297,4 +540,4 @@ function Def() {
|
||||
<li className="list-group-item"><ThreeDots/></li>
|
||||
<li className="list-group-item"><ThreeDots/></li>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import {CompetitionView} from "./CompetitionView.jsx";
|
||||
|
||||
export function CompetitionRoot() {
|
||||
return <>
|
||||
<h1>Competition</h1>
|
||||
<h1>Compétition</h1>
|
||||
<LoadingProvider>
|
||||
<Outlet/>
|
||||
</LoadingProvider>
|
||||
@ -25,12 +25,16 @@ export function getCompetitionChildren() {
|
||||
element: <CompetitionEdit/>
|
||||
},
|
||||
{
|
||||
path: 'view/:id',
|
||||
path: ':id/view',
|
||||
element: <CompetitionView/>
|
||||
},
|
||||
{
|
||||
path: ':id/register',
|
||||
element: <CompetitionRegisterAdmin/>
|
||||
element: <CompetitionRegisterAdmin source="admin"/>
|
||||
},
|
||||
{
|
||||
path: ':id/club/register',
|
||||
element: <CompetitionRegisterAdmin source="club"/>
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@ -3,7 +3,10 @@ import {useLoadingSwitcher} from "../../hooks/useLoading.jsx";
|
||||
import {useFetch} from "../../hooks/useFetch.js";
|
||||
import {AxiosError} from "../../components/AxiosError.jsx";
|
||||
import {useAuth} from "../../hooks/useAuth.jsx";
|
||||
import {isClubAdmin} from "../../utils/Tools.js";
|
||||
import {apiAxios, isClubAdmin} from "../../utils/Tools.js";
|
||||
import {ThreeDots} from "react-loader-spinner";
|
||||
import {useEffect, useState} from "react";
|
||||
import {toast} from "react-toastify";
|
||||
|
||||
export function CompetitionView() {
|
||||
|
||||
@ -43,6 +46,7 @@ const inscText = (type) => {
|
||||
|
||||
function MakeContent({data}) {
|
||||
const {userinfo} = useAuth()
|
||||
const navigate = useNavigate()
|
||||
|
||||
return <div className="card mb-4">
|
||||
<div className="card-header">
|
||||
@ -57,10 +61,18 @@ function MakeContent({data}) {
|
||||
<p><strong>Organisateur :</strong> {data.clubName}</p>
|
||||
<p><strong>Type d'inscription :</strong> {inscText(data.registerMode)}</p>
|
||||
{(data.registerMode === "FREE" || data.registerMode === "CLUB_ADMIN") &&
|
||||
<p><strong>Date d'inscription :</strong> Du {new Date(data.startRegister.split('+')[0]).toLocaleString()} au {new Date(data.endRegister.split('+')[0]).toLocaleString()}</p>
|
||||
<p><strong>Date d'inscription
|
||||
:</strong> Du {new Date(data.startRegister.split('+')[0]).toLocaleString()} au {new Date(data.endRegister.split('+')[0]).toLocaleString()}
|
||||
</p>
|
||||
}
|
||||
{(data.registerMode === "CLUB_ADMIN" && isClubAdmin(userinfo)) || data.registerMode === "FREE" &&
|
||||
<button type="button" className="btn btn-primary" disabled={new Date() < new Date(data.startRegister.split('+')[0]) || new Date() > new Date(data.endRegister.split('+')[0])}>Inscription</button>
|
||||
|
||||
{(data.registerMode === "FREE" || data.registerMode === "CLUB_ADMIN") && isClubAdmin(userinfo) &&
|
||||
<button type="button" className="btn btn-primary"
|
||||
disabled={new Date() < new Date(data.startRegister.split('+')[0]) || new Date() > new Date(data.endRegister.split('+')[0])}
|
||||
onClick={_ => navigate("/competition/" + data.id + "/club/register")}>Inscription</button>
|
||||
}
|
||||
{data.registerMode === "FREE" && !isClubAdmin(userinfo) &&
|
||||
<SelfRegister data2={data}/>
|
||||
}
|
||||
{data.registerMode === "HELLOASSO" &&
|
||||
<p><strong>Billetterie :</strong> <a
|
||||
@ -70,3 +82,101 @@ function MakeContent({data}) {
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
function SelfRegister({data2}) {
|
||||
const {id} = useParams()
|
||||
const setLoading = useLoadingSwitcher()
|
||||
const {data, refresh, error} = useFetch(`/competition/${id}/register/user`, setLoading, 1)
|
||||
|
||||
const [weight, setWeight] = useState("")
|
||||
const [cat, setCat] = useState(0)
|
||||
|
||||
useEffect(() => {
|
||||
if (data && data.length > 0) {
|
||||
setWeight(data[0].weight || "")
|
||||
setCat(data[0].overCategory || 0)
|
||||
}
|
||||
}, [data]);
|
||||
|
||||
const disabled = new Date() < new Date(data2.startRegister.split('+')[0]) || new Date() > new Date(data2.endRegister.split('+')[0])
|
||||
|
||||
const handleUnregister = () => {
|
||||
if (window.confirm("Êtes-vous sûr de vouloir vous désinscrire ?")) {
|
||||
toast.promise(apiAxios.delete(`/competition/${id}/register/${data[0].id}/user`), {
|
||||
pending: "Désinscription en cours",
|
||||
success: "Désinscription réalisée",
|
||||
error: {
|
||||
render({data}) {
|
||||
return data.response.data || "Erreur"
|
||||
}
|
||||
}
|
||||
}).finally(() => {
|
||||
refresh(`/competition/${id}/register/user`)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const sendSubmit = (new_state) => {
|
||||
toast.promise(apiAxios.post(`/competition/${id}/register/user`, new_state), {
|
||||
pending: "Enregistrement en cours",
|
||||
success: "Inscription réalisée",
|
||||
error: {
|
||||
render({data}) {
|
||||
return data.response.data || "Combattant non trouvé"
|
||||
}
|
||||
}
|
||||
}).finally(() => {
|
||||
refresh(`/competition/${id}/register/user`)
|
||||
})
|
||||
}
|
||||
|
||||
const handleSubmit = (e) => {
|
||||
sendSubmit({
|
||||
licence: 0, fname: "", lname: "", weight: weight, overCategory: cat, lockEdit: false, id: null
|
||||
})
|
||||
}
|
||||
|
||||
return <>
|
||||
{data
|
||||
? data.length > 0
|
||||
? <div style={{textAlign: "right", maxWidth: "20em"}}>
|
||||
<h4 style={{textAlign: "left"}}>Mon inscription</h4>
|
||||
<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" disabled={disabled}
|
||||
name="weight" aria-describedby="weight" value={weight} onChange={e => setWeight(e.target.value)}/>
|
||||
</div>
|
||||
|
||||
<div style={{textAlign: "left"}}>Catégorie normalisée: {data[0].categorie}</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} disabled={disabled}
|
||||
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>
|
||||
<button type="button" className="btn btn-danger" disabled={disabled} style={{marginRight: "0.5em"}}
|
||||
onClick={handleUnregister}>Se désinscrire
|
||||
</button>
|
||||
<button type="button" className="btn btn-primary" disabled={disabled}
|
||||
onClick={handleSubmit}>Enregister
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
: <button type="button" className="btn btn-primary" disabled={disabled} onClick={handleSubmit}>S'inscrire</button>
|
||||
: error
|
||||
? <AxiosError error={error}/>
|
||||
: <Def/>
|
||||
}
|
||||
</>
|
||||
}
|
||||
|
||||
function Def() {
|
||||
return <div className="list-group">
|
||||
<li className="list-group-item"><ThreeDots/></li>
|
||||
</div>
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user