W n8n attention vm
This commit is contained in:
parent
b4b8d88d9d
commit
d56a0d8a9a
@ -398,38 +398,7 @@ export function MissionsAdminPanel() {
|
||||
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
// 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
|
||||
// First create the mission without the logo
|
||||
const formattedData: {
|
||||
name: string;
|
||||
oddScope: string[];
|
||||
@ -443,7 +412,6 @@ export function MissionsAdminPanel() {
|
||||
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[],
|
||||
@ -461,10 +429,9 @@ export function MissionsAdminPanel() {
|
||||
'gardien-memoire': gardienDeLaMemoire || ''
|
||||
},
|
||||
volunteers: (volontaires || []).filter(Boolean) as string[],
|
||||
logo: logoUrl
|
||||
};
|
||||
|
||||
// Create the mission with the logo URL
|
||||
// Create the mission first
|
||||
const createResponse = await fetch('/api/missions', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@ -479,6 +446,53 @@ export function MissionsAdminPanel() {
|
||||
throw new Error(responseData.error || responseData.details || 'Failed to create mission');
|
||||
}
|
||||
|
||||
const missionId = responseData.id;
|
||||
|
||||
// Now upload the logo if it exists
|
||||
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');
|
||||
formData.append('missionId', missionId);
|
||||
|
||||
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();
|
||||
|
||||
// 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) {
|
||||
console.error('Error uploading logo:', error);
|
||||
toast({
|
||||
title: "Warning",
|
||||
description: "Failed to upload logo. Mission was created but without logo.",
|
||||
variant: "destructive",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
toast({
|
||||
title: "Mission créée avec succès",
|
||||
description: "La mission a été créée et les intégrations sont en cours.",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user