Adapt frontend to SAM API: RUT auth, new types, helpdesk endpoints

- Login: RUT-based (SAM auth) instead of email
- API client: updated all endpoints to /api/helpdesk/*
- Types: match SAM response format (nombre, apPaterno, perfil)
- Dashboard: uses new DashboardStats with dailyCounts
- Tickets: title instead of subject, requesterName/assigneeName
- KB: categoryName/authorName instead of nested objects
- Removed register page (SAM manages users)
This commit is contained in:
Nurfog committed 2026-09-10 11:27:35 -03:00
1 parent 0cca57f21e
commit f56f6365d2
11 files changed
+285 -718

No files matched your search

+21 -71
View File
@@ -1,42 +1,26 @@
"use client";
import { useEffect, useState } from "react";
import { useState } from "react";
import { useRouter } from "next/navigation";
import { createTicket, getAgents, type User } from "@/lib/api";
import { createTicket } from "@/lib/api";
import Link from "next/link";
export default function NewTicketPage() {
const router = useRouter();
const [agents, setAgents] = useState<User[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
const [subject, setSubject] = useState("");
const [title, setTitle] = useState("");
const [description, setDescription] = useState("");
const [priority, setPriority] = useState("medium");
const [category, setCategory] = useState("");
const [assigneeId, setAssigneeId] = useState("");
useEffect(() => {
getAgents().catch((): User[] => [
{ id: 2, name: "Carlos Méndez", email: "carlos@test.com", role: "agent" as const },
{ id: 4, name: "Ana García", email: "ana@test.com", role: "agent" as const },
]).then((data) => setAgents(data));
}, []);
const [priority, setPriority] = useState("Medium");
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setError("");
setLoading(true);
try {
const ticket = await createTicket({
subject,
description,
priority,
category,
assigneeId: assigneeId ? parseInt(assigneeId) : undefined,
});
router.push(`/tickets/${ticket.id}`);
const result = await createTicket({ title, description, priority });
router.push(`/tickets/${result.id}`);
} catch (err: any) {
setError(err.message || "Error al crear el ticket");
} finally {
@@ -73,8 +57,8 @@ export default function NewTicketPage() {
type="text"
className="form-control"
placeholder="Describe brevemente el problema o solicitud"
value={subject}
onChange={(e) => setSubject(e.target.value)}
value={title}
onChange={(e) => setTitle(e.target.value)}
required
autoFocus
/>
@@ -92,52 +76,19 @@ export default function NewTicketPage() {
></textarea>
</div>
<div className="row g-3 mb-4">
<div className="col-md-4">
<label className="form-label fw-semibold">Prioridad</label>
<select
className="form-select"
value={priority}
onChange={(e) => setPriority(e.target.value)}
>
<option value="low">Baja</option>
<option value="medium">Media</option>
<option value="high">Alta</option>
<option value="urgent">Urgente</option>
</select>
</div>
<div className="col-md-4">
<label className="form-label fw-semibold">Categoría</label>
<select
className="form-select"
value={category}
onChange={(e) => setCategory(e.target.value)}
required
>
<option value="">Seleccionar categoría</option>
<option value="Software">Software</option>
<option value="Hardware">Hardware</option>
<option value="Red">Red</option>
<option value="Acceso">Acceso</option>
<option value="Correo">Correo</option>
<option value="Otro">Otro</option>
</select>
</div>
<div className="col-md-4">
<label className="form-label fw-semibold">Asignar a</label>
<select
className="form-select"
value={assigneeId}
onChange={(e) => setAssigneeId(e.target.value)}
>
<option value="">Sin asignar</option>
{agents.map((a) => (
<option key={a.id} value={a.id}>{a.name}</option>
))}
</select>
</div>
<div className="mb-4">
<label className="form-label fw-semibold">Prioridad</label>
<select
className="form-select"
style={{ maxWidth: "200px" }}
value={priority}
onChange={(e) => setPriority(e.target.value)}
>
<option value="Low">Baja</option>
<option value="Medium">Media</option>
<option value="High">Alta</option>
<option value="Critical">Crítica</option>
</select>
</div>
<div className="d-flex gap-2">
@@ -179,7 +130,6 @@ export default function NewTicketPage() {
<li>Sé específico en el asunto del ticket</li>
<li>Incluye pasos para reproducir el problema</li>
<li>Adjunta capturas de pantalla si es posible</li>
<li>Selecciona la categoría correcta para una atención más rápida</li>
<li>Asigna la prioridad adecuada según el impacto</li>
</ul>
</div>