Mission enregis
This commit is contained in:
parent
929081b664
commit
aed9f7daa6
@ -399,10 +399,17 @@ export function MissionsAdminPanel() {
|
||||
|
||||
// Handle mission submission
|
||||
const handleSubmitMission = async () => {
|
||||
logger.debug('handleSubmitMission called', {
|
||||
activeTab,
|
||||
isLastTab: activeTab === "membres"
|
||||
});
|
||||
|
||||
if (!validateMission()) {
|
||||
logger.debug('Validation failed, returning early');
|
||||
return;
|
||||
}
|
||||
|
||||
logger.debug('Validation passed, setting isSubmitting to true');
|
||||
setIsSubmitting(true);
|
||||
|
||||
try {
|
||||
@ -422,21 +429,61 @@ export function MissionsAdminPanel() {
|
||||
logo: missionData.logo // Ensure logo data is included
|
||||
};
|
||||
|
||||
logger.debug('Prepared mission data', {
|
||||
hasName: !!missionSubmitData.name,
|
||||
hasOddScope: !!missionSubmitData.oddScope,
|
||||
hasLogo: !!missionSubmitData.logo,
|
||||
logoType: missionSubmitData.logo ? typeof missionSubmitData.logo : 'null',
|
||||
servicesCount: missionSubmitData.services?.length || 0,
|
||||
profilsCount: missionSubmitData.profils?.length || 0,
|
||||
volunteersCount: missionSubmitData.volunteers?.length || 0,
|
||||
hasGuardians: !!(missionSubmitData.guardians && Object.keys(missionSubmitData.guardians).length > 0)
|
||||
});
|
||||
|
||||
// Test JSON serialization before sending
|
||||
let jsonString;
|
||||
try {
|
||||
jsonString = JSON.stringify(missionSubmitData);
|
||||
logger.debug('JSON.stringify successful', { jsonLength: jsonString.length });
|
||||
} catch (jsonError) {
|
||||
logger.error('JSON.stringify failed', {
|
||||
error: jsonError instanceof Error ? jsonError.message : String(jsonError),
|
||||
missionDataKeys: Object.keys(missionSubmitData)
|
||||
});
|
||||
throw new Error(`Failed to serialize mission data: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`);
|
||||
}
|
||||
|
||||
logger.debug('Sending fetch request to /api/missions');
|
||||
// Send to API
|
||||
const response = await fetch('/api/missions', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(missionSubmitData),
|
||||
body: jsonString,
|
||||
});
|
||||
|
||||
logger.debug('Fetch response received', {
|
||||
status: response.status,
|
||||
ok: response.ok,
|
||||
statusText: response.statusText
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
logger.error('API returned error response', {
|
||||
status: response.status,
|
||||
error: errorData.error,
|
||||
errorData
|
||||
});
|
||||
throw new Error(errorData.error || 'Failed to create mission');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
logger.debug('Mission created successfully', {
|
||||
missionId: data.mission?.id,
|
||||
success: data.success
|
||||
});
|
||||
|
||||
toast({
|
||||
title: "Mission créée avec succès",
|
||||
@ -447,6 +494,19 @@ export function MissionsAdminPanel() {
|
||||
router.push('/missions');
|
||||
|
||||
} catch (error) {
|
||||
logger.error('Error creating mission', {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
errorType: error instanceof Error ? error.constructor.name : typeof error,
|
||||
missionData: {
|
||||
hasName: !!missionData.name,
|
||||
hasOddScope: !!missionData.oddScope,
|
||||
hasLogo: !!missionData.logo,
|
||||
servicesCount: selectedServices.length,
|
||||
profilsCount: selectedProfils.length,
|
||||
volunteersCount: volontaires.length,
|
||||
hasGuardians: !!(gardienDuTemps && gardienDeLaParole && gardienDeLaMemoire)
|
||||
}
|
||||
});
|
||||
toast({
|
||||
title: "Erreur",
|
||||
description: error instanceof Error ? error.message : "Une erreur est survenue lors de la création de la mission",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user