Arreglo de error en detalle y data con espacio en cursos.
This commit is contained in:
commit
3d0f898a8a
30 files changed
+8081
No files matched your search
+41
@@ -0,0 +1,41 @@
|
|||||||
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
/.pnp
|
||||||
|
.pnp.*
|
||||||
|
.yarn/*
|
||||||
|
!.yarn/patches
|
||||||
|
!.yarn/plugins
|
||||||
|
!.yarn/releases
|
||||||
|
!.yarn/versions
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# next.js
|
||||||
|
/.next/
|
||||||
|
/out/
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
*.pem
|
||||||
|
|
||||||
|
# debug
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
.pnpm-debug.log*
|
||||||
|
|
||||||
|
# env files (can opt-in for committing if needed)
|
||||||
|
.env*
|
||||||
|
|
||||||
|
# vercel
|
||||||
|
.vercel
|
||||||
|
|
||||||
|
# typescript
|
||||||
|
*.tsbuildinfo
|
||||||
|
next-env.d.ts
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# Portal Empresas
|
||||||
|
|
||||||
|
Aplicación web corporativa construida con [Next.js](https://nextjs.org).
|
||||||
|
|
||||||
|
## Requisitos
|
||||||
|
|
||||||
|
- Node.js 18+
|
||||||
|
- pnpm (recomendado)
|
||||||
|
|
||||||
|
## Instalación
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm install
|
||||||
|
```
|
||||||
|
|
||||||
|
## Desarrollo
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm next dev
|
||||||
|
```
|
||||||
|
|
||||||
|
Abrir [http://localhost:3000](http://localhost:3000).
|
||||||
|
|
||||||
|
## Build
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm build
|
||||||
|
pnpm start
|
||||||
|
```
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { defineConfig, globalIgnores } from "eslint/config";
|
||||||
|
import nextVitals from "eslint-config-next/core-web-vitals";
|
||||||
|
import nextTs from "eslint-config-next/typescript";
|
||||||
|
|
||||||
|
const eslintConfig = defineConfig([
|
||||||
|
...nextVitals,
|
||||||
|
...nextTs,
|
||||||
|
// Override default ignores of eslint-config-next.
|
||||||
|
globalIgnores([
|
||||||
|
// Default ignores of eslint-config-next:
|
||||||
|
".next/**",
|
||||||
|
"out/**",
|
||||||
|
"build/**",
|
||||||
|
"next-env.d.ts",
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
export default eslintConfig;
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import type { NextConfig } from "next";
|
||||||
|
|
||||||
|
const nextConfig: NextConfig = {
|
||||||
|
/* config options here */
|
||||||
|
reactCompiler: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default nextConfig;
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"name": "portalempresas",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"dev": "next dev",
|
||||||
|
"build": "next build",
|
||||||
|
"start": "next start",
|
||||||
|
"lint": "eslint"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@boxicons/react": "^1.0.3",
|
||||||
|
"bootstrap": "^5.3.8",
|
||||||
|
"next": "16.2.10",
|
||||||
|
"react": "19.2.4",
|
||||||
|
"react-dom": "19.2.4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@tailwindcss/postcss": "^4",
|
||||||
|
"@types/node": "^20",
|
||||||
|
"@types/react": "^19",
|
||||||
|
"@types/react-dom": "^19",
|
||||||
|
"babel-plugin-react-compiler": "1.0.0",
|
||||||
|
"eslint": "^9",
|
||||||
|
"eslint-config-next": "16.2.10",
|
||||||
|
"tailwindcss": "^4",
|
||||||
|
"typescript": "^5"
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+4180
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,6 @@
|
|||||||
|
allowBuilds:
|
||||||
|
sharp: true
|
||||||
|
unrs-resolver: true
|
||||||
|
ignoredBuiltDependencies:
|
||||||
|
- sharp
|
||||||
|
- unrs-resolver
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
const config = {
|
||||||
|
plugins: {
|
||||||
|
"@tailwindcss/postcss": {},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>
|
||||||
|
After Width: | Height: | Size: 391 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>
|
||||||
|
After Width: | Height: | Size: 1.0 KiB |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
||||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1 @@
|
|||||||
|
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>
|
||||||
|
After Width: | Height: | Size: 128 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>
|
||||||
|
After Width: | Height: | Size: 385 B |
+1373
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,62 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
|
||||||
|
//const API = process.env.NEXT_PUBLIC_API_URL ?? "https://api.devops.norteamericano.cl";
|
||||||
|
const API_BASE_EMPRESAS = "https://api.devops.norteamericano.cl/api/Empresas";
|
||||||
|
const API_BASE_INFORMES = "https://api.devops.norteamericano.cl/api/Informes/cursos-empresa";
|
||||||
|
|
||||||
|
export async function GET(req: NextRequest) {
|
||||||
|
try {
|
||||||
|
const { searchParams } = new URL(req.url);
|
||||||
|
const tipo = searchParams.get("tipo");
|
||||||
|
const varA = searchParams.get("varA");
|
||||||
|
const varB = searchParams.get("varB");
|
||||||
|
const varC = searchParams.get("varC");
|
||||||
|
const cursoId = searchParams.get("cursoId");
|
||||||
|
const varZ = searchParams.get("varZ");
|
||||||
|
const varY = searchParams.get("varY");
|
||||||
|
const varX = searchParams.get("varX");
|
||||||
|
|
||||||
|
const usaInformes = tipo && varA !== null && varB !== null && varC !== null && cursoId !== null;
|
||||||
|
|
||||||
|
if (usaInformes) {
|
||||||
|
const url = `${API_BASE_INFORMES}?tipo=${encodeURIComponent(tipo)}&varA=${encodeURIComponent(varA)}&varB=${encodeURIComponent(varB)}&varC=${encodeURIComponent(varC)}&cursoId=${encodeURIComponent(cursoId)}`;
|
||||||
|
const res = await fetch(url);
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
|
if (!data || (Array.isArray(data) && data.length === 0)) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "No se encontraron cursos" },
|
||||||
|
{ status: 404 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json(data, { status: res.status });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tipo || varZ === null || varY === null || varX === null) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "Faltan parámetros obligatorios: tipo, varZ, varY, varX (Empresas) o tipo, varA, varB, varC, cursoId (Informes)" },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = `${API_BASE_EMPRESAS}?tipo=${encodeURIComponent(tipo)}&varZ=${encodeURIComponent(varZ)}&varY=${encodeURIComponent(varY)}&varX=${encodeURIComponent(varX)}`;
|
||||||
|
|
||||||
|
const res = await fetch(url);
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
|
if (!data || (Array.isArray(data) && data.length === 0)) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "No se encontraron cursos" },
|
||||||
|
{ status: 404 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json(data, { status: res.status });
|
||||||
|
} catch {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "Error al obtener datos" },
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
|
||||||
|
const API_BASE = "https://api.devops.norteamericano.cl/api/Informes/cursos-empresa";
|
||||||
|
|
||||||
|
export async function GET(req: NextRequest) {
|
||||||
|
try {
|
||||||
|
const { searchParams } = new URL(req.url);
|
||||||
|
const tipo = searchParams.get("tipo");
|
||||||
|
const varA = searchParams.get("varA");
|
||||||
|
const varB = searchParams.get("varB");
|
||||||
|
const varC = searchParams.get("varC");
|
||||||
|
const cursoId = searchParams.get("cursoId");
|
||||||
|
|
||||||
|
if (!tipo || !varA || !varB || !varC || !cursoId) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "Faltan parámetros: tipo, varA, varB, varC, cursoId" },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = `${API_BASE}?tipo=${encodeURIComponent(tipo)}&varA=${encodeURIComponent(varA)}&varB=${encodeURIComponent(varB)}&varC=${encodeURIComponent(varC)}&cursoId=${encodeURIComponent(cursoId)}`;
|
||||||
|
|
||||||
|
const res = await fetch(url);
|
||||||
|
const data = await res.json();
|
||||||
|
|
||||||
|
if (!data || (Array.isArray(data) && data.length === 0)) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "No se encontraron cursos" },
|
||||||
|
{ status: 404 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json(data, { status: res.status });
|
||||||
|
} catch {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "Error al obtener datos del dashboard" },
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
const API_ENDPOINT = "https://api.devops.norteamericano.cl/api/Auth/portal-login";
|
||||||
|
|
||||||
|
export async function POST(req: Request) {
|
||||||
|
try {
|
||||||
|
const { rut, password } = await req.json();
|
||||||
|
|
||||||
|
if (!rut || !password) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "Rut y contraseña son requeridos" },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const res = await fetch(API_ENDPOINT, {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ rut, password }),
|
||||||
|
});
|
||||||
|
const data = await res.json();
|
||||||
|
return NextResponse.json(data, { status: res.status });
|
||||||
|
} catch {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "Usuario o contraseña incorrectos" },
|
||||||
|
{ status: 401 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,234 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import React, { useState } from 'react';
|
||||||
|
|
||||||
|
export default function AdministradorEmpresa() {
|
||||||
|
// Estado para alternar entre paneles ('menu', 'contrasena', 'info')
|
||||||
|
const [vistaActiva, setVistaActiva] = useState<'menu' | 'contrasena' | 'info'>('menu');
|
||||||
|
|
||||||
|
// Estados para los campos de los formularios
|
||||||
|
const [nuevoPass, setNuevoPass] = useState('');
|
||||||
|
const [rznSocial, setRznSocial] = useState('');
|
||||||
|
const [giro, setGiro] = useState('');
|
||||||
|
const [direccion, setDireccion] = useState('');
|
||||||
|
const [contacto, setContacto] = useState('');
|
||||||
|
const [region, setRegion] = useState('');
|
||||||
|
const [comuna, setComuna] = useState('');
|
||||||
|
const [fono, setFono] = useState('');
|
||||||
|
const [email, setEmail] = useState('');
|
||||||
|
|
||||||
|
// Simulación de acciones de guardado
|
||||||
|
const handleGuardarPass = (e: React.MouseEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
console.log('Guardando contraseña:', nuevoPass);
|
||||||
|
// Aquí puedes disparar tu lógica de modal o peticiones API
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleGuardarDatos = (e: React.MouseEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
console.log('Guardando datos corporativos:', { rznSocial, giro, direccion, contacto, region, comuna, fono, email });
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="dashboard-content">
|
||||||
|
<header className="dashboard-toolbar">
|
||||||
|
<a href="#!" className="menu-toggle"><i className="bi bi-list"></i></a>
|
||||||
|
<a href="#!" onClick={(e) => { e.preventDefault(); setVistaActiva('menu'); }}>Administrador</a>/
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div className="container mt-4">
|
||||||
|
|
||||||
|
{/* SECCIÓN PRINCIPAL: TARJETAS (div_principal) */}
|
||||||
|
{vistaActiva === 'menu' && (
|
||||||
|
<div className="col-md-12" id="div_principal">
|
||||||
|
<div className="row">
|
||||||
|
<div className="col-md-4">
|
||||||
|
<a href="#!" className="text-decoration-none" onClick={(e) => { e.preventDefault(); setVistaActiva('contrasena'); }}>
|
||||||
|
<div className="card rounded shadow-sm">
|
||||||
|
<div className="row g-0 text-center">
|
||||||
|
<div className="col-md-2"></div>
|
||||||
|
<div className="col-md-8">
|
||||||
|
<div className="card-body">
|
||||||
|
<h5><i className="bi bi-pencil-square"></i></h5>
|
||||||
|
<h5 className="card-title">Contraseña</h5>
|
||||||
|
<p className="card-text text-muted">Cambiar la contraseña actual</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div className="col-md-4">
|
||||||
|
<a href="#!" className="text-decoration-none" onClick={(e) => { e.preventDefault(); setVistaActiva('info'); }}>
|
||||||
|
<div className="card rounded shadow-sm">
|
||||||
|
<div className="row g-0 text-center">
|
||||||
|
<div className="col-md-12">
|
||||||
|
<div className="card-body">
|
||||||
|
<h5><i className="bi bi-info-square"></i></h5>
|
||||||
|
<h5 className="card-title">Información</h5>
|
||||||
|
<p className="card-text text-muted">Actualiza información de la empresa</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="col-md-4" id="asd"></div>
|
||||||
|
|
||||||
|
{/* SECCIÓN: CAMBIO DE CONTRASEÑA (div_contrasena) */}
|
||||||
|
{vistaActiva === 'contrasena' && (
|
||||||
|
<div className="col-md-8 mx-auto" id="div_contrasena">
|
||||||
|
<div className="row g-2">
|
||||||
|
<div className="col-md-12">
|
||||||
|
<h5 className="text-decoration-underline"><small>Cambio de contraseña</small></h5>
|
||||||
|
</div>
|
||||||
|
<div className="input-group">
|
||||||
|
<div className="form-floating">
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
className="form-control"
|
||||||
|
id="TextBoxNuevoPass"
|
||||||
|
placeholder="Password"
|
||||||
|
value={nuevoPass}
|
||||||
|
onChange={(e) => setNuevoPass(e.target.value)}
|
||||||
|
/>
|
||||||
|
<label htmlFor="TextBoxNuevoPass">Contraseña nueva</label>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-success text-decoration-none input-group-text"
|
||||||
|
onClick={handleGuardarPass}
|
||||||
|
>
|
||||||
|
Guardar nueva contraseña
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="col-md-12 mt-2">
|
||||||
|
<button type="button" className="btn btn-secondary btn-sm" onClick={() => setVistaActiva('menu')}>Volver</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* SECCIÓN: ACTUALIZACIÓN DE DATOS (div_info) */}
|
||||||
|
{vistaActiva === 'info' && (
|
||||||
|
<div className="col-md-8 mx-auto" id="div_info">
|
||||||
|
<div className="row g-2">
|
||||||
|
<div className="col-md-12">
|
||||||
|
<h5 className="text-decoration-underline"><small>Actualización de datos</small></h5>
|
||||||
|
</div>
|
||||||
|
<div className="form-floating mb-2">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="form-control"
|
||||||
|
id="TextBoxRzn"
|
||||||
|
placeholder="Razón social"
|
||||||
|
value={rznSocial}
|
||||||
|
onChange={(e) => setRznSocial(e.target.value)}
|
||||||
|
/>
|
||||||
|
<label htmlFor="TextBoxRzn">Razón social</label>
|
||||||
|
</div>
|
||||||
|
<div className="form-floating mb-2">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="form-control"
|
||||||
|
id="TextBoxGiro"
|
||||||
|
placeholder="Giro"
|
||||||
|
value={giro}
|
||||||
|
onChange={(e) => setGiro(e.target.value)}
|
||||||
|
/>
|
||||||
|
<label htmlFor="TextBoxGiro">Giro</label>
|
||||||
|
</div>
|
||||||
|
<div className="form-floating mb-2">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="form-control"
|
||||||
|
id="TextBoxDirec"
|
||||||
|
placeholder="Direccion"
|
||||||
|
value={direccion}
|
||||||
|
onChange={(e) => setDireccion(e.target.value)}
|
||||||
|
/>
|
||||||
|
<label htmlFor="TextBoxDirec">Dirección</label>
|
||||||
|
</div>
|
||||||
|
<div className="form-floating mb-2">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="form-control"
|
||||||
|
id="TextBoxContact"
|
||||||
|
placeholder="Contacto"
|
||||||
|
value={contacto}
|
||||||
|
onChange={(e) => setContacto(e.target.value)}
|
||||||
|
/>
|
||||||
|
<label htmlFor="TextBoxContact">Contacto</label>
|
||||||
|
</div>
|
||||||
|
<div className="col-md mb-2">
|
||||||
|
<div className="form-floating">
|
||||||
|
<select
|
||||||
|
id="DropDownListRegion"
|
||||||
|
className="form-select"
|
||||||
|
value={region}
|
||||||
|
onChange={(e) => setRegion(e.target.value)}
|
||||||
|
>
|
||||||
|
<option value="">Seleccione Región</option>
|
||||||
|
{/* Agregar opciones */}
|
||||||
|
</select>
|
||||||
|
<label htmlFor="DropDownListRegion">Región</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="col-md mb-2">
|
||||||
|
<div className="form-floating">
|
||||||
|
<select
|
||||||
|
id="DropDownListComuna"
|
||||||
|
className="form-select"
|
||||||
|
value={comuna}
|
||||||
|
onChange={(e) => setComuna(e.target.value)}
|
||||||
|
>
|
||||||
|
<option value="">Seleccione Comuna</option>
|
||||||
|
{/* Agregar opciones */}
|
||||||
|
</select>
|
||||||
|
<label htmlFor="DropDownListComuna">Comuna</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="form-floating mb-2">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="form-control"
|
||||||
|
id="TextBoxFono"
|
||||||
|
placeholder="Fono"
|
||||||
|
value={fono}
|
||||||
|
onChange={(e) => setFono(e.target.value)}
|
||||||
|
/>
|
||||||
|
<label htmlFor="TextBoxFono">Fono</label>
|
||||||
|
</div>
|
||||||
|
<div className="form-floating mb-2">
|
||||||
|
<input
|
||||||
|
type="email"
|
||||||
|
className="form-control"
|
||||||
|
id="TextBoxMail"
|
||||||
|
placeholder="Email"
|
||||||
|
value={email}
|
||||||
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
|
/>
|
||||||
|
<label htmlFor="TextBoxMail">Email</label>
|
||||||
|
</div>
|
||||||
|
<div className="col-md-12 mt-2 d-flex gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn text-decoration-none text-white"
|
||||||
|
style={{ backgroundColor: '#198754' }} // Reemplazo de tu clase .verde-ichn
|
||||||
|
onClick={handleGuardarDatos}
|
||||||
|
>
|
||||||
|
Actualizar Datos
|
||||||
|
</button>
|
||||||
|
<button type="button" className="btn btn-secondary" onClick={() => setVistaActiva('menu')}>Volver</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
export default function Contratos() {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<h1>Contratos listados</h1>
|
||||||
|
)};
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,217 @@
|
|||||||
|
'use client'
|
||||||
|
import { Book, BookBookmark } from "@boxicons/react/index";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useState, useEffect } from "react"; // 1. Agregado useEffect
|
||||||
|
import Link from 'next/link';
|
||||||
|
|
||||||
|
interface Curso {
|
||||||
|
Codigo: string;
|
||||||
|
TipoCurso: string;
|
||||||
|
Curso: string;
|
||||||
|
Profesor: string;
|
||||||
|
Sede: string;
|
||||||
|
horario: string;
|
||||||
|
FechaInicio: string;
|
||||||
|
FechaTermino: string;
|
||||||
|
RollBook: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Cursos() {
|
||||||
|
const router = useRouter();
|
||||||
|
const [cursos, setCursos] = useState<Curso[]>([]);
|
||||||
|
const [filtro, setFiltro] = useState<'cursando' | 'cursados'>('cursando');
|
||||||
|
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
|
// 2. Ejecutar la función cuando el componente se monte
|
||||||
|
useEffect(() => {
|
||||||
|
CargaVistaCursos();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function CargaVistaCursos() {
|
||||||
|
setError("");
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const stored = sessionStorage.getItem("userData");
|
||||||
|
if (!stored) {
|
||||||
|
setError("Sesión no encontrada");
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const userData = JSON.parse(stored);
|
||||||
|
const rut = userData?.user?.idEmpresas || userData?.idempresas || "";
|
||||||
|
|
||||||
|
// 3. CAMBIO CLAVE: Mapear los parámetros tal como los espera tu archivo de la API Route
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
tipo: "HISTORYEMPCOURSE",
|
||||||
|
varZ: rut, // Antes varA
|
||||||
|
varY: " ", // Tu ejemplo usa espacio en blanco (%20) o "0"
|
||||||
|
varX: "0", // Antes varC
|
||||||
|
});
|
||||||
|
|
||||||
|
// 4. CAMBIO CLAVE: Agregar el signo "?" que faltaba antes de los parámetros
|
||||||
|
const res = await fetch(`/api/cursos?${params.toString()}`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
// Intentar leer el JSON de error que retorna tu API route
|
||||||
|
const errData = await res.json().catch(() => ({}));
|
||||||
|
const errMsg = errData.error || `Error ${res.status}: ${res.statusText}`;
|
||||||
|
setError(errMsg);
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data: Curso[] = await res.json();
|
||||||
|
|
||||||
|
if (!data || (Array.isArray(data) && data.length === 0)) {
|
||||||
|
setError("No se encontraron cursos");
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const cursosLimpios: Curso[] = data.map((curso) => ({
|
||||||
|
Codigo: String(curso.Codigo),
|
||||||
|
TipoCurso: curso.TipoCurso,
|
||||||
|
Curso: (curso.Curso || "").trim(),
|
||||||
|
Profesor: (curso.Profesor || "").trim(),
|
||||||
|
Sede: curso.Sede,
|
||||||
|
horario: curso.horario,
|
||||||
|
// FechaInicio: (curso["Fecha Inicio"] || "").trim(),
|
||||||
|
// FechaTermino: (curso["Fecha Termino"] || "").trim(),
|
||||||
|
FechaInicio: ((curso as unknown as Record<string, string>)["Fecha Inicio"] || "").trim(),
|
||||||
|
FechaTermino: ((curso as unknown as Record<string, string>)["Fecha Termino"] || "").trim(),
|
||||||
|
RollBook: Number(curso.RollBook),
|
||||||
|
}));
|
||||||
|
// Guardas los datos ya limpios en el estado
|
||||||
|
setCursos(cursosLimpios);
|
||||||
|
//setCursos(data);
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : "Error de conexión con el servidor");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const renderEstadoBadge = (rollBook: number, fechaTerminoStr: string) => {
|
||||||
|
// const fechaTermino = new Date(fechaTerminoStr);
|
||||||
|
// const ahora = new Date();
|
||||||
|
const [dia, mes, anio] = fechaTerminoStr.split('-');
|
||||||
|
const fechaTermino = new Date(Number(anio), Number(mes) - 1, Number(dia));
|
||||||
|
const ahora = new Date();
|
||||||
|
|
||||||
|
if (rollBook === 0 && fechaTermino >= ahora) {
|
||||||
|
|
||||||
|
return <span className="badge bg-primary" style={{ fontWeight: 'normal' }}>Cursando</span>;
|
||||||
|
} else if (rollBook === 0 && fechaTermino < ahora) {
|
||||||
|
|
||||||
|
return <span className="badge bg-warning text-dark" style={{ fontWeight: 'normal' }}>Pendiente por cerrar</span>;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
return <span className="badge bg-success" style={{ fontWeight: 'normal' }}>Cerrado</span>;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
const cursosFiltrados = cursos.filter((curso) => {
|
||||||
|
const [dia, mes, anio] = curso.FechaTermino.split('-');
|
||||||
|
const fechaTermino = new Date(Number(anio), Number(mes) - 1, Number(dia));
|
||||||
|
const ahora = new Date();
|
||||||
|
if (filtro === 'cursando') {
|
||||||
|
return fechaTermino >= ahora;
|
||||||
|
} else {
|
||||||
|
return fechaTermino < ahora;
|
||||||
|
}
|
||||||
|
// if (filtro === 'cursando') {
|
||||||
|
// return curso.RollBook === 0;
|
||||||
|
// } else {
|
||||||
|
// return curso.RollBook !== 0;
|
||||||
|
// }
|
||||||
|
});
|
||||||
|
|
||||||
|
// Renderizado de carga y estados de error
|
||||||
|
if (loading) return <div className="text-center py-5">Cargando cursos...</div>;
|
||||||
|
if (error) return <div className="alert alert-danger my-3">{error}</div>;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="row">
|
||||||
|
<div className="col-md-6">
|
||||||
|
<button type="button"
|
||||||
|
onClick={() => setFiltro('cursando')}
|
||||||
|
className={`btn w-100 shadow p-3 mb-5 rounded ${filtro === 'cursando' ? 'btn-primary text-white' : 'btn-light'}`}
|
||||||
|
>
|
||||||
|
<div className="mb-4">
|
||||||
|
<h3 className="float-start me-1"><Book /></h3>
|
||||||
|
<h5 className="float-start"><strong>Cursando</strong></h5>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="col-md-6">
|
||||||
|
<button type="button"
|
||||||
|
onClick={() => setFiltro('cursados')}
|
||||||
|
className={`btn w-100 shadow p-3 mb-5 rounded ${filtro === 'cursados' ? 'btn-primary text-white' : 'btn-light'}`} >
|
||||||
|
<div className="mb-4">
|
||||||
|
<h3 className="float-start me-1"><BookBookmark /></h3>
|
||||||
|
<h5 className="float-start"><strong>Cursados</strong></h5>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="row">
|
||||||
|
<div className="col-md-12">
|
||||||
|
<div className="table-responsive" id="listado_cursos">
|
||||||
|
<table className="table table-sm mb-0" style={{ fontSize: '12px' }}>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th scope="col" style={{ width: '5%' }}></th>
|
||||||
|
<th className="text-center" scope="col" style={{ width: '5%' }}>ID</th>
|
||||||
|
<th className="text-center" scope="col" style={{ width: '5%' }}>Tipo</th>
|
||||||
|
<th scope="col" style={{ width: '20%' }}>Curso</th>
|
||||||
|
<th scope="col" style={{ width: '15%' }}>Profesor</th>
|
||||||
|
<th className="text-center" scope="col" style={{ width: '7%' }}>Sede</th>
|
||||||
|
<th className="text-center" scope="col" style={{ width: '14%' }}>Horario</th>
|
||||||
|
<th className="text-center" scope="col" style={{ width: '7%' }}>Inicio</th>
|
||||||
|
<th className="text-center" scope="col" style={{ width: '7%' }}>Término</th>
|
||||||
|
<th className="text-center" scope="col" style={{ width: '10%' }}>Estado</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{cursosFiltrados.map((curso, index) => (
|
||||||
|
<tr key={curso.Codigo || index}>
|
||||||
|
<td className="text-start" style={{ width: '5%' }}>
|
||||||
|
<Link href={`/dashboard/cursos/detalle?codigo=${curso.Codigo}&tipo=${encodeURIComponent(curso.TipoCurso)}&rollbook=${curso.RollBook}`}>
|
||||||
|
<span className="badge bg-primary" style={{ fontWeight: 'normal' }}>Ver</span>
|
||||||
|
</Link>
|
||||||
|
</td>
|
||||||
|
<td className="text-center" style={{ width: '5%' }}>{curso.Codigo}</td>
|
||||||
|
<td className="text-center" style={{ width: '5%' }}>{curso.TipoCurso}</td>
|
||||||
|
<td className="text-start" style={{ width: '20%' }}>{curso.Curso}</td>
|
||||||
|
<td className="text-start" style={{ width: '15%' }}>{curso.Profesor}</td>
|
||||||
|
<td className="text-center" style={{ width: '7%' }}>{curso.Sede}</td>
|
||||||
|
<td className="text-center" style={{ width: '14%' }}>{curso.horario}</td>
|
||||||
|
<td className="text-center" style={{ width: '7%' }}>{curso.FechaInicio}</td>
|
||||||
|
<td className="text-center" style={{ width: '7%' }}>{curso.FechaTermino}</td>
|
||||||
|
<td className="text-center" style={{ width: '10%' }}>
|
||||||
|
{renderEstadoBadge(curso.RollBook, curso.FechaTermino)}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
{cursosFiltrados.length === 0 && (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={10} className="text-center py-4 text-muted">
|
||||||
|
No hay cursos disponibles en esta categoría.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { Package, Cog, Menu, X } from "@boxicons/react";
|
||||||
|
import "bootstrap/dist/css/bootstrap.min.css";
|
||||||
|
|
||||||
|
const menuItems = [
|
||||||
|
{ label: "Dashboard", icon: <Menu />, url: "/dashboard" },
|
||||||
|
// { label: "Contratos", icon: "👥", url: "/dashboard/contratos" },
|
||||||
|
{ label: "Cursos", icon: <Package />, url: "/dashboard/cursos" },
|
||||||
|
// { label: "Reportes", icon: "📈", url: "/dashboard/reportes" },
|
||||||
|
{ label: "Configuración", icon: <Cog />, url: "/dashboard/administrador" },
|
||||||
|
];
|
||||||
|
|
||||||
|
export default function DashboardLayout({
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
const [collapsed, setCollapsed] = useState(false);
|
||||||
|
const [userData, setUserData] = useState<Record<string, unknown> | null>(
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const stored = sessionStorage.getItem("userData");
|
||||||
|
if (stored) {
|
||||||
|
const parsed = JSON.parse(stored);
|
||||||
|
setUserData(parsed.user || parsed);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const u = userData as Record<string, unknown> | null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex h-screen w-screen">
|
||||||
|
<aside
|
||||||
|
className={`flex flex-col bg-gray-900 text-white transition-all duration-300 shrink-0 ${
|
||||||
|
collapsed ? "w-16" : "w-64"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<div className="flex shrink-0 h-16 items-center justify-between px-4">
|
||||||
|
{!collapsed && <span className="text-xl font-bold">SAM</span>}
|
||||||
|
<button
|
||||||
|
onClick={() => setCollapsed(!collapsed)}
|
||||||
|
className="rounded p-1 hover:bg-gray-700"
|
||||||
|
>
|
||||||
|
{collapsed ? "☰" : "✕"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<nav className="flex-1 space-y-1 px-2 py-4">
|
||||||
|
{menuItems.map((item) => (
|
||||||
|
<button
|
||||||
|
key={item.label}
|
||||||
|
onClick={() => (window.location.href = item.url)}
|
||||||
|
className="flex w-full items-center gap-3 rounded-lg px-3 py-2 text-sm hover:bg-gray-700"
|
||||||
|
>
|
||||||
|
<span className="text-lg">{item.icon}</span>
|
||||||
|
{!collapsed && <span>{item.label}</span>}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</nav>
|
||||||
|
</aside>
|
||||||
|
<main className="flex flex-1 flex-col min-w-0">
|
||||||
|
<header className="flex shrink-0 h-16 items-center justify-between border-b bg-white px-8">
|
||||||
|
<h2 className="text-xl font-semibold text-gray-800">Dashboard</h2>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-6">
|
||||||
|
{u && (
|
||||||
|
<div className="flex flex-col items-end text-right text-sm">
|
||||||
|
<span className="font-semibold text-gray-800">
|
||||||
|
{(u.Nombre as string) || "Sin Nombre"}
|
||||||
|
</span>
|
||||||
|
<span className="text-xs text-gray-500">
|
||||||
|
{(u.GiroEmpresa as string) || ""}
|
||||||
|
{(u.GiroEmpresa && u.NombreComuna ? " • " : "")}
|
||||||
|
{(u.NombreComuna as string) || ""}
|
||||||
|
</span>
|
||||||
|
{(u.Contacto as string) && (
|
||||||
|
<span className="text-xs text-gray-400">
|
||||||
|
Contacto: {u.Contacto as string}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="h-9 w-9 rounded-full bg-indigo-600 flex items-center justify-center font-bold text-white text-sm shadow-sm uppercase">
|
||||||
|
{((u?.Nombre as string)?.charAt(0)) || "EMP"}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<div className="flex-1 overflow-y-auto bg-gray-50 p-8">{children}</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,185 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
|
interface Curso {
|
||||||
|
Codigo: number;
|
||||||
|
TipoCurso: string;
|
||||||
|
Curso: string;
|
||||||
|
Contrato: number;
|
||||||
|
EmpresaRut: string;
|
||||||
|
EmpresaNombre: string;
|
||||||
|
Profesor: string;
|
||||||
|
Asignacion: string;
|
||||||
|
Sede: string;
|
||||||
|
Periodo: string;
|
||||||
|
Sala: string;
|
||||||
|
Jornada: string;
|
||||||
|
HoraInicio: string;
|
||||||
|
HoraTermino: string;
|
||||||
|
InicioSesion: string;
|
||||||
|
TerminoSesion: string;
|
||||||
|
SesionRegistrada: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function DashboardPage() {
|
||||||
|
const [fechaActual, setFechaActual] = useState("");
|
||||||
|
const [cursos, setCursos] = useState<Curso[]>([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
inicio();
|
||||||
|
cards();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function cards() {
|
||||||
|
setError("");
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
|
||||||
|
const stored = sessionStorage.getItem("userData");
|
||||||
|
if (!stored) {
|
||||||
|
setError("Sesión no encontrada");
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const userData = JSON.parse(stored);
|
||||||
|
const rut = userData?.user?.idEmpresas || userData?.idempresas || "";
|
||||||
|
|
||||||
|
const hoy = new Date();
|
||||||
|
const varA = `${hoy.getFullYear()}-${String(hoy.getMonth() + 1).padStart(2, "0")}-${String(hoy.getDate()).padStart(2, "0")}`;
|
||||||
|
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
tipo: "CURSOSALDIAEMP",
|
||||||
|
varA,
|
||||||
|
varB: rut,
|
||||||
|
varC: "0",
|
||||||
|
cursoId: "0",
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await fetch(`/api/cursos?${params}`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
const errMsg = `Error ${res.status}: ${res.statusText}`;
|
||||||
|
setError(errMsg);
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data: Curso[] = await res.json();
|
||||||
|
|
||||||
|
if (!data || (Array.isArray(data) && data.length === 0)) {
|
||||||
|
setError("No se encontraron cursos para hoy");
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setCursos(data);
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : "Error de conexión con el servidor");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function inicio() {
|
||||||
|
const hoy = new Date();
|
||||||
|
const fecha = hoy.toLocaleString();
|
||||||
|
setFechaActual(fecha);
|
||||||
|
}
|
||||||
|
|
||||||
|
const activos = cursos.filter((c) => c.SesionRegistrada !== "0").length;
|
||||||
|
const pendientes = cursos.filter((c) => c.InicioSesion === "Pendiente").length;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="mb-4 flex items-center justify-between">
|
||||||
|
<div className="text-xs text-gray-500">
|
||||||
|
Último acceso: {fechaActual || "Cargando..."}
|
||||||
|
</div>
|
||||||
|
{error && (
|
||||||
|
<div className="rounded-lg bg-red-50 border border-red-200 px-4 py-2 text-xs text-red-700">
|
||||||
|
{error}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 gap-6 md:grid-cols-3">
|
||||||
|
<div className="rounded-xl bg-white p-6 shadow">
|
||||||
|
<p className="text-sm text-gray-500">Total Cursos Hoy</p>
|
||||||
|
<p className="mt-1 text-3xl font-bold text-gray-900">
|
||||||
|
{loading ? "..." : cursos.length}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="rounded-xl bg-white p-6 shadow">
|
||||||
|
<p className="text-sm text-gray-500">Activos</p>
|
||||||
|
<p className="mt-1 text-3xl font-bold text-green-600">
|
||||||
|
{loading ? "..." : activos}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="rounded-xl bg-white p-6 shadow">
|
||||||
|
<p className="text-sm text-gray-500">Pendientes</p>
|
||||||
|
<p className="mt-1 text-3xl font-bold text-amber-600">
|
||||||
|
{loading ? "..." : pendientes}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mt-8 overflow-hidden rounded-xl bg-white shadow">
|
||||||
|
<table className="w-full text-left text-sm">
|
||||||
|
<thead className="border-b bg-gray-50 text-xs uppercase text-gray-500">
|
||||||
|
<tr>
|
||||||
|
<th className="px-6 py-3">Curso</th>
|
||||||
|
<th className="px-6 py-3">Profesor</th>
|
||||||
|
<th className="px-6 py-3">Horario</th>
|
||||||
|
<th className="px-6 py-3">Sala</th>
|
||||||
|
<th className="px-6 py-3">Estado</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="divide-y divide-gray-100 border-b">
|
||||||
|
{loading ? (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={5} className="px-6 py-8 text-center text-gray-400">
|
||||||
|
Cargando cursos...
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
) : cursos.length === 0 ? (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={5} className="px-6 py-8 text-center text-gray-400">
|
||||||
|
No hay cursos para hoy
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
) : (
|
||||||
|
cursos.map((row) => (
|
||||||
|
<tr key={row.Codigo} className="hover:bg-gray-50">
|
||||||
|
<td className="px-6 py-4 font-medium text-gray-900">
|
||||||
|
{row.Curso}
|
||||||
|
</td>
|
||||||
|
<td className="px-6 py-4 text-gray-600">{row.Profesor}</td>
|
||||||
|
<td className="px-6 py-4 text-gray-600">
|
||||||
|
{row.HoraInicio.slice(0, 5)} - {row.HoraTermino.slice(0, 5)}
|
||||||
|
</td>
|
||||||
|
<td className="px-6 py-4 text-gray-600">{row.Sala}</td>
|
||||||
|
<td className="px-6 py-4">
|
||||||
|
<span
|
||||||
|
className={`inline-block rounded-full px-3 py-1 text-xs font-medium ${
|
||||||
|
row.SesionRegistrada !== "0"
|
||||||
|
? "bg-green-100 text-green-700"
|
||||||
|
: "bg-amber-100 text-amber-700"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{row.SesionRegistrada !== "0" ? "Activo" : "Pendiente"}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
'use client'
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
export default function Reportes() {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<h1>Reportes listados</h1>
|
||||||
|
)};
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
@@ -0,0 +1,26 @@
|
|||||||
|
@import "tailwindcss";
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--background: #ffffff;
|
||||||
|
--foreground: #171717;
|
||||||
|
}
|
||||||
|
|
||||||
|
@theme inline {
|
||||||
|
--color-background: var(--background);
|
||||||
|
--color-foreground: var(--foreground);
|
||||||
|
--font-sans: var(--font-geist-sans);
|
||||||
|
--font-mono: var(--font-geist-mono);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
:root {
|
||||||
|
--background: #0a0a0a;
|
||||||
|
--foreground: #ededed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: var(--background);
|
||||||
|
color: var(--foreground);
|
||||||
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import type { Metadata } from "next";
|
||||||
|
import { Geist, Geist_Mono } from "next/font/google";
|
||||||
|
import "./globals.css";
|
||||||
|
|
||||||
|
const geistSans = Geist({
|
||||||
|
variable: "--font-geist-sans",
|
||||||
|
subsets: ["latin"],
|
||||||
|
});
|
||||||
|
|
||||||
|
const geistMono = Geist_Mono({
|
||||||
|
variable: "--font-geist-mono",
|
||||||
|
subsets: ["latin"],
|
||||||
|
});
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "SAM",
|
||||||
|
description: "Generated by create next app",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function RootLayout({
|
||||||
|
children,
|
||||||
|
}: Readonly<{
|
||||||
|
children: React.ReactNode;
|
||||||
|
}>) {
|
||||||
|
return (
|
||||||
|
<html
|
||||||
|
lang="en"
|
||||||
|
data-scroll-behavior="smooth"
|
||||||
|
className={`${geistSans.variable} ${geistMono.variable} h-full antialiased`}>
|
||||||
|
<body className="min-h-full flex flex-col">{children}</body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
|
||||||
|
export default function Home() {
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const [username, setUsername] = useState("");
|
||||||
|
const [password, setPassword] = useState("");
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
async function handleLogin() {
|
||||||
|
setError("");
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch("/api/log", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({ rut: username, password: password }),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
const errMsg = `Error ${res.status}: ${res.statusText}`;
|
||||||
|
setError(errMsg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await res.json();
|
||||||
|
console.log(data);
|
||||||
|
if (!data || (Array.isArray(data) && data.length === 0) || (typeof data === "object" && Object.keys(data).length === 0)) {
|
||||||
|
setError("No se recibieron datos del servidor");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sessionStorage.setItem("userData", JSON.stringify(data));
|
||||||
|
router.push("/dashboard");
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : "Error de conexión con el servidor");
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex h-screen w-screen">
|
||||||
|
<div
|
||||||
|
className="hidden md:flex w-1/2 bg-cover bg-center"
|
||||||
|
style={{
|
||||||
|
backgroundImage:
|
||||||
|
"url('https://images.unsplash.com/photo-1519681393784-d120267933ba?q=80&w=2940&auto=format&fit=crop')",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div className="flex w-full md:w-1/2 items-center justify-center bg-gray-50 p-8">
|
||||||
|
<div className="w-full max-w-sm rounded-2xl bg-white p-8 shadow-lg">
|
||||||
|
<h1 className="mb-8 text-center text-3xl font-bold text-gray-900">
|
||||||
|
SAM
|
||||||
|
</h1>
|
||||||
|
<div className="space-y-5">
|
||||||
|
{error && (
|
||||||
|
<div className="rounded-lg bg-red-50 border border-red-200 px-4 py-3 text-sm text-red-700">
|
||||||
|
{error}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div>
|
||||||
|
<label
|
||||||
|
htmlFor="username"
|
||||||
|
className="mb-1 block text-sm font-medium text-gray-700"
|
||||||
|
>
|
||||||
|
Usuario
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="username"
|
||||||
|
type="text"
|
||||||
|
placeholder="Ingresa tu usuario"
|
||||||
|
value={username}
|
||||||
|
onChange={(e) => setUsername(e.target.value)}
|
||||||
|
className="w-full rounded-lg border border-gray-300 px-4 py-2 text-gray-900 outline-none transition focus:border-blue-500 focus:ring-2 focus:ring-blue-200"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label
|
||||||
|
htmlFor="password"
|
||||||
|
className="mb-1 block text-sm font-medium text-gray-700"
|
||||||
|
>
|
||||||
|
Contraseña
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="password"
|
||||||
|
type="password"
|
||||||
|
placeholder="Ingresa tu contraseña"
|
||||||
|
value={password}
|
||||||
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
|
className="w-full rounded-lg border border-gray-300 px-4 py-2 text-gray-900 outline-none transition focus:border-blue-500 focus:ring-2 focus:ring-blue-200"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleLogin}
|
||||||
|
disabled={loading}
|
||||||
|
className="w-full rounded-lg bg-blue-600 px-4 py-2 font-semibold text-white transition hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed"
|
||||||
|
>
|
||||||
|
{loading ? "Ingresando..." : "Login"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
Whitespace-only changes.
@@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2017",
|
||||||
|
"lib": ["dom", "dom.iterable", "esnext"],
|
||||||
|
"allowJs": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"strict": true,
|
||||||
|
"noEmit": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"incremental": true,
|
||||||
|
"plugins": [
|
||||||
|
{
|
||||||
|
"name": "next"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["./src/*"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"next-env.d.ts",
|
||||||
|
"**/*.ts",
|
||||||
|
"**/*.tsx",
|
||||||
|
".next/types/**/*.ts",
|
||||||
|
".next/dev/types/**/*.ts",
|
||||||
|
"**/*.mts"
|
||||||
|
],
|
||||||
|
"exclude": ["node_modules"]
|
||||||
|
}
|
||||||
Reference in new issue
Block a user