W n8n attention vm

This commit is contained in:
alma 2025-05-24 20:30:18 +02:00
parent d56a0d8a9a
commit 7bcaf2fc4c

View File

@ -397,22 +397,10 @@ export function MissionsAdminPanel() {
} }
setIsSubmitting(true); setIsSubmitting(true);
try { try {
// First create the mission without the logo // Prepare the mission data without files
const formattedData: { const formattedData = {
name: string;
oddScope: string[];
niveau?: string;
intention?: string;
missionType?: string;
donneurDOrdre?: string;
projection?: string;
services?: string[];
participation?: string;
profils?: string[];
guardians: Record<string, string>;
volunteers: string[];
} = {
name: missionData.name || '', name: missionData.name || '',
oddScope: (Array.isArray(missionData.oddScope) ? missionData.oddScope : [missionData.oddScope]).filter(Boolean) as string[], oddScope: (Array.isArray(missionData.oddScope) ? missionData.oddScope : [missionData.oddScope]).filter(Boolean) as string[],
niveau: missionData.niveau, niveau: missionData.niveau,
@ -431,7 +419,7 @@ export function MissionsAdminPanel() {
volunteers: (volontaires || []).filter(Boolean) as string[], volunteers: (volontaires || []).filter(Boolean) as string[],
}; };
// Create the mission first // Create the mission first to get the mission ID
const createResponse = await fetch('/api/missions', { const createResponse = await fetch('/api/missions', {
method: 'POST', method: 'POST',
headers: { headers: {
@ -443,62 +431,38 @@ export function MissionsAdminPanel() {
const responseData = await createResponse.json(); const responseData = await createResponse.json();
if (!createResponse.ok) { if (!createResponse.ok) {
throw new Error(responseData.error || responseData.details || 'Failed to create mission'); throw new Error(responseData.error || 'Failed to create mission');
} }
const missionId = responseData.id; // If we have a logo, upload it to Minio
// Now upload the logo if it exists
if (missionData.logo) { if (missionData.logo) {
try { try {
const response = await fetch(missionData.logo); const logoFormData = new FormData();
const blob = await response.blob(); logoFormData.append('missionId', responseData.mission.id);
const formData = new FormData(); logoFormData.append('type', 'logo');
formData.append('file', blob, 'logo.png'); logoFormData.append('file', missionData.logo);
formData.append('type', 'logo');
formData.append('missionId', missionId);
const uploadResponse = await fetch('/api/missions/upload', { const logoUploadResponse = await fetch('/api/missions/upload', {
method: 'POST', method: 'POST',
body: formData, body: logoFormData,
}); });
if (!uploadResponse.ok) { if (!logoUploadResponse.ok) {
throw new Error('Failed to upload logo'); console.warn('Failed to upload logo:', await logoUploadResponse.text());
}
const uploadData = await uploadResponse.json();
// Update the mission with the logo URL
const updateResponse = await fetch(`/api/missions/${missionId}`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
logo: uploadData.url
}),
});
if (!updateResponse.ok) {
console.error('Failed to update mission with logo URL');
} }
} catch (error) { } catch (error) {
console.error('Error uploading logo:', error); console.error('Error uploading logo:', error);
toast({
title: "Warning",
description: "Failed to upload logo. Mission was created but without logo.",
variant: "destructive",
});
} }
} }
toast({ toast({
title: "Mission créée avec succès", title: "Mission créée avec succès",
description: "La mission a été créée et les intégrations sont en cours.", description: "Tous les gardiens ont été assignés et la mission a été enregistrée.",
}); });
// Redirect to missions list
router.push('/missions'); router.push('/missions');
} catch (error) { } catch (error) {
console.error('Error creating mission:', error); console.error('Error creating mission:', error);
toast({ toast({