W n8n attention vm
This commit is contained in:
parent
6274f3a401
commit
b33ee11327
@ -126,16 +126,15 @@ export function FileUpload({
|
|||||||
const selectedFile = e.target.files[0];
|
const selectedFile = e.target.files[0];
|
||||||
if (validateFile(selectedFile)) {
|
if (validateFile(selectedFile)) {
|
||||||
setFile(selectedFile);
|
setFile(selectedFile);
|
||||||
// If this is a new mission, call onFileSelect instead of waiting for upload
|
// Immediately upload the file
|
||||||
if (isNewMission && onFileSelect) {
|
handleUpload(selectedFile);
|
||||||
onFileSelect(selectedFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUpload = async () => {
|
const handleUpload = async (uploadFile?: File) => {
|
||||||
if (!file) {
|
const fileToUpload = uploadFile || file;
|
||||||
|
if (!fileToUpload) {
|
||||||
console.error('Upload failed: No file selected');
|
console.error('Upload failed: No file selected');
|
||||||
toast({
|
toast({
|
||||||
title: 'Upload failed',
|
title: 'Upload failed',
|
||||||
@ -158,7 +157,7 @@ export function FileUpload({
|
|||||||
// For new missions, just notify through the callback and don't try to upload
|
// For new missions, just notify through the callback and don't try to upload
|
||||||
if (isNewMission) {
|
if (isNewMission) {
|
||||||
if (onFileSelect) {
|
if (onFileSelect) {
|
||||||
onFileSelect(file);
|
onFileSelect(fileToUpload);
|
||||||
}
|
}
|
||||||
toast({
|
toast({
|
||||||
title: 'File selected',
|
title: 'File selected',
|
||||||
@ -180,9 +179,9 @@ export function FileUpload({
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log('Starting upload process...', {
|
console.log('Starting upload process...', {
|
||||||
fileName: file.name,
|
fileName: fileToUpload.name,
|
||||||
fileSize: file.size,
|
fileSize: fileToUpload.size,
|
||||||
fileType: file.type,
|
fileType: fileToUpload.type,
|
||||||
missionId,
|
missionId,
|
||||||
userId: session.user.id,
|
userId: session.user.id,
|
||||||
uploadType: type
|
uploadType: type
|
||||||
@ -194,7 +193,7 @@ export function FileUpload({
|
|||||||
try {
|
try {
|
||||||
// Create form data
|
// Create form data
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', file);
|
formData.append('file', fileToUpload);
|
||||||
formData.append('missionId', missionId);
|
formData.append('missionId', missionId);
|
||||||
formData.append('type', type);
|
formData.append('type', type);
|
||||||
|
|
||||||
@ -240,7 +239,7 @@ export function FileUpload({
|
|||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: 'File uploaded successfully',
|
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',
|
variant: 'default',
|
||||||
});
|
});
|
||||||
}, 1000);
|
}, 1000);
|
||||||
@ -354,7 +353,7 @@ export function FileUpload({
|
|||||||
variant="default"
|
variant="default"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="bg-blue-600 hover:bg-blue-700 text-white"
|
className="bg-blue-600 hover:bg-blue-700 text-white"
|
||||||
onClick={handleUpload}
|
onClick={() => handleUpload()}
|
||||||
>
|
>
|
||||||
<Check className="h-4 w-4 mr-1" />
|
<Check className="h-4 w-4 mr-1" />
|
||||||
Upload
|
Upload
|
||||||
|
|||||||
@ -88,6 +88,20 @@ export function MissionsAdminPanel() {
|
|||||||
// Check if mission is valid (has all required guardiens)
|
// Check if mission is valid (has all required guardiens)
|
||||||
const isMissionValid = gardienDuTemps !== null && gardienDeLaParole !== null && gardienDeLaMemoire !== null;
|
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
|
// Fetch users and groups on component mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
@ -384,16 +398,11 @@ export function MissionsAdminPanel() {
|
|||||||
|
|
||||||
setIsSubmitting(true);
|
setIsSubmitting(true);
|
||||||
try {
|
try {
|
||||||
// Format the data before sending
|
|
||||||
const formattedData = {
|
const formattedData = {
|
||||||
name: missionData.name,
|
...missionData,
|
||||||
|
logo: uploadedLogoPath || null,
|
||||||
|
attachments: uploadedAttachmentPaths.map(path => ({ filePath: path })),
|
||||||
oddScope: Array.isArray(missionData.oddScope) ? missionData.oddScope : [missionData.oddScope],
|
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,
|
services: selectedServices,
|
||||||
profils: selectedProfils,
|
profils: selectedProfils,
|
||||||
guardians: {
|
guardians: {
|
||||||
@ -402,10 +411,6 @@ export function MissionsAdminPanel() {
|
|||||||
'gardien-memoire': gardienDeLaMemoire
|
'gardien-memoire': gardienDeLaMemoire
|
||||||
},
|
},
|
||||||
volunteers: volontaires,
|
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));
|
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');
|
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({
|
toast({
|
||||||
title: "Mission créée avec succès",
|
title: "Mission créée avec succès",
|
||||||
description: "La mission a été créée et les intégrations sont en cours.",
|
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>
|
<label className="block text-sm font-medium mb-1 text-gray-700">Logo</label>
|
||||||
<FileUpload
|
<FileUpload
|
||||||
type="logo"
|
type="logo"
|
||||||
missionId={missionId || ""}
|
missionId={draftMissionId}
|
||||||
isNewMission={!missionId}
|
isNewMission={false}
|
||||||
onFileSelect={(file) => {
|
|
||||||
// Store the selected file in state for later upload
|
|
||||||
setSelectedLogoFile(file);
|
|
||||||
console.log('Logo file selected for later upload:', file.name);
|
|
||||||
}}
|
|
||||||
onUploadComplete={(data) => {
|
onUploadComplete={(data) => {
|
||||||
// Handle logo upload complete
|
|
||||||
if (data?.filePath) {
|
if (data?.filePath) {
|
||||||
setMissionData(prev => ({
|
setUploadedLogoPath(data.filePath);
|
||||||
...prev,
|
setMissionData(prev => ({ ...prev, logo: data.filePath }));
|
||||||
logo: data.filePath
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
onFileSelect={undefined}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -906,7 +870,16 @@ export function MissionsAdminPanel() {
|
|||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
if (e.target.files && e.target.files.length > 0) {
|
if (e.target.files && e.target.files.length > 0) {
|
||||||
const file = e.target.files[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]);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user