/** * Publishing Rules Component * Phase 6: Site Integration & Multi-Destination Publishing */ import React, { useState } from 'react'; import { PlusIcon, TrashIcon, ArrowUpIcon, ArrowDownIcon } from '../../icons'; import Button from '../ui/button/Button'; import Checkbox from '../form/input/Checkbox'; import Label from '../form/Label'; import SelectDropdown from '../form/SelectDropdown'; export interface PublishingRule { id: string; content_type: string; trigger: 'auto' | 'manual' | 'scheduled'; destinations: string[]; priority: number; enabled: boolean; schedule?: string; // Cron expression for scheduled } interface PublishingRulesProps { rules: PublishingRule[]; onChange: (rules: PublishingRule[]) => void; } const CONTENT_TYPES = [ { value: 'blog_post', label: 'Blog Post' }, { value: 'page', label: 'Page' }, { value: 'product', label: 'Product' }, { value: 'all', label: 'All Content' }, ]; const TRIGGERS = [ { value: 'auto', label: 'Auto-Publish' }, { value: 'manual', label: 'Manual' }, { value: 'scheduled', label: 'Scheduled' }, ]; const DESTINATIONS = [ { value: 'sites', label: 'IGNY8 Sites' }, { value: 'wordpress', label: 'WordPress' }, { value: 'shopify', label: 'Shopify' }, ]; export default function PublishingRules({ rules, onChange }: PublishingRulesProps) { const [localRules, setLocalRules] = useState(rules); const handleAddRule = () => { const newRule: PublishingRule = { id: `rule_${Date.now()}`, content_type: 'all', trigger: 'manual', destinations: ['sites'], priority: localRules.length + 1, enabled: true, }; const updated = [...localRules, newRule]; setLocalRules(updated); onChange(updated); }; const handleDeleteRule = (id: string) => { const updated = localRules.filter((r) => r.id !== id); setLocalRules(updated); onChange(updated); }; const handleUpdateRule = (id: string, field: keyof PublishingRule, value: any) => { const updated = localRules.map((rule) => rule.id === id ? { ...rule, [field]: value } : rule ); setLocalRules(updated); onChange(updated); }; const handleMoveRule = (id: string, direction: 'up' | 'down') => { const index = localRules.findIndex((r) => r.id === id); if (index === -1) return; const newIndex = direction === 'up' ? index - 1 : index + 1; if (newIndex < 0 || newIndex >= localRules.length) return; const updated = [...localRules]; [updated[index], updated[newIndex]] = [updated[newIndex], updated[index]]; // Update priorities updated.forEach((rule, i) => { rule.priority = i + 1; }); setLocalRules(updated); onChange(updated); }; const handleToggleDestinations = (ruleId: string, destination: string) => { const rule = localRules.find((r) => r.id === ruleId); if (!rule) return; const destinations = rule.destinations.includes(destination) ? rule.destinations.filter((d) => d !== destination) : [...rule.destinations, destination]; handleUpdateRule(ruleId, 'destinations', destinations); }; return (

Advanced Publishing Rules

Set specific rules for different types of content

Example: Publish blog posts to WordPress but guides to your main site

{localRules.length === 0 ? (

No publishing rules configured

) : (
{localRules.map((rule, index) => (
handleUpdateRule(rule.id, 'content_type', value) } />
handleUpdateRule(rule.id, 'trigger', value) } />
{rule.priority}
handleUpdateRule(rule.id, 'enabled', e.target.checked) } label="Enabled" />
{DESTINATIONS.map((dest) => ( handleToggleDestinations(rule.id, dest.value)} label={dest.label} /> ))}
{rule.trigger === 'scheduled' && (
handleUpdateRule(rule.id, 'schedule', e.target.value) } placeholder="0 0 * * *" className="mt-1 w-full px-3 py-2 border border-gray-300 dark:border-gray-700 rounded-md dark:bg-gray-800 dark:text-white" />

Cron format: minute hour day month weekday

)}
))}
)}
); }