mensaje por equipo y por sala

This commit is contained in:
2026-02-06 15:01:35 -05:00
parent afc895c85d
commit 9cd68bcd3e
4 changed files with 177 additions and 27 deletions
@@ -9,7 +9,7 @@ import SelectorEquipo from "@/app/Components/InformacionEquipos/SelectorEquipo";
import { useState } from "react"; import { useState } from "react";
import "./informacionequipo.css"; import "./informacionequipo.css";
export default function InformacionEquipo({ export default function InformacionEquipo({
defaultKey, defaultKey,
}: { }: {
+2 -1
View File
@@ -1,4 +1,5 @@
import EnviarMensaje from "@/app/Components/EviarMensaje/EnviarMensaje"; import EnviarMensaje from "@/app/Components/EviarMensaje/EnviarMensaje";
import EnviarMensajeSala from "@/app/Components/EviarMensaje/EnviarMensajeSala";
import Toggle from "@/app/Components/Global/Toggle/Toggle"; import Toggle from "@/app/Components/Global/Toggle/Toggle";
export default async function Page(props: { export default async function Page(props: {
@@ -32,7 +33,7 @@ export default async function Page(props: {
key: "Sala", key: "Sala",
label: "Sala", label: "Sala",
content: ( content: (
<EnviarMensaje <EnviarMensajeSala
key={2} key={2}
titulo="Seleccione una sala" titulo="Seleccione una sala"
opciones={["PECERA", "PCNET1", "PCNET2", "PCNET3"]} opciones={["PECERA", "PCNET1", "PCNET2", "PCNET3"]}
+65 -25
View File
@@ -1,35 +1,74 @@
"use client"; "use client";
import { useState } from "react";
// Definimos la interfaz de props import { useEffect, useState } from "react";
import axios from "axios";
import { envConfig } from "@/app/lib/config";
interface EnviarMensajeProps { interface EnviarMensajeProps {
titulo: string; titulo: string;
opciones: string[]; opciones: string[]; // se deja por compatibilidad, pero ya no se usa
} }
const EnviarMensaje = ({ titulo, opciones }: EnviarMensajeProps) => { /* MISMA interfaz que tu SelectorEquipo */
interface Equipos {
id_equipo: number;
id_plataforma: number;
id_area_ubicacion: number;
nombre_equipo: string;
ubicacion: string;
activo: boolean;
ip: string;
areaUbicacion: { area: string };
plataforma: { nombre: string };
}
const EnviarMensaje = ({ titulo }: EnviarMensajeProps) => {
const [equipos, setEquipos] = useState<Equipos[]>([]);
const [seleccion, setSeleccion] = useState(""); const [seleccion, setSeleccion] = useState("");
const [mensaje, setMensaje] = useState(""); const [mensaje, setMensaje] = useState("");
const [customMsg, setCustomMsg] = useState(""); const [customMsg, setCustomMsg] = useState("");
useEffect(() => {
const fetchEquipos = async () => {
try {
const response = await axios.get(`${envConfig.apiUrl}/equipo`);
setEquipos(response.data);
} catch (error) {
console.error("Error cargando equipos:", error);
}
};
fetchEquipos();
}, []);
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => { const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault(); e.preventDefault();
// Aquí puedes manejar el envío (guardar en estado global, enviar a backend, etc.)
console.log({
equipo: seleccion,
mensaje,
customMsg,
});
}; };
return ( return (
<form className="containerForm" onSubmit={handleSubmit}> <form className="containerForm" onSubmit={handleSubmit}>
{/* Selección principal */}
<label className="label">{titulo}</label> <label className="label">{titulo}</label>
<div className="groupInput"> <div className="groupInput">
<select <select
value={seleccion} value={seleccion}
onChange={(e) => setSeleccion(e.target.value)} onChange={(e) => setSeleccion(e.target.value)}
> >
<option value="">-- {titulo} --</option> <option value="">-- Selecciona un equipo --</option>
{opciones.map((opt, idx) => (
<option key={idx} value={opt}> {equipos.map((eq) => (
{opt} <option key={eq.id_equipo} value={eq.id_equipo}>
{eq.ubicacion} {eq.nombre_equipo} {eq.plataforma.nombre}{" "}
{eq.areaUbicacion.area}
</option> </option>
))} ))}
</select> </select>
@@ -37,25 +76,22 @@ const EnviarMensaje = ({ titulo, opciones }: EnviarMensajeProps) => {
{/* Selección de mensaje */} {/* Selección de mensaje */}
<label className="label">Seleccione el mensaje</label> <label className="label">Seleccione el mensaje</label>
<div className="groupInput"> <div className="groupInput">
<select value={mensaje} onChange={(e) => setMensaje(e.target.value)}> <select value={mensaje} onChange={(e) => setMensaje(e.target.value)}>
<option value="">-- Seleccione el mensaje --</option> <option value="">-- Seleccione el mensaje --</option>
{[ <option value="cerrar">No olvides cerrar sesión</option>
{ value: "cerrar", label: "No olvides cerrar sesión" }, <option value="alerta1"> Atención</option>
{ value: "alerta1", label: "⚠️ Atención" }, <option value="alerta2">🔔 Aviso importante</option>
{ value: "alerta2", label: "🔔 Aviso importante" }, <option value="alerta3"> Confirmación</option>
{ value: "alerta3", label: "✅ Confirmación" },
].map((msg, idx) => (
<option key={idx} value={msg.value}>
{msg.label}
</option>
))}
</select> </select>
<input type="checkbox" style={{minWidth:"20px", width:"20px",maxWidth:"30px"}}/>
<input type="checkbox" style={{ minWidth: 20, width: 20 }} />
</div> </div>
{/* Mensaje personalizado */} {/* Mensaje personalizado */}
<label className="label">Mensaje personalizado</label> <label className="label">Mensaje personalizado</label>
<div className="groupInput"> <div className="groupInput">
<input <input
type="text" type="text"
@@ -63,12 +99,16 @@ const EnviarMensaje = ({ titulo, opciones }: EnviarMensajeProps) => {
onChange={(e) => setCustomMsg(e.target.value)} onChange={(e) => setCustomMsg(e.target.value)}
placeholder="Escribe tu mensaje..." placeholder="Escribe tu mensaje..."
/> />
<input type="checkbox" style={{minWidth:"20px", width:"20px",maxWidth:"30px"}}/>
<input type="checkbox" style={{ minWidth: 20, width: 20 }} />
</div> </div>
{/* Botón */}
{/* Botón de enviar */} <button
<button className="button buttonSearch" type="submit" style={{marginTop:"1rem"}}> className="button buttonSearch"
type="submit"
style={{ marginTop: "1rem" }}
>
Mandar mensaje Mandar mensaje
</button> </button>
</form> </form>
@@ -0,0 +1,109 @@
"use client";
import { useEffect, useState } from "react";
import axios from "axios";
import { envConfig } from "@/app/lib/config";
interface EnviarMensajeProps {
titulo: string;
opciones: string[];
}
/* 🔵 INTERFAZ SALAS */
interface AreaUbicacion {
id_area_ubicacion: number;
area: string;
}
const EnviarMensajeSala = ({ titulo }: EnviarMensajeProps) => {
const [salas, setSalas] = useState<AreaUbicacion[]>([]);
const [seleccion, setSeleccion] = useState("");
const [mensaje, setMensaje] = useState("");
const [customMsg, setCustomMsg] = useState("");
/* 🔵 FETCH SOLO SALAS */
useEffect(() => {
const fetchSalas = async () => {
try {
const response = await axios.get(`${envConfig.apiUrl}/area-ubicacion`);
setSalas(response.data);
} catch (error) {
console.error("Error cargando salas:", error);
}
};
fetchSalas();
}, []);
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
console.log({
sala: seleccion,
mensaje,
customMsg,
});
};
return (
<form className="containerForm" onSubmit={handleSubmit}>
{/* 🔵 SELECT SALAS */}
<label className="label">{titulo}</label>
<div className="groupInput">
<select
value={seleccion}
onChange={(e) => setSeleccion(e.target.value)}
>
<option value="">-- Selecciona una sala --</option>
{salas.map((sala) => (
<option key={sala.id_area_ubicacion} value={sala.id_area_ubicacion}>
{sala.area}
</option>
))}
</select>
</div>
{/* Selección de mensaje */}
<label className="label">Seleccione el mensaje</label>
<div className="groupInput">
<select value={mensaje} onChange={(e) => setMensaje(e.target.value)}>
<option value="">-- Seleccione el mensaje --</option>
<option value="cerrar">No olvides cerrar sesión</option>
<option value="alerta1"> Atención</option>
<option value="alerta2">🔔 Aviso importante</option>
<option value="alerta3"> Confirmación</option>
</select>
<input type="checkbox" style={{ minWidth: 20, width: 20 }} />
</div>
{/* Mensaje personalizado */}
<label className="label">Mensaje personalizado</label>
<div className="groupInput">
<input
type="text"
value={customMsg}
onChange={(e) => setCustomMsg(e.target.value)}
placeholder="Escribe tu mensaje..."
/>
<input type="checkbox" style={{ minWidth: 20, width: 20 }} />
</div>
{/* Botón */}
<button
className="button buttonSearch"
type="submit"
style={{ marginTop: "1rem" }}
>
Mandar mensaje
</button>
</form>
);
};
export default EnviarMensajeSala;