added credenciales and comented
This commit is contained in:
@@ -10,7 +10,7 @@ import { SO_POR_EQUIPO } from "@/data/so_por_equipo";
|
||||
import { PROCESADORES_POR_EQUIPO } from "@/data/procesadores";
|
||||
import { useRouter } from "next/navigation";
|
||||
import "../app/styles/layout/agregarEquipo.scss";
|
||||
interface FormData {
|
||||
interface FormData {
|
||||
inventario: string;
|
||||
serie: string;
|
||||
lugar: string;
|
||||
@@ -25,8 +25,8 @@ import "../app/styles/layout/agregarEquipo.scss";
|
||||
id_uso: number;
|
||||
id_marca: number;
|
||||
id_periferico: number;
|
||||
id_laboratorio: number | null; // ✅ ahora acepta null
|
||||
id_proyecto: number | null; // ✅ ahora acepta null
|
||||
id_laboratorio: number | null;
|
||||
id_proyecto: number | null;
|
||||
isImpresora: boolean;
|
||||
}
|
||||
export default function Page() {
|
||||
@@ -70,7 +70,6 @@ export default function Page() {
|
||||
}
|
||||
}, [inventario]);
|
||||
|
||||
|
||||
// Interfaces
|
||||
interface TipoUso {
|
||||
id_uso: number;
|
||||
@@ -190,7 +189,7 @@ export default function Page() {
|
||||
}
|
||||
};
|
||||
fetchProcesador();
|
||||
}, []); // Ya no depende de tiposEquipo (si la API los da todos juntos)
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchPerifericos = async () => {
|
||||
@@ -203,7 +202,12 @@ export default function Page() {
|
||||
const response = await axios.get(`${api_url}/equipos/perifericos`, {
|
||||
headers,
|
||||
});
|
||||
setPerifericos(response.data);
|
||||
|
||||
const ordenados = response.data.sort((a: any, b: any) =>
|
||||
a.periferico.localeCompare(b.periferico)
|
||||
);
|
||||
|
||||
setPerifericos(ordenados);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
toast.error("No se pudieron cargar los periféricos");
|
||||
@@ -265,18 +269,18 @@ export default function Page() {
|
||||
setFormData((prev) => {
|
||||
let newValue: string | number | null | boolean = value;
|
||||
|
||||
if (field.startsWith("id_")) {
|
||||
if (value === "" || value === 0) {
|
||||
// Para campos opcionales, usamos null en lugar de 0
|
||||
if (field === "id_laboratorio" || field === "id_proyecto") {
|
||||
newValue = null;
|
||||
} else {
|
||||
newValue = 0;
|
||||
}
|
||||
} else {
|
||||
newValue = Number(value);
|
||||
}
|
||||
}
|
||||
if (field.startsWith("id_")) {
|
||||
if (value === "" || value === 0) {
|
||||
// Para campos opcionales, usamos null en lugar de 0
|
||||
if (field === "id_laboratorio" || field === "id_proyecto") {
|
||||
newValue = null;
|
||||
} else {
|
||||
newValue = 0;
|
||||
}
|
||||
} else {
|
||||
newValue = Number(value);
|
||||
}
|
||||
}
|
||||
if (field === "id_tipo_equipo") {
|
||||
const idTipoEquipo = Number(value);
|
||||
const tipoSeleccionado = tiposEquipo.find(
|
||||
@@ -380,8 +384,15 @@ if (field.startsWith("id_")) {
|
||||
await axios.post(`${api_url}/equipos/crear`, dataToSend, { headers });
|
||||
toast.success("Equipo guardado correctamente");
|
||||
router.push("/escaner");
|
||||
} catch (err) {
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
|
||||
if (err.response && err.response.status === 400) {
|
||||
const mensaje = err.response.data?.message || "El equipo ya 1existe";
|
||||
toast.error(mensaje);
|
||||
return;
|
||||
}
|
||||
|
||||
toast.error("Error al guardar el equipo");
|
||||
}
|
||||
};
|
||||
@@ -605,7 +616,6 @@ if (field.startsWith("id_")) {
|
||||
<div className="formGroup">
|
||||
<label>Laboratorio</label>
|
||||
<select
|
||||
|
||||
value={formData.id_laboratorio ?? ""}
|
||||
onChange={(e) =>
|
||||
handleInputChange("id_laboratorio", e.target.value)
|
||||
@@ -673,3 +683,4 @@ if (field.startsWith("id_")) {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
//IO
|
||||
|
||||
@@ -378,6 +378,7 @@ export default function Editar() {
|
||||
lugar: formData.lugar,
|
||||
id_sistema_operativo: formData.id_sistema_operativo,
|
||||
id_tipo_uso: formData.id_uso,
|
||||
id_periferico:formData.id_periferico,
|
||||
serie: formData.serie,
|
||||
modelo: formData.modelo,
|
||||
id_marca: formData.id_marca,
|
||||
@@ -389,7 +390,7 @@ export default function Editar() {
|
||||
headers,
|
||||
});
|
||||
toast.success("Equipo actualizado correctamente");
|
||||
router.push("/escaner");
|
||||
// router.push("/escaner");
|
||||
} catch (error) {
|
||||
console.error("Error al guardar:", error);
|
||||
toast.error("Hubo un error al guardar el equipo.");
|
||||
|
||||
@@ -14,6 +14,7 @@ interface EquiposImpresion {
|
||||
laserAltoVolumenColor: string;
|
||||
impresora3D: string;
|
||||
plotter: string;
|
||||
// credencial: string;
|
||||
}
|
||||
|
||||
export default function Pregunta1EP() {
|
||||
@@ -27,6 +28,7 @@ export default function Pregunta1EP() {
|
||||
laserAltoVolumenColor: "0",
|
||||
impresora3D: "0",
|
||||
plotter: "0",
|
||||
// credencial: "0",
|
||||
});
|
||||
|
||||
const api_url = process.env.NEXT_PUBLIC_API_URL;
|
||||
@@ -52,6 +54,7 @@ export default function Pregunta1EP() {
|
||||
laserAltoVolumenColor: "0",
|
||||
impresora3D: "0",
|
||||
plotter: "0",
|
||||
// credencial: "0",
|
||||
};
|
||||
|
||||
data.forEach((item: any) => {
|
||||
@@ -89,6 +92,9 @@ export default function Pregunta1EP() {
|
||||
case "3D":
|
||||
valores.impresora3D = total;
|
||||
break;
|
||||
// case "IMPRESORA CREDENCIALES":
|
||||
// valores.credencial = total;
|
||||
// break;
|
||||
case "PLOTTER":
|
||||
valores.plotter = total;
|
||||
break;
|
||||
@@ -213,6 +219,15 @@ export default function Pregunta1EP() {
|
||||
disabled
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* <div className="item">
|
||||
<label>Credencial</label>
|
||||
<input
|
||||
type="text"
|
||||
value={equipos.credencial}
|
||||
disabled
|
||||
/>
|
||||
</div> */}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user