mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-04-05 20:51:26 +00:00
feat: Finalisation formulaire dynamique
This commit is contained in:
@ -177,6 +177,8 @@ export default function FormTemplateBuilder({
|
||||
initialData,
|
||||
groups,
|
||||
isEditing,
|
||||
masterFile = null,
|
||||
onMasterFileUpload,
|
||||
}) {
|
||||
const [formConfig, setFormConfig] = useState({
|
||||
id: initialData?.id || 0,
|
||||
@ -186,7 +188,9 @@ export default function FormTemplateBuilder({
|
||||
});
|
||||
|
||||
const [selectedGroups, setSelectedGroups] = useState(
|
||||
initialData?.groups?.map((g) => g.id) || []
|
||||
initialData?.groups?.map((g) =>
|
||||
typeof g === 'object' && g !== null ? g.id : g
|
||||
) || []
|
||||
);
|
||||
|
||||
const [showAddFieldModal, setShowAddFieldModal] = useState(false);
|
||||
@ -209,7 +213,11 @@ export default function FormTemplateBuilder({
|
||||
submitLabel: 'Envoyer',
|
||||
fields: initialData.formMasterData?.fields || [],
|
||||
});
|
||||
setSelectedGroups(initialData.groups?.map((g) => g.id) || []);
|
||||
setSelectedGroups(
|
||||
initialData.groups?.map((g) =>
|
||||
typeof g === 'object' && g !== null ? g.id : g
|
||||
) || []
|
||||
);
|
||||
}
|
||||
}, [initialData]);
|
||||
|
||||
@ -256,6 +264,21 @@ export default function FormTemplateBuilder({
|
||||
const handleFieldSubmit = (data, currentField, editIndex) => {
|
||||
const isHeadingType = data.type.startsWith('heading');
|
||||
const isContentTypeOnly = data.type === 'paragraph' || isHeadingType;
|
||||
const effectiveMasterFile = masterFile || currentField?.masterFileToUpload;
|
||||
|
||||
if (currentField?.masterFileToUpload && onMasterFileUpload) {
|
||||
onMasterFileUpload(currentField.masterFileToUpload);
|
||||
}
|
||||
|
||||
// Un champ fichier nécessite un document source déjà uploadé.
|
||||
if (data.type === 'file' && !effectiveMasterFile) {
|
||||
setSaveMessage({
|
||||
type: 'error',
|
||||
text:
|
||||
'Veuillez d\'abord uploader le document du formulaire avant d\'ajouter un champ fichier.',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const fieldData = {
|
||||
...data,
|
||||
@ -653,7 +676,7 @@ export default function FormTemplateBuilder({
|
||||
<h3 className="text-lg font-semibold mb-4">Aperçu du formulaire</h3>
|
||||
<div className="border-2 border-dashed border-gray-300 p-6 rounded">
|
||||
{formConfig.fields.length > 0 ? (
|
||||
<FormRenderer formConfig={formConfig} />
|
||||
<FormRenderer formConfig={formConfig} masterFile={masterFile} />
|
||||
) : (
|
||||
<p className="text-gray-500 italic text-center">
|
||||
Ajoutez des champs pour voir l'aperçu
|
||||
@ -668,6 +691,8 @@ export default function FormTemplateBuilder({
|
||||
isOpen={showAddFieldModal}
|
||||
onClose={() => setShowAddFieldModal(false)}
|
||||
onSubmit={handleFieldSubmit}
|
||||
hasMasterFile={Boolean(masterFile)}
|
||||
onMasterFileUpload={onMasterFileUpload}
|
||||
editingField={
|
||||
editingIndex >= 0
|
||||
? formConfig.fields[editingIndex]
|
||||
|
||||
Reference in New Issue
Block a user