W n8n attention vm
This commit is contained in:
parent
67d79233ad
commit
e37edbce19
@ -51,6 +51,24 @@ interface Group {
|
||||
type GuardienRole = 'temps' | 'parole' | 'memoire';
|
||||
type UserRole = GuardienRole | 'volontaire';
|
||||
|
||||
interface MissionData {
|
||||
name?: string;
|
||||
logo?: {
|
||||
data: string;
|
||||
name: string;
|
||||
type: string;
|
||||
};
|
||||
oddScope?: string[];
|
||||
niveau?: string;
|
||||
intention?: string;
|
||||
missionType?: string;
|
||||
donneurDOrdre?: string;
|
||||
projection?: string;
|
||||
services?: string[];
|
||||
profils?: string[];
|
||||
participation?: string;
|
||||
}
|
||||
|
||||
export function MissionsAdminPanel() {
|
||||
const router = useRouter();
|
||||
const [selectedServices, setSelectedServices] = useState<string[]>([]);
|
||||
@ -66,19 +84,7 @@ export function MissionsAdminPanel() {
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [selectedLogoFile, setSelectedLogoFile] = useState<File | null>(null);
|
||||
const [selectedAttachments, setSelectedAttachments] = useState<File[]>([]);
|
||||
const [missionData, setMissionData] = useState<{
|
||||
name?: string;
|
||||
logo?: string;
|
||||
oddScope?: string[];
|
||||
niveau?: string;
|
||||
intention?: string;
|
||||
missionType?: string;
|
||||
donneurDOrdre?: string;
|
||||
projection?: string;
|
||||
services?: string[];
|
||||
participation?: string;
|
||||
profils?: string[];
|
||||
}>({});
|
||||
const [missionData, setMissionData] = useState<MissionData>({});
|
||||
|
||||
// State for storing fetched data
|
||||
const [users, setUsers] = useState<User[]>([]);
|
||||
@ -399,63 +405,31 @@ export function MissionsAdminPanel() {
|
||||
setIsSubmitting(true);
|
||||
|
||||
try {
|
||||
// First, upload the logo if it exists
|
||||
let logoPath = null;
|
||||
if (missionData.logo) {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('type', 'logo');
|
||||
formData.append('file', missionData.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();
|
||||
logoPath = uploadData.filePath;
|
||||
} 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 logo path
|
||||
const formattedData = {
|
||||
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 || ''
|
||||
},
|
||||
volunteers: (volontaires || []).filter(Boolean) as string[],
|
||||
logo: logoPath
|
||||
// Prepare the mission data
|
||||
const guardians = {
|
||||
"gardien-temps": gardienDuTemps,
|
||||
"gardien-parole": gardienDeLaParole,
|
||||
"gardien-memoire": gardienDeLaMemoire
|
||||
};
|
||||
|
||||
|
||||
const missionSubmitData = {
|
||||
...missionData,
|
||||
services: selectedServices,
|
||||
profils: selectedProfils,
|
||||
guardians,
|
||||
volunteers: volontaires,
|
||||
logo: missionData.logo // This will now include the full logo data object
|
||||
};
|
||||
|
||||
console.log('Submitting mission data:', JSON.stringify(missionSubmitData, null, 2));
|
||||
|
||||
// Send to API
|
||||
const response = await fetch('/api/missions', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(formattedData),
|
||||
body: JSON.stringify(missionSubmitData),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
@ -522,15 +496,13 @@ export function MissionsAdminPanel() {
|
||||
<label className="block text-sm font-medium mb-1 text-gray-700">Logo</label>
|
||||
<FileUpload
|
||||
type="logo"
|
||||
missionId={draftMissionId}
|
||||
isNewMission={false}
|
||||
onUploadComplete={(data) => {
|
||||
if (data?.filePath) {
|
||||
setUploadedLogoPath(data.filePath);
|
||||
setMissionData(prev => ({ ...prev, logo: data.filePath }));
|
||||
}
|
||||
isNewMission={true}
|
||||
onFileSelect={(fileData) => {
|
||||
setMissionData(prev => ({
|
||||
...prev,
|
||||
logo: fileData
|
||||
}));
|
||||
}}
|
||||
onFileSelect={undefined}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user