W n8n attention vm

This commit is contained in:
alma 2025-05-24 19:59:08 +02:00
parent 6274f3a401
commit b33ee11327
2 changed files with 45 additions and 73 deletions

View File

@ -126,16 +126,15 @@ export function FileUpload({
const selectedFile = e.target.files[0];
if (validateFile(selectedFile)) {
setFile(selectedFile);
// If this is a new mission, call onFileSelect instead of waiting for upload
if (isNewMission && onFileSelect) {
onFileSelect(selectedFile);
}
// Immediately upload the file
handleUpload(selectedFile);
}
}
};
const handleUpload = async () => {
if (!file) {
const handleUpload = async (uploadFile?: File) => {
const fileToUpload = uploadFile || file;
if (!fileToUpload) {
console.error('Upload failed: No file selected');
toast({
title: 'Upload failed',
@ -158,7 +157,7 @@ export function FileUpload({
// For new missions, just notify through the callback and don't try to upload
if (isNewMission) {
if (onFileSelect) {
onFileSelect(file);
onFileSelect(fileToUpload);
}
toast({
title: 'File selected',
@ -180,9 +179,9 @@ export function FileUpload({
}
console.log('Starting upload process...', {
fileName: file.name,
fileSize: file.size,
fileType: file.type,
fileName: fileToUpload.name,
fileSize: fileToUpload.size,
fileType: fileToUpload.type,
missionId,
userId: session.user.id,
uploadType: type
@ -194,7 +193,7 @@ export function FileUpload({
try {
// Create form data
const formData = new FormData();
formData.append('file', file);
formData.append('file', fileToUpload);
formData.append('missionId', missionId);
formData.append('type', type);
@ -240,7 +239,7 @@ export function FileUpload({
toast({
title: 'File uploaded successfully',
description: type === 'logo' ? 'Logo has been updated' : `${file.name} has been added to attachments`,
description: type === 'logo' ? 'Logo has been updated' : `${fileToUpload.name} has been added to attachments`,
variant: 'default',
});
}, 1000);
@ -354,7 +353,7 @@ export function FileUpload({
variant="default"
size="sm"
className="bg-blue-600 hover:bg-blue-700 text-white"
onClick={handleUpload}
onClick={() => handleUpload()}
>
<Check className="h-4 w-4 mr-1" />
Upload
@ -377,4 +376,4 @@ export function FileUpload({
)}
</div>
);
}
}

View File

@ -88,6 +88,20 @@ export function MissionsAdminPanel() {
// Check if mission is valid (has all required guardiens)
const isMissionValid = gardienDuTemps !== null && gardienDeLaParole !== null && gardienDeLaMemoire !== null;
// Add a draft mission ID for uploads
const [draftMissionId, setDraftMissionId] = useState<string>("");
const [uploadedLogoPath, setUploadedLogoPath] = useState<string | null>(null);
const [uploadedAttachmentPaths, setUploadedAttachmentPaths] = useState<string[]>([]);
// Generate a draft mission ID on mount
useEffect(() => {
if (!draftMissionId) {
const userId = typeof window !== 'undefined' && window.localStorage.getItem('userId');
const id = `draft-${userId || 'nouser'}-${Date.now()}`;
setDraftMissionId(id);
}
}, [draftMissionId]);
// Fetch users and groups on component mount
useEffect(() => {
const fetchData = async () => {
@ -384,16 +398,11 @@ export function MissionsAdminPanel() {
setIsSubmitting(true);
try {
// Format the data before sending
const formattedData = {
name: missionData.name,
...missionData,
logo: uploadedLogoPath || null,
attachments: uploadedAttachmentPaths.map(path => ({ filePath: path })),
oddScope: Array.isArray(missionData.oddScope) ? missionData.oddScope : [missionData.oddScope],
niveau: missionData.niveau,
intention: missionData.intention,
missionType: missionData.missionType,
donneurDOrdre: missionData.donneurDOrdre,
projection: missionData.projection,
participation: missionData.participation,
services: selectedServices,
profils: selectedProfils,
guardians: {
@ -402,10 +411,6 @@ export function MissionsAdminPanel() {
'gardien-memoire': gardienDeLaMemoire
},
volunteers: volontaires,
// Only include logo if it exists and has a path
logo: missionData.logo || null,
// Don't send attachments directly - they should be handled separately
attachments: undefined
};
console.log('Submitting mission data:', JSON.stringify(formattedData, null, 2));
@ -426,40 +431,6 @@ export function MissionsAdminPanel() {
throw new Error(data.error || data.details || 'Failed to create mission');
}
// Handle file uploads after mission creation if needed
if (data?.mission?.id && (selectedLogoFile || selectedAttachments.length > 0)) {
// Upload logo
if (selectedLogoFile) {
const result = await import('@/lib/s3').then(mod => mod.uploadMissionFile({
missionId: data.mission.id,
file: selectedLogoFile,
type: 'logo',
}));
if (!result.success) {
toast({
title: "Erreur",
description: result.error || "Erreur lors de l'upload du logo",
variant: "destructive",
});
}
}
// Upload attachments
for (const file of selectedAttachments) {
const result = await import('@/lib/s3').then(mod => mod.uploadMissionFile({
missionId: data.mission.id,
file,
type: 'attachment',
}));
if (!result.success) {
toast({
title: "Erreur",
description: result.error || `Erreur lors de l'upload du fichier ${file.name}`,
variant: "destructive",
});
}
}
}
toast({
title: "Mission créée avec succès",
description: "La mission a été créée et les intégrations sont en cours.",
@ -515,22 +486,15 @@ export function MissionsAdminPanel() {
<label className="block text-sm font-medium mb-1 text-gray-700">Logo</label>
<FileUpload
type="logo"
missionId={missionId || ""}
isNewMission={!missionId}
onFileSelect={(file) => {
// Store the selected file in state for later upload
setSelectedLogoFile(file);
console.log('Logo file selected for later upload:', file.name);
}}
missionId={draftMissionId}
isNewMission={false}
onUploadComplete={(data) => {
// Handle logo upload complete
if (data?.filePath) {
setMissionData(prev => ({
...prev,
logo: data.filePath
}));
setUploadedLogoPath(data.filePath);
setMissionData(prev => ({ ...prev, logo: data.filePath }));
}
}}
onFileSelect={undefined}
/>
</div>
@ -906,7 +870,16 @@ export function MissionsAdminPanel() {
onChange={(e) => {
if (e.target.files && e.target.files.length > 0) {
const file = e.target.files[0];
setSelectedAttachments(prev => [...prev, file]);
// Immediately upload the file
import('@/lib/s3').then(mod => mod.uploadMissionFile({
missionId: draftMissionId,
file,
type: 'attachment',
})).then(result => {
if (result.success && result.data?.filePath) {
setUploadedAttachmentPaths(prev => [...prev, result.data.filePath]);
}
});
}
}}
/>