From 36b64f7e5c234cba6d1553dfdbc1e9300c82a36c Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sun, 22 Jun 2025 00:37:45 +0000 Subject: [PATCH] Fix: Restore user identification and improve chart Restore the user identification section in the header. Improve the category chart by removing the value from the center and improving the tooltip display. --- src/components/dashboard/CategoryChart.tsx | 24 +++---- src/components/layout/Header.tsx | 74 +++++++++++++++++++++- 2 files changed, 81 insertions(+), 17 deletions(-) diff --git a/src/components/dashboard/CategoryChart.tsx b/src/components/dashboard/CategoryChart.tsx index 8de11b6..73428df 100644 --- a/src/components/dashboard/CategoryChart.tsx +++ b/src/components/dashboard/CategoryChart.tsx @@ -11,7 +11,6 @@ interface CategoryChartProps { const CategoryChart: React.FC = ({ categories, isLoading = false }) => { const validCategories = categories.filter(cat => cat.valor > 0); - const totalValue = validCategories.reduce((sum, cat) => sum + cat.valor, 0); const renderCustomizedLabel = ({ cx, cy, midAngle, innerRadius, outerRadius, percent, index }: any) => { if (percent < 0.05) return null; @@ -60,10 +59,10 @@ const CategoryChart: React.FC = ({ categories, isLoading = f const renderCustomTooltip = ({ active, payload }: any) => { if (active && payload && payload.length) { return ( -
-

{payload[0].name}

-

{formatCurrency(payload[0].value)}

-

{`${(payload[0].payload.percentage * 100).toFixed(1)}%`}

+
+

{payload[0].name}

+

{formatCurrency(payload[0].value)}

+

{`${(payload[0].payload.percentage * 100).toFixed(1)}%`}

); } @@ -88,17 +87,17 @@ const CategoryChart: React.FC = ({ categories, isLoading = f Verifique se existem transações do tipo 'despesa' cadastradas
) : ( -
+
= ({ categories, isLoading = f - {/* Valor total no centro */} -
-
{formatCurrency(totalValue)}
-
)} diff --git a/src/components/layout/Header.tsx b/src/components/layout/Header.tsx index 57aede5..c0342e1 100644 --- a/src/components/layout/Header.tsx +++ b/src/components/layout/Header.tsx @@ -1,7 +1,17 @@ -import { Menu } from 'lucide-react'; +import { Menu, User, LogOut } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { useIsMobile } from '@/hooks/use-mobile'; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu"; +import { supabase } from '@/integrations/supabase/client'; +import { useToast } from '@/hooks/use-toast'; +import { useNavigate } from 'react-router-dom'; +import { useState, useEffect } from 'react'; interface HeaderProps { onMenuToggle: () => void; @@ -9,6 +19,45 @@ interface HeaderProps { export default function Header({ onMenuToggle }: HeaderProps) { const isMobile = useIsMobile(); + const { toast } = useToast(); + const navigate = useNavigate(); + const [userEmail, setUserEmail] = useState(''); + + useEffect(() => { + // Buscar dados do usuário logado + const getUserData = async () => { + const { data: { user } } = await supabase.auth.getUser(); + if (user?.email) { + setUserEmail(user.email); + } + }; + + getUserData(); + }, []); + + const handleLogout = async () => { + try { + const { error } = await supabase.auth.signOut(); + if (error) throw error; + + // Limpar localStorage + localStorage.removeItem('userEmail'); + + toast({ + title: "Logout realizado", + description: "Você foi desconectado com sucesso" + }); + + navigate('/auth'); + } catch (error) { + console.error('Erro no logout:', error); + toast({ + title: "Erro no logout", + description: "Ocorreu um erro ao sair da conta", + variant: "destructive" + }); + } + }; return (
@@ -26,6 +75,29 @@ export default function Header({ onMenuToggle }: HeaderProps) {

Finance Home

+ + {/* User Menu */} +
+ + + + + + + + Sair + + + +
); }