feat: Persist new barber shops to Supabase and use a unified ID for new barberia users and their shops.
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user