mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-04-04 04:01:27 +00:00
feat: WIP finalisation partie signature des parents [N3WTS-17]
This commit is contained in:
@ -1,209 +0,0 @@
|
||||
import React, { useState } from 'react';
|
||||
import Modal from '@/components/Modal';
|
||||
import { FolderPlus, FileText, FilePlus2, ArrowLeft, Settings2, Upload as UploadIcon } from 'lucide-react';
|
||||
import FormTemplateBuilder from '@/components/Form/FormTemplateBuilder';
|
||||
import FileUpload from '@/components/Form/FileUpload';
|
||||
|
||||
export default function CreateDocumentModal({
|
||||
isOpen,
|
||||
onClose,
|
||||
onCreateGroup,
|
||||
onCreateParentFile,
|
||||
onCreateSchoolFileMaster,
|
||||
groups = [],
|
||||
}) {
|
||||
const [step, setStep] = useState('main'); // main | choose_form | form_builder | file_upload
|
||||
const [fileName, setFileName] = useState('');
|
||||
const [selectedGroupsFileUpload, setSelectedGroupsFileUpload] = useState([]);
|
||||
const [uploadedFile, setUploadedFile] = useState(null);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!isOpen) {
|
||||
setStep('main');
|
||||
setFileName('');
|
||||
setSelectedGroupsFileUpload([]);
|
||||
setUploadedFile(null);
|
||||
}
|
||||
}, [isOpen]);
|
||||
|
||||
// Handler pour chaque type
|
||||
const handleSelect = (type) => {
|
||||
if (type === 'groupe') {
|
||||
setStep('main');
|
||||
onCreateGroup();
|
||||
onClose();
|
||||
}
|
||||
if (type === 'formulaire') {
|
||||
setStep('choose_form');
|
||||
}
|
||||
if (type === 'parent') {
|
||||
setStep('main');
|
||||
onCreateParentFile();
|
||||
onClose();
|
||||
}
|
||||
};
|
||||
|
||||
// Retour au menu principal
|
||||
const handleBack = () => setStep('main');
|
||||
|
||||
// Submit pour formulaire existant
|
||||
const handleFileUploadSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
if (!fileName || selectedGroupsFileUpload.length === 0 || !uploadedFile) return;
|
||||
onCreateSchoolFileMaster({
|
||||
name: fileName,
|
||||
group_ids: selectedGroupsFileUpload,
|
||||
file: uploadedFile,
|
||||
});
|
||||
onClose();
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
isOpen={isOpen}
|
||||
setIsOpen={onClose}
|
||||
title="Créer un document"
|
||||
modalClassName="w-full max-w-md"
|
||||
>
|
||||
{step === 'main' && (
|
||||
<div className="flex flex-col gap-6 py-4">
|
||||
<button
|
||||
className="flex items-center gap-3 px-4 py-3 rounded-lg bg-blue-50 hover:bg-blue-100 border border-blue-200 transition"
|
||||
onClick={() => handleSelect('groupe')}
|
||||
>
|
||||
<FolderPlus className="w-6 h-6 text-blue-600" />
|
||||
<span className="font-semibold text-blue-800">Dossier d&aposinscription</span>
|
||||
</button>
|
||||
<button
|
||||
className="flex items-center gap-3 px-4 py-3 rounded-lg bg-emerald-50 hover:bg-emerald-100 border border-emerald-200 transition"
|
||||
onClick={() => handleSelect('formulaire')}
|
||||
>
|
||||
<FileText className="w-6 h-6 text-emerald-600" />
|
||||
<span className="font-semibold text-emerald-800">Formulaire scolaire</span>
|
||||
</button>
|
||||
<button
|
||||
className="flex items-center gap-3 px-4 py-3 rounded-lg bg-orange-50 hover:bg-orange-100 border border-orange-200 transition"
|
||||
onClick={() => handleSelect('parent')}
|
||||
>
|
||||
<FilePlus2 className="w-6 h-6 text-orange-500" />
|
||||
<span className="font-semibold text-orange-700">Pièce à fournir</span>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{step === 'choose_form' && (
|
||||
<div className="flex flex-col gap-4 py-4">
|
||||
<button
|
||||
className="flex items-center gap-3 px-4 py-3 rounded-lg bg-emerald-100 hover:bg-emerald-200 border border-emerald-300 transition"
|
||||
onClick={() => setStep('form_builder')}
|
||||
>
|
||||
<Settings2 className="w-6 h-6 text-emerald-700" />
|
||||
<span className="font-semibold text-emerald-900">Formulaire personnalisé</span>
|
||||
</button>
|
||||
<button
|
||||
className="flex items-center gap-3 px-4 py-3 rounded-lg bg-gray-100 hover:bg-gray-200 border border-gray-300 transition"
|
||||
onClick={() => setStep('file_upload')}
|
||||
>
|
||||
<UploadIcon className="w-6 h-6 text-gray-700" />
|
||||
<span className="font-semibold text-gray-900">Importer un formulaire existant</span>
|
||||
</button>
|
||||
<button
|
||||
className="flex items-center gap-2 text-gray-600 hover:text-gray-900 mt-2"
|
||||
onClick={handleBack}
|
||||
>
|
||||
<ArrowLeft className="w-5 h-5" />
|
||||
<span>Retour</span>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{step === 'form_builder' && (
|
||||
<div>
|
||||
<button
|
||||
className="flex items-center gap-2 text-gray-600 hover:text-gray-900 mb-2"
|
||||
onClick={handleBack}
|
||||
>
|
||||
<ArrowLeft className="w-5 h-5" />
|
||||
<span>Retour</span>
|
||||
</button>
|
||||
<FormTemplateBuilder
|
||||
onSave={(data) => {
|
||||
onCreateSchoolFileMaster(data);
|
||||
onClose();
|
||||
}}
|
||||
groups={groups}
|
||||
isEditing={false}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{step === 'file_upload' && (
|
||||
<div>
|
||||
<button
|
||||
className="flex items-center gap-2 text-gray-600 hover:text-gray-900 mb-2"
|
||||
onClick={handleBack}
|
||||
>
|
||||
<ArrowLeft className="w-5 h-5" />
|
||||
<span>Retour</span>
|
||||
</button>
|
||||
<form className="flex flex-col gap-4" onSubmit={handleFileUploadSubmit}>
|
||||
<input
|
||||
type="text"
|
||||
className="border rounded px-3 py-2"
|
||||
placeholder="Nom du formulaire"
|
||||
value={fileName}
|
||||
onChange={e => setFileName(e.target.value)}
|
||||
required
|
||||
/>
|
||||
{/* Sélecteur de groupes à cocher */}
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-medium text-gray-700">
|
||||
Groupes d'inscription <span className="text-red-500">*</span>
|
||||
</label>
|
||||
<div className="space-y-2 max-h-32 overflow-y-auto border rounded-md p-2">
|
||||
{groups && groups.length > 0 ? (
|
||||
groups.map((group) => (
|
||||
<label key={group.id} className="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={selectedGroupsFileUpload.includes(group.id)}
|
||||
onChange={(e) => {
|
||||
if (e.target.checked) {
|
||||
setSelectedGroupsFileUpload([
|
||||
...selectedGroupsFileUpload,
|
||||
group.id,
|
||||
]);
|
||||
} else {
|
||||
setSelectedGroupsFileUpload(
|
||||
selectedGroupsFileUpload.filter((id) => id !== group.id)
|
||||
);
|
||||
}
|
||||
}}
|
||||
className="mr-2 text-blue-600"
|
||||
/>
|
||||
<span className="text-sm">{group.name}</span>
|
||||
</label>
|
||||
))
|
||||
) : (
|
||||
<p className="text-gray-500 text-sm">
|
||||
Aucun groupe disponible
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<FileUpload
|
||||
selectionMessage="Sélectionnez le fichier du formulaire"
|
||||
onFileSelect={setUploadedFile}
|
||||
required
|
||||
enable
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
className="bg-emerald-600 text-white px-4 py-2 rounded font-bold mt-2"
|
||||
disabled={!fileName || selectedGroupsFileUpload.length === 0 || !uploadedFile}
|
||||
>
|
||||
Créer le formulaire
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@ -6,8 +6,6 @@ import {
|
||||
Star,
|
||||
ChevronDown,
|
||||
Plus,
|
||||
Archive,
|
||||
Eye
|
||||
} from 'lucide-react';
|
||||
import Modal from '@/components/Modal';
|
||||
import FormTemplateBuilder from '@/components/Form/FormTemplateBuilder';
|
||||
@ -31,11 +29,9 @@ import {
|
||||
} from '@/app/actions/registerFileGroupAction';
|
||||
import RegistrationFileGroupForm from '@/components/Structure/Files/RegistrationFileGroupForm';
|
||||
import logger from '@/utils/logger';
|
||||
import ParentFiles from './ParentFiles';
|
||||
import Popup from '@/components/Popup';
|
||||
import Loader from '@/components/Loader';
|
||||
import { useNotification } from '@/context/NotificationContext';
|
||||
import CreateDocumentModal from '@/components/Structure/Files/CreateDocumentModal';
|
||||
import FileUpload from '@/components/Form/FileUpload';
|
||||
import SectionTitle from '@/components/SectionTitle';
|
||||
import DropdownMenu from '@/components/DropdownMenu';
|
||||
|
||||
Reference in New Issue
Block a user