Mission enregis
This commit is contained in:
parent
aed9f7daa6
commit
11f578dcfd
@ -399,16 +399,22 @@ export function MissionsAdminPanel() {
|
||||
|
||||
// Handle mission submission
|
||||
const handleSubmitMission = async () => {
|
||||
console.log('[handleSubmitMission] Function called', {
|
||||
activeTab,
|
||||
isLastTab: activeTab === "membres"
|
||||
});
|
||||
logger.debug('handleSubmitMission called', {
|
||||
activeTab,
|
||||
isLastTab: activeTab === "membres"
|
||||
});
|
||||
|
||||
if (!validateMission()) {
|
||||
console.log('[handleSubmitMission] Validation failed, returning early');
|
||||
logger.debug('Validation failed, returning early');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[handleSubmitMission] Validation passed, setting isSubmitting to true');
|
||||
logger.debug('Validation passed, setting isSubmitting to true');
|
||||
setIsSubmitting(true);
|
||||
|
||||
@ -429,6 +435,16 @@ export function MissionsAdminPanel() {
|
||||
logo: missionData.logo // Ensure logo data is included
|
||||
};
|
||||
|
||||
console.log('[handleSubmitMission] 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)
|
||||
});
|
||||
logger.debug('Prepared mission data', {
|
||||
hasName: !!missionSubmitData.name,
|
||||
hasOddScope: !!missionSubmitData.oddScope,
|
||||
@ -444,8 +460,10 @@ export function MissionsAdminPanel() {
|
||||
let jsonString;
|
||||
try {
|
||||
jsonString = JSON.stringify(missionSubmitData);
|
||||
console.log('[handleSubmitMission] JSON.stringify successful', { jsonLength: jsonString.length });
|
||||
logger.debug('JSON.stringify successful', { jsonLength: jsonString.length });
|
||||
} catch (jsonError) {
|
||||
console.error('[handleSubmitMission] JSON.stringify failed', jsonError);
|
||||
logger.error('JSON.stringify failed', {
|
||||
error: jsonError instanceof Error ? jsonError.message : String(jsonError),
|
||||
missionDataKeys: Object.keys(missionSubmitData)
|
||||
@ -453,6 +471,7 @@ export function MissionsAdminPanel() {
|
||||
throw new Error(`Failed to serialize mission data: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`);
|
||||
}
|
||||
|
||||
console.log('[handleSubmitMission] Sending fetch request to /api/missions');
|
||||
logger.debug('Sending fetch request to /api/missions');
|
||||
// Send to API
|
||||
const response = await fetch('/api/missions', {
|
||||
@ -463,6 +482,11 @@ export function MissionsAdminPanel() {
|
||||
body: jsonString,
|
||||
});
|
||||
|
||||
console.log('[handleSubmitMission] Fetch response received', {
|
||||
status: response.status,
|
||||
ok: response.ok,
|
||||
statusText: response.statusText
|
||||
});
|
||||
logger.debug('Fetch response received', {
|
||||
status: response.status,
|
||||
ok: response.ok,
|
||||
@ -471,6 +495,11 @@ export function MissionsAdminPanel() {
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
console.error('[handleSubmitMission] API returned error response', {
|
||||
status: response.status,
|
||||
error: errorData.error,
|
||||
errorData
|
||||
});
|
||||
logger.error('API returned error response', {
|
||||
status: response.status,
|
||||
error: errorData.error,
|
||||
@ -480,6 +509,10 @@ export function MissionsAdminPanel() {
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log('[handleSubmitMission] Mission created successfully', {
|
||||
missionId: data.mission?.id,
|
||||
success: data.success
|
||||
});
|
||||
logger.debug('Mission created successfully', {
|
||||
missionId: data.mission?.id,
|
||||
success: data.success
|
||||
@ -494,6 +527,20 @@ export function MissionsAdminPanel() {
|
||||
router.push('/missions');
|
||||
|
||||
} catch (error) {
|
||||
console.error('[handleSubmitMission] Error creating mission', {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
errorType: error instanceof Error ? error.constructor.name : typeof error,
|
||||
errorStack: error instanceof Error ? error.stack : undefined,
|
||||
missionData: {
|
||||
hasName: !!missionData.name,
|
||||
hasOddScope: !!missionData.oddScope,
|
||||
hasLogo: !!missionData.logo,
|
||||
servicesCount: selectedServices.length,
|
||||
profilsCount: selectedProfils.length,
|
||||
volunteersCount: volontaires.length,
|
||||
hasGuardians: !!(gardienDuTemps && gardienDeLaParole && gardienDeLaMemoire)
|
||||
}
|
||||
});
|
||||
logger.error('Error creating mission', {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
errorType: error instanceof Error ? error.constructor.name : typeof error,
|
||||
@ -513,6 +560,7 @@ export function MissionsAdminPanel() {
|
||||
variant: "destructive",
|
||||
});
|
||||
} finally {
|
||||
console.log('[handleSubmitMission] Finally block - setting isSubmitting to false');
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
@ -1465,9 +1513,16 @@ export function MissionsAdminPanel() {
|
||||
<Button
|
||||
className="bg-blue-600 hover:bg-blue-700 text-white"
|
||||
onClick={() => {
|
||||
console.log('[BUTTON CLICK] Button clicked', {
|
||||
activeTab,
|
||||
isLastTab: activeTab === "membres",
|
||||
isSubmitting
|
||||
});
|
||||
if (isLastTab()) {
|
||||
console.log('[BUTTON CLICK] Calling handleSubmitMission');
|
||||
handleSubmitMission();
|
||||
} else {
|
||||
console.log('[BUTTON CLICK] Calling goToNextTab instead');
|
||||
goToNextTab();
|
||||
}
|
||||
}}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user