From 97d62a61f15c2d9e9d8017502ca94c785e345de8 Mon Sep 17 00:00:00 2001 From: 230417 <230417@epvc.pt> Date: Tue, 3 Mar 2026 14:59:19 +0000 Subject: [PATCH] =?UTF-8?q?atualiza=C3=A7=C3=B5es=20do=20dashboard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/Dashboard.tsx | 53 ++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/web/src/pages/Dashboard.tsx b/web/src/pages/Dashboard.tsx index 63a86e8..dddf65a 100644 --- a/web/src/pages/Dashboard.tsx +++ b/web/src/pages/Dashboard.tsx @@ -13,7 +13,7 @@ import { Tabs } from '../components/ui/tabs'; import { currency } from '../lib/format'; import { useApp } from '../context/AppContext'; import { supabase } from '../lib/supabase'; -import { Product } from '../types'; +import { Product, BarberShop } from '../types'; import { BarChart, Bar, CartesianGrid, ResponsiveContainer, Tooltip, XAxis } from 'recharts'; import { CalendarWeekView } from '../components/CalendarWeekView'; import { @@ -71,12 +71,35 @@ const parseDate = (value: string) => new Date(value.replace(' ', 'T')); type TabId = 'overview' | 'appointments' | 'history' | 'orders' | 'services' | 'products' | 'barbers' | 'settings'; export default function Dashboard() { + const { user, shops, shopsReady } = useApp(); + const shop = shops.find((s) => s.id === user?.shopId); + + if (!user || user.role !== 'barbearia') return
Área exclusiva para barbearias.
; + + if (!shop && !shopsReady) { + return ( +
+
+
+

A carregar painel...

+ +
+
+ ); + } + if (!shop) return
Barbearia não encontrada.
; + + return ; +} + +function DashboardInner({ shop }: { shop: BarberShop }) { // Importa estado global interligado com Supabase (ex: updateAppointmentStatus reflete-se na BD) const { user, users, - shops, - shopsReady, appointments, orders, updateAppointmentStatus, @@ -90,10 +113,6 @@ export default function Dashboard() { deleteBarber, updateShopDetails, } = useApp(); - const shop = shops.find((s) => s.id === user?.shopId); - - - const [activeTab, setActiveTab] = useState('overview'); const [period, setPeriod] = useState('semana'); @@ -115,26 +134,6 @@ export default function Dashboard() { const [barberName, setBarberName] = useState(''); const [barberSpecs, setBarberSpecs] = useState(''); - if (!user || user.role !== 'barbearia') return
Área exclusiva para barbearias.
; - - // Aguarda o refreshShops terminar antes de declarar que a loja não existe - // (Evita o erro imediatamente após o registo quando os dados ainda estão a carregar) - if (!shop && !shopsReady) { - return ( -
-
-
-

A carregar painel...

- -
-
- ); - } - if (!shop) return
Barbearia não encontrada.
; - const periodMatch = periods[period]; // Agendamentos filtrados pela barbearia logada e pela janela de tempo selecionada