Init PMPR-34
This commit is contained in:
@@ -1,75 +0,0 @@
|
|||||||
import { useEffect, useState } from "preact/hooks";
|
|
||||||
|
|
||||||
interface Promotion {
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Student {
|
|
||||||
id: number;
|
|
||||||
firstName: string;
|
|
||||||
lastName: string;
|
|
||||||
mail: string;
|
|
||||||
promotionId: number;
|
|
||||||
promotionName: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function ConsultStudents_test() {
|
|
||||||
const [data, setData] = useState<
|
|
||||||
{ promotions: Promotion[]; students: Student[] } | null
|
|
||||||
>(null);
|
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchData = async () => {
|
|
||||||
try {
|
|
||||||
const response = await fetch("/students/api/insert_students");
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Error fetching data: ${response.statusText}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await response.json();
|
|
||||||
setData(result);
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Error fetching data:", err);
|
|
||||||
setError("Failed to load data. Please try again later.");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchData();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<section>
|
|
||||||
<h2>Consult Students</h2>
|
|
||||||
{error && <p className="error">{error}</p>}
|
|
||||||
{data?.promotions.map((promo) => (
|
|
||||||
<div key={promo.id}>
|
|
||||||
<h3>Promotion: {promo.id}</h3>
|
|
||||||
<table>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>ID</th>
|
|
||||||
<th>First Name</th>
|
|
||||||
<th>Last Name</th>
|
|
||||||
<th>Email</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{data.students
|
|
||||||
.filter((student) => student.promotionId === promo.id)
|
|
||||||
.map((student) => (
|
|
||||||
<tr key={student.id}>
|
|
||||||
<td>{student.id}</td>
|
|
||||||
<td>{student.firstName}</td>
|
|
||||||
<td>{student.lastName}</td>
|
|
||||||
<td>{student.mail}</td>
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -8,9 +8,8 @@ const properties: AppProperties = {
|
|||||||
index: "Homepage",
|
index: "Homepage",
|
||||||
overview: "Mobility overview",
|
overview: "Mobility overview",
|
||||||
edit_mobility: "Mobility management",
|
edit_mobility: "Mobility management",
|
||||||
consult_students_test: "Test consult students",
|
|
||||||
},
|
},
|
||||||
adminOnly: ["edit_mobility", "consult_students_test"],
|
adminOnly: ["edit_mobility"],
|
||||||
};
|
};
|
||||||
|
|
||||||
export default properties;
|
export default properties;
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
import ConsultStudents_test from "$root/routes/(apps)/mobility/(_islands)/ConsultStudents_test.tsx";
|
|
||||||
import {
|
|
||||||
getPartialsConfig,
|
|
||||||
makePartials,
|
|
||||||
} from "$root/defaults/makePartials.tsx";
|
|
||||||
import { FreshContext } from "$fresh/server.ts";
|
|
||||||
import { State } from "$root/routes/_middleware.ts";
|
|
||||||
//import EditStudents from "../(_islands)/EditStudents.tsx";
|
|
||||||
|
|
||||||
// deno-lint-ignore require-await
|
|
||||||
async function Mobility(_request: Request, _context: FreshContext<State>) {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<h1>Test consult students</h1>
|
|
||||||
<ConsultStudents_test />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const config = getPartialsConfig();
|
|
||||||
export default makePartials(Mobility);
|
|
||||||
@@ -10,7 +10,7 @@ import { State } from "$root/routes/_middleware.ts";
|
|||||||
async function Mobility(_request: Request, _context: FreshContext<State>) {
|
async function Mobility(_request: Request, _context: FreshContext<State>) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1>Edit mobility</h1>
|
<h1>Mobility overview</h1>
|
||||||
<ConsultMobility />
|
<ConsultMobility />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user