W n8n attention vm
This commit is contained in:
parent
d56a0d8a9a
commit
7bcaf2fc4c
@ -395,24 +395,12 @@ export function MissionsAdminPanel() {
|
||||
if (!validateMission()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
setIsSubmitting(true);
|
||||
|
||||
try {
|
||||
// First create the mission without the logo
|
||||
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[];
|
||||
} = {
|
||||
// Prepare the mission data without files
|
||||
const formattedData = {
|
||||
name: missionData.name || '',
|
||||
oddScope: (Array.isArray(missionData.oddScope) ? missionData.oddScope : [missionData.oddScope]).filter(Boolean) as string[],
|
||||
niveau: missionData.niveau,
|
||||
@ -431,7 +419,7 @@ export function MissionsAdminPanel() {
|
||||
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', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@ -443,62 +431,38 @@ export function MissionsAdminPanel() {
|
||||
const responseData = await createResponse.json();
|
||||
|
||||
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;
|
||||
|
||||
// Now upload the logo if it exists
|
||||
// If we have a logo, upload it to Minio
|
||||
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', {
|
||||
const logoFormData = new FormData();
|
||||
logoFormData.append('missionId', responseData.mission.id);
|
||||
logoFormData.append('type', 'logo');
|
||||
logoFormData.append('file', missionData.logo);
|
||||
|
||||
const logoUploadResponse = 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
|
||||
}),
|
||||
body: logoFormData,
|
||||
});
|
||||
|
||||
if (!updateResponse.ok) {
|
||||
console.error('Failed to update mission with logo URL');
|
||||
if (!logoUploadResponse.ok) {
|
||||
console.warn('Failed to upload logo:', await logoUploadResponse.text());
|
||||
}
|
||||
} 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.",
|
||||
description: "Tous les gardiens ont été assignés et la mission a été enregistrée.",
|
||||
});
|
||||
|
||||
|
||||
// Redirect to missions list
|
||||
router.push('/missions');
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error creating mission:', error);
|
||||
toast({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user