W n8n attention vm
This commit is contained in:
parent
b33ee11327
commit
b4b8d88d9d
@ -398,24 +398,74 @@ export function MissionsAdminPanel() {
|
||||
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
const formattedData = {
|
||||
...missionData,
|
||||
logo: uploadedLogoPath || null,
|
||||
attachments: uploadedAttachmentPaths.map(path => ({ filePath: path })),
|
||||
oddScope: Array.isArray(missionData.oddScope) ? missionData.oddScope : [missionData.oddScope],
|
||||
services: selectedServices,
|
||||
profils: selectedProfils,
|
||||
// First upload the logo if it exists
|
||||
let logoUrl = null;
|
||||
if (missionData.logo) {
|
||||
try {
|
||||
const response = await fetch(missionData.logo);
|
||||
const blob = await response.blob();
|
||||
const formData = new FormData();
|
||||
formData.append('file', blob, 'logo.png');
|
||||
formData.append('type', 'logo');
|
||||
|
||||
const uploadResponse = await fetch('/api/missions/upload', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if (!uploadResponse.ok) {
|
||||
throw new Error('Failed to upload logo');
|
||||
}
|
||||
|
||||
const uploadData = await uploadResponse.json();
|
||||
logoUrl = uploadData.url; // This should be the public Minio URL
|
||||
} catch (error) {
|
||||
console.error('Error uploading logo:', error);
|
||||
toast({
|
||||
title: "Warning",
|
||||
description: "Failed to upload logo. Mission will be created without logo.",
|
||||
variant: "destructive",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare the mission data with the logo URL
|
||||
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[];
|
||||
logo?: string | null;
|
||||
} = {
|
||||
name: missionData.name || '',
|
||||
oddScope: (Array.isArray(missionData.oddScope) ? missionData.oddScope : [missionData.oddScope]).filter(Boolean) as string[],
|
||||
niveau: missionData.niveau,
|
||||
intention: missionData.intention,
|
||||
missionType: missionData.missionType,
|
||||
donneurDOrdre: missionData.donneurDOrdre,
|
||||
projection: missionData.projection,
|
||||
services: (selectedServices || []).filter(Boolean) as string[],
|
||||
participation: missionData.participation,
|
||||
profils: (selectedProfils || []).filter(Boolean) as string[],
|
||||
guardians: {
|
||||
'gardien-temps': gardienDuTemps,
|
||||
'gardien-parole': gardienDeLaParole,
|
||||
'gardien-memoire': gardienDeLaMemoire
|
||||
'gardien-temps': gardienDuTemps || '',
|
||||
'gardien-parole': gardienDeLaParole || '',
|
||||
'gardien-memoire': gardienDeLaMemoire || ''
|
||||
},
|
||||
volunteers: volontaires,
|
||||
volunteers: (volontaires || []).filter(Boolean) as string[],
|
||||
logo: logoUrl
|
||||
};
|
||||
|
||||
console.log('Submitting mission data:', JSON.stringify(formattedData, null, 2));
|
||||
|
||||
const response = await fetch('/api/missions', {
|
||||
// Create the mission with the logo URL
|
||||
const createResponse = await fetch('/api/missions', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@ -423,12 +473,10 @@ export function MissionsAdminPanel() {
|
||||
body: JSON.stringify(formattedData),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
console.log('Response status:', response.status);
|
||||
console.log('Response data:', data);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error || data.details || 'Failed to create mission');
|
||||
const responseData = await createResponse.json();
|
||||
|
||||
if (!createResponse.ok) {
|
||||
throw new Error(responseData.error || responseData.details || 'Failed to create mission');
|
||||
}
|
||||
|
||||
toast({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user