From b4b8d88d9dbe97bf948e45a26acd389105b10f70 Mon Sep 17 00:00:00 2001 From: alma Date: Sat, 24 May 2025 20:25:04 +0200 Subject: [PATCH] W n8n attention vm --- components/missions/missions-admin-panel.tsx | 88 +++++++++++++++----- 1 file changed, 68 insertions(+), 20 deletions(-) diff --git a/components/missions/missions-admin-panel.tsx b/components/missions/missions-admin-panel.tsx index 6ca1d8da..8c1e9863 100644 --- a/components/missions/missions-admin-panel.tsx +++ b/components/missions/missions-admin-panel.tsx @@ -398,24 +398,74 @@ export function MissionsAdminPanel() { setIsSubmitting(true); try { - const formattedData = { - ...missionData, - logo: uploadedLogoPath || null, - attachments: uploadedAttachmentPaths.map(path => ({ filePath: path })), - oddScope: Array.isArray(missionData.oddScope) ? missionData.oddScope : [missionData.oddScope], - services: selectedServices, - profils: selectedProfils, + // 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 + 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[]; + 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: { - 'gardien-temps': gardienDuTemps, - 'gardien-parole': gardienDeLaParole, - 'gardien-memoire': gardienDeLaMemoire + 'gardien-temps': gardienDuTemps || '', + 'gardien-parole': gardienDeLaParole || '', + 'gardien-memoire': gardienDeLaMemoire || '' }, - volunteers: volontaires, + volunteers: (volontaires || []).filter(Boolean) as string[], + logo: logoUrl }; - console.log('Submitting mission data:', JSON.stringify(formattedData, null, 2)); - - const response = await fetch('/api/missions', { + // Create the mission with the logo URL + const createResponse = await fetch('/api/missions', { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -423,12 +473,10 @@ export function MissionsAdminPanel() { body: JSON.stringify(formattedData), }); - const data = await response.json(); - console.log('Response status:', response.status); - console.log('Response data:', data); - - if (!response.ok) { - throw new Error(data.error || data.details || 'Failed to create mission'); + const responseData = await createResponse.json(); + + if (!createResponse.ok) { + throw new Error(responseData.error || responseData.details || 'Failed to create mission'); } toast({