diff --git a/README.md b/README.md index 1414252..a66ffc7 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next- ![Preview](image.png) +username: admin +password: p4ssw0rd + ## Getting Started First, run the development server: diff --git a/components/app-sidebar.tsx b/components/app-sidebar.tsx index 7b3b544..6330b45 100644 --- a/components/app-sidebar.tsx +++ b/components/app-sidebar.tsx @@ -1,4 +1,5 @@ "use client"; +import { getUser } from "@/lib/usersService"; import { Sidebar, @@ -50,12 +51,14 @@ const items = [ }, ]; +const realUser = await getUser() + // Datos del usuario (esto luego vendrĂ¡ de tu auth) const user = { - name: "Levi Planelles", - email: "levi@example.com", + name: `${realUser.firstname} ${realUser.lastname}`, + email: realUser.email, avatar: "/avatar.jpg", // o null si no tienes imagen - initials: "LP" + initials: `${realUser.firstname.charAt(0)}${realUser.lastname.charAt(0)}` }; export function AppSidebar() { diff --git a/lib/dolibarrClient.ts b/lib/dolibarrClient.ts new file mode 100644 index 0000000..c4803c8 --- /dev/null +++ b/lib/dolibarrClient.ts @@ -0,0 +1,16 @@ +export async function dolibarrFetch(endpoint: string, options: RequestInit = {}) { + const apiKey = process.env.NEXT_PUBLIC_DOLIBARR_API_KEY + console.log(apiKey) + const url = `${process.env.NEXT_PUBLIC_API_URL}/${endpoint}?DOLAPIKEY=${process.env.NEXT_PUBLIC_DOLIBARR_API_KEY}`; + // ${process.env.DOLIBARR_API_KEY} + console.log(url) + + const res = await fetch(url); + + if (!res.ok) { + console.error("Error en la llamada Dolibarr:", res.status, await res.text()); + throw new Error("Dolibarr API error"); + } + + return res.json(); +} \ No newline at end of file diff --git a/lib/projectsService.ts b/lib/projectsService.ts new file mode 100644 index 0000000..8091c60 --- /dev/null +++ b/lib/projectsService.ts @@ -0,0 +1,5 @@ +import { dolibarrFetch } from "./dolibarrClient"; + +export async function getProjects() { + return dolibarrFetch("projects"); +} diff --git a/lib/usersService.ts b/lib/usersService.ts new file mode 100644 index 0000000..3c04a45 --- /dev/null +++ b/lib/usersService.ts @@ -0,0 +1,5 @@ +import { dolibarrFetch } from "./dolibarrClient"; + +export async function getUser() { + return dolibarrFetch("users/3"); +} \ No newline at end of file