/** * Publisher Settings Page * Configure automatic approval, publishing limits, and scheduling * Uses store-based activeSite instead of URL-based siteId (BUG FIX) */ import React, { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import PageMeta from '../../components/common/PageMeta'; import PageHeader from '../../components/common/PageHeader'; import { Card } from '../../components/ui/card'; import Button from '../../components/ui/button/Button'; import IconButton from '../../components/ui/button/IconButton'; import Label from '../../components/form/Label'; import InputField from '../../components/form/input/InputField'; import Switch from '../../components/form/switch/Switch'; import { useToast } from '../../components/ui/toast/ToastContainer'; import { fetchAPI } from '../../services/api'; import { useSiteStore } from '../../store/siteStore'; import { BoltIcon, LayersIcon, CalendarIcon, InfoIcon, CloseIcon, PlusIcon, Loader2Icon } from '../../icons'; export default function PublishSettings() { const navigate = useNavigate(); const toast = useToast(); const { activeSite } = useSiteStore(); // Use store instead of URL params const [loading, setLoading] = useState(false); const [saving, setSaving] = useState(false); const [settings, setSettings] = useState(null); // Load publishing settings for active site const loadSettings = async () => { if (!activeSite) return; try { setLoading(true); const response = await fetchAPI(`/v1/integration/sites/${activeSite.id}/publishing-settings/`); setSettings(response.data || response); } catch (error: any) { console.error('Failed to load publishing settings:', error); // Set defaults if endpoint fails setSettings({ auto_approval_enabled: true, auto_publish_enabled: true, daily_publish_limit: 3, weekly_publish_limit: 15, monthly_publish_limit: 50, publish_days: ['mon', 'tue', 'wed', 'thu', 'fri'], publish_time_slots: ['09:00', '14:00', '18:00'], }); } finally { setLoading(false); } }; // Save publishing settings const saveSettings = async (newSettings: any) => { if (!activeSite) return; try { setSaving(true); const response = await fetchAPI(`/v1/integration/sites/${activeSite.id}/publishing-settings/`, { method: 'PATCH', body: JSON.stringify(newSettings), }); setSettings(response.data || response); toast.success('Publishing settings saved successfully'); } catch (error: any) { console.error('Failed to save publishing settings:', error); toast.error('Failed to save publishing settings'); } finally { setSaving(false); } }; // Load settings on mount and when active site changes useEffect(() => { if (activeSite) { loadSettings(); } }, [activeSite]); if (!activeSite) { return (

Please select a site to configure publishing settings.

); } if (loading) { return (

Loading publishing settings...

); } if (!settings) { return null; } return ( <>
{/* 3 Cards in a Row */}
{/* Card 1: Automation */}

Automation

Configure automatic content approval and publishing to WordPress

{ const newSettings = { ...settings, auto_approval_enabled: checked }; setSettings(newSettings); saveSettings({ auto_approval_enabled: checked }); }} />

Automatically approve content after review

{ const newSettings = { ...settings, auto_publish_enabled: checked }; setSettings(newSettings); saveSettings({ auto_publish_enabled: checked }); }} />

Publish approved content to WordPress

{/* Card 2: Publishing Limits */}

Limits

Set maximum articles to publish per day, week, and month

{ const value = Math.max(1, Math.min(50, parseInt(e.target.value) || 1)); setSettings({ ...settings, daily_publish_limit: value }); }} />

Articles per day

{ const value = Math.max(1, Math.min(200, parseInt(e.target.value) || 1)); setSettings({ ...settings, weekly_publish_limit: value }); }} />

Articles per week

{ const value = Math.max(1, Math.min(500, parseInt(e.target.value) || 1)); setSettings({ ...settings, monthly_publish_limit: value }); }} />

Articles per month

{/* Card 3: Schedule (Days + Time Slots) */}

Schedule

Select which days and times to automatically publish content

{[ { value: 'mon', label: 'M' }, { value: 'tue', label: 'T' }, { value: 'wed', label: 'W' }, { value: 'thu', label: 'T' }, { value: 'fri', label: 'F' }, { value: 'sat', label: 'S' }, { value: 'sun', label: 'S' }, ].map((day) => ( ))}
{(settings.publish_time_slots || []).length > 0 && ( )}

In your local timezone. Content will be published at these times on selected days.

{(settings.publish_time_slots || ['09:00', '14:00', '18:00']).length === 0 ? (
No time slots configured. Add at least one time slot.
) : ( (settings.publish_time_slots || ['09:00', '14:00', '18:00']).map((time: string, index: number) => (
#{index + 1} { const newSlots = [...(settings.publish_time_slots || [])]; newSlots[index] = e.target.value; setSettings({ ...settings, publish_time_slots: newSlots }); }} className="flex-1" /> } variant="ghost" tone="danger" size="sm" title="Remove this time slot" onClick={() => { const newSlots = (settings.publish_time_slots || []).filter((_: string, i: number) => i !== index); setSettings({ ...settings, publish_time_slots: newSlots }); }} />
)) )}
{/* Info Box */}

How Publishing Works

  • Content moves from Draft → Review → Approved → Published
  • Auto-approval moves content from Review to Approved automatically
  • Auto-publish sends Approved content to your WordPress site
  • You can always manually publish content using the "Publish to Site" button
{/* Save Button */}
); }