feat: add category registration system to club and user
This commit is contained in:
parent
a5d3973394
commit
b419e2f58d
@ -349,7 +349,8 @@ public class CompetitionService {
|
|||||||
.chain(model -> registerRepository.find("competition.id = ?1 AND membre = ?2", id, model).firstResult()
|
.chain(model -> registerRepository.find("competition.id = ?1 AND membre = ?2", id, model).firstResult()
|
||||||
.call(rm -> rm == null ? Uni.createFrom().voidItem() :
|
.call(rm -> rm == null ? Uni.createFrom().voidItem() :
|
||||||
Mutiny.fetch(rm.getCategoriesInscrites()))
|
Mutiny.fetch(rm.getCategoriesInscrites()))
|
||||||
.map(rm -> rm == null ? List.of() : List.of(SimpleRegisterComb.fromModel(rm, List.of()))));
|
.map(rm -> rm == null ? List.of() : List.of(SimpleRegisterComb.fromModel(rm, List.of())
|
||||||
|
.setCategorieInscrite(rm.getCategoriesInscrites()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Uni<SimpleRegisterComb> addRegisterComb(SecurityCtx securityCtx, Long id, RegisterRequestData data,
|
public Uni<SimpleRegisterComb> addRegisterComb(SecurityCtx securityCtx, Long id, RegisterRequestData data,
|
||||||
@ -423,7 +424,8 @@ public class CompetitionService {
|
|||||||
throw new DForbiddenException(trad.t("insc.err1"));
|
throw new DForbiddenException(trad.t("insc.err1"));
|
||||||
}))
|
}))
|
||||||
.chain(combModel -> updateRegister(data, c, combModel, false)))
|
.chain(combModel -> updateRegister(data, c, combModel, false)))
|
||||||
.map(r -> SimpleRegisterComb.fromModel(r, r.getMembre().getLicences()));
|
.map(r -> SimpleRegisterComb.fromModel(r, r.getMembre().getLicences())
|
||||||
|
.setCategorieInscrite(r.getCategoriesInscrites()));
|
||||||
|
|
||||||
return repository.findById(id)
|
return repository.findById(id)
|
||||||
.invoke(Unchecked.consumer(cm -> {
|
.invoke(Unchecked.consumer(cm -> {
|
||||||
@ -438,7 +440,7 @@ public class CompetitionService {
|
|||||||
throw new DForbiddenException(trad.t("insc.err2"));
|
throw new DForbiddenException(trad.t("insc.err2"));
|
||||||
}))
|
}))
|
||||||
.chain(combModel -> updateRegister(data, c, combModel, false)))
|
.chain(combModel -> updateRegister(data, c, combModel, false)))
|
||||||
.map(r -> SimpleRegisterComb.fromModel(r, List.of()));
|
.map(r -> SimpleRegisterComb.fromModel(r, List.of()).setCategorieInscrite(r.getCategoriesInscrites()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Uni<RegisterModel> updateRegister(RegisterRequestData data, CompetitionModel c,
|
private Uni<RegisterModel> updateRegister(RegisterRequestData data, CompetitionModel c,
|
||||||
|
|||||||
@ -381,11 +381,15 @@ public class KeycloakService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Optional<UserRepresentation> getUserById(String userId) {
|
public Optional<UserRepresentation> getUserById(String userId) {
|
||||||
|
try {
|
||||||
UserResource user = keycloak.realm(realm).users().get(userId);
|
UserResource user = keycloak.realm(realm).users().get(userId);
|
||||||
if (user == null)
|
if (user == null)
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
else
|
else
|
||||||
return Optional.of(user.toRepresentation());
|
return Optional.of(user.toRepresentation());
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String makeLogin(MembreModel model) {
|
private String makeLogin(MembreModel model) {
|
||||||
|
|||||||
@ -44,8 +44,8 @@ service.momentanement.indisponible=Service momentan
|
|||||||
asso.introuvable=Association introuvable
|
asso.introuvable=Association introuvable
|
||||||
erreur.lors.calcul.du.trie=Erreur lors du calcul du tri
|
erreur.lors.calcul.du.trie=Erreur lors du calcul du tri
|
||||||
page.out.of.range=Page out of range
|
page.out.of.range=Page out of range
|
||||||
le.membre.appartient.pas.a.votre.club=Le membre n°%d n?appartient pas à votre club
|
le.membre.appartient.pas.a.votre.club=Le membre n°%d n'appartient pas à votre club
|
||||||
email.deja.utilise.par=L?adresse e-mail '%s' est déjà utilisée par %s %s
|
email.deja.utilise.par=L'adresse e-mail '%s' est déjà utilisée par %s %s
|
||||||
try.edit.licence=Pour enregistrer un nouveau membre, veuillez laisser le champ licence vide. (Tentative de modification non autorisée du nom sur la licence %d pour %s %s)
|
try.edit.licence=Pour enregistrer un nouveau membre, veuillez laisser le champ licence vide. (Tentative de modification non autorisée du nom sur la licence %d pour %s %s)
|
||||||
email.deja.utilise=Adresse e-mail déjà utilisée
|
email.deja.utilise=Adresse e-mail déjà utilisée
|
||||||
regiter.new.membre=Pour enregistrer un nouveau membre, veuillez utiliser le bouton prévu à cet effet.
|
regiter.new.membre=Pour enregistrer un nouveau membre, veuillez utiliser le bouton prévu à cet effet.
|
||||||
@ -61,23 +61,23 @@ licence.rm.err1=Impossible de supprimer une licence pour laquelle un paiement es
|
|||||||
licence.deja.demandee=Licence déjà demandée
|
licence.deja.demandee=Licence déjà demandée
|
||||||
impossible.de.supprimer.une.licence.deja.validee=Impossible de supprimer une licence déjà validée
|
impossible.de.supprimer.une.licence.deja.validee=Impossible de supprimer une licence déjà validée
|
||||||
impossible.de.supprimer.une.licence.deja.payee=Impossible de supprimer une licence déjà payée
|
impossible.de.supprimer.une.licence.deja.payee=Impossible de supprimer une licence déjà payée
|
||||||
vous.ne.pouvez.pas.creer.de.competition=Vous n?êtes pas autorisé à créer une compétition
|
vous.ne.pouvez.pas.creer.de.competition=Vous n'êtes pas autorisé à créer une compétition
|
||||||
user.not.found=Utilisateur %s introuvable
|
user.not.found=Utilisateur %s introuvable
|
||||||
inscription.fermee=Inscription fermée
|
inscription.fermee=Inscription fermée
|
||||||
insc.err1=Vous n?êtes pas autorisé à inscrire ce membre (décision de l?administrateur de la compétition)
|
insc.err1=Vous n'êtes pas autorisé à inscrire ce membre (décision de l'administrateur de la compétition)
|
||||||
insc.err2=Vous n?êtes pas autorisé à vous inscrire (décision de l?administrateur de la compétition)
|
insc.err2=Vous n'êtes pas autorisé à vous inscrire (décision de l'administrateur de la compétition)
|
||||||
insc.err3=Modification bloquée par l?administrateur de la compétition
|
insc.err3=Modification bloquée par l'administrateur de la compétition
|
||||||
licence.non.trouve=Licence %s introuvable
|
licence.non.trouve=Licence %s introuvable
|
||||||
nom.et.prenom.requis=Nom et prénom obligatoires
|
nom.et.prenom.requis=Nom et prénom obligatoires
|
||||||
combattant.non.trouve=Combattant %s %s introuvable
|
combattant.non.trouve=Combattant %s %s introuvable
|
||||||
le.membre.n.existe.pas=Le membre n°%d n?existe pas
|
le.membre.n.existe.pas=Le membre n°%d n'existe pas
|
||||||
competition.is.not.internal=Competition is not INTERNAL
|
competition.is.not.internal=Competition is not INTERNAL
|
||||||
erreur.de.format.des.contacts=Format des contacts invalide
|
erreur.de.format.des.contacts=Format des contacts invalide
|
||||||
competition.not.found=Compétition introuvable
|
competition.not.found=Compétition introuvable
|
||||||
saison.non.valid=Saison invalide
|
saison.non.valid=Saison invalide
|
||||||
demande.d.affiliation.deja.existante=Une demande d?affiliation existe déjà
|
demande.d.affiliation.deja.existante=Une demande d'affiliation existe déjà
|
||||||
affiliation.deja.existante=Affiliation déjà existante
|
affiliation.deja.existante=Affiliation déjà existante
|
||||||
licence.membre.n.1.inconnue=Licence du membre n°1 inconnue
|
licence.membre.n.1.inconnue=Licence du membre n°1 inconnue
|
||||||
licence.membre.n.2.inconnue=Licence du membre n°2 inconnue
|
licence.membre.n.2.inconnue=Licence du membre n°2 inconnue
|
||||||
licence.membre.n.3.inconnue=Licence du membre n°3 inconnue
|
licence.membre.n.3.inconnue=Licence du membre n°3 inconnue
|
||||||
demande.d.affiliation.non.trouve=Demande d?affiliation introuvable
|
demande.d.affiliation.non.trouve=Demande d'affiliation introuvable
|
||||||
@ -1,14 +0,0 @@
|
|||||||
import Keycloak from "keycloak-js";
|
|
||||||
|
|
||||||
const vite_url = import.meta.env.VITE_URL;
|
|
||||||
const client_id = import.meta.env.VITE_CLIENT_ID;
|
|
||||||
|
|
||||||
const keycloak = new Keycloak({
|
|
||||||
url: `${vite_url}/auth-api`,
|
|
||||||
realm: "safca",
|
|
||||||
clientId: client_id,
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default keycloak;
|
|
||||||
@ -132,7 +132,8 @@ function QuickAdd({sendRegister, source, data2, error2}) {
|
|||||||
<label htmlFor="inputState2" className="form-label align-self-center" style={{margin: "0 0.5em 0 0"}}>
|
<label htmlFor="inputState2" className="form-label align-self-center" style={{margin: "0 0.5em 0 0"}}>
|
||||||
{t('catégorieàAjouter')}<br/> <small>({t('siDisponiblePourLaCatégorieDages')})</small>
|
{t('catégorieàAjouter')}<br/> <small>({t('siDisponiblePourLaCatégorieDages')})</small>
|
||||||
</label>
|
</label>
|
||||||
<CategoriesList error2={error2} availableCats={data2} categories={categories} setCategories={setCategories_}/>
|
<CategoriesList error2={error2} availableCats={data2.sort((a, b) => a.name.localeCompare(b.name))} categories={categories}
|
||||||
|
setCategories={setCategories_}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="row">
|
<div className="row">
|
||||||
|
|||||||
@ -3,9 +3,9 @@ import {useLoadingSwitcher} from "../../hooks/useLoading.jsx";
|
|||||||
import {useFetch} from "../../hooks/useFetch.js";
|
import {useFetch} from "../../hooks/useFetch.js";
|
||||||
import {AxiosError} from "../../components/AxiosError.jsx";
|
import {AxiosError} from "../../components/AxiosError.jsx";
|
||||||
import {useAuth} from "../../hooks/useAuth.jsx";
|
import {useAuth} from "../../hooks/useAuth.jsx";
|
||||||
import {apiAxios, getToastMessage, isClubAdmin} from "../../utils/Tools.js";
|
import {apiAxios, applyOverCategory, getCatName, getToastMessage, isClubAdmin} from "../../utils/Tools.js";
|
||||||
import {ThreeDots} from "react-loader-spinner";
|
import {ThreeDots} from "react-loader-spinner";
|
||||||
import {useEffect, useState} from "react";
|
import React, {useEffect, useState} from "react";
|
||||||
import {toast} from "react-toastify";
|
import {toast} from "react-toastify";
|
||||||
import {useTranslation} from "react-i18next";
|
import {useTranslation} from "react-i18next";
|
||||||
import i18n from "i18next";
|
import i18n from "i18next";
|
||||||
@ -97,15 +97,18 @@ function SelfRegister({data2}) {
|
|||||||
const {id} = useParams()
|
const {id} = useParams()
|
||||||
const setLoading = useLoadingSwitcher()
|
const setLoading = useLoadingSwitcher()
|
||||||
const {data, refresh, error} = useFetch(`/competition/${id}/register/user`, setLoading, 1)
|
const {data, refresh, error} = useFetch(`/competition/${id}/register/user`, setLoading, 1)
|
||||||
|
const {data: data3, error: error2} = useFetch(`/competition/${id}/categories`, setLoading, 1)
|
||||||
const {t} = useTranslation();
|
const {t} = useTranslation();
|
||||||
|
|
||||||
const [weight, setWeight] = useState("")
|
const [weight, setWeight] = useState("")
|
||||||
const [cat, setCat] = useState(0)
|
const [cat, setCat] = useState(0)
|
||||||
|
const [categories, setCategories] = useState([])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data && data.length > 0) {
|
if (data && data.length > 0) {
|
||||||
setWeight(data[0].weight || "")
|
setWeight(data[0].weight || "")
|
||||||
setCat(data[0].overCategory || 0)
|
setCat(data[0].overCategory || 0)
|
||||||
|
setCategories(data[0].categoriesInscrites || [])
|
||||||
}
|
}
|
||||||
}, [data]);
|
}, [data]);
|
||||||
|
|
||||||
@ -129,14 +132,27 @@ function SelfRegister({data2}) {
|
|||||||
|
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
sendSubmit({
|
sendSubmit({
|
||||||
licence: 0, fname: "", lname: "", weight: weight, overCategory: cat, lockEdit: false, id: null
|
licence: 0, fname: "", lname: "", weight: weight, overCategory: cat, lockEdit: false, id: null, categoriesInscrites: categories
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const setCategories_ = (e, catId) => {
|
||||||
|
if (e.target.checked) {
|
||||||
|
if (!categories.includes(catId)) {
|
||||||
|
setCategories([...categories, catId])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setCategories(categories.filter(c => c !== catId))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const currenCat = data?.length > 0 && data[0]?.categorie !== "" ? applyOverCategory(data[0]?.categorie, cat) : "";
|
||||||
|
const availableCats = data3 ? (currenCat !== "" ? data3.filter(c => c.categories.includes(currenCat)) : data3).sort((a, b) => a.name.localeCompare(b.name)) : []
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
{data
|
{data
|
||||||
? data.length > 0
|
? data.length > 0
|
||||||
? <div style={{textAlign: "right", maxWidth: "20em"}}>
|
? <div style={{textAlign: "right", maxWidth: "30em"}}>
|
||||||
<h4 style={{textAlign: "left"}}>{t('comp.monInscription')}</h4>
|
<h4 style={{textAlign: "left"}}>{t('comp.monInscription')}</h4>
|
||||||
<div className="input-group mb-3">
|
<div className="input-group mb-3">
|
||||||
<span className="input-group-text" id="weight">{t("comp.modal.poids")}</span>
|
<span className="input-group-text" id="weight">{t("comp.modal.poids")}</span>
|
||||||
@ -144,7 +160,7 @@ function SelfRegister({data2}) {
|
|||||||
name="weight" aria-describedby="weight" value={weight} onChange={e => setWeight(e.target.value)}/>
|
name="weight" aria-describedby="weight" value={weight} onChange={e => setWeight(e.target.value)}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style={{textAlign: "left"}}>{t('comp.catégorieNormalisée')}: {data[0].categorie}</div>
|
<div style={{textAlign: "left"}}>{t('comp.catégorieNormalisée')}: {getCatName(data[0].categorie)}</div>
|
||||||
<div className="input-group mb-3">
|
<div className="input-group mb-3">
|
||||||
<span className="input-group-text" id="categorie">{t("comp.modal.surclassement")}</span>
|
<span className="input-group-text" id="categorie">{t("comp.modal.surclassement")}</span>
|
||||||
<select className="form-select" aria-label="categorie" name="categorie" value={cat} disabled={disabled}
|
<select className="form-select" aria-label="categorie" name="categorie" value={cat} disabled={disabled}
|
||||||
@ -155,6 +171,25 @@ function SelfRegister({data2}) {
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="d-flex flex-wrap mb-3">
|
||||||
|
<label htmlFor="inputState2" className="form-label align-self-center" style={{margin: "0 0.5em 0 0"}}>
|
||||||
|
{t('catégorie')} :
|
||||||
|
</label>
|
||||||
|
{error2 ? <AxiosError error={error2}/> : <>
|
||||||
|
{availableCats && availableCats.length === 0 && <div>{t('aucuneCatégorieDisponible')}</div>}
|
||||||
|
{availableCats && availableCats.map((cat, index) =>
|
||||||
|
<div key={cat.id} className="input-group"
|
||||||
|
style={{display: "contents"}}>
|
||||||
|
<div className="input-group-text">
|
||||||
|
<input className="form-check-input mt-0" type="checkbox"
|
||||||
|
id={"categoriesInput" + index} checked={categories.includes(cat.id)} aria-label={cat.name}
|
||||||
|
onChange={e => setCategories_(e, cat.id)}/>
|
||||||
|
<label style={{marginLeft: "0.5em"}} htmlFor={"categoriesInput" + index}>{cat.name}</label>
|
||||||
|
</div>
|
||||||
|
</div>)}
|
||||||
|
</>}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<button type="button" className="btn btn-danger" disabled={disabled} style={{marginRight: "0.5em"}}
|
<button type="button" className="btn btn-danger" disabled={disabled} style={{marginRight: "0.5em"}}
|
||||||
onClick={handleUnregister}>{t('button.seDésinscrire')}
|
onClick={handleUnregister}>{t('button.seDésinscrire')}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user