From 0ddac07cbea3f71c1b18bcaa08f211f02ab67461 Mon Sep 17 00:00:00 2001 From: bender Date: Wed, 11 Mar 2026 20:53:12 +0000 Subject: [PATCH] Update src/app/dashboard/page.tsx --- src/app/dashboard/page.tsx | 229 +++++++++++++++++++++---------------- 1 file changed, 128 insertions(+), 101 deletions(-) diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index a425bf9..fa04a86 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -1,13 +1,13 @@ "use client"; -import { useEffect, useState } from 'react'; -import { useRouter } from 'next/navigation'; -import { ThemeProvider } from '@/providers/themeProvider/ThemeProvider'; +import { useEffect, useState } from "react"; +import { useRouter } from "next/navigation"; +import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider"; import NavbarStyleCentered from '@/components/navbar/NavbarStyleCentered/NavbarStyleCentered'; import FooterBase from '@/components/sections/footer/FooterBase'; -import { LogOut, User, Settings } from 'lucide-react'; +import { LogOut, User, Mail, Zap } from 'lucide-react'; -interface User { +interface UserData { id: string; name: string; email: string; @@ -15,34 +15,48 @@ interface User { export default function DashboardPage() { const router = useRouter(); - const [user, setUser] = useState(null); + const [user, setUser] = useState(null); const [loading, setLoading] = useState(true); + const [error, setError] = useState(""); useEffect(() => { - // Check if user is authenticated - const token = localStorage.getItem('token'); - const userData = localStorage.getItem('user'); + const checkAuth = async () => { + const token = localStorage.getItem("authToken"); + const userData = localStorage.getItem("user"); - if (!token) { - router.push('/auth'); - return; - } + if (!token || !userData) { + router.push("/auth/login"); + return; + } - if (userData) { - setUser(JSON.parse(userData)); - } - setLoading(false); + try { + const response = await fetch("/api/auth/verify", { + headers: { Authorization: `Bearer ${token}` }, + }); + + if (!response.ok) { + localStorage.removeItem("authToken"); + localStorage.removeItem("user"); + router.push("/auth/login"); + return; + } + + setUser(JSON.parse(userData)); + } catch (err) { + setError("Erro ao verificar sessão"); + console.error(err); + } finally { + setLoading(false); + } + }; + + checkAuth(); }, [router]); - const handleLogout = async () => { - try { - await fetch('/api/auth/logout', { method: 'POST' }); - localStorage.removeItem('token'); - localStorage.removeItem('user'); - router.push('/'); - } catch (error) { - console.error('Logout failed:', error); - } + const handleLogout = () => { + localStorage.removeItem("authToken"); + localStorage.removeItem("user"); + router.push("/"); }; if (loading) { @@ -59,10 +73,33 @@ export default function DashboardPage() { secondaryButtonStyle="glass" headingFontWeight="extrabold" > -
+
-
-

Carregando...

+
+

Carregando...

+
+
+ + ); + } + + if (error) { + return ( + +
+
+

{error}

@@ -91,92 +128,82 @@ export default function DashboardPage() { { name: "Comunidade", id: "community" }, { name: "Perfil", id: "profile" } ]} - button={{ text: "Sair", onClick: handleLogout }} + button={{ text: "Sair", href: "/" }} brandName="FitFlow Pro" />
-
+
- {/* Welcome Section */} -
-

- Bem-vindo de volta, {user?.name}! -

-

Aqui está seu dashboard pessoal de fitness

-
+

Dashboard

- {/* Quick Stats Grid */} -
- {[ - { label: 'Treinos', value: '24', icon: '💪' }, - { label: 'Calorias', value: '2.4k', icon: '🔥' }, - { label: 'Passos', value: '15.2k', icon: '👣' }, - { label: 'Sequência', value: '7 dias', icon: '🔥' }, - ].map((stat, idx) => ( -
-
{stat.icon}
-

{stat.label}

-

{stat.value}

-
- ))} -
- - {/* Main Content */} -
- {/* User Profile Card */} -
-
-
- -
-

{user?.name}

-

{user?.email}

- -
-
- - {/* Recent Activity */} -
-
-

Atividade Recente

-
- {[ - { title: 'Treino de Perna', time: 'Hoje às 10:30', status: '✅' }, - { title: 'Corida Matinal', time: 'Ontem às 06:00', status: '✅' }, - { title: 'Treino de Costas', time: '2 dias atrás', status: '✅' }, - ].map((activity, idx) => ( -
+ {user && ( +
+
+

Bem-vindo, {user.name}!

+ +
+
+
+
-

{activity.title}

-

{activity.time}

+

Nome

+

{user.name}

- {activity.status}
- ))} +
+ +
+

Email

+

{user.email}

+
+
+
+ +
+
+

Status da Sessão

+
+
+

Conectado

+
+
+
+
+
+ +
+
+ +

Treinos

+

0

+

Treinos concluídos

+
+ +
+ +

Nutrição

+

0

+

Refeições rastreadas

+
+ +
+ +

Cardio

+

0 km

+

Distância total

-
-
- {/* Action Buttons */} -
- {[ - { label: 'Iniciar Treino', color: 'bg-primary-cta' }, - { label: 'Registrar Refeição', color: 'bg-accent' }, - { label: 'Ver Progresso', color: 'bg-secondary-cta' }, - ].map((btn, idx) => ( - ))} -
+
+ )}
@@ -185,7 +212,7 @@ export default function DashboardPage() { columns={[ { title: "Produto", items: [ - { label: "Dashboard", href: "dashboard" }, + { label: "Dashboard", href: "/dashboard" }, { label: "Treino", href: "training" }, { label: "Nutrição", href: "nutrition" }, { label: "Cardio Hub", href: "cardio" }