mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
feat: Mise en place des actions pour chaque state du RF, possibilité
d'éditer le formulaire de création de RF (reste à submit un PUT)
This commit is contained in:
@ -6,12 +6,9 @@ import { useTranslations } from 'next-intl';
|
||||
import StatusLabel from '@/components/StatusLabel';
|
||||
import Popup from '@/components/Popup';
|
||||
import Loader from '@/components/Loader';
|
||||
import AlertWithModal from '@/components/AlertWithModal';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import DropdownMenu from '@/components/DropdownMenu';
|
||||
import {
|
||||
Search,
|
||||
MoreVertical,
|
||||
Send,
|
||||
Edit,
|
||||
Archive,
|
||||
@ -19,14 +16,12 @@ import {
|
||||
CheckCircle,
|
||||
Plus,
|
||||
Upload,
|
||||
Eye,
|
||||
} from 'lucide-react';
|
||||
import Modal from '@/components/Modal';
|
||||
import { useEstablishment } from '@/context/EstablishmentContext';
|
||||
|
||||
import {
|
||||
CURRENT_YEAR,
|
||||
NEXT_YEAR,
|
||||
HISTORICAL,
|
||||
fetchRegisterForms,
|
||||
sendRegisterForm,
|
||||
archiveRegisterForm,
|
||||
@ -34,9 +29,7 @@ import {
|
||||
editRegisterFormWithBinaryFile,
|
||||
} from '@/app/actions/subscriptionAction';
|
||||
|
||||
import { fetchClasses, updateDatas } from '@/app/actions/schoolAction';
|
||||
|
||||
import { fetchProfiles } from '@/app/actions/authAction';
|
||||
import { fetchClasses } from '@/app/actions/schoolAction';
|
||||
|
||||
import {
|
||||
FE_ADMIN_SUBSCRIPTIONS_EDIT_URL,
|
||||
@ -51,11 +44,14 @@ import logger from '@/utils/logger';
|
||||
import { PhoneLabel } from '@/components/PhoneLabel';
|
||||
import FileUpload from '@/components/FileUpload';
|
||||
import FilesModal from '@/components/Inscription/FilesModal';
|
||||
import { getCurrentSchoolYear, getNextSchoolYear } from '@/utils/Date';
|
||||
|
||||
import {
|
||||
getCurrentSchoolYear,
|
||||
getNextSchoolYear,
|
||||
getHistoricalYears,
|
||||
} from '@/utils/Date';
|
||||
RegistrationFormStatus,
|
||||
CURRENT_YEAR,
|
||||
NEXT_YEAR,
|
||||
HISTORICAL,
|
||||
} from '@/utils/constants';
|
||||
|
||||
export default function Page({ params: { locale } }) {
|
||||
const t = useTranslations('subscriptions');
|
||||
@ -68,9 +64,8 @@ export default function Page({ params: { locale } }) {
|
||||
useState([]);
|
||||
const [registrationFormsDataHistorical, setRegistrationFormsDataHistorical] =
|
||||
useState([]);
|
||||
const currentSchoolYear = getCurrentSchoolYear(); // Exemple : "2024-2025"
|
||||
const nextSchoolYear = getNextSchoolYear(); // Exemple : "2025-2026"
|
||||
const historicalYears = getHistoricalYears();
|
||||
const currentSchoolYear = getCurrentSchoolYear();
|
||||
const nextSchoolYear = getNextSchoolYear();
|
||||
const [totalCurrentSchoolYearPages, setTotalCurrentSchoolYearPages] =
|
||||
useState(1);
|
||||
const [totalNextSchoolYearPages, setTotalNextSchoolYearPages] = useState(1);
|
||||
@ -81,7 +76,7 @@ export default function Page({ params: { locale } }) {
|
||||
useState(1);
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [activeTab, setActiveTab] = useState('currentYear');
|
||||
const [activeTab, setActiveTab] = useState(CURRENT_YEAR);
|
||||
const [totalCurrentYear, setTotalCurrentYear] = useState(0);
|
||||
const [totalNextYear, setTotalNextYear] = useState(0);
|
||||
const [totalHistorical, setTotalHistorical] = useState(0);
|
||||
@ -91,7 +86,6 @@ export default function Page({ params: { locale } }) {
|
||||
const [classes, setClasses] = useState([]);
|
||||
const [reloadFetch, setReloadFetch] = useState(false);
|
||||
|
||||
const [profiles, setProfiles] = useState([]);
|
||||
const [isOpenAddGuardian, setIsOpenAddGuardian] = useState(false);
|
||||
|
||||
const [isFilesModalOpen, setIsFilesModalOpen] = useState(false);
|
||||
@ -217,13 +211,6 @@ export default function Page({ params: { locale } }) {
|
||||
fetchRegisterForms(selectedEstablishmentId, HISTORICAL)
|
||||
.then(registerFormHistoricalDataHandler)
|
||||
.catch(requestErrorHandler),
|
||||
fetchProfiles()
|
||||
.then((data) => {
|
||||
setProfiles(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.error('Error fetching profileRoles:', error);
|
||||
}),
|
||||
])
|
||||
.then(() => {
|
||||
setIsLoading(false);
|
||||
@ -275,13 +262,13 @@ export default function Page({ params: { locale } }) {
|
||||
* UseEffect to update page count of tab
|
||||
*/
|
||||
useEffect(() => {
|
||||
if (activeTab === 'currentYear') {
|
||||
if (activeTab === CURRENT_YEAR) {
|
||||
setTotalCurrentSchoolYearPages(
|
||||
Math.ceil(totalCurrentYear / itemsPerPage)
|
||||
);
|
||||
} else if (activeTab === 'nextYear') {
|
||||
} else if (activeTab === NEXT_YEAR) {
|
||||
setTotalNextSchoolYearPages(Math.ceil(totalNextYear / itemsPerPage));
|
||||
} else if (activeTab === 'historical') {
|
||||
} else if (activeTab === HISTORICAL) {
|
||||
setTotalHistoricalPages(Math.ceil(totalHistorical / itemsPerPage));
|
||||
}
|
||||
}, [currentSchoolYearPage]);
|
||||
@ -390,7 +377,13 @@ export default function Page({ params: { locale } }) {
|
||||
};
|
||||
|
||||
const handlePageChange = (newPage) => {
|
||||
setCurrentSchoolYearPage(newPage);
|
||||
if (activeTab === CURRENT_YEAR) {
|
||||
setCurrentSchoolYearPage(newPage);
|
||||
} else if (activeTab === NEXT_YEAR) {
|
||||
setCurrentSchoolNextYearPage(newPage);
|
||||
} else if (activeTab === HISTORICAL) {
|
||||
setCurrentSchoolHistoricalYearPage(newPage);
|
||||
}
|
||||
};
|
||||
|
||||
const updateRF = (updatedData) => {
|
||||
@ -475,7 +468,22 @@ export default function Page({ params: { locale } }) {
|
||||
|
||||
const getActionsByStatus = (row) => {
|
||||
const actions = {
|
||||
1: [
|
||||
// Etat "A envoyer" :
|
||||
// - Editer le formulaire de création
|
||||
// - Envoyer le formulaire aux parents
|
||||
// - Archiver le dossier
|
||||
[RegistrationFormStatus.STATUS_TO_SEND]: [
|
||||
{
|
||||
icon: (
|
||||
<span title="Editer le formulaire de création">
|
||||
<Edit className="w-5 h-5 text-blue-500 hover:text-blue-700" />
|
||||
</span>
|
||||
),
|
||||
onClick: () =>
|
||||
router.push(
|
||||
`${FE_ADMIN_SUBSCRIPTIONS_CREATE_URL}?id=${row.student.id}&school_year=${activeTab}`
|
||||
),
|
||||
},
|
||||
{
|
||||
icon: (
|
||||
<span title="Envoyer le dossier">
|
||||
@ -490,7 +498,42 @@ export default function Page({ params: { locale } }) {
|
||||
),
|
||||
},
|
||||
],
|
||||
2: [
|
||||
// Etat "En attente" :
|
||||
// - Editer le formulaire de création
|
||||
// - Renvoyer le formulaire aux parents
|
||||
// - Archiver le dossier
|
||||
[RegistrationFormStatus.STATUS_PENDING]: [
|
||||
{
|
||||
icon: (
|
||||
<span title="Editer le formulaire de création">
|
||||
<Edit className="w-5 h-5 text-blue-500 hover:text-blue-700" />
|
||||
</span>
|
||||
),
|
||||
onClick: () =>
|
||||
router.push(
|
||||
`${FE_ADMIN_SUBSCRIPTIONS_CREATE_URL}?id=${row.student.id}&school_year=${activeTab}`
|
||||
),
|
||||
},
|
||||
{
|
||||
icon: (
|
||||
<span title="Renvoyer le dossier">
|
||||
<Send className="w-5 h-5 text-green-500 hover:text-green-700" />
|
||||
</span>
|
||||
),
|
||||
onClick: () =>
|
||||
sendConfirmRegisterForm(
|
||||
row.student.id,
|
||||
row.student.last_name,
|
||||
row.student.first_name
|
||||
),
|
||||
},
|
||||
],
|
||||
// Etat "Signé" :
|
||||
// - Editer le formulaire d'inscription
|
||||
// - Visualiser les documents signés par les parents
|
||||
// - Valider le dossier d'inscription
|
||||
// - Archiver le dossier
|
||||
[RegistrationFormStatus.STATUS_TO_VALIDATE]: [
|
||||
{
|
||||
icon: (
|
||||
<span title="Editer le dossier">
|
||||
@ -499,11 +542,9 @@ export default function Page({ params: { locale } }) {
|
||||
),
|
||||
onClick: () =>
|
||||
router.push(
|
||||
`${FE_ADMIN_SUBSCRIPTIONS_EDIT_URL}?studentId=${row.student.id}`
|
||||
`${FE_ADMIN_SUBSCRIPTIONS_EDIT_URL}?studentId=${row.student.id}&enabled=true`
|
||||
),
|
||||
},
|
||||
],
|
||||
3: [
|
||||
{
|
||||
icon: (
|
||||
<span title="Voir les fichiers">
|
||||
@ -524,7 +565,27 @@ export default function Page({ params: { locale } }) {
|
||||
},
|
||||
},
|
||||
],
|
||||
5: [
|
||||
// Etat "A relancer" - NON TESTE
|
||||
[RegistrationFormStatus.STATUS_TO_FOLLOW_UP]: [
|
||||
// To do...
|
||||
],
|
||||
// Etat "Validé" :
|
||||
// - Editer le formulaire d'inscription
|
||||
// - Visualiser les documents signés par les parents
|
||||
// - A ajouter : Action pour éditer le suivi de l'élève
|
||||
// - Archiver le dossier
|
||||
[RegistrationFormStatus.STATUS_VALIDATED]: [
|
||||
{
|
||||
icon: (
|
||||
<span title="Editer le dossier">
|
||||
<Edit className="w-5 h-5 text-blue-500 hover:text-blue-700" />
|
||||
</span>
|
||||
),
|
||||
onClick: () =>
|
||||
router.push(
|
||||
`${FE_ADMIN_SUBSCRIPTIONS_EDIT_URL}?studentId=${row.student.id}&enabled=true`
|
||||
),
|
||||
},
|
||||
{
|
||||
icon: (
|
||||
<span title="Voir les fichiers">
|
||||
@ -534,7 +595,37 @@ export default function Page({ params: { locale } }) {
|
||||
onClick: () => openFilesModal(row),
|
||||
},
|
||||
],
|
||||
7: [
|
||||
// Etat "Archivé"
|
||||
// - Editer le formulaire d'inscription en lecture seule
|
||||
[RegistrationFormStatus.STATUS_ARCHIVED]: [
|
||||
{
|
||||
icon: (
|
||||
<span title="Editer le dossier">
|
||||
<Eye className="w-5 h-5 text-purple-500 hover:text-purple-700" />
|
||||
</span>
|
||||
),
|
||||
onClick: () =>
|
||||
router.push(
|
||||
`${FE_ADMIN_SUBSCRIPTIONS_EDIT_URL}?studentId=${row.student.id}&enabled=false`
|
||||
),
|
||||
},
|
||||
],
|
||||
// Etat "En attente de signature de SEPA" :
|
||||
// - Editer le formulaire d'inscription
|
||||
// - Visualiser les documents signés par les parents
|
||||
// - Archiver le dossier
|
||||
[RegistrationFormStatus.STATUS_SEPA_PENDING]: [
|
||||
{
|
||||
icon: (
|
||||
<span title="Editer le dossier">
|
||||
<Edit className="w-5 h-5 text-blue-500 hover:text-blue-700" />
|
||||
</span>
|
||||
),
|
||||
onClick: () =>
|
||||
router.push(
|
||||
`${FE_ADMIN_SUBSCRIPTIONS_EDIT_URL}?studentId=${row.student.id}&enabled=true`
|
||||
),
|
||||
},
|
||||
{
|
||||
icon: (
|
||||
<span title="Voir les fichiers">
|
||||
@ -544,7 +635,23 @@ export default function Page({ params: { locale } }) {
|
||||
onClick: () => openFilesModal(row),
|
||||
},
|
||||
],
|
||||
8: [
|
||||
// Etat "SEPA à envoyer" :
|
||||
// - Editer le formulaire d'inscription
|
||||
// - Visualiser les documents signés par les parents
|
||||
// - Envoyer le mandat SEPA aux parents
|
||||
// - Archiver le dossier
|
||||
[RegistrationFormStatus.STATUS_SEPA_TO_SEND]: [
|
||||
{
|
||||
icon: (
|
||||
<span title="Editer le dossier">
|
||||
<Edit className="w-5 h-5 text-blue-500 hover:text-blue-700" />
|
||||
</span>
|
||||
),
|
||||
onClick: () =>
|
||||
router.push(
|
||||
`${FE_ADMIN_SUBSCRIPTIONS_EDIT_URL}?studentId=${row.student.id}&enabled=true`
|
||||
),
|
||||
},
|
||||
{
|
||||
icon: (
|
||||
<span title="Voir les fichiers">
|
||||
@ -566,7 +673,7 @@ export default function Page({ params: { locale } }) {
|
||||
{
|
||||
icon: (
|
||||
<span title="Archiver le dossier">
|
||||
<Archive className="w-5 h-5 text-gray-500 hover:text-gray-700" />
|
||||
<Archive className="w-5 h-5 text-red-500 hover:text-red-700" />
|
||||
</span>
|
||||
),
|
||||
onClick: () =>
|
||||
@ -625,9 +732,10 @@ export default function Page({ params: { locale } }) {
|
||||
},
|
||||
{
|
||||
name: t('phone'),
|
||||
transform: (row) => (
|
||||
<PhoneLabel phoneNumber={row.student.guardians[0]?.phone} />
|
||||
),
|
||||
transform: (row) =>
|
||||
row.student.guardians[0]?.phone ? (
|
||||
<PhoneLabel phoneNumber={row.student.guardians[0]?.phone} />
|
||||
) : null, // N'affiche rien si le numéro de téléphone est absent
|
||||
},
|
||||
{
|
||||
name: t('lastUpdateDate'),
|
||||
@ -683,8 +791,8 @@ export default function Page({ params: { locale } }) {
|
||||
</span>
|
||||
</>
|
||||
}
|
||||
active={activeTab === 'currentYear'}
|
||||
onClick={() => setActiveTab('currentYear')}
|
||||
active={activeTab === CURRENT_YEAR}
|
||||
onClick={() => setActiveTab(CURRENT_YEAR)}
|
||||
/>
|
||||
|
||||
{/* Tab pour l'année scolaire prochaine */}
|
||||
@ -697,8 +805,8 @@ export default function Page({ params: { locale } }) {
|
||||
</span>
|
||||
</>
|
||||
}
|
||||
active={activeTab === 'nextYear'}
|
||||
onClick={() => setActiveTab('nextYear')}
|
||||
active={activeTab === NEXT_YEAR}
|
||||
onClick={() => setActiveTab(NEXT_YEAR)}
|
||||
/>
|
||||
|
||||
{/* Tab pour l'historique */}
|
||||
@ -711,16 +819,16 @@ export default function Page({ params: { locale } }) {
|
||||
</span>
|
||||
</>
|
||||
}
|
||||
active={activeTab === 'historical'}
|
||||
onClick={() => setActiveTab('historical')}
|
||||
active={activeTab === HISTORICAL}
|
||||
onClick={() => setActiveTab(HISTORICAL)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="border-b border-gray-200 mb-6 w-full">
|
||||
{activeTab === 'currentYear' ||
|
||||
activeTab === 'nextYear' ||
|
||||
activeTab === 'historical' ? (
|
||||
{activeTab === CURRENT_YEAR ||
|
||||
activeTab === NEXT_YEAR ||
|
||||
activeTab === HISTORICAL ? (
|
||||
<React.Fragment>
|
||||
<div className="flex justify-between items-center mb-4 w-full">
|
||||
<div className="relative flex-grow">
|
||||
@ -752,25 +860,25 @@ export default function Page({ params: { locale } }) {
|
||||
<Table
|
||||
key={`${currentSchoolYearPage}-${searchTerm}`}
|
||||
data={
|
||||
activeTab === 'currentYear'
|
||||
activeTab === CURRENT_YEAR
|
||||
? registrationFormsDataCurrentYear
|
||||
: activeTab === 'nextYear'
|
||||
: activeTab === NEXT_YEAR
|
||||
? registrationFormsDataNextYear
|
||||
: registrationFormsDataHistorical
|
||||
}
|
||||
columns={columns}
|
||||
itemsPerPage={itemsPerPage}
|
||||
currentPage={
|
||||
activeTab === 'currentYear'
|
||||
activeTab === CURRENT_YEAR
|
||||
? currentSchoolYearPage
|
||||
: activeTab === 'nextYear'
|
||||
: activeTab === NEXT_YEAR
|
||||
? currentSchoolNextYearPage
|
||||
: currentSchoolHistoricalYearPage
|
||||
}
|
||||
totalPages={
|
||||
activeTab === 'currentYear'
|
||||
activeTab === CURRENT_YEAR
|
||||
? totalCurrentSchoolYearPages
|
||||
: activeTab === 'nextYear'
|
||||
: activeTab === NEXT_YEAR
|
||||
? totalNextSchoolYearPages
|
||||
: totalHistoricalPages
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user