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