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

fix: handle store_sync_config as array in autosync toggle #100

Fixed TypeError: U.map is not a function when toggling autosync on the
webshops page. The issue was that store_sync_config was not always being
treated as an array in the optimistic UI update, causing .map() to fail.

- Ensure store_sync_config is always properly initialized as an array
- Add proper fallback with all required properties (enabled, sync_frequency)
- Fix both the optimistic update and error revert handlers

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

Co-Authored-By: Claude <noreply@anthropic.com>
Claude 5 месяцев назад
Родитель
Сommit
8245e51d49
1 измененных файлов с 16 добавлено и 6 удалено
  1. 16 6
      shopcall.ai-main/src/components/IntegrationsContent.tsx

+ 16 - 6
shopcall.ai-main/src/components/IntegrationsContent.tsx

@@ -350,12 +350,17 @@ export function IntegrationsContent() {
     // Optimistic UI update - immediately update the local state
     // Optimistic UI update - immediately update the local state
     setConnectedShops(prev => prev.map(shop => {
     setConnectedShops(prev => prev.map(shop => {
       if (shop.id === storeId) {
       if (shop.id === storeId) {
+        // Ensure store_sync_config is always an array with proper structure
+        const currentConfig = Array.isArray(shop.store_sync_config) && shop.store_sync_config.length > 0
+          ? shop.store_sync_config[0]
+          : { enabled: false, sync_frequency: 'hourly' };
+
         return {
         return {
           ...shop,
           ...shop,
-          store_sync_config: shop.store_sync_config?.map(config => ({
-            ...config,
+          store_sync_config: [{
+            ...currentConfig,
             enabled: newEnabled
             enabled: newEnabled
-          })) || [{ enabled: newEnabled }]
+          }]
         };
         };
       }
       }
       return shop;
       return shop;
@@ -399,12 +404,17 @@ export function IntegrationsContent() {
       // Revert the optimistic update on error
       // Revert the optimistic update on error
       setConnectedShops(prev => prev.map(shop => {
       setConnectedShops(prev => prev.map(shop => {
         if (shop.id === storeId) {
         if (shop.id === storeId) {
+          // Ensure store_sync_config is always an array with proper structure
+          const existingConfig = Array.isArray(shop.store_sync_config) && shop.store_sync_config.length > 0
+            ? shop.store_sync_config[0]
+            : { enabled: false, sync_frequency: 'hourly' };
+
           return {
           return {
             ...shop,
             ...shop,
-            store_sync_config: shop.store_sync_config?.map(config => ({
-              ...config,
+            store_sync_config: [{
+              ...existingConfig,
               enabled: currentEnabled // Revert to original value
               enabled: currentEnabled // Revert to original value
-            })) || [{ enabled: currentEnabled }]
+            }]
           };
           };
         }
         }
         return shop;
         return shop;