feat: Persist new barber shops to Supabase and use a unified ID for new barberia users and their shops.

This commit is contained in:
2026-02-26 16:47:40 +00:00
parent a9ac6dc310
commit e5a167beb8

View File

@@ -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,