From d56a0d8a9aa13c523e2bd486b7604b565b2568b3 Mon Sep 17 00:00:00 2001 From: alma Date: Sat, 24 May 2025 20:27:44 +0200 Subject: [PATCH] W n8n attention vm --- components/missions/missions-admin-panel.tsx | 84 ++++++++++++-------- 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/components/missions/missions-admin-panel.tsx b/components/missions/missions-admin-panel.tsx index 8c1e9863..301f7cba 100644 --- a/components/missions/missions-admin-panel.tsx +++ b/components/missions/missions-admin-panel.tsx @@ -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; 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.",