From 7bcaf2fc4cd9489e2e1d597dff360faf65c35be4 Mon Sep 17 00:00:00 2001 From: alma Date: Sat, 24 May 2025 20:30:18 +0200 Subject: [PATCH] W n8n attention vm --- components/missions/missions-admin-panel.tsx | 76 ++++++-------------- 1 file changed, 20 insertions(+), 56 deletions(-) diff --git a/components/missions/missions-admin-panel.tsx b/components/missions/missions-admin-panel.tsx index 301f7cba..1cf38c29 100644 --- a/components/missions/missions-admin-panel.tsx +++ b/components/missions/missions-admin-panel.tsx @@ -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; - 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({