mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-04-05 20:51:26 +00:00
feat: Gestion de l'affichage des documents validés et non validés sur la page parent [N3WTS-2]
This commit is contained in:
@ -33,6 +33,27 @@ export default function ValidateSubscription({
|
||||
const [isPageValid, setIsPageValid] = useState(false);
|
||||
// Pour la validation/refus des documents
|
||||
const [docStatuses, setDocStatuses] = useState({}); // {index: 'accepted'|'refused'}
|
||||
|
||||
// Met à jour docStatuses selon isValidated des templates récupérés
|
||||
useEffect(() => {
|
||||
// On construit la map index -> status à partir des templates
|
||||
const newStatuses = {};
|
||||
// Fiche élève (pas de validation individuelle)
|
||||
newStatuses[0] = undefined;
|
||||
// School templates
|
||||
schoolFileTemplates.forEach((tpl, i) => {
|
||||
if (typeof tpl.isValidated === 'boolean') {
|
||||
newStatuses[1 + i] = tpl.isValidated ? 'accepted' : 'refused';
|
||||
}
|
||||
});
|
||||
// Parent templates
|
||||
parentFileTemplates.forEach((tpl, i) => {
|
||||
if (typeof tpl.isValidated === 'boolean') {
|
||||
newStatuses[1 + schoolFileTemplates.length + i] = tpl.isValidated ? 'accepted' : 'refused';
|
||||
}
|
||||
});
|
||||
setDocStatuses(s => ({ ...s, ...newStatuses }));
|
||||
}, [schoolFileTemplates, parentFileTemplates]);
|
||||
const [showRefusedPopup, setShowRefusedPopup] = useState(false);
|
||||
|
||||
// Affiche la popup de confirmation finale (tous docs validés et classe sélectionnée)
|
||||
@ -155,8 +176,8 @@ export default function ValidateSubscription({
|
||||
.map((doc, idx) => ({ ...doc, idx }))
|
||||
.filter((doc, idx) => docStatuses[idx] === 'refused');
|
||||
|
||||
// Récupère la liste des documents à cocher (inclut la fiche élève)
|
||||
const docIndexes = allTemplates.map((_, idx) => idx);
|
||||
// Récupère la liste des documents à cocher (hors fiche élève)
|
||||
const docIndexes = allTemplates.map((_, idx) => idx).filter(idx => idx !== 0);
|
||||
const allChecked = docIndexes.length > 0 && docIndexes.every(idx => docStatuses[idx] === 'accepted' || docStatuses[idx] === 'refused');
|
||||
const allValidated = docIndexes.length > 0 && docIndexes.every(idx => docStatuses[idx] === 'accepted');
|
||||
const hasRefused = docIndexes.some(idx => docStatuses[idx] === 'refused');
|
||||
@ -223,84 +244,75 @@ export default function ValidateSubscription({
|
||||
)}
|
||||
</span>
|
||||
<span className="flex-1">{template.name}</span>
|
||||
{/* 3 boutons côte à côte : À traiter / Validé / Refusé (pour tous les documents, y compris fiche élève) */}
|
||||
<span className="ml-2 flex gap-1">
|
||||
<button
|
||||
type="button"
|
||||
className={`px-2 py-1 rounded-full text-xs font-medium border transition-colors focus:outline-none focus:ring-2 focus:ring-blue-400
|
||||
${docStatuses[index] === undefined ? 'bg-gray-300 text-gray-700 border-gray-400' : 'bg-white text-gray-500 border-gray-300'}`}
|
||||
aria-pressed={docStatuses[index] === undefined}
|
||||
onClick={e => {
|
||||
e.stopPropagation();
|
||||
setDocStatuses(s => ({ ...s, [index]: undefined }));
|
||||
}}
|
||||
>À traiter</button>
|
||||
<button
|
||||
type="button"
|
||||
className={`px-2 py-1 rounded-full text-xs font-medium border transition-colors focus:outline-none focus:ring-2 focus:ring-blue-400 flex items-center gap-1
|
||||
${docStatuses[index] === 'accepted' ? 'bg-emerald-500 text-white border-emerald-500' : 'bg-white text-emerald-600 border-emerald-300'}`}
|
||||
aria-pressed={docStatuses[index] === 'accepted'}
|
||||
onClick={e => {
|
||||
e.stopPropagation();
|
||||
setDocStatuses(s => ({ ...s, [index]: 'accepted' }));
|
||||
// Appel API pour valider le document (hors fiche élève)
|
||||
if (index > 0 && handleValidateOrRefuseDoc) {
|
||||
// index 0 = fiche élève, ensuite school puis parent puis SEPA
|
||||
let template = null;
|
||||
let type = null;
|
||||
if (index > 0 && index <= schoolFileTemplates.length) {
|
||||
template = schoolFileTemplates[index - 1];
|
||||
type = 'school';
|
||||
} else if (index > schoolFileTemplates.length && index <= schoolFileTemplates.length + parentFileTemplates.length) {
|
||||
template = parentFileTemplates[index - 1 - schoolFileTemplates.length];
|
||||
type = 'parent';
|
||||
{/* 2 boutons : Validé / Refusé (sauf fiche élève) */}
|
||||
{index !== 0 && (
|
||||
<span className="ml-2 flex gap-1">
|
||||
<button
|
||||
type="button"
|
||||
className={`px-2 py-1 rounded-full text-xs font-medium border transition-colors focus:outline-none focus:ring-2 focus:ring-blue-400 flex items-center gap-1
|
||||
${docStatuses[index] === 'accepted' ? 'bg-emerald-500 text-white border-emerald-500' : 'bg-white text-emerald-600 border-emerald-300'}`}
|
||||
aria-pressed={docStatuses[index] === 'accepted'}
|
||||
onClick={e => {
|
||||
e.stopPropagation();
|
||||
setDocStatuses(s => ({ ...s, [index]: 'accepted' }));
|
||||
// Appel API pour valider le document
|
||||
if (handleValidateOrRefuseDoc) {
|
||||
let template = null;
|
||||
let type = null;
|
||||
if (index > 0 && index <= schoolFileTemplates.length) {
|
||||
template = schoolFileTemplates[index - 1];
|
||||
type = 'school';
|
||||
} else if (index > schoolFileTemplates.length && index <= schoolFileTemplates.length + parentFileTemplates.length) {
|
||||
template = parentFileTemplates[index - 1 - schoolFileTemplates.length];
|
||||
type = 'parent';
|
||||
}
|
||||
if (template && template.id) {
|
||||
handleValidateOrRefuseDoc({
|
||||
templateId: template.id,
|
||||
type,
|
||||
validated: true,
|
||||
csrfToken,
|
||||
});
|
||||
}
|
||||
}
|
||||
if (template && template.id) {
|
||||
handleValidateOrRefuseDoc({
|
||||
templateId: template.id,
|
||||
type,
|
||||
validated: true,
|
||||
csrfToken,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<span className="text-lg">✓</span> Validé
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={`px-2 py-1 rounded-full text-xs font-medium border transition-colors focus:outline-none focus:ring-2 focus:ring-blue-400 flex items-center gap-1
|
||||
${docStatuses[index] === 'refused' ? 'bg-red-500 text-white border-red-500' : 'bg-white text-red-600 border-red-300'}`}
|
||||
aria-pressed={docStatuses[index] === 'refused'}
|
||||
onClick={e => {
|
||||
e.stopPropagation();
|
||||
setDocStatuses(s => ({ ...s, [index]: 'refused' }));
|
||||
// Appel API pour refuser le document
|
||||
if (handleValidateOrRefuseDoc) {
|
||||
let template = null;
|
||||
let type = null;
|
||||
if (index > 0 && index <= schoolFileTemplates.length) {
|
||||
template = schoolFileTemplates[index - 1];
|
||||
type = 'school';
|
||||
} else if (index > schoolFileTemplates.length && index <= schoolFileTemplates.length + parentFileTemplates.length) {
|
||||
template = parentFileTemplates[index - 1 - schoolFileTemplates.length];
|
||||
type = 'parent';
|
||||
}
|
||||
if (template && template.id) {
|
||||
handleValidateOrRefuseDoc({
|
||||
templateId: template.id,
|
||||
type,
|
||||
validated: false,
|
||||
csrfToken,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<span className="text-lg">✓</span> Validé
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={`px-2 py-1 rounded-full text-xs font-medium border transition-colors focus:outline-none focus:ring-2 focus:ring-blue-400 flex items-center gap-1
|
||||
${docStatuses[index] === 'refused' ? 'bg-red-500 text-white border-red-500' : 'bg-white text-red-600 border-red-300'}`}
|
||||
aria-pressed={docStatuses[index] === 'refused'}
|
||||
onClick={e => {
|
||||
e.stopPropagation();
|
||||
setDocStatuses(s => ({ ...s, [index]: 'refused' }));
|
||||
// Appel API pour refuser le document (hors fiche élève)
|
||||
if (index > 0 && handleValidateOrRefuseDoc) {
|
||||
let template = null;
|
||||
let type = null;
|
||||
if (index > 0 && index <= schoolFileTemplates.length) {
|
||||
template = schoolFileTemplates[index - 1];
|
||||
type = 'school';
|
||||
} else if (index > schoolFileTemplates.length && index <= schoolFileTemplates.length + parentFileTemplates.length) {
|
||||
template = parentFileTemplates[index - 1 - schoolFileTemplates.length];
|
||||
type = 'parent';
|
||||
}
|
||||
if (template && template.id) {
|
||||
handleValidateOrRefuseDoc({
|
||||
templateId: template.id,
|
||||
type,
|
||||
validated: false,
|
||||
csrfToken,
|
||||
});
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<span className="text-lg">✗</span> Refusé
|
||||
</button>
|
||||
</span>
|
||||
}}
|
||||
>
|
||||
<span className="text-lg">✗</span> Refusé
|
||||
</button>
|
||||
</span>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
@ -377,7 +389,7 @@ export default function ValidateSubscription({
|
||||
<span>
|
||||
{`Le dossier d'inscription de ${firstName} ${lastName} va être refusé. Un email sera envoyé au responsable à l'adresse : `}
|
||||
<span className="font-semibold text-blue-700">{email}</span>
|
||||
{` avec la liste des documents non validés :`}
|
||||
{' avec la liste des documents non validés :'}
|
||||
<ul className="list-disc ml-6 mt-2">
|
||||
{refusedDocs.map(doc => (
|
||||
<li key={doc.idx}>{doc.name}</li>
|
||||
|
||||
Reference in New Issue
Block a user