Files
front-AT/app/Components/Equipos/equipos.tsx
T

129 lines
3.4 KiB
TypeScript
Raw Normal View History

2025-09-24 15:46:04 -06:00
"use client";
import axios from "axios";
import { envConfig } from "@/app/lib/config";
import { useState } from "react";
interface Data {
nombre_equipo: string;
id_equipo: number;
id_plataforma: number;
id_area_ubicacion: number;
2026-01-13 18:51:56 -06:00
ubicacion: string;
}
interface Plataforma {
id_plataforma: number;
nombre: string;
}
interface Area {
id_area_ubicacion: number;
area: string;
extra: string;
2025-09-24 15:46:04 -06:00
}
2025-09-23 14:13:23 -06:00
export default function Equipos() {
2026-01-13 18:51:56 -06:00
const [id, setId] = useState("");
const [data, setData] = useState<Data | null>(null);
const [plataforma, setPlataforma] = useState<Plataforma[]>([]);
const [area, setArea] = useState<Area[]>([]);
const [ubicacion, setUbicacion] = useState("");
const [nombre, setNombre] = useState("");
2025-09-24 15:46:04 -06:00
2026-01-13 18:51:56 -06:00
const [idPlataforma, setIdPlataforma] = useState<number | "">("");
const [idArea, setIdArea] = useState<number | "">("");
const handleSubmit = async (e: React.FormEvent) => {
2025-10-01 10:12:41 -06:00
e.preventDefault();
2025-09-24 15:46:04 -06:00
2026-01-13 18:51:56 -06:00
const [equipoRes, plataformaRes, areaRes] = await Promise.all([
axios.get(`${envConfig.apiUrl}/equipo/${id}`),
axios.get(`${envConfig.apiUrl}/alumno-inscrito/plataforma`),
axios.get(`${envConfig.apiUrl}/area-ubicacion`)
]);
const equipo = equipoRes.data as Data;
setData(equipo);
setNombre(equipo.nombre_equipo);
setUbicacion(equipo.ubicacion);
setIdPlataforma(equipo.id_plataforma);
setIdArea(equipo.id_area_ubicacion);
setPlataforma(plataformaRes.data);
setArea(areaRes.data);
2025-09-24 15:46:04 -06:00
};
2025-09-23 14:13:23 -06:00
return (
2026-01-13 18:51:56 -06:00
<form className="containerForm" onSubmit={handleSubmit}>
2025-09-23 14:13:23 -06:00
<div className="groupInput">
2025-09-24 15:46:04 -06:00
<input
2026-01-13 18:51:56 -06:00
placeholder="Número de Equipo a buscar..."
value={id}
onChange={(e) => setId(e.target.value)}
2025-09-24 15:46:04 -06:00
/>
2026-01-13 18:51:56 -06:00
<button type="submit" className="button buttonSearch">
2025-09-24 15:46:04 -06:00
Buscar
</button>
2025-09-23 14:13:23 -06:00
</div>
2025-09-24 15:46:04 -06:00
2026-01-13 18:51:56 -06:00
{data && (
2025-09-24 15:46:04 -06:00
<div>
2026-01-13 18:51:56 -06:00
<label className="label">Ubicación</label>
2025-09-24 15:46:04 -06:00
<input
type="text"
2026-01-13 18:51:56 -06:00
value={ubicacion}
onChange={(e) => setUbicacion(e.target.value)}
2025-09-24 15:46:04 -06:00
/>
<label className="label">Nombre</label>
2026-01-13 18:51:56 -06:00
<input
type="text"
value={nombre}
onChange={(e) => setNombre(e.target.value)}
/>
2025-09-24 15:46:04 -06:00
<label className="label">Plataforma</label>
2026-01-13 18:51:56 -06:00
<select
value={idPlataforma}
onChange={(e) => setIdPlataforma(Number(e.target.value))}
>
<option value="">Elige</option>
{plataforma.map((plat) => (
<option key={plat.id_plataforma} value={plat.id_plataforma}>
{plat.nombre}
</option>
))}
2025-09-24 15:46:04 -06:00
</select>
2026-01-13 18:51:56 -06:00
<label className="label">Área Ubicación</label>
<select
value={idArea}
onChange={(e) => setIdArea(Number(e.target.value))}
>
<option value="">Elige</option>
{area.map((a) => (
<option key={a.id_area_ubicacion} value={a.id_area_ubicacion}>
{a.area}
</option>
))}
2025-09-24 15:46:04 -06:00
</select>
2026-01-13 18:51:56 -06:00
<div className="containerButton" style={{ marginTop: "1rem" }}>
<button type="button" className="button buttonSearch">
Nuevo
</button>
<button type="button" className="button buttonSearch">
Editar
</button>
2025-09-24 15:46:04 -06:00
</div>
</div>
)}
2025-09-23 14:13:23 -06:00
</form>
);
}