From e5a167beb88ed74d1f2bee454b7737ab77b6f76f Mon Sep 17 00:00:00 2001 From: 230417 <230417@epvc.pt> Date: Thu, 26 Feb 2026 16:47:40 +0000 Subject: [PATCH] feat: Persist new barber shops to Supabase and use a unified ID for new barberia users and their shops. --- web/src/context/AppContext.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/web/src/context/AppContext.tsx b/web/src/context/AppContext.tsx index ae93813..e0e9faf 100644 --- a/web/src/context/AppContext.tsx +++ b/web/src/context/AppContext.tsx @@ -153,6 +153,19 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => { products: [], }; shops = [...shops, shop]; + + // 🔹 INSERT REAL NA BD SUPABASE + // Garante que a mobile app e outros clients consigam obter esta nova loja + void supabase.from('shops').insert([ + { + id: shopIdFromOwner, + name: shopName, + address: 'Endereço a definir', + rating: 0 + } + ]).then(({ error }) => { + if (error) console.error("Erro ao sincronizar shop nova na BD:", error); + }); } } @@ -227,7 +240,8 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => { if (exists) return false; if (payload.role === 'barbearia') { - const shopId = nanoid(); + const userId = nanoid(); // Geramos o userId agora e usamos como shopId + const shopId = userId; const shop: BarberShop = { id: shopId, name: shopName || `Barbearia ${payload.name}`, @@ -237,7 +251,7 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => { services: [], products: [], }; - const user: User = { ...payload, id: nanoid(), role: 'barbearia', shopId }; + const user: User = { ...payload, id: userId, role: 'barbearia', shopId }; setState((s) => ({ ...s, user,