From d4b960b68a7e5ffdd85d13f236a0c5368c1d2813 Mon Sep 17 00:00:00 2001 From: IO420 <320154041@pcpuma.acatlan.unam.mx> Date: Tue, 27 Jan 2026 17:51:44 -0600 Subject: [PATCH] create and update machine --- app/Components/Equipos/equipos.tsx | 95 +++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 16 deletions(-) diff --git a/app/Components/Equipos/equipos.tsx b/app/Components/Equipos/equipos.tsx index f1a5d22..073f906 100644 --- a/app/Components/Equipos/equipos.tsx +++ b/app/Components/Equipos/equipos.tsx @@ -10,7 +10,7 @@ interface Data { id_plataforma: number; id_area_ubicacion: number; ubicacion: string; - ip:string + ip: string; } interface Plataforma { @@ -38,6 +38,7 @@ export default function Equipos() { const [idArea, setIdArea] = useState(""); const [isEditing, setIsEditing] = useState(false); + const [isCreating, setIsCreating] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); @@ -70,7 +71,7 @@ export default function Equipos() { ubicacion: ubicacion, id_plataforma: idPlataforma, id_area_ubicacion: idArea, - ip:data.ip + ip: data.ip, }); // Actualiza el estado local @@ -90,19 +91,73 @@ export default function Equipos() { } }; + const handleNuevo = async () => { + try { + const [plataformaRes, areaRes] = await Promise.all([ + axios.get(`${envConfig.apiUrl}/alumno-inscrito/plataforma`), + axios.get(`${envConfig.apiUrl}/area-ubicacion`), + ]); + + setPlataforma(plataformaRes.data); + setArea(areaRes.data); + + setData({ + id_equipo: 0, + nombre_equipo: "", + ubicacion: "", + id_plataforma: 0, + id_area_ubicacion: 0, + ip: "", + }); + + setNombre(""); + setUbicacion(""); + setIdPlataforma(""); + setIdArea(""); + + setIsCreating(true); + setIsEditing(true); + } catch (error) { + toast.error("Error al preparar formulario"); + } + }; + + const handleCreate = async () => { + try { + await axios.post(`${envConfig.apiUrl}/equipo`, { + nombre_equipo: nombre, + ubicacion, + id_plataforma: idPlataforma, + id_area_ubicacion: idArea, + ip: "0.0.0.0", + }); + + toast.success("Equipo creado correctamente"); + + setIsCreating(false); + setIsEditing(false); + setData(null); + } catch (error: any) { + const message = + error?.response?.data?.message || "Error al crear el equipo"; + toast.error(message); + } + }; + return (
-
- setId(e.target.value)} - /> - - -
+ {!isCreating && ( +
+ setId(e.target.value)} + /> + +
+ )} {data && (
@@ -156,7 +211,7 @@ export default function Equipos() { @@ -164,14 +219,22 @@ export default function Equipos() { ) : ( <> -