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