mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 16:03:21 +00:00
refactor: Refactorisation du login et de admin/subscription
This commit is contained in:
@ -2,11 +2,10 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import InscriptionFormShared from '@/components/Inscription/InscriptionFormShared';
|
||||
import { FE_ADMIN_SUBSCRIPTIONS_URL,
|
||||
BE_SUBSCRIPTION_STUDENT_URL,
|
||||
BE_SUBSCRIPTION_REGISTERFORM_URL } from '@/utils/Url';
|
||||
import { FE_ADMIN_SUBSCRIPTIONS_URL } from '@/utils/Url';
|
||||
import useCsrfToken from '@/hooks/useCsrfToken';
|
||||
import { mockStudent } from '@/data/mockStudent';
|
||||
import { editRegisterForm, fetchRegisterForm } from '@/app/lib/subscriptionAction';
|
||||
|
||||
const useFakeData = process.env.NEXT_PUBLIC_USE_FAKE_DATA === 'true';
|
||||
|
||||
@ -24,22 +23,21 @@ export default function Page() {
|
||||
setInitialData(mockStudent);
|
||||
setIsLoading(false);
|
||||
} else {
|
||||
fetch(`${BE_SUBSCRIPTION_STUDENT_URL}/${studentId}`) // Utilisation de studentId au lieu de codeDI
|
||||
.then(response => response.json())
|
||||
fetchRegisterForm(studentId)
|
||||
.then(data => {
|
||||
console.log('Fetched data:', data); // Pour le débogage
|
||||
const formattedData = {
|
||||
id: data.id,
|
||||
nom: data.nom,
|
||||
prenom: data.prenom,
|
||||
adresse: data.adresse,
|
||||
dateNaissance: data.dateNaissance,
|
||||
lieuNaissance: data.lieuNaissance,
|
||||
codePostalNaissance: data.codePostalNaissance,
|
||||
nationalite: data.nationalite,
|
||||
medecinTraitant: data.medecinTraitant,
|
||||
niveau: data.niveau,
|
||||
responsables: data.responsables || []
|
||||
last_name: data.last_name,
|
||||
first_name: data.first_name,
|
||||
address: data.address,
|
||||
birth_date: data.birth_date,
|
||||
birth_place: data.birth_place,
|
||||
birth_postal_code: data.birth_postal_code,
|
||||
nationality: data.nationality,
|
||||
attending_physician: data.attending_physician,
|
||||
level: data.level,
|
||||
guardians: data.guardians || []
|
||||
};
|
||||
setInitialData(formattedData);
|
||||
setIsLoading(false);
|
||||
@ -58,18 +56,8 @@ export default function Page() {
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${BE_SUBSCRIPTION_REGISTERFORM_URL}/${studentId}`, { // Utilisation de studentId
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
credentials: 'include',
|
||||
body: JSON.stringify(data),
|
||||
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
const result = await editRegisterForm(studentId, data, csrfToken);
|
||||
// Utilisation de studentId
|
||||
console.log('Success:', result);
|
||||
// Redirection après succès
|
||||
window.location.href = FE_ADMIN_SUBSCRIPTIONS_URL;
|
||||
|
||||
@ -21,7 +21,7 @@ import {
|
||||
PENDING,
|
||||
SUBSCRIBED,
|
||||
ARCHIVED,
|
||||
fetchRegisterForm,
|
||||
fetchRegisterForms,
|
||||
createRegisterForm,
|
||||
sendRegisterForm,
|
||||
archiveRegisterForm,
|
||||
@ -159,13 +159,13 @@ const registerFormArchivedDataHandler = (data) => {
|
||||
useEffect(() => {
|
||||
const fetchDataAndSetState = () => {
|
||||
if (!useFakeData) {
|
||||
fetchRegisterForm(PENDING, currentPage, itemsPerPage, searchTerm)
|
||||
fetchRegisterForms(PENDING, currentPage, itemsPerPage, searchTerm)
|
||||
.then(registerFormPendingDataHandler)
|
||||
.catch(requestErrorHandler)
|
||||
fetchRegisterForm(SUBSCRIBED)
|
||||
fetchRegisterForms(SUBSCRIBED)
|
||||
.then(registerFormSubscribedDataHandler)
|
||||
.catch(requestErrorHandler)
|
||||
fetchRegisterForm(ARCHIVED)
|
||||
fetchRegisterForms(ARCHIVED)
|
||||
.then(registerFormArchivedDataHandler)
|
||||
.catch(requestErrorHandler)
|
||||
} else {
|
||||
@ -184,7 +184,7 @@ const registerFormArchivedDataHandler = (data) => {
|
||||
// Modifier le useEffect pour la recherche
|
||||
useEffect(() => {
|
||||
const timeoutId = setTimeout(() => {
|
||||
fetchRegisterForm(PENDING, currentPage, itemsPerPage, searchTerm)
|
||||
fetchRegisterForms(PENDING, currentPage, itemsPerPage, searchTerm)
|
||||
.then(registerFormPendingDataHandler)
|
||||
.catch(requestErrorHandler)
|
||||
}, 500); // Debounce la recherche
|
||||
|
||||
Reference in New Issue
Block a user