correction grande partie des items
This commit is contained in:
18
hooks.ts
18
hooks.ts
@@ -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
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user