feat: Add support for updating shop payment methods and social networks in updateShopDetails.
This commit is contained in:
@@ -564,8 +564,7 @@ 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, imageUrl, ...dbPayload } = payload as any;
|
||||
const { services, products, barbers, id: _id, imageUrl, paymentMethods, socialNetworks, ...dbPayload } = payload as any;
|
||||
|
||||
// Usar upsert em vez de update para contornar a política de RLS que bloqueia UPDATEs.
|
||||
// Incluir os dados existentes da loja para não sobrescrever campos com null.
|
||||
@@ -576,6 +575,8 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
|
||||
const updateData: Record<string, any> = { ...dbPayload };
|
||||
if (resolvedImageUrl !== undefined) updateData.image_url = resolvedImageUrl;
|
||||
if (paymentMethods !== undefined) updateData.payment_methods = paymentMethods;
|
||||
if (socialNetworks !== undefined) updateData.social_networks = socialNetworks;
|
||||
if (!updateData.name) updateData.name = currentShop?.name || 'Barbearia';
|
||||
if (!updateData.address && dbPayload.address !== undefined) updateData.address = dbPayload.address;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user