mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
refactor: Refactorisation du login et de admin/subscription
This commit is contained in:
@ -5,7 +5,8 @@ import Table from '@/components/Table';
|
||||
import { Edit } from 'lucide-react';
|
||||
import StatusLabel from '@/components/StatusLabel';
|
||||
import useLocalStorage from '@/hooks/useLocalStorage';
|
||||
import { BE_SUBSCRIPTION_CHILDRENS_URL , FE_PARENTS_EDIT_INSCRIPTION_URL } from '@/utils/Url';
|
||||
import { FE_PARENTS_EDIT_INSCRIPTION_URL } from '@/utils/Url';
|
||||
import { fetchChildren } from '@/app/lib/subscriptionAction';
|
||||
|
||||
export default function ParentHomePage() {
|
||||
const [actions, setActions] = useState([]);
|
||||
@ -17,34 +18,22 @@ export default function ParentHomePage() {
|
||||
useEffect(() => {
|
||||
if (!userId) return;
|
||||
|
||||
const fetchActions = async () => {
|
||||
const response = await fetch('/api/actions');
|
||||
const data = await response.json();
|
||||
setActions(data);
|
||||
};
|
||||
|
||||
const fetchEleves = async () => {
|
||||
const response = await fetch(`${BE_SUBSCRIPTION_CHILDRENS_URL}/${userId}`);
|
||||
const data = await response.json();
|
||||
console.log(data);
|
||||
|
||||
setChildren(data);
|
||||
};
|
||||
|
||||
fetchEleves();
|
||||
fetchChildren(userId).then(data => {
|
||||
setChildren(data);
|
||||
});
|
||||
}, [userId]);
|
||||
|
||||
function handleEdit(eleveId) {
|
||||
// Logique pour éditer le dossier de l'élève
|
||||
console.log(`Edit dossier for eleve id: ${eleveId}`);
|
||||
console.log(`Edit dossier for student id: ${eleveId}`);
|
||||
router.push(`${FE_PARENTS_EDIT_INSCRIPTION_URL}?id=${userId}&studentId=${eleveId}`);
|
||||
}
|
||||
const actionColumns = [
|
||||
{ name: 'Action', transform: (row) => row.action },
|
||||
];
|
||||
|
||||
const getShadowColor = (etat) => {
|
||||
switch (etat) {
|
||||
const getShadowColor = (status) => {
|
||||
switch (status) {
|
||||
case 1:
|
||||
return 'shadow-blue-500'; // Couleur d'ombre plus visible
|
||||
case 2:
|
||||
@ -73,12 +62,12 @@ export default function ParentHomePage() {
|
||||
<h2 className="text-xl font-semibold mb-4">Enfants</h2>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
{children.map((child) => (
|
||||
<div key={child.eleve.id} className={`border p-4 rounded shadow ${getShadowColor(child.etat)}`}>
|
||||
<div key={child.student.id} className={`border p-4 rounded shadow ${getShadowColor(child.status)}`}>
|
||||
<div className="flex justify-between items-center">
|
||||
<h3 className="text-lg font-semibold">{child.eleve.nom} {child.eleve.prenom}</h3>
|
||||
<Edit className="cursor-pointer" onClick={() => handleEdit(child.eleve.id)} />
|
||||
<h3 className="text-lg font-semibold">{child.student.last_name} {child.student.first_name}</h3>
|
||||
<Edit className="cursor-pointer" onClick={() => handleEdit(child.student.id)} />
|
||||
</div>
|
||||
<StatusLabel etat={child.etat } showDropdown={false}/>
|
||||
<StatusLabel etat={child.status } showDropdown={false}/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user