add backend connection, projectsService and usersService
This commit is contained in:
parent
c66fbf19c0
commit
17eba11f0b
|
|
@ -2,6 +2,9 @@ This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-
|
|||
|
||||

|
||||
|
||||
username: admin
|
||||
password: p4ssw0rd
|
||||
|
||||
## Getting Started
|
||||
|
||||
First, run the development server:
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import { dolibarrFetch } from "./dolibarrClient";
|
||||
|
||||
export async function getProjects() {
|
||||
return dolibarrFetch("projects");
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import { dolibarrFetch } from "./dolibarrClient";
|
||||
|
||||
export async function getUser() {
|
||||
return dolibarrFetch("users/3");
|
||||
}
|
||||
Loading…
Reference in New Issue