fixes and final pre launch verifcation md

This commit is contained in:
IGNY8 VPS (Salman)
2026-01-17 17:47:16 +00:00
parent ccb5b1d26d
commit 3a65fb919a
9 changed files with 418 additions and 16 deletions

View File

@@ -171,6 +171,8 @@ class UnifiedSiteSettingsViewSet(viewsets.ViewSet):
site = get_object_or_404(Site, id=site_id, account=request.user.account) site = get_object_or_404(Site, id=site_id, account=request.user.account)
data = request.data data = request.data
logger.info(f"[UnifiedSettings] Received update for site {site_id}: {data}")
try: try:
# Get or create AutomationConfig # Get or create AutomationConfig
automation_config, _ = AutomationConfig.objects.get_or_create( automation_config, _ = AutomationConfig.objects.get_or_create(
@@ -194,6 +196,7 @@ class UnifiedSiteSettingsViewSet(viewsets.ViewSet):
# Update stage configuration # Update stage configuration
if 'stages' in data: if 'stages' in data:
logger.info(f"[UnifiedSettings] Updating stages: {data['stages']}")
self._update_stage_config(automation_config, data['stages']) self._update_stage_config(automation_config, data['stages'])
# Update delays # Update delays
@@ -205,6 +208,7 @@ class UnifiedSiteSettingsViewSet(viewsets.ViewSet):
automation_config.between_stage_delay = delays['between_stage'] automation_config.between_stage_delay = delays['between_stage']
automation_config.save() automation_config.save()
logger.info(f"[UnifiedSettings] AutomationConfig saved for site {site_id}")
# Update publishing settings # Update publishing settings
if 'publishing' in data: if 'publishing' in data:
@@ -239,13 +243,15 @@ class UnifiedSiteSettingsViewSet(viewsets.ViewSet):
'enabled': automation_config.stage_1_enabled, 'enabled': automation_config.stage_1_enabled,
'batch_size': automation_config.stage_1_batch_size, 'batch_size': automation_config.stage_1_batch_size,
'per_run_limit': automation_config.max_keywords_per_run, 'per_run_limit': automation_config.max_keywords_per_run,
'use_testing': False, # Default, can be stored in metadata later 'use_testing': automation_config.stage_1_use_testing,
'budget_pct': automation_config.stage_1_budget_pct,
}, },
'2': { '2': {
'enabled': automation_config.stage_2_enabled, 'enabled': automation_config.stage_2_enabled,
'batch_size': automation_config.stage_2_batch_size, 'batch_size': automation_config.stage_2_batch_size,
'per_run_limit': automation_config.max_clusters_per_run, 'per_run_limit': automation_config.max_clusters_per_run,
'use_testing': False, 'use_testing': automation_config.stage_2_use_testing,
'budget_pct': automation_config.stage_2_budget_pct,
}, },
'3': { '3': {
'enabled': automation_config.stage_3_enabled, 'enabled': automation_config.stage_3_enabled,
@@ -256,19 +262,22 @@ class UnifiedSiteSettingsViewSet(viewsets.ViewSet):
'enabled': automation_config.stage_4_enabled, 'enabled': automation_config.stage_4_enabled,
'batch_size': automation_config.stage_4_batch_size, 'batch_size': automation_config.stage_4_batch_size,
'per_run_limit': automation_config.max_tasks_per_run, 'per_run_limit': automation_config.max_tasks_per_run,
'use_testing': False, 'use_testing': automation_config.stage_4_use_testing,
'budget_pct': automation_config.stage_4_budget_pct,
}, },
'5': { '5': {
'enabled': automation_config.stage_5_enabled, 'enabled': automation_config.stage_5_enabled,
'batch_size': automation_config.stage_5_batch_size, 'batch_size': automation_config.stage_5_batch_size,
'per_run_limit': automation_config.max_content_per_run, 'per_run_limit': automation_config.max_content_per_run,
'use_testing': False, 'use_testing': automation_config.stage_5_use_testing,
'budget_pct': automation_config.stage_5_budget_pct,
}, },
'6': { '6': {
'enabled': automation_config.stage_6_enabled, 'enabled': automation_config.stage_6_enabled,
'batch_size': automation_config.stage_6_batch_size, 'batch_size': automation_config.stage_6_batch_size,
'per_run_limit': automation_config.max_images_per_run, 'per_run_limit': automation_config.max_images_per_run,
'use_testing': False, 'use_testing': automation_config.stage_6_use_testing,
'budget_pct': automation_config.stage_6_budget_pct,
}, },
'7': { '7': {
'enabled': automation_config.stage_7_enabled, 'enabled': automation_config.stage_7_enabled,
@@ -306,8 +315,11 @@ class UnifiedSiteSettingsViewSet(viewsets.ViewSet):
for stage in stages: for stage in stages:
num = stage.get('number') num = stage.get('number')
if not num: if not num:
logger.warning(f"[UnifiedSettings] Stage missing 'number': {stage}")
continue continue
logger.info(f"[UnifiedSettings] Processing stage {num}: enabled={stage.get('enabled')}, batch_size={stage.get('batch_size')}, per_run_limit={stage.get('per_run_limit')}, use_testing={stage.get('use_testing')}, budget_pct={stage.get('budget_pct')}")
if num == 1: if num == 1:
if 'enabled' in stage: if 'enabled' in stage:
automation_config.stage_1_enabled = stage['enabled'] automation_config.stage_1_enabled = stage['enabled']
@@ -315,6 +327,10 @@ class UnifiedSiteSettingsViewSet(viewsets.ViewSet):
automation_config.stage_1_batch_size = stage['batch_size'] automation_config.stage_1_batch_size = stage['batch_size']
if 'per_run_limit' in stage: if 'per_run_limit' in stage:
automation_config.max_keywords_per_run = stage['per_run_limit'] automation_config.max_keywords_per_run = stage['per_run_limit']
if 'use_testing' in stage:
automation_config.stage_1_use_testing = stage['use_testing']
if 'budget_pct' in stage:
automation_config.stage_1_budget_pct = stage['budget_pct']
elif num == 2: elif num == 2:
if 'enabled' in stage: if 'enabled' in stage:
automation_config.stage_2_enabled = stage['enabled'] automation_config.stage_2_enabled = stage['enabled']
@@ -322,6 +338,10 @@ class UnifiedSiteSettingsViewSet(viewsets.ViewSet):
automation_config.stage_2_batch_size = stage['batch_size'] automation_config.stage_2_batch_size = stage['batch_size']
if 'per_run_limit' in stage: if 'per_run_limit' in stage:
automation_config.max_clusters_per_run = stage['per_run_limit'] automation_config.max_clusters_per_run = stage['per_run_limit']
if 'use_testing' in stage:
automation_config.stage_2_use_testing = stage['use_testing']
if 'budget_pct' in stage:
automation_config.stage_2_budget_pct = stage['budget_pct']
elif num == 3: elif num == 3:
if 'enabled' in stage: if 'enabled' in stage:
automation_config.stage_3_enabled = stage['enabled'] automation_config.stage_3_enabled = stage['enabled']
@@ -336,6 +356,10 @@ class UnifiedSiteSettingsViewSet(viewsets.ViewSet):
automation_config.stage_4_batch_size = stage['batch_size'] automation_config.stage_4_batch_size = stage['batch_size']
if 'per_run_limit' in stage: if 'per_run_limit' in stage:
automation_config.max_tasks_per_run = stage['per_run_limit'] automation_config.max_tasks_per_run = stage['per_run_limit']
if 'use_testing' in stage:
automation_config.stage_4_use_testing = stage['use_testing']
if 'budget_pct' in stage:
automation_config.stage_4_budget_pct = stage['budget_pct']
elif num == 5: elif num == 5:
if 'enabled' in stage: if 'enabled' in stage:
automation_config.stage_5_enabled = stage['enabled'] automation_config.stage_5_enabled = stage['enabled']
@@ -343,6 +367,10 @@ class UnifiedSiteSettingsViewSet(viewsets.ViewSet):
automation_config.stage_5_batch_size = stage['batch_size'] automation_config.stage_5_batch_size = stage['batch_size']
if 'per_run_limit' in stage: if 'per_run_limit' in stage:
automation_config.max_content_per_run = stage['per_run_limit'] automation_config.max_content_per_run = stage['per_run_limit']
if 'use_testing' in stage:
automation_config.stage_5_use_testing = stage['use_testing']
if 'budget_pct' in stage:
automation_config.stage_5_budget_pct = stage['budget_pct']
elif num == 6: elif num == 6:
if 'enabled' in stage: if 'enabled' in stage:
automation_config.stage_6_enabled = stage['enabled'] automation_config.stage_6_enabled = stage['enabled']
@@ -350,8 +378,14 @@ class UnifiedSiteSettingsViewSet(viewsets.ViewSet):
automation_config.stage_6_batch_size = stage['batch_size'] automation_config.stage_6_batch_size = stage['batch_size']
if 'per_run_limit' in stage: if 'per_run_limit' in stage:
automation_config.max_images_per_run = stage['per_run_limit'] automation_config.max_images_per_run = stage['per_run_limit']
if 'use_testing' in stage:
automation_config.stage_6_use_testing = stage['use_testing']
if 'budget_pct' in stage:
automation_config.stage_6_budget_pct = stage['budget_pct']
elif num == 7: elif num == 7:
if 'enabled' in stage: if 'enabled' in stage:
automation_config.stage_7_enabled = stage['enabled'] automation_config.stage_7_enabled = stage['enabled']
if 'per_run_limit' in stage: if 'per_run_limit' in stage:
automation_config.max_approvals_per_run = stage['per_run_limit'] automation_config.max_approvals_per_run = stage['per_run_limit']
logger.info(f"[UnifiedSettings] After update - stage_1_batch_size={automation_config.stage_1_batch_size}, max_keywords_per_run={automation_config.max_keywords_per_run}")

View File

@@ -0,0 +1,76 @@
# Generated migration for adding use_testing and budget_pct per AI stage
from django.db import migrations, models
class Migration(migrations.Migration):
"""
Add use_testing and budget_pct fields per AI stage to AutomationConfig.
AI stages are: 1 (Keywords→Clusters), 2 (Clusters→Ideas), 4 (Tasks→Content),
5 (Content→Prompts), 6 (Prompts→Images)
"""
dependencies = [
('automation', '0008_automationconfig_max_approvals_per_run_and_more'),
]
operations = [
# Stage 1 use_testing and budget_pct
migrations.AddField(
model_name='automationconfig',
name='stage_1_use_testing',
field=models.BooleanField(default=False, help_text='Use testing model for Stage 1'),
),
migrations.AddField(
model_name='automationconfig',
name='stage_1_budget_pct',
field=models.IntegerField(default=15, help_text='Budget percentage for Stage 1'),
),
# Stage 2 use_testing and budget_pct
migrations.AddField(
model_name='automationconfig',
name='stage_2_use_testing',
field=models.BooleanField(default=False, help_text='Use testing model for Stage 2'),
),
migrations.AddField(
model_name='automationconfig',
name='stage_2_budget_pct',
field=models.IntegerField(default=10, help_text='Budget percentage for Stage 2'),
),
# Stage 4 use_testing and budget_pct
migrations.AddField(
model_name='automationconfig',
name='stage_4_use_testing',
field=models.BooleanField(default=False, help_text='Use testing model for Stage 4'),
),
migrations.AddField(
model_name='automationconfig',
name='stage_4_budget_pct',
field=models.IntegerField(default=40, help_text='Budget percentage for Stage 4'),
),
# Stage 5 use_testing and budget_pct
migrations.AddField(
model_name='automationconfig',
name='stage_5_use_testing',
field=models.BooleanField(default=False, help_text='Use testing model for Stage 5'),
),
migrations.AddField(
model_name='automationconfig',
name='stage_5_budget_pct',
field=models.IntegerField(default=5, help_text='Budget percentage for Stage 5'),
),
# Stage 6 use_testing and budget_pct
migrations.AddField(
model_name='automationconfig',
name='stage_6_use_testing',
field=models.BooleanField(default=False, help_text='Use testing model for Stage 6'),
),
migrations.AddField(
model_name='automationconfig',
name='stage_6_budget_pct',
field=models.IntegerField(default=30, help_text='Budget percentage for Stage 6'),
),
]

View File

@@ -40,6 +40,20 @@ class AutomationConfig(models.Model):
stage_5_batch_size = models.IntegerField(default=1, help_text="Content at a time") stage_5_batch_size = models.IntegerField(default=1, help_text="Content at a time")
stage_6_batch_size = models.IntegerField(default=1, help_text="Images - sequential") stage_6_batch_size = models.IntegerField(default=1, help_text="Images - sequential")
# Use testing model per stage (only for AI stages: 1, 2, 4, 5, 6)
stage_1_use_testing = models.BooleanField(default=False, help_text="Use testing model for Stage 1")
stage_2_use_testing = models.BooleanField(default=False, help_text="Use testing model for Stage 2")
stage_4_use_testing = models.BooleanField(default=False, help_text="Use testing model for Stage 4")
stage_5_use_testing = models.BooleanField(default=False, help_text="Use testing model for Stage 5")
stage_6_use_testing = models.BooleanField(default=False, help_text="Use testing model for Stage 6")
# Budget percentage per stage (only for AI stages: 1, 2, 4, 5, 6)
stage_1_budget_pct = models.IntegerField(default=15, help_text="Budget percentage for Stage 1")
stage_2_budget_pct = models.IntegerField(default=10, help_text="Budget percentage for Stage 2")
stage_4_budget_pct = models.IntegerField(default=40, help_text="Budget percentage for Stage 4")
stage_5_budget_pct = models.IntegerField(default=5, help_text="Budget percentage for Stage 5")
stage_6_budget_pct = models.IntegerField(default=30, help_text="Budget percentage for Stage 6")
# Delay configuration (in seconds) # Delay configuration (in seconds)
within_stage_delay = models.IntegerField(default=3, help_text="Delay between batches within a stage (seconds)") within_stage_delay = models.IntegerField(default=3, help_text="Delay between batches within a stage (seconds)")
between_stage_delay = models.IntegerField(default=5, help_text="Delay between stage transitions (seconds)") between_stage_delay = models.IntegerField(default=5, help_text="Delay between stage transitions (seconds)")

View File

@@ -0,0 +1,264 @@
# IGNY8 v1.8.0 Launch Verification Checklist
**Version:** 1.8.0
**Created:** January 17, 2026
**Purpose:** Final end-to-end verification before production launch
---
## Quick Status
| Section | Items | Status |
|---------|-------|--------|
| 1. User Journey | 12 | ⏳ |
| 2. Content Paths | 8 | ⏳ |
| 3. Settings Verification | 10 | ⏳ |
| 4. Analytics & Billing | 7 | ⏳ |
| 5. Documentation | 6 | ⏳ |
| 6. Design Standards | 5 | ⏳ |
| 7. Future Update Rules | 4 | ⏳ |
---
# 1. USER JOURNEY VERIFICATION
## 1.1 - Registration & Onboarding
| # | Test | Expected | Pass |
|---|------|----------|------|
| 1 | Visit `/register` | Form renders, validation works | [ ] |
| 2 | Submit registration | Account created, redirects to wizard | [ ] |
| 3 | Onboarding wizard Step 1 | Welcome screen, "Get Started" works | [ ] |
| 4 | Onboarding wizard Step 2 | Add site with industry/sectors | [ ] |
| 5 | Onboarding wizard Step 3 | WordPress integration (can skip) | [ ] |
| 6 | Onboarding wizard Step 4 | Add initial keywords (can skip) | [ ] |
| 7 | Onboarding wizard Step 5 | Completion summary, go to dashboard | [ ] |
## 1.2 - Authentication Flows
| # | Test | Expected | Pass |
|---|------|----------|------|
| 8 | Login with email/password | JWT issued, redirects to dashboard | [ ] |
| 9 | Forgot password flow | Reset email sent, link works | [ ] |
| 10 | Change password (in-app) | Password updated, session valid | [ ] |
| 11 | Logout | Session cleared, redirect to login | [ ] |
| 12 | Token refresh | Automatic refresh before expiry | [ ] |
---
# 2. CONTENT PIPELINE PATHS
## 2.1 - Manual Pipeline (Full Path)
| Stage | Action | Verify | Pass |
|-------|--------|--------|------|
| 1 | Add keywords manually | Keywords appear in list, status: pending | [ ] |
| 2 | Run clustering | Clusters created, keywords linked | [ ] |
| 3 | Generate ideas from cluster | Ideas created with title/brief | [ ] |
| 4 | Convert ideas to tasks | Tasks appear in Writer Queue | [ ] |
| 5 | Generate content | Full article with HTML + meta | [ ] |
| 6 | Generate image | Featured image attached to content | [ ] |
| 7 | Review content | Editor works, preview renders | [ ] |
| 8 | Publish to WordPress | Content appears on WP site | [ ] |
## 2.2 - Automated Pipeline
| # | Test | Expected | Pass |
|---|------|----------|------|
| 1 | Configure automation (Site Settings > Automation) | Settings save, schedule displays | [ ] |
| 2 | Run automation manually (Run Now) | All enabled stages execute in order | [ ] |
| 3 | Pause automation mid-run | Run pauses after current item | [ ] |
| 4 | Resume paused automation | Continues from saved stage | [ ] |
| 5 | Skip stage configuration | Skipped stages show 0 processed | [ ] |
| 6 | Per-run limits respected | Stages stop at configured limit | [ ] |
## 2.3 - Publishing Paths
| # | Test | Expected | Pass |
|---|------|----------|------|
| 1 | Manual publish (single) | Content published immediately | [ ] |
| 2 | Schedule for future | Content scheduled, shows in calendar | [ ] |
| 3 | Bulk schedule | Multiple items scheduled with stagger | [ ] |
| 4 | Auto-approval flow | Review → Approved automatically | [ ] |
| 5 | Auto-publish flow | Scheduled → Published at time | [ ] |
| 6 | Unschedule content | Content removed from schedule | [ ] |
---
# 3. SETTINGS VERIFICATION
## 3.1 - Site Settings Tabs
| Tab | Settings to Verify | Pass |
|-----|-------------------|------|
| **General** | Site name, URL, industry, sectors, description | [ ] |
| **Automation** | Schedule, stages, batch sizes, per-run limits | [ ] |
| **Integrations** | WordPress connection status, sync settings | [ ] |
## 3.2 - Automation Settings (Unified)
| Setting | Verify | Pass |
|---------|--------|------|
| Enable/disable toggle | Saves and reflects in next run | [ ] |
| Frequency (hourly/daily/weekly) | Next run calculates correctly | [ ] |
| Scheduled days | Only selected days show in schedule | [ ] |
| Time slots | Run starts within selected window | [ ] |
| Stage enable/disable | Disabled stages skipped | [ ] |
| Batch sizes | Correct items per batch | [ ] |
| Per-run limits | Stage stops at limit | [ ] |
| Testing model selection | Uses correct model (is_testing) | [ ] |
## 3.3 - Account Settings
| Setting | Page | Verify | Pass |
|---------|------|--------|------|
| Organization name | Account tab | Saves and displays | [ ] |
| Profile info | Profile tab | Name, timezone save | [ ] |
| Password change | Profile tab | Requires old password | [ ] |
| Team members | Team tab | Can invite, list shows | [ ] |
---
# 4. ANALYTICS & BILLING
## 4.1 - Credits System
| Test | Expected | Pass |
|------|----------|------|
| Header displays balance | Shows full number (12,000 not 12k) | [ ] |
| Clustering consumes credits | Balance decreases correctly | [ ] |
| Idea generation consumes credits | Balance decreases correctly | [ ] |
| Content generation consumes credits | Token-based calculation correct | [ ] |
| Image generation by tier | Basic=5, Quality=15, Premium=25 | [ ] |
| Zero credits blocks AI | Shows "insufficient credits" error | [ ] |
| Transaction logged | Appears in credit history | [ ] |
## 4.2 - Billing & Payments
| Test | Expected | Pass |
|------|----------|------|
| Current plan displays | Shows correct plan name + price | [ ] |
| Upgrade flow works | Stripe/PayPal checkout opens | [ ] |
| Payment history shows | Past invoices listed | [ ] |
| Subscription renewal date | Calculated correctly | [ ] |
| Credits reset date | Matches billing cycle | [ ] |
---
# 5. DOCUMENTATION CHECK
## 5.1 - Core Documentation
| Document | Status | Verified |
|----------|--------|----------|
| `docs/INDEX.md` - v1.8.0 | Updated | [ ] |
| `CHANGELOG.md` - v1.8.0 | Updated | [ ] |
| `10-MODULES/AUTOMATION.md` | Reflects unified settings | [ ] |
| `10-MODULES/PUBLISHER.md` | Reflects unified settings | [ ] |
| `20-API/ENDPOINTS.md` | unified-settings endpoint added | [ ] |
| `30-FRONTEND/PAGES.md` | Removed pages documented | [ ] |
## 5.2 - Help Content
| Help Section | Accurate | Pass |
|--------------|----------|------|
| Getting Started | Matches current wizard flow | [ ] |
| Pipeline flow | 7-stage + publish accurate | [ ] |
| Settings descriptions | Matches current UI | [ ] |
| FAQ answers | Still accurate | [ ] |
---
# 6. DESIGN STANDARDS COMPLIANCE
## 6.1 - UI Consistency Check
| Area | Standard | Verified |
|------|----------|----------|
| Module colors | Planner=green, Writer=yellow, Automation=blue, Publisher=purple | [ ] |
| Buttons | Using `<Button>` component everywhere | [ ] |
| Forms | Using `<InputField>`, `<SelectDropdown>` | [ ] |
| Cards | Using `<Card>` with consistent padding | [ ] |
| Loading states | Global loader, no per-page spinners | [ ] |
## 6.2 - Layout Standards
| Rule | Verified |
|------|----------|
| Global padding from AppLayout only (no page-level padding) | [ ] |
| Consistent header height and spacing | [ ] |
| Sidebar navigation states (active, hover) correct | [ ] |
| Responsive breakpoints working (mobile, tablet, desktop) | [ ] |
---
# 7. FUTURE UPDATE RULES
## 7.1 - Version Numbering
```
MAJOR.MINOR.PATCH
MAJOR (X.0.0): Breaking changes, major features
MINOR (x.X.0): New features, significant improvements
PATCH (x.x.X): Bug fixes, minor improvements
```
## 7.2 - Update Checklist (For Every Release)
```
[ ] Update CHANGELOG.md with version entry
[ ] Update docs/INDEX.md version number
[ ] Update relevant module docs if changed
[ ] Update API docs if endpoints changed
[ ] Run ESLint and fix violations
[ ] Run TypeScript strict check
[ ] Test affected user flows manually
```
## 7.3 - Code Standards (Enforce)
| Rule | Enforcement |
|------|-------------|
| Use design system components | ESLint rule |
| No inline styles (use Tailwind) | ESLint rule |
| TypeScript strict mode | tsconfig |
| No console.log in production | ESLint rule |
| API responses typed | TypeScript |
## 7.4 - Documentation Rules
| Document | Update When |
|----------|-------------|
| CHANGELOG.md | Every release |
| Module docs | Module changes |
| API ENDPOINTS.md | Endpoint added/changed/removed |
| PAGES.md | Route added/changed/removed |
| Help content | User-facing feature changes |
---
# SIGN-OFF
## Pre-Launch Approval
| Role | Name | Date | Signature |
|------|------|------|-----------|
| Developer | | | |
| QA | | | |
| Owner | | | |
## Notes
```
Use this space for any issues found during verification:
```
---
**Document Owner:** IGNY8 Team
**Next Review:** After each major version release

View File

@@ -5,7 +5,7 @@
## 1. Design System Consolidation ## 1. Design System Consolidation
✅ Update the rules files, to follow the rules in all changes for styles, for components, for coding rules, to use consistent design ✅ Update the rules files, a follow the rules in all changes for styles, for components, for coding rules, to use consistent design
--- ---

View File

@@ -84,6 +84,10 @@ export default function AIAutomationSettings({ siteId }: AIAutomationSettingsPro
const [landscapeImageSize, setLandscapeImageSize] = useState('2560x1440'); const [landscapeImageSize, setLandscapeImageSize] = useState('2560x1440');
const [squareImageSize, setSquareImageSize] = useState('2048x2048'); const [squareImageSize, setSquareImageSize] = useState('2048x2048');
// Toast ref to avoid dependency issues
const toastRef = React.useRef(toast);
toastRef.current = toast;
// Load unified settings // Load unified settings
const loadSettings = useCallback(async () => { const loadSettings = useCallback(async () => {
try { try {
@@ -92,11 +96,11 @@ export default function AIAutomationSettings({ siteId }: AIAutomationSettingsPro
setSettings(data); setSettings(data);
} catch (error) { } catch (error) {
console.error('Failed to load unified settings:', error); console.error('Failed to load unified settings:', error);
toast.error(`Failed to load settings: ${(error as Error).message}`); toastRef.current.error(`Failed to load settings: ${(error as Error).message}`);
} finally { } finally {
setLoading(false); setLoading(false);
} }
}, [siteId, toast]); }, [siteId]);
// Load image settings from tenant-wide AI settings API // Load image settings from tenant-wide AI settings API
const loadImageSettings = useCallback(async () => { const loadImageSettings = useCallback(async () => {
@@ -133,9 +137,13 @@ export default function AIAutomationSettings({ siteId }: AIAutomationSettingsPro
try { try {
setSaving(true); setSaving(true);
// Save unified settings // Build payload - only send fields that can be updated (not read-only ones)
const updated = await updateUnifiedSiteSettings(siteId, { const payload = {
automation: settings.automation, automation: {
enabled: settings.automation.enabled,
frequency: settings.automation.frequency,
time: settings.automation.time,
},
stages: settings.stages.map(s => ({ stages: settings.stages.map(s => ({
number: s.number, number: s.number,
enabled: s.enabled, enabled: s.enabled,
@@ -151,7 +159,13 @@ export default function AIAutomationSettings({ siteId }: AIAutomationSettingsPro
publish_days: settings.publishing.publish_days, publish_days: settings.publishing.publish_days,
time_slots: settings.publishing.time_slots, time_slots: settings.publishing.time_slots,
}, },
}); };
console.log('[AIAutomationSettings] Saving payload:', JSON.stringify(payload, null, 2));
// Save unified settings
const updated = await updateUnifiedSiteSettings(siteId, payload);
console.log('[AIAutomationSettings] Received updated settings:', JSON.stringify(updated.stages, null, 2));
setSettings(updated); setSettings(updated);
// Save image settings // Save image settings
@@ -165,10 +179,10 @@ export default function AIAutomationSettings({ siteId }: AIAutomationSettingsPro
}), }),
}); });
toast.success('Settings saved successfully'); toastRef.current.success('Settings saved successfully');
} catch (error) { } catch (error) {
console.error('Failed to save settings:', error); console.error('Failed to save settings:', error);
toast.error(`Failed to save settings: ${(error as Error).message}`); toastRef.current.error(`Failed to save settings: ${(error as Error).message}`);
} finally { } finally {
setSaving(false); setSaving(false);
} }
@@ -178,7 +192,7 @@ export default function AIAutomationSettings({ siteId }: AIAutomationSettingsPro
const handleReset = () => { const handleReset = () => {
loadSettings(); loadSettings();
loadImageSettings(); loadImageSettings();
toast.info('Settings reset to last saved values'); toastRef.current.info('Settings reset to last saved values');
}; };
// Update automation settings // Update automation settings
@@ -460,7 +474,7 @@ export default function AIAutomationSettings({ siteId }: AIAutomationSettingsPro
<BoltIcon className="w-5 h-5 text-purple-600 dark:text-purple-400" /> <BoltIcon className="w-5 h-5 text-purple-600 dark:text-purple-400" />
</div> </div>
<div> <div>
<h3 className="font-semibold text-gray-900 dark:text-white">Stage Configuration</h3> <h3 className="font-semibold text-gray-900 dark:text-white">Automation Stages Settings</h3>
<p className="text-sm text-gray-500">Configure each automation stage</p> <p className="text-sm text-gray-500">Configure each automation stage</p>
</div> </div>
</div> </div>