feat: Add shopsReady state to AppContext to prevent premature "shop not found" messages on the dashboard while data loads.

This commit is contained in:
2026-03-03 14:53:56 +00:00
parent 23171b0d02
commit 0518f5dd96

View File

@@ -132,7 +132,7 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
setState((s) => ({ ...s, user: undefined }));
};
const applyProfile = async (userId: string, email?: string | null) => {
const applyProfile = async (userId: string, email?: string | null, userMetadata?: any) => {
const { data, error } = await supabase
.from('profiles')
.select('id,name,role,shop_name')
@@ -167,10 +167,10 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
: [...s.users, nextUser];
let shops = s.shops;
if (data.shop_name && shopId) {
if (shopId) {
const exists = shops.some((shop) => shop.id === shopId);
if (!exists) {
shopNameToInsert = data.shop_name.trim();
shopNameToInsert = data.shop_name?.trim() || userMetadata?.shopName?.trim() || `Barbearia de ${displayName}`;
needsInsert = true;
const newShop: BarberShop = {
id: shopId,
@@ -212,7 +212,7 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
setLoading(false);
if (session?.user) {
applyProfile(session.user.id, session.user.email)
applyProfile(session.user.id, session.user.email, session.user.user_metadata)
.then(() => { if (mounted) refreshShops(); })
.catch(console.error);
} else {