add backend connection, projectsService and usersService

This commit is contained in:
Levi Planelles 2025-12-12 13:53:37 +01:00
parent c66fbf19c0
commit 17eba11f0b
5 changed files with 35 additions and 3 deletions

View File

@ -2,6 +2,9 @@ This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-
![Preview](image.png) ![Preview](image.png)
username: admin
password: p4ssw0rd
## Getting Started ## Getting Started
First, run the development server: First, run the development server:

View File

@ -1,4 +1,5 @@
"use client"; "use client";
import { getUser } from "@/lib/usersService";
import { import {
Sidebar, Sidebar,
@ -50,12 +51,14 @@ const items = [
}, },
]; ];
const realUser = await getUser()
// Datos del usuario (esto luego vendrá de tu auth) // Datos del usuario (esto luego vendrá de tu auth)
const user = { const user = {
name: "Levi Planelles", name: `${realUser.firstname} ${realUser.lastname}`,
email: "levi@example.com", email: realUser.email,
avatar: "/avatar.jpg", // o null si no tienes imagen avatar: "/avatar.jpg", // o null si no tienes imagen
initials: "LP" initials: `${realUser.firstname.charAt(0)}${realUser.lastname.charAt(0)}`
}; };
export function AppSidebar() { export function AppSidebar() {

16
lib/dolibarrClient.ts Normal file
View File

@ -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();
}

5
lib/projectsService.ts Normal file
View File

@ -0,0 +1,5 @@
import { dolibarrFetch } from "./dolibarrClient";
export async function getProjects() {
return dolibarrFetch("projects");
}

5
lib/usersService.ts Normal file
View File

@ -0,0 +1,5 @@
import { dolibarrFetch } from "./dolibarrClient";
export async function getUser() {
return dolibarrFetch("users/3");
}