From 42d32126241d92ccc27fe2e2454326c3a85941af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Un=20=C3=89picier?= Date: Sat, 28 Sep 2024 17:12:57 +0200 Subject: [PATCH] :sparkles: Statistics page fetch data --- app/statistics/hooks/useData.js | 34 +++++++++++++++++++++++++++++---- app/statistics/page.jsx | 14 ++++++++++++-- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/app/statistics/hooks/useData.js b/app/statistics/hooks/useData.js index 730f911..638e12c 100644 --- a/app/statistics/hooks/useData.js +++ b/app/statistics/hooks/useData.js @@ -1,10 +1,36 @@ -import { useState } from 'react'; +import { useEffect, useState } from 'react'; export const useData = () => { - const [settingsOpened, setSettingsOpened] = useState(false); + const [userData, setUserData] = useState(null); + + useEffect(() => { + (async () => { + const token = localStorage.getItem('token'); + + const request = await fetch( + 'https://lovemap-backend.vercel.app/user', + { + method: 'GET', + headers: { + Authorization: token, + }, + } + ); + + const response = await request.json(); + + const formattedResponse = { + ...response.user, + createdat: new Date(response.user.createdat).toLocaleDateString( + 'fr-FR' + ), + }; + + setUserData(formattedResponse); + })(); + }, []); return { - settingsOpened, - setSettingsOpened, + userData, }; }; diff --git a/app/statistics/page.jsx b/app/statistics/page.jsx index 2dd52fc..3636e8e 100644 --- a/app/statistics/page.jsx +++ b/app/statistics/page.jsx @@ -9,18 +9,28 @@ import Link from 'next/link'; import SlotCounter from 'react-slot-counter'; // --------------------------------------------------------------------------------------------------------------------- +// -------------------------------------------------- Hooks & Utils ---------------------------------------------------- +import { useData } from './hooks/useData'; +// --------------------------------------------------------------------------------------------------------------------- + // ------------------------------------------------- Assets & Styles --------------------------------------------------- import SettingsIcon from '@/assets/SettingsIcon'; import './styles.scss'; // --------------------------------------------------------------------------------------------------------------------- const Statistics = () => { + const { userData } = useData(); + + if (!userData) { + return; + } + return (
-

Un Épicier

-

Créé le: 02/09/2024

+

{userData.username}

+

Créé le: {userData.createdat}