mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
feat: ajout des documents d'inscription [#20]
This commit is contained in:
@ -16,29 +16,10 @@ export default function Page() {
|
||||
const studentId = searchParams.get('studentId'); // Changé de codeDI à studentId
|
||||
|
||||
const [initialData, setInitialData] = useState(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
const [formErrors, setFormErrors] = useState({});
|
||||
const csrfToken = useCsrfToken();
|
||||
|
||||
useEffect(() => {
|
||||
if (useFakeData) {
|
||||
setInitialData(mockStudent);
|
||||
} else {
|
||||
fetchRegisterForm(studentId)
|
||||
.then(data => {
|
||||
console.log('Fetched data:', data); // Pour le débogage
|
||||
const formattedData = {
|
||||
...data,
|
||||
guardians: data.guardians || []
|
||||
};
|
||||
setInitialData(formattedData);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching student data:', error);
|
||||
});
|
||||
}
|
||||
setIsLoading(false);
|
||||
}, [studentId]); // Dépendance changée à studentId
|
||||
|
||||
const handleSubmit = (data) => {
|
||||
if (useFakeData) {
|
||||
@ -64,11 +45,10 @@ export default function Page() {
|
||||
|
||||
return (
|
||||
<InscriptionFormShared
|
||||
initialData={initialData}
|
||||
studentId={studentId}
|
||||
csrfToken={csrfToken}
|
||||
onSubmit={handleSubmit}
|
||||
cancelUrl={FE_ADMIN_SUBSCRIPTIONS_URL}
|
||||
isLoading={isLoading}
|
||||
errors={formErrors}
|
||||
/>
|
||||
);
|
||||
|
||||
@ -320,99 +320,79 @@ useEffect(()=>{
|
||||
};
|
||||
|
||||
const createRF = (updatedData) => {
|
||||
console.log('createRF updatedData:', updatedData);
|
||||
|
||||
if (updatedData.selectedGuardians.length !== 0) {
|
||||
const selectedGuardiansIds = updatedData.selectedGuardians.map(guardianId => guardianId)
|
||||
|
||||
const data = {
|
||||
student: {
|
||||
last_name: updatedData.studentLastName,
|
||||
first_name: updatedData.studentFirstName,
|
||||
},
|
||||
idGuardians: selectedGuardiansIds
|
||||
student: {
|
||||
last_name: updatedData.studentLastName,
|
||||
first_name: updatedData.studentFirstName,
|
||||
},
|
||||
idGuardians: selectedGuardiansIds
|
||||
};
|
||||
|
||||
createRegisterForm(data,csrfToken)
|
||||
.then(data => {
|
||||
console.log('Success:', data);
|
||||
setRegistrationFormsDataPending(prevState => {
|
||||
if (prevState) {
|
||||
return [...prevState, data];
|
||||
createRegisterForm(data, csrfToken)
|
||||
.then(data => {
|
||||
// Mise à jour immédiate des données
|
||||
setRegistrationFormsDataPending(prevState => [...(prevState || []), data]);
|
||||
setTotalPending(prev => prev + 1);
|
||||
if (updatedData.autoMail) {
|
||||
sendConfirmRegisterForm(data.student.id, updatedData.studentLastName, updatedData.studentFirstName);
|
||||
}
|
||||
return [data];
|
||||
});
|
||||
setTotalPending(totalPending+1);
|
||||
if (updatedData.autoMail) {
|
||||
sendConfirmRegisterForm(data.student.id, updatedData.studentLastName, updatedData.studentFirstName);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
closeModal();
|
||||
// Forcer le rechargement complet des données
|
||||
setReloadFetch(true);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
else {
|
||||
// Création d'un profil associé à l'adresse mail du responsable saisie
|
||||
// Le profil est inactif
|
||||
const data = {
|
||||
email: updatedData.guardianEmail,
|
||||
password: 'Provisoire01!',
|
||||
username: updatedData.guardianEmail,
|
||||
is_active: 0, // On rend le profil inactif : impossible de s'y connecter dans la fenêtre du login tant qu'il ne s'est pas inscrit
|
||||
droit:2 // Profil PARENT
|
||||
}
|
||||
createProfile(data,csrfToken)
|
||||
});
|
||||
} else {
|
||||
const data = {
|
||||
email: updatedData.guardianEmail,
|
||||
password: 'Provisoire01!',
|
||||
username: updatedData.guardianEmail,
|
||||
is_active: 0,
|
||||
droit: 2
|
||||
}
|
||||
|
||||
createProfile(data, csrfToken)
|
||||
.then(response => {
|
||||
console.log('Success:', response);
|
||||
if (response.id) {
|
||||
let idProfile = response.id;
|
||||
if (response.id) {
|
||||
const data = {
|
||||
student: {
|
||||
last_name: updatedData.studentLastName,
|
||||
first_name: updatedData.studentFirstName,
|
||||
guardians: [{
|
||||
email: updatedData.guardianEmail,
|
||||
phone: updatedData.guardianPhone,
|
||||
associated_profile: response.id
|
||||
}],
|
||||
sibling: []
|
||||
}
|
||||
};
|
||||
|
||||
const data = {
|
||||
student: {
|
||||
last_name: updatedData.studentLastName,
|
||||
first_name: updatedData.studentFirstName,
|
||||
guardians: [
|
||||
{
|
||||
email: updatedData.guardianEmail,
|
||||
phone: updatedData.guardianPhone,
|
||||
associated_profile: idProfile // Association entre le responsable de l'élève et le profil créé par défaut précédemment
|
||||
}
|
||||
],
|
||||
sibling: []
|
||||
}
|
||||
};
|
||||
|
||||
createRegisterForm(data,csrfToken)
|
||||
.then(data => {
|
||||
console.log('Success:', data);
|
||||
setRegistrationFormsDataPending(prevState => {
|
||||
if (prevState && prevState.length > 0) {
|
||||
return [...prevState, data];
|
||||
}
|
||||
return prevState;
|
||||
});
|
||||
setTotalPending(totalPending+1);
|
||||
if (updatedData.autoMail) {
|
||||
sendConfirmRegisterForm(data.student.id, updatedData.studentLastName, updatedData.studentFirstName);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
createRegisterForm(data, csrfToken)
|
||||
.then(data => {
|
||||
// Mise à jour immédiate des données
|
||||
setRegistrationFormsDataPending(prevState => [...(prevState || []), data]);
|
||||
setTotalPending(prev => prev + 1);
|
||||
if (updatedData.autoMail) {
|
||||
sendConfirmRegisterForm(data.student.id, updatedData.studentLastName, updatedData.studentFirstName);
|
||||
}
|
||||
closeModal();
|
||||
// Forcer le rechargement complet des données
|
||||
setReloadFetch(true);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching data:', error);
|
||||
error = error.errorMessage;
|
||||
console.log(error);
|
||||
console.error('Error:', error);
|
||||
});
|
||||
}
|
||||
closeModal();
|
||||
setReloadFetch(true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const columns = [
|
||||
{ name: t('studentName'), transform: (row) => row.student.last_name },
|
||||
{ name: t('studentFistName'), transform: (row) => row.student.first_name },
|
||||
@ -426,11 +406,11 @@ const columns = [
|
||||
)
|
||||
},
|
||||
{ name: t('files'), transform: (row) =>
|
||||
(row.registerForms != null) &&(
|
||||
(row.registration_file != null) &&(
|
||||
<ul>
|
||||
<li className="flex items-center gap-2">
|
||||
<FileText size={16} />
|
||||
<a href={ `${BASE_URL}${row.registerForms}`} target='_blank'>{row.registerForms?.split('/').pop()}</a>
|
||||
<a href={ `${BASE_URL}${row.registration_file}`} target='_blank'>{row.registration_file?.split('/').pop()}</a>
|
||||
</li>
|
||||
</ul>
|
||||
) },
|
||||
@ -507,11 +487,11 @@ const columnsSubscribed = [
|
||||
)
|
||||
},
|
||||
{ name: t('files'), transform: (row) =>
|
||||
(row.registerForm != null) &&(
|
||||
(row.registration_file != null) &&(
|
||||
<ul>
|
||||
<li className="flex items-center gap-2">
|
||||
<FileText size={16} />
|
||||
<a href={ `${BASE_URL}${row.registerForm}`} target='_blank'>{row.registerForm?.split('/').pop()}</a>
|
||||
<a href={ `${BASE_URL}${row.registration_file}`} target='_blank'>{row.registration_file?.split('/').pop()}</a>
|
||||
</li>
|
||||
</ul>
|
||||
) },
|
||||
@ -677,7 +657,7 @@ const handleFileUpload = ({file, name, is_required, order}) => {
|
||||
text={(
|
||||
<>
|
||||
{t('subscribeFiles')}
|
||||
<span className="ml-2 text-sm text-gray-400">({totalSubscribed})</span>
|
||||
<span className="ml-2 text-sm text-gray-400">({fichiers.length})</span>
|
||||
</>
|
||||
)}
|
||||
active={activeTab === 'subscribeFiles'}
|
||||
@ -735,12 +715,14 @@ const handleFileUpload = ({file, name, is_required, order}) => {
|
||||
{/*SI STATE == subscribeFiles */}
|
||||
{activeTab === 'subscribeFiles' && (
|
||||
<div>
|
||||
<button
|
||||
onClick={() => { setIsModalOpen(true); setIsEditing(false); }}
|
||||
className="flex items-center bg-emerald-600 text-white p-2 rounded-full shadow hover:bg-emerald-900 transition duration-200 ml-4"
|
||||
>
|
||||
<Plus className="w-5 h-5" />
|
||||
</button>
|
||||
<div className="flex justify-end mb-4">
|
||||
<button
|
||||
onClick={() => { setIsModalOpen(true); setIsEditing(false); }}
|
||||
className="flex items-center bg-emerald-600 text-white p-2 rounded-full shadow hover:bg-emerald-900 transition duration-200"
|
||||
>
|
||||
<Plus className="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
<Modal
|
||||
isOpen={isModalOpen}
|
||||
setIsOpen={setIsModalOpen}
|
||||
|
||||
@ -16,60 +16,17 @@ export default function Page() {
|
||||
const router = useRouter();
|
||||
|
||||
const [initialData, setInitialData] = useState(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const csrfToken = useCsrfToken();
|
||||
const [currentProfil, setCurrentProfil] = useState("");
|
||||
const [lastGuardianId, setLastGuardianId] = useState(1);
|
||||
|
||||
useEffect(() => {
|
||||
if (!studentId || !idProfil) {
|
||||
console.error('Missing studentId or idProfil');
|
||||
return;
|
||||
}
|
||||
|
||||
if (useFakeData) {
|
||||
setInitialData(mockStudent);
|
||||
setLastGuardianId(999);
|
||||
setIsLoading(false);
|
||||
} else {
|
||||
Promise.all([
|
||||
// Fetch eleve data
|
||||
fetchRegisterForm(studentId),
|
||||
// Fetch last guardian ID
|
||||
fetchLastGuardian()
|
||||
])
|
||||
.then(async ([studentData, guardianData]) => {
|
||||
const formattedData = {
|
||||
...studentData,
|
||||
guardians: studentData.guardians || []
|
||||
};
|
||||
|
||||
setInitialData(formattedData);
|
||||
setLastGuardianId(guardianData.lastid);
|
||||
|
||||
let profils = studentData.profils;
|
||||
const currentProf = profils.find(profil => profil.id === idProfil);
|
||||
if (currentProf) {
|
||||
setCurrentProfil(currentProf);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching data:', error);
|
||||
})
|
||||
.finally(() => {
|
||||
setIsLoading(false);
|
||||
});
|
||||
}
|
||||
}, [studentId, idProfil]);
|
||||
|
||||
const handleSubmit = async (data) => {
|
||||
if (useFakeData) {
|
||||
console.log('Fake submit:', data);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
const result = await editRegisterForm(studentId, data, csrfToken);
|
||||
console.log('Success:', result);
|
||||
router.push(FE_PARENTS_HOME_URL);
|
||||
@ -80,7 +37,7 @@ export default function Page() {
|
||||
|
||||
return (
|
||||
<InscriptionFormShared
|
||||
initialData={initialData}
|
||||
studentId={studentId}
|
||||
csrfToken={csrfToken}
|
||||
onSubmit={handleSubmit}
|
||||
cancelUrl={FE_PARENTS_HOME_URL}
|
||||
|
||||
@ -41,7 +41,7 @@ export const fetchRegisterForms = (type=PENDING, page='', pageSize='', search =
|
||||
};
|
||||
|
||||
export const fetchRegisterForm = (id) =>{
|
||||
return fetch(`${BE_SUBSCRIPTION_STUDENT_URL}/${id}`) // Utilisation de studentId au lieu de codeDI
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTERFORM_URL}/${id}`) // Utilisation de studentId au lieu de codeDI
|
||||
.then(requestResponseHandler)
|
||||
}
|
||||
export const fetchLastGuardian = () =>{
|
||||
@ -98,31 +98,36 @@ export const sendRegisterForm = (id) => {
|
||||
|
||||
}
|
||||
|
||||
export const fetchRegisterFormFileTemplate = () => {
|
||||
const request = new Request(
|
||||
`${BE_SUBSCRIPTION_REGISTRATIONFORMFILE_TEMPLATE_URL}`,
|
||||
{
|
||||
method:'GET',
|
||||
headers: {
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
}
|
||||
);
|
||||
return fetch(request).then(requestResponseHandler)
|
||||
|
||||
|
||||
export const fetchRegisterFormFile = (id = null) => {
|
||||
let url = `${BE_SUBSCRIPTION_REGISTRATIONFORMFILE_URL}`
|
||||
if (id) {
|
||||
url = `${BE_SUBSCRIPTION_REGISTRATIONFORMFILE_URL}/${id}`;
|
||||
}
|
||||
const request = new Request(
|
||||
`${url}`,
|
||||
{
|
||||
method:'GET',
|
||||
headers: {
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
}
|
||||
);
|
||||
return fetch(request).then(requestResponseHandler)
|
||||
};
|
||||
|
||||
export const fetchRegisterFormFile = (id) => {
|
||||
const request = new Request(
|
||||
`${BE_SUBSCRIPTION_REGISTRATIONFORMFILE_URL}/${id}`,
|
||||
{
|
||||
method:'GET',
|
||||
headers: {
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
}
|
||||
);
|
||||
return fetch(request).then(requestResponseHandler)
|
||||
};
|
||||
export const editRegistrationFormFile= (fileId, data, csrfToken) => {
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTRATIONFORMFILE_URL}/${fileId}`, {
|
||||
method: 'PUT',
|
||||
body: data,
|
||||
headers: {
|
||||
'X-CSRFToken': csrfToken,
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
.then(requestResponseHandler)
|
||||
}
|
||||
|
||||
export const createRegistrationFormFile = (data,csrfToken) => {
|
||||
|
||||
@ -137,6 +142,33 @@ export const createRegistrationFormFile = (data,csrfToken) => {
|
||||
.then(requestResponseHandler)
|
||||
}
|
||||
|
||||
export const deleteRegisterFormFile= (fileId,csrfToken) => {
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTRATIONFORMFILE_URL}/${fileId}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'X-CSRFToken': csrfToken,
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchRegisterFormFileTemplate = (id = null) => {
|
||||
let url = `${BE_SUBSCRIPTION_REGISTRATIONFORMFILE_TEMPLATE_URL}`;
|
||||
if(id){
|
||||
url = `${BE_SUBSCRIPTION_REGISTRATIONFORMFILE_TEMPLATE_URL}/${id}`;
|
||||
}
|
||||
const request = new Request(
|
||||
`${url}`,
|
||||
{
|
||||
method:'GET',
|
||||
headers: {
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
}
|
||||
);
|
||||
return fetch(request).then(requestResponseHandler)
|
||||
};
|
||||
|
||||
export const createRegistrationFormFileTemplate = (data,csrfToken) => {
|
||||
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTRATIONFORMFILE_TEMPLATE_URL}`, {
|
||||
|
||||
Reference in New Issue
Block a user