From 0518f5dd96b34e52509d86a31befa5c967bb6e9a Mon Sep 17 00:00:00 2001 From: 230417 <230417@epvc.pt> Date: Tue, 3 Mar 2026 14:53:56 +0000 Subject: [PATCH] feat: Add `shopsReady` state to `AppContext` to prevent premature "shop not found" messages on the dashboard while data loads. --- web/src/context/AppContext.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/web/src/context/AppContext.tsx b/web/src/context/AppContext.tsx index fbf1a25..ceb2e59 100644 --- a/web/src/context/AppContext.tsx +++ b/web/src/context/AppContext.tsx @@ -132,7 +132,7 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => { setState((s) => ({ ...s, user: undefined })); }; - const applyProfile = async (userId: string, email?: string | null) => { + const applyProfile = async (userId: string, email?: string | null, userMetadata?: any) => { const { data, error } = await supabase .from('profiles') .select('id,name,role,shop_name') @@ -167,10 +167,10 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => { : [...s.users, nextUser]; let shops = s.shops; - if (data.shop_name && shopId) { + if (shopId) { const exists = shops.some((shop) => shop.id === shopId); if (!exists) { - shopNameToInsert = data.shop_name.trim(); + shopNameToInsert = data.shop_name?.trim() || userMetadata?.shopName?.trim() || `Barbearia de ${displayName}`; needsInsert = true; const newShop: BarberShop = { id: shopId, @@ -212,7 +212,7 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => { setLoading(false); if (session?.user) { - applyProfile(session.user.id, session.user.email) + applyProfile(session.user.id, session.user.email, session.user.user_metadata) .then(() => { if (mounted) refreshShops(); }) .catch(console.error); } else {