Просмотр исходного кода

fix(custom-content): resolve race condition showing "no shop registered"

Add isShopSelecting state to ShopContext to track when shop selection
is complete. The previous isLoading state only tracked store fetching,
not the subsequent shop selection from the fetched stores, causing
intermittent "no shop registered" errors on the custom content page.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fszontagh 4 месяцев назад
Родитель
Сommit
e4dcf40ede

+ 2 - 2
shopcall.ai-main/src/components/CustomContentList.tsx

@@ -58,7 +58,7 @@ export function CustomContentList({
   const [viewContentId, setViewContentId] = useState<string | null>(null);
   const [retryingId, setRetryingId] = useState<string | null>(null);
   const { toast } = useToast();
-  const { selectedShop, isLoading: isShopLoading } = useShop();
+  const { selectedShop, isLoading: isShopLoading, isShopSelecting } = useShop();
 
   // Fetch content list
   const { data, isLoading, refetch } = useQuery({
@@ -204,7 +204,7 @@ export function CustomContentList({
   };
 
   // Show loading state while shop is being determined from URL or while fetching content
-  if (isShopLoading || isLoading) {
+  if (isShopLoading || isShopSelecting || isLoading) {
     return (
       <div className="text-center py-8 text-slate-400 flex items-center justify-center gap-2">
         <Loader2 className="h-4 w-4 animate-spin" />

+ 5 - 1
shopcall.ai-main/src/components/context/ShopContext.tsx

@@ -15,6 +15,7 @@ interface ShopContextType {
   stores: StoreData[];
   setStores: (stores: StoreData[]) => void;
   isLoading: boolean;
+  isShopSelecting: boolean;
   storesLoaded: boolean;
   refreshStores: () => Promise<void>;
 }
@@ -25,6 +26,7 @@ export const ShopProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
   const [selectedShop, setSelectedShopState] = useState<StoreData | null>(null);
   const [stores, setStoresState] = useState<StoreData[]>([]);
   const [isLoading, setIsLoading] = useState(true);
+  const [isShopSelecting, setIsShopSelecting] = useState(true);
   const [storesLoaded, setStoresLoaded] = useState(false);
 
   // Wrap setStores to track when stores are actually loaded (memoized to prevent re-renders)
@@ -88,6 +90,7 @@ export const ShopProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
         setSelectedShopState(shopFromUrl);
         localStorage.setItem('selected_shop_id', urlShopId);
         setIsLoading(false);
+        setIsShopSelecting(false);
         return;
       }
     }
@@ -112,6 +115,7 @@ export const ShopProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
       setSelectedShopState(activeStores[0]);
     }
     setIsLoading(false);
+    setIsShopSelecting(false);
   }, [stores, storesLoaded]);
 
   const setSelectedShop = (shop: StoreData | null) => {
@@ -124,7 +128,7 @@ export const ShopProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
   };
 
   return (
-    <ShopContext.Provider value={{ selectedShop, setSelectedShop, stores, setStores, isLoading, storesLoaded, refreshStores: fetchStores }}>
+    <ShopContext.Provider value={{ selectedShop, setSelectedShop, stores, setStores, isLoading, isShopSelecting, storesLoaded, refreshStores: fetchStores }}>
       {children}
     </ShopContext.Provider>
   );