feat: add AI-generated study plan creation dialog and API integration

- Implemented CreatePlanDialog component for generating study plans using AI.
- Integrated postAPI function for handling API requests.
- Updated planes.tsx to include AI plan generation logic.
- Modified usuarios.tsx to enable email confirmation for new users.
- Added Switch component for UI consistency.
- Created api.ts for centralized API handling.
- Developed carreras.tsx for managing career data with filtering and CRUD operations.
- Added CarreraFormDialog and CarreraDetailDialog for creating and editing career details.
- Implemented CriterioFormDialog for adding criteria to careers.
This commit is contained in:
2025-08-25 09:29:22 -06:00
parent ca3fed69b2
commit 012a5a58b0
12 changed files with 1590 additions and 246 deletions

34
src/lib/api.ts Normal file
View File

@@ -0,0 +1,34 @@
// api.ts
const API_BASE =
(import.meta.env.VITE_API_BASE?.replace(/\/$/, "")) ||
"http://localhost:3001"; // 👈 tu Bun.serve real
export async function postAPI<T=any>(path: string, body: any): Promise<T> {
const url = `${API_BASE}${path}`;
const r = await fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
// Si necesitas cookies, agrega: credentials: "include",
body: JSON.stringify(body),
});
const ct = r.headers.get("content-type") || "";
const isHTML = ct.includes("text/html");
const text = await r.text();
if (!r.ok) {
throw new Error(
isHTML
? "El servidor respondió HTML (probable 404 del dashboard/puerto 3000). Revisa API_BASE y el puerto."
: text
);
}
// Si el server devolvió JSON correctamente:
if (ct.includes("application/json")) return JSON.parse(text) as T;
// Último recurso: intenta parsear
try { return JSON.parse(text) as T } catch {
throw new Error("Respuesta no-JSON desde la API.");
}
}