correction grande partie des items

This commit is contained in:
2026-02-16 22:14:45 +01:00
parent 85a585131e
commit 78dc8813f1
2 changed files with 44 additions and 12 deletions

View File

@@ -257,8 +257,10 @@ export const useProjects = (user: UserProfile | null) => {
}]
};
}));
return newChap.id.toString();
} catch (err) {
console.error("Failed to add chapter", err);
return null;
}
};
@@ -279,15 +281,16 @@ export const useProjects = (user: UserProfile | null) => {
}
};
const createEntity = async (projectId: string, type: EntityType) => {
const createEntity = async (projectId: string, type: EntityType, initialData?: Partial<Entity>) => {
try {
const entityPayload = {
project_id: projectId,
type: type,
name: `Nouveau ${type}`,
description: '',
details: '',
attributes: '{}'
name: initialData?.name || `Nouveau ${type}`,
description: initialData?.description || '',
details: initialData?.details || '',
attributes: initialData?.attributes ? JSON.stringify(initialData.attributes) : '{}',
// Handle customValues if they exist in initialData, though not in original payload
};
const newEntity = await api.data.create<any>('entities', entityPayload);
@@ -302,12 +305,15 @@ export const useProjects = (user: UserProfile | null) => {
name: entityPayload.name,
description: entityPayload.description,
details: entityPayload.details,
attributes: JSON.parse(entityPayload.attributes)
attributes: JSON.parse(entityPayload.attributes),
customValues: initialData?.customValues || {}
}]
};
}));
return newEntity.id.toString();
} catch (err) {
console.error("Failed to create entity", err);
throw err; // Re-throw to let caller know
}
};