mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
70 lines
2.2 KiB
JavaScript
70 lines
2.2 KiB
JavaScript
'use client';
|
|
import React, { useState } from 'react';
|
|
import { useSearchParams, useRouter } from 'next/navigation';
|
|
import InscriptionFormShared from '@/components/Inscription/InscriptionFormShared';
|
|
import { FE_ADMIN_SUBSCRIPTIONS_URL } from '@/utils/Url';
|
|
import { useCsrfToken } from '@/context/CsrfContext';
|
|
import { useEstablishment } from '@/context/EstablishmentContext';
|
|
import { editRegisterForm } from '@/app/actions/subscriptionAction';
|
|
import logger from '@/utils/logger';
|
|
import Loader from '@/components/Loader';
|
|
import { useNotification } from '@/context/NotificationContext';
|
|
|
|
export default function Page() {
|
|
const router = useRouter();
|
|
const { showNotification } = useNotification();
|
|
const searchParams = useSearchParams();
|
|
const studentId = searchParams.get('studentId');
|
|
const enable = searchParams.get('enabled') === 'true';
|
|
|
|
const [formErrors, setFormErrors] = useState({});
|
|
const csrfToken = useCsrfToken();
|
|
const { selectedEstablishmentId, apiDocuseal } = useEstablishment();
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
const handleSubmit = (data) => {
|
|
setIsLoading(true);
|
|
editRegisterForm(studentId, data, csrfToken)
|
|
.then((result) => {
|
|
setIsLoading(false);
|
|
logger.debug('Success:', result);
|
|
showNotification(
|
|
"Dossier d'inscription soumis avec succès",
|
|
'success',
|
|
'Succès'
|
|
);
|
|
router.push(FE_ADMIN_SUBSCRIPTIONS_URL);
|
|
})
|
|
.catch((error) => {
|
|
setIsLoading(false);
|
|
logger.error('Error:', error.message);
|
|
showNotification(
|
|
"Erreur lors de la soumission du dossier d'inscription",
|
|
'error',
|
|
'Erreur'
|
|
);
|
|
if (error.details) {
|
|
logger.error('Form errors:', error.details);
|
|
setFormErrors(error.details);
|
|
}
|
|
});
|
|
};
|
|
|
|
if (isLoading) {
|
|
return <Loader />;
|
|
}
|
|
|
|
return (
|
|
<InscriptionFormShared
|
|
studentId={studentId}
|
|
csrfToken={csrfToken}
|
|
selectedEstablishmentId={selectedEstablishmentId}
|
|
apiDocuseal = {apiDocuseal}
|
|
onSubmit={handleSubmit}
|
|
cancelUrl={FE_ADMIN_SUBSCRIPTIONS_URL}
|
|
errors={formErrors}
|
|
enable={enable}
|
|
/>
|
|
);
|
|
}
|