From e9d8a3ea88e201b3a67e0e3d3b98ec98a4202697 Mon Sep 17 00:00:00 2001 From: 230417 <230417@epvc.pt> Date: Wed, 4 Mar 2026 11:56:32 +0000 Subject: [PATCH] appcontext --- web/src/context/AppContext.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/web/src/context/AppContext.tsx b/web/src/context/AppContext.tsx index 6f66171..d2b74a1 100644 --- a/web/src/context/AppContext.tsx +++ b/web/src/context/AppContext.tsx @@ -464,22 +464,29 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => { const updateShopDetails: AppContextValue['updateShopDetails'] = async (shopId, payload) => { // Remover arrays relacionais que não são colunas na tabela shops - const { services, products, barbers, id: _id, ...dbPayload } = payload as any; + const { services, products, barbers, id: _id, imageUrl, ...dbPayload } = payload as any; // Usar upsert em vez de update para contornar a política de RLS que bloqueia UPDATEs. - // O upsert usa INSERT ... ON CONFLICT que é permitido pela política de INSERT. // Incluir os dados existentes da loja para não sobrescrever campos com null. const currentShop = state.shops.find(s => s.id === shopId); + + // O backend usa image_url, não imageUrl. Se existir novo no payload usa, senão fallback para o atual. + const resolvedImageUrl = imageUrl ?? currentShop?.imageUrl; + const { error } = await supabase.from('shops').upsert({ id: shopId, name: currentShop?.name || 'Barbearia', address: currentShop?.address || '', rating: currentShop?.rating ?? 0, - imageUrl: currentShop?.imageUrl, + image_url: resolvedImageUrl, ...dbPayload, - }); + }, { onConflict: 'id' }); + if (error) { console.error('updateShopDetails error:', error); + } else if (payload.name) { + // Sincroniza o nome com a tabela profiles + await supabase.from('profiles').update({ shop_name: payload.name }).eq('id', shopId); } // Sempre atualiza o estado local também