#41 feat: Shop disable / enable feature

Закрыто
5 месяцев назад открыта fszontagh · комментариев: 3
Szontágh Ferenc прокомментировал 5 месяцев назад

Allow to the users to disable / enable shops. When shop is disabled, disable the background sync (but allow manual sync)

Allow to the users to disable / enable shops. When shop is disabled, disable the background sync (but allow manual sync)
claude прокомментировал 5 месяцев назад
Соавтор

@fszontagh I'm starting work on this issue now!

I'll implement a shop disable/enable feature that will:

  1. Add a UI toggle in the frontend to enable/disable shops
  2. Update the database to track the enabled/disabled state
  3. Modify the background sync logic to skip disabled shops while still allowing manual sync
  4. Ensure the store_sync_config table properly reflects the enabled state

I'll begin by examining the current implementation and then make the necessary changes.

@fszontagh I'm starting work on this issue now! I'll implement a shop disable/enable feature that will: 1. Add a UI toggle in the frontend to enable/disable shops 2. Update the database to track the enabled/disabled state 3. Modify the background sync logic to skip disabled shops while still allowing manual sync 4. Ensure the `store_sync_config` table properly reflects the enabled state I'll begin by examining the current implementation and then make the necessary changes.
claude упомянул эту задачу в коммите 5 месяцев назад
claude прокомментировал 5 месяцев назад
Соавтор

✅ Feature Implementation Complete

I've successfully implemented the shop disable/enable feature as requested. Here's what was done:

🎨 Frontend Changes

Updated IntegrationsContent.tsx:

  • Added a new "Background Sync" column to the stores table
  • Implemented a toggle Switch component for each store to enable/disable background sync
  • Added handleToggleStoreEnabled function to manage the toggle state
  • Modified fetchStores to include store_sync_config data via query parameter
  • Toggle is automatically disabled during active sync operations to prevent conflicts
  • Users receive clear toast notifications when toggling:
    • Enabled: "Background sync will resume"
    • Disabled: "Background sync is paused (manual sync still available)"

🔧 Backend Changes

Updated supabase/functions/api/index.ts:

  • Added new PUT /api/stores/:id/enable endpoint to handle enable/disable requests
  • Modified GET /api/stores to support include_sync_config=true query parameter
  • Endpoint validates store ownership before allowing updates
  • Automatically creates store_sync_config if it doesn't exist
  • Updates existing config with proper timestamp tracking

Updated supabase/functions/shoprenter-scheduled-sync/index.ts:

  • Modified to query stores with their store_sync_config data
  • Added filtering logic to skip disabled stores
  • Checks both enabled status and next_sync_at timing
  • Updates store_sync_config timestamps after successful sync
  • Auto-creates config for stores that don't have one yet

✨ Key Features

  1. Background Sync Control: Users can enable/disable background sync per shop
  2. Manual Sync Always Available: Even when disabled, manual sync button still works
  3. Smart Filtering: Scheduled sync functions automatically skip disabled shops
  4. Safe Operations: Toggle is disabled during active syncs to prevent race conditions
  5. Consistent Implementation: Both WooCommerce and ShopRenter scheduled sync now use the same pattern

📋 What Happens When Disabled

  • ✅ Scheduled background sync skips the shop
  • ✅ Manual sync button still works
  • ✅ Shop remains connected and active
  • ✅ All data and settings are preserved
  • ✅ Can be re-enabled anytime with a single click

🚀 Deployment

All changes have been:

  • ✅ Committed to the repository (commit 3fb1f67)
  • ✅ Pushed to origin/main
  • ✅ Edge Functions deployed to Supabase:
    • api (79.7kB)
    • shoprenter-scheduled-sync (85.37kB)

🔍 Testing Notes

The implementation leverages the existing store_sync_config table structure, which already had an enabled field. The WooCommerce scheduled sync was already checking this field, and I've now made the ShopRenter scheduled sync consistent with the same pattern.

@fszontagh The feature is ready for testing! Let me know if you'd like any adjustments to the UI/UX or behavior.

## ✅ Feature Implementation Complete I've successfully implemented the shop disable/enable feature as requested. Here's what was done: ### 🎨 Frontend Changes **Updated `IntegrationsContent.tsx`:** - Added a new "Background Sync" column to the stores table - Implemented a toggle Switch component for each store to enable/disable background sync - Added `handleToggleStoreEnabled` function to manage the toggle state - Modified `fetchStores` to include `store_sync_config` data via query parameter - Toggle is automatically disabled during active sync operations to prevent conflicts - Users receive clear toast notifications when toggling: - **Enabled**: "Background sync will resume" - **Disabled**: "Background sync is paused (manual sync still available)" ### 🔧 Backend Changes **Updated `supabase/functions/api/index.ts`:** - Added new `PUT /api/stores/:id/enable` endpoint to handle enable/disable requests - Modified `GET /api/stores` to support `include_sync_config=true` query parameter - Endpoint validates store ownership before allowing updates - Automatically creates `store_sync_config` if it doesn't exist - Updates existing config with proper timestamp tracking **Updated `supabase/functions/shoprenter-scheduled-sync/index.ts`:** - Modified to query stores with their `store_sync_config` data - Added filtering logic to skip disabled stores - Checks both `enabled` status and `next_sync_at` timing - Updates `store_sync_config` timestamps after successful sync - Auto-creates config for stores that don't have one yet ### ✨ Key Features 1. **Background Sync Control**: Users can enable/disable background sync per shop 2. **Manual Sync Always Available**: Even when disabled, manual sync button still works 3. **Smart Filtering**: Scheduled sync functions automatically skip disabled shops 4. **Safe Operations**: Toggle is disabled during active syncs to prevent race conditions 5. **Consistent Implementation**: Both WooCommerce and ShopRenter scheduled sync now use the same pattern ### 📋 What Happens When Disabled - ✅ Scheduled background sync **skips** the shop - ✅ Manual sync button **still works** - ✅ Shop remains connected and active - ✅ All data and settings are preserved - ✅ Can be re-enabled anytime with a single click ### 🚀 Deployment All changes have been: - ✅ Committed to the repository (commit 3fb1f67) - ✅ Pushed to origin/main - ✅ Edge Functions deployed to Supabase: - `api` (79.7kB) - `shoprenter-scheduled-sync` (85.37kB) ### 🔍 Testing Notes The implementation leverages the existing `store_sync_config` table structure, which already had an `enabled` field. The WooCommerce scheduled sync was already checking this field, and I've now made the ShopRenter scheduled sync consistent with the same pattern. @fszontagh The feature is ready for testing! Let me know if you'd like any adjustments to the UI/UX or behavior.
claude прокомментировал 5 месяцев назад
Соавтор

📊 Implementation Summary

Architecture Flow

┌─────────────────────────────────────────────────────────────┐
│                     User Interface (Frontend)                │
│  ┌──────────────────────────────────────────────────────┐  │
│  │  Webshops Page - IntegrationsContent.tsx             │  │
│  │  ┌────────────────────────────────────────────────┐  │  │
│  │  │  Store Table                                    │  │  │
│  │  │  ├─ Store Info                                  │  │  │
│  │  │  ├─ Platform Badge                              │  │  │
│  │  │  ├─ Sync Status                                 │  │  │
│  │  │  ├─ [NEW] Background Sync Toggle Switch ◄─────┐│  │  │
│  │  │  │   • Shows Enabled/Disabled status           ││  │  │
│  │  │  │   • Disabled during active sync             ││  │  │
│  │  │  └─ Actions (Manual Sync, AI Config, etc.)     ││  │  │
│  │  └────────────────────────────────────────────────┘  │  │
│  └──────────────────────────────────────────────────────┘  │
└────────────────────────────┬────────────────────────────────┘
                             │
                             │ PUT /api/stores/:id/enable
                             │ { enabled: true/false }
                             ▼
┌─────────────────────────────────────────────────────────────┐
│                   Backend API (Edge Function)                │
│  ┌──────────────────────────────────────────────────────┐  │
│  │  api/index.ts - New Endpoint                         │  │
│  │  PUT /stores/:id/enable                              │  │
│  │  • Validates store ownership                         │  │
│  │  • Updates/creates store_sync_config                 │  │
│  │  • Returns success/error response                    │  │
│  └──────────────────────────────────────────────────────┘  │
└────────────────────────────┬────────────────────────────────┘
                             │
                             │ UPDATE store_sync_config
                             │ SET enabled = true/false
                             ▼
┌─────────────────────────────────────────────────────────────┐
│                    Database (Supabase)                       │
│  ┌──────────────────────────────────────────────────────┐  │
│  │  store_sync_config table                             │  │
│  │  • id (UUID)                                         │  │
│  │  • store_id (FK to stores)                           │  │
│  │  • enabled (BOOLEAN) ◄───────────────────────────┐  │  │
│  │  • sync_frequency (TEXT)                          │  │  │
│  │  • last_sync_at (TIMESTAMP)                       │  │  │
│  │  • next_sync_at (TIMESTAMP)                       │  │  │
│  │  • sync_products/orders/customers (BOOLEAN)       │  │  │
│  └──────────────────────────────────────────────────────┘  │
└────────────────────────────┬────────────────────────────────┘
                             │
                             │ pg_cron triggers hourly
                             │ SELECT stores WHERE enabled=true
                             ▼
┌─────────────────────────────────────────────────────────────┐
│           Scheduled Sync (Edge Functions)                    │
│  ┌──────────────────────────────────────────────────────┐  │
│  │  shoprenter-scheduled-sync / woocommerce-scheduled   │  │
│  │  • Query stores with store_sync_config               │  │
│  │  • Filter: enabled = true AND next_sync_at <= now    │  │
│  │  • Skip disabled stores ◄────────────────────────────┤  │
│  │  • Process only enabled stores                       │  │
│  │  • Update sync timestamps after completion           │  │
│  └──────────────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────────┘

State Flow

User Toggles Switch
       │
       ▼
┌─────────────────┐
│  enabled: true  │ ──► Background sync runs hourly (pg_cron)
│                 │     Manual sync also available
└─────────────────┘

       │ User clicks toggle
       ▼
┌─────────────────┐
│ enabled: false  │ ──► Background sync SKIPPED
│                 │     Manual sync STILL works
└─────────────────┘

       │ User clicks toggle again
       ▼
┌─────────────────┐
│  enabled: true  │ ──► Background sync resumes
│                 │     Next sync scheduled automatically
└─────────────────┘

Files Modified

  1. shopcall.ai-main/src/components/IntegrationsContent.tsx (+85 lines)

    • Added Background Sync column and toggle UI
    • Implemented toggle handler function
    • Updated interface and API calls
  2. supabase/functions/api/index.ts (+70 lines)

    • Added PUT /stores/:id/enable endpoint
    • Enhanced GET /stores with sync config support
  3. supabase/functions/shoprenter-scheduled-sync/index.ts (+71 lines)

    • Added enabled status filtering
    • Added sync config timestamp updates
    • Made consistent with WooCommerce pattern
## 📊 Implementation Summary ### Architecture Flow ``` ┌─────────────────────────────────────────────────────────────┐ │ User Interface (Frontend) │ │ ┌──────────────────────────────────────────────────────┐ │ │ │ Webshops Page - IntegrationsContent.tsx │ │ │ │ ┌────────────────────────────────────────────────┐ │ │ │ │ │ Store Table │ │ │ │ │ │ ├─ Store Info │ │ │ │ │ │ ├─ Platform Badge │ │ │ │ │ │ ├─ Sync Status │ │ │ │ │ │ ├─ [NEW] Background Sync Toggle Switch ◄─────┐│ │ │ │ │ │ │ • Shows Enabled/Disabled status ││ │ │ │ │ │ │ • Disabled during active sync ││ │ │ │ │ │ └─ Actions (Manual Sync, AI Config, etc.) ││ │ │ │ │ └────────────────────────────────────────────────┘ │ │ │ └──────────────────────────────────────────────────────┘ │ └────────────────────────────┬────────────────────────────────┘ │ │ PUT /api/stores/:id/enable │ { enabled: true/false } ▼ ┌─────────────────────────────────────────────────────────────┐ │ Backend API (Edge Function) │ │ ┌──────────────────────────────────────────────────────┐ │ │ │ api/index.ts - New Endpoint │ │ │ │ PUT /stores/:id/enable │ │ │ │ • Validates store ownership │ │ │ │ • Updates/creates store_sync_config │ │ │ │ • Returns success/error response │ │ │ └──────────────────────────────────────────────────────┘ │ └────────────────────────────┬────────────────────────────────┘ │ │ UPDATE store_sync_config │ SET enabled = true/false ▼ ┌─────────────────────────────────────────────────────────────┐ │ Database (Supabase) │ │ ┌──────────────────────────────────────────────────────┐ │ │ │ store_sync_config table │ │ │ │ • id (UUID) │ │ │ │ • store_id (FK to stores) │ │ │ │ • enabled (BOOLEAN) ◄───────────────────────────┐ │ │ │ │ • sync_frequency (TEXT) │ │ │ │ │ • last_sync_at (TIMESTAMP) │ │ │ │ │ • next_sync_at (TIMESTAMP) │ │ │ │ │ • sync_products/orders/customers (BOOLEAN) │ │ │ │ └──────────────────────────────────────────────────────┘ │ └────────────────────────────┬────────────────────────────────┘ │ │ pg_cron triggers hourly │ SELECT stores WHERE enabled=true ▼ ┌─────────────────────────────────────────────────────────────┐ │ Scheduled Sync (Edge Functions) │ │ ┌──────────────────────────────────────────────────────┐ │ │ │ shoprenter-scheduled-sync / woocommerce-scheduled │ │ │ │ • Query stores with store_sync_config │ │ │ │ • Filter: enabled = true AND next_sync_at <= now │ │ │ │ • Skip disabled stores ◄────────────────────────────┤ │ │ │ • Process only enabled stores │ │ │ │ • Update sync timestamps after completion │ │ │ └──────────────────────────────────────────────────────┘ │ └─────────────────────────────────────────────────────────────┘ ``` ### State Flow ``` User Toggles Switch │ ▼ ┌─────────────────┐ │ enabled: true │ ──► Background sync runs hourly (pg_cron) │ │ Manual sync also available └─────────────────┘ │ User clicks toggle ▼ ┌─────────────────┐ │ enabled: false │ ──► Background sync SKIPPED │ │ Manual sync STILL works └─────────────────┘ │ User clicks toggle again ▼ ┌─────────────────┐ │ enabled: true │ ──► Background sync resumes │ │ Next sync scheduled automatically └─────────────────┘ ``` ### Files Modified 1. **`shopcall.ai-main/src/components/IntegrationsContent.tsx`** (+85 lines) - Added Background Sync column and toggle UI - Implemented toggle handler function - Updated interface and API calls 2. **`supabase/functions/api/index.ts`** (+70 lines) - Added PUT /stores/:id/enable endpoint - Enhanced GET /stores with sync config support 3. **`supabase/functions/shoprenter-scheduled-sync/index.ts`** (+71 lines) - Added enabled status filtering - Added sync config timestamp updates - Made consistent with WooCommerce pattern
Войдите, чтобы присоединиться к обсуждению.
Нет этапа
Нет ответственного
2 участников
Загрузка...
Отмена
Сохранить
Пока нет содержимого.