feat: Ajout d'une fonction de dissociation entre un responsable et un

élève
This commit is contained in:
N3WT DE COMPET
2025-03-20 20:28:12 +01:00
parent fb73f9e9a8
commit 3bcc620ee1
9 changed files with 148 additions and 40 deletions

View File

@ -1,12 +1,12 @@
'use client'
import React, { useState, useEffect } from 'react';
import { fetchProfileRoles, updateProfileRoles, deleteProfileRoles } from '@/app/actions/authAction';
import { dissociateGuardian } from '@/app/actions/subscriptionAction';
import logger from '@/utils/logger';
import { useEstablishment } from '@/context/EstablishmentContext';
import DjangoCSRFToken from '@/components/DjangoCSRFToken';
import { useCsrfToken } from '@/context/CsrfContext';
import ProfileDirectory from '@/components/ProfileDirectory';
import { BE_AUTH_PROFILES_ROLES_URL } from '@/utils/Url';
export default function Page() {
const [profileRoles, setProfileRoles] = useState([]);
@ -54,12 +54,23 @@ export default function Page() {
});
};
const handleDissociate = (studentId, guardianId) => {
return dissociateGuardian(studentId, guardianId)
.then(() => {
logger.debug("Guardian dissociated successfully:", guardianId);
})
.catch(error => {
logger.error('Error dissociating guardian:', error);
throw error;
});
};
return (
<div className='p-8'>
<DjangoCSRFToken csrfToken={csrfToken} />
<div className="w-full p-4">
<ProfileDirectory profileRoles={profileRoles} handleActivateProfile={handleEdit} handleDeleteProfile={handleDelete} />
<ProfileDirectory profileRoles={profileRoles} handleActivateProfile={handleEdit} handleDeleteProfile={handleDelete} handleDissociateGuardian={handleDissociate} />
</div>
</div>
);

View File

@ -151,4 +151,18 @@ export const fetchTemplatesFromRegistrationFiles = async (id) => {
throw new Error('Erreur lors de la récupération des fichiers associés au groupe');
}
return response.json();
}
}
export const dissociateGuardian = async (studentId, guardianId) => {
const response = await fetch(`${BE_SUBSCRIPTION_STUDENTS_URL}/${studentId}/guardians/${guardianId}/dissociate`, {
credentials: 'include',
method: 'PUT',
headers: {
'Accept': 'application/json',
},
});
if (!response.ok) {
throw new Error('Erreur lors de la dissociation.');
}
return response.json();
};