mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 16:03:21 +00:00
feat: Gestion des documents parent
This commit is contained in:
@ -29,7 +29,9 @@ import {
|
||||
|
||||
import {
|
||||
fetchRegistrationSchoolFileMasters,
|
||||
createRegistrationTemplates,
|
||||
fetchRegistrationParentFileMasters,
|
||||
createRegistrationSchoolFileTemplate,
|
||||
createRegistrationParentFileTemplate,
|
||||
fetchRegistrationFileGroups,
|
||||
cloneTemplate
|
||||
} from "@/app/actions/registerFileGroupAction";
|
||||
@ -73,6 +75,7 @@ export default function Page({ params: { locale } }) {
|
||||
const [itemsPerPage, setItemsPerPage] = useState(10); // Définir le nombre d'éléments par page
|
||||
|
||||
const [schoolFileMasters, setSchoolFileMasters] = useState([]);
|
||||
const [parentFileMasters, setParentFileMasters] = useState([]);
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [isOpenAffectationClasse, setIsOpenAffectationClasse] = useState(false);
|
||||
const [student, setStudent] = useState('');
|
||||
@ -220,6 +223,13 @@ useEffect(() => {
|
||||
.catch(err => {
|
||||
logger.debug(err.message);
|
||||
}),
|
||||
fetchRegistrationParentFileMasters()
|
||||
.then(data => {
|
||||
setParentFileMasters(data);
|
||||
})
|
||||
.catch(err => {
|
||||
logger.debug(err.message);
|
||||
}),
|
||||
fetchRegistrationDiscounts(selectedEstablishmentId)
|
||||
.then(data => {
|
||||
setRegistrationDiscounts(data);
|
||||
@ -462,6 +472,7 @@ useEffect(()=>{
|
||||
.then(data => {
|
||||
// Cloner les schoolFileTemplates pour chaque templateMaster du fileGroup
|
||||
const masters = schoolFileMasters.filter(file => file.groups.includes(selectedFileGroup));
|
||||
const parent_masters = parentFileMasters.filter(file => file.groups.includes(selectedFileGroup));
|
||||
const clonePromises = masters.map((templateMaster, index) => {
|
||||
return cloneTemplate(templateMaster.id, updatedData.guardianEmail, templateMaster.is_required)
|
||||
.then(clonedDocument => {
|
||||
@ -474,7 +485,7 @@ useEffect(()=>{
|
||||
registration_form: data.student.id
|
||||
};
|
||||
|
||||
return createRegistrationTemplates(cloneData, csrfToken)
|
||||
return createRegistrationSchoolFileTemplate(cloneData, csrfToken)
|
||||
.then(response => {
|
||||
logger.debug('Template enregistré avec succès:', response);
|
||||
})
|
||||
@ -487,6 +498,22 @@ useEffect(()=>{
|
||||
});
|
||||
});
|
||||
|
||||
// Créer les parentFileTemplates pour chaque parentMaster
|
||||
const parentClonePromises = parent_masters.map((parentMaster, index) => {
|
||||
const parentTemplateData = {
|
||||
master: parentMaster.id,
|
||||
registration_form: data.student.id
|
||||
};
|
||||
|
||||
return createRegistrationParentFileTemplate(parentTemplateData, csrfToken)
|
||||
.then(response => {
|
||||
logger.debug('Parent template enregistré avec succès:', response);
|
||||
})
|
||||
.catch(error => {
|
||||
logger.error('Erreur lors de l\'enregistrement du parent template:', error);
|
||||
});
|
||||
});
|
||||
|
||||
// Attendre que tous les clones soient créés
|
||||
Promise.all(clonePromises)
|
||||
.then(() => {
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import { BE_SUBSCRIPTION_REGISTRATIONFILE_GROUPS_URL,
|
||||
BE_SUBSCRIPTION_REGISTRATION_SCHOOL_FILE_TEMPLATES_URL,
|
||||
BE_SUBSCRIPTION_REGISTRATIONSCHOOL_FILE_MASTERS_URL,
|
||||
BE_SUBSCRIPTION_REGISTRATION_SCHOOL_FILE_MASTERS_URL,
|
||||
BE_SUBSCRIPTION_REGISTRATION_PARENT_FILE_MASTERS_URL,
|
||||
BE_SUBSCRIPTION_REGISTRATION_PARENT_FILE_TEMPLATES_URL,
|
||||
FE_API_DOCUSEAL_CLONE_URL,
|
||||
FE_API_DOCUSEAL_DOWNLOAD_URL,
|
||||
FE_API_DOCUSEAL_GENERATE_TOKEN
|
||||
@ -17,7 +18,9 @@ const requestResponseHandler = async (response) => {
|
||||
const error = new Error(body?.errorMessage || "Une erreur est survenue");
|
||||
error.details = body;
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
// FETCH requests
|
||||
|
||||
export async function fetchRegistrationFileGroups(establishment) {
|
||||
const response = await fetch(`${BE_SUBSCRIPTION_REGISTRATIONFILE_GROUPS_URL}?establishment_id=${establishment}`, {
|
||||
@ -30,7 +33,73 @@ export async function fetchRegistrationFileGroups(establishment) {
|
||||
throw new Error('Failed to fetch file groups');
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
};
|
||||
|
||||
export const fetchRegistrationFileFromGroup = async (groupId) => {
|
||||
const response = await fetch(`${BE_SUBSCRIPTION_REGISTRATIONFILE_GROUPS_URL}/${groupId}/school_file_templates`, {
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error('Erreur lors de la récupération des fichiers associés au groupe');
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const fetchRegistrationSchoolFileMasters = (id = null) => {
|
||||
let url = `${BE_SUBSCRIPTION_REGISTRATION_SCHOOL_FILE_MASTERS_URL}`;
|
||||
if(id){
|
||||
url = `${BE_SUBSCRIPTION_REGISTRATION_SCHOOL_FILE_MASTERS_URL}/${id}`;
|
||||
}
|
||||
const request = new Request(
|
||||
`${url}`,
|
||||
{
|
||||
method:'GET',
|
||||
headers: {
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
}
|
||||
);
|
||||
return fetch(request).then(requestResponseHandler)
|
||||
};
|
||||
|
||||
export const fetchRegistrationParentFileMasters = (id = null) => {
|
||||
let url = `${BE_SUBSCRIPTION_REGISTRATION_PARENT_FILE_MASTERS_URL}`
|
||||
if (id) {
|
||||
url = `${BE_SUBSCRIPTION_REGISTRATION_PARENT_FILE_MASTERS_URL}/${id}`;
|
||||
}
|
||||
const request = new Request(
|
||||
`${url}`,
|
||||
{
|
||||
method:'GET',
|
||||
headers: {
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
}
|
||||
);
|
||||
return fetch(request).then(requestResponseHandler)
|
||||
};
|
||||
|
||||
export const fetchRegistrationSchoolFileTemplates = (id = null) => {
|
||||
let url = `${BE_SUBSCRIPTION_REGISTRATION_SCHOOL_FILE_TEMPLATES_URL}`
|
||||
if (id) {
|
||||
url = `${BE_SUBSCRIPTION_REGISTRATION_SCHOOL_FILE_TEMPLATES_URL}/${id}`;
|
||||
}
|
||||
const request = new Request(
|
||||
`${url}`,
|
||||
{
|
||||
method:'GET',
|
||||
headers: {
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
}
|
||||
);
|
||||
return fetch(request).then(requestResponseHandler)
|
||||
};
|
||||
|
||||
// CREATE requests
|
||||
|
||||
export async function createRegistrationFileGroup(groupData, csrfToken) {
|
||||
const response = await fetch(`${BE_SUBSCRIPTION_REGISTRATIONFILE_GROUPS_URL}`, {
|
||||
@ -48,19 +117,62 @@ export async function createRegistrationFileGroup(groupData, csrfToken) {
|
||||
}
|
||||
|
||||
return response.json();
|
||||
}
|
||||
};
|
||||
|
||||
export async function deleteRegistrationFileGroup(groupId, csrfToken) {
|
||||
const response = await fetch(`${BE_SUBSCRIPTION_REGISTRATIONFILE_GROUPS_URL}/${groupId}`, {
|
||||
method: 'DELETE',
|
||||
export const createRegistrationSchoolFileMaster = (data,csrfToken) => {
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTRATION_SCHOOL_FILE_MASTERS_URL}`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
headers: {
|
||||
'X-CSRFToken': csrfToken,
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
credentials: 'include'
|
||||
});
|
||||
credentials: 'include',
|
||||
})
|
||||
.then(requestResponseHandler)
|
||||
};
|
||||
|
||||
return response;
|
||||
}
|
||||
export const createRegistrationParentFileMaster = (data,csrfToken) => {
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTRATION_PARENT_FILE_MASTERS_URL}`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
headers: {
|
||||
'X-CSRFToken': csrfToken,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
.then(requestResponseHandler)
|
||||
};
|
||||
|
||||
export const createRegistrationSchoolFileTemplate = (data,csrfToken) => {
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTRATION_SCHOOL_FILE_TEMPLATES_URL}`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
headers: {
|
||||
'X-CSRFToken': csrfToken,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
.then(requestResponseHandler)
|
||||
};
|
||||
|
||||
export const createRegistrationParentFileTemplate = (data,csrfToken) => {
|
||||
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTRATION_PARENT_FILE_TEMPLATES_URL}`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
headers: {
|
||||
'X-CSRFToken': csrfToken,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
.then(requestResponseHandler)
|
||||
};
|
||||
|
||||
// EDIT requests
|
||||
|
||||
export const editRegistrationFileGroup = async (groupId, groupData, csrfToken) => {
|
||||
const response = await fetch(`${BE_SUBSCRIPTION_REGISTRATIONFILE_GROUPS_URL}/${groupId}`, {
|
||||
@ -79,49 +191,18 @@ export const editRegistrationFileGroup = async (groupId, groupData, csrfToken) =
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const fetchRegistrationFileFromGroup = async (groupId) => {
|
||||
const response = await fetch(`${BE_SUBSCRIPTION_REGISTRATIONFILE_GROUPS_URL}/${groupId}/schoolFileTemplates`, {
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error('Erreur lors de la récupération des fichiers associés au groupe');
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export const fetchRegistrationParentFileMasters = (id = null) => {
|
||||
let url = `${BE_SUBSCRIPTION_REGISTRATION_PARENT_FILE_MASTERS_URL}`
|
||||
if (id) {
|
||||
url = `${BE_SUBSCRIPTION_REGISTRATION_PARENT_FILE_MASTERS_URL}/${id}`;
|
||||
}
|
||||
const request = new Request(
|
||||
`${url}`,
|
||||
{
|
||||
method:'GET',
|
||||
headers: {
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
}
|
||||
);
|
||||
return fetch(request).then(requestResponseHandler)
|
||||
};
|
||||
|
||||
export const createRegistrationParentFileMaster = (data,csrfToken) => {
|
||||
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTRATION_PARENT_FILE_MASTERS_URL}`, {
|
||||
method: 'POST',
|
||||
export const editRegistrationSchoolFileMaster = (fileId, data, csrfToken) => {
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTRATION_SCHOOL_FILE_MASTERS_URL}/${fileId}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(data),
|
||||
headers: {
|
||||
'X-CSRFToken': csrfToken,
|
||||
'Content-Type': 'application/json',
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
.then(requestResponseHandler)
|
||||
}
|
||||
.then(requestResponseHandler)
|
||||
};
|
||||
|
||||
export const editRegistrationParentFileMaster = (id, data, csrfToken) => {
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTRATION_PARENT_FILE_MASTERS_URL}/${id}`, {
|
||||
@ -134,36 +215,9 @@ export const editRegistrationParentFileMaster = (id, data, csrfToken) => {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then(requestResponseHandler)
|
||||
}
|
||||
|
||||
export const deleteRegistrationParentFileMaster = (id, csrfToken) => {
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTRATION_PARENT_FILE_MASTERS_URL}/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'X-CSRFToken': csrfToken,
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchRegistrationSchoolFileTemplates = (id = null) => {
|
||||
let url = `${BE_SUBSCRIPTION_REGISTRATION_SCHOOL_FILE_TEMPLATES_URL}`
|
||||
if (id) {
|
||||
url = `${BE_SUBSCRIPTION_REGISTRATION_SCHOOL_FILE_TEMPLATES_URL}/${id}`;
|
||||
}
|
||||
const request = new Request(
|
||||
`${url}`,
|
||||
{
|
||||
method:'GET',
|
||||
headers: {
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
}
|
||||
);
|
||||
return fetch(request).then(requestResponseHandler)
|
||||
};
|
||||
|
||||
export const editRegistrationTemplates = (fileId, data, csrfToken) => {
|
||||
export const editRegistrationSchoolFileTemplates = (fileId, data, csrfToken) => {
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTRATION_SCHOOL_FILE_TEMPLATES_URL}/${fileId}`, {
|
||||
method: 'PUT',
|
||||
body: data,
|
||||
@ -173,23 +227,43 @@ export const editRegistrationTemplates = (fileId, data, csrfToken) => {
|
||||
credentials: 'include',
|
||||
})
|
||||
.then(requestResponseHandler)
|
||||
}
|
||||
};
|
||||
|
||||
export const createRegistrationTemplates = (data,csrfToken) => {
|
||||
// DELETE requests
|
||||
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTRATION_SCHOOL_FILE_TEMPLATES_URL}`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
export async function deleteRegistrationFileGroup(groupId, csrfToken) {
|
||||
const response = await fetch(`${BE_SUBSCRIPTION_REGISTRATIONFILE_GROUPS_URL}/${groupId}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'X-CSRFToken': csrfToken,
|
||||
},
|
||||
credentials: 'include'
|
||||
});
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
export const deleteRegistrationSchoolFileMaster = (fileId,csrfToken) => {
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTRATION_SCHOOL_FILE_MASTERS_URL}/${fileId}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'X-CSRFToken': csrfToken,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
.then(requestResponseHandler)
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteRegistrationTemplates = (fileId,csrfToken) => {
|
||||
export const deleteRegistrationParentFileMaster = (id, csrfToken) => {
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTRATION_PARENT_FILE_MASTERS_URL}/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'X-CSRFToken': csrfToken,
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
};
|
||||
|
||||
export const deleteRegistrationSchoolFileTemplates = (fileId,csrfToken) => {
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTRATION_SCHOOL_FILE_TEMPLATES_URL}/${fileId}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
@ -197,61 +271,9 @@ export const deleteRegistrationTemplates = (fileId,csrfToken) => {
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchRegistrationSchoolFileMasters = (id = null) => {
|
||||
let url = `${BE_SUBSCRIPTION_REGISTRATIONSCHOOL_FILE_MASTERS_URL}`;
|
||||
if(id){
|
||||
url = `${BE_SUBSCRIPTION_REGISTRATIONSCHOOL_FILE_MASTERS_URL}/${id}`;
|
||||
}
|
||||
const request = new Request(
|
||||
`${url}`,
|
||||
{
|
||||
method:'GET',
|
||||
headers: {
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
}
|
||||
);
|
||||
return fetch(request).then(requestResponseHandler)
|
||||
};
|
||||
|
||||
export const createRegistrationSchoolFileMaster = (data,csrfToken) => {
|
||||
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTRATIONSCHOOL_FILE_MASTERS_URL}`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
headers: {
|
||||
'X-CSRFToken': csrfToken,
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
.then(requestResponseHandler)
|
||||
}
|
||||
|
||||
export const deleteRegistrationSchoolFileMaster = (fileId,csrfToken) => {
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTRATIONSCHOOL_FILE_MASTERS_URL}/${fileId}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'X-CSRFToken': csrfToken,
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
}
|
||||
|
||||
export const editRegistrationSchoolFileMaster = (fileId, data, csrfToken) => {
|
||||
return fetch(`${BE_SUBSCRIPTION_REGISTRATIONSCHOOL_FILE_MASTERS_URL}/${fileId}`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(data),
|
||||
headers: {
|
||||
'X-CSRFToken': csrfToken,
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
.then(requestResponseHandler)
|
||||
}
|
||||
// API requests
|
||||
|
||||
export const cloneTemplate = (templateId, email, is_required) => {
|
||||
return fetch(`${FE_API_DOCUSEAL_CLONE_URL}`, {
|
||||
@ -266,7 +288,7 @@ export const cloneTemplate = (templateId, email, is_required) => {
|
||||
})
|
||||
})
|
||||
.then(requestResponseHandler)
|
||||
}
|
||||
};
|
||||
|
||||
export const downloadTemplate = (slug) => {
|
||||
return fetch(`${FE_API_DOCUSEAL_DOWNLOAD_URL}/${slug}`, {
|
||||
@ -276,7 +298,7 @@ export const downloadTemplate = (slug) => {
|
||||
}
|
||||
})
|
||||
.then(requestResponseHandler)
|
||||
}
|
||||
};
|
||||
|
||||
export const generateToken = (email, id = null) => {
|
||||
return fetch(`${FE_API_DOCUSEAL_GENERATE_TOKEN}`, {
|
||||
|
||||
@ -162,7 +162,20 @@ export const fetchSchoolFileTemplatesFromRegistrationFiles = async (id) => {
|
||||
throw new Error('Erreur lors de la récupération des fichiers associés au groupe');
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
};
|
||||
|
||||
export const fetchParentFileTemplatesFromRegistrationFiles = async (id) => {
|
||||
const response = await fetch(`${BE_SUBSCRIPTION_REGISTERFORMS_URL}/${id}/parent_file_templates`, {
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
});
|
||||
if (!response.ok) {
|
||||
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`, {
|
||||
|
||||
Reference in New Issue
Block a user