import { useState, useEffect } from 'react'; import PageMeta from '../../components/common/PageMeta'; import PageHeader from '../../components/common/PageHeader'; import ModuleNavigationTabs from '../../components/navigation/ModuleNavigationTabs'; import { useToast } from '../../components/ui/toast/ToastContainer'; import { fetchAuthorProfiles, createAuthorProfile, updateAuthorProfile, deleteAuthorProfile, AuthorProfile } from '../../services/api'; import { Card } from '../../components/ui/card'; import Button from '../../components/ui/button/Button'; import FormModal, { FormField } from '../../components/common/FormModal'; import Badge from '../../components/ui/badge/Badge'; import { PlusIcon, BoltIcon, UserIcon, ShootingStarIcon, ImageIcon } from '../../icons'; export default function AuthorProfiles() { const toast = useToast(); const [profiles, setProfiles] = useState([]); const [loading, setLoading] = useState(true); const [isModalOpen, setIsModalOpen] = useState(false); const [editingProfile, setEditingProfile] = useState(null); const [formData, setFormData] = useState({ name: '', description: '', tone: '', language: 'en', is_active: true, }); useEffect(() => { loadProfiles(); }, []); const loadProfiles = async () => { try { setLoading(true); const response = await fetchAuthorProfiles(); setProfiles(response.results || []); } catch (error: any) { toast.error(`Failed to load author profiles: ${error.message}`); } finally { setLoading(false); } }; const handleCreate = () => { setEditingProfile(null); setFormData({ name: '', description: '', tone: '', language: 'en', is_active: true, }); setIsModalOpen(true); }; const handleEdit = (profile: AuthorProfile) => { setEditingProfile(profile); setFormData({ name: profile.name, description: profile.description, tone: profile.tone, language: profile.language, is_active: profile.is_active, }); setIsModalOpen(true); }; const handleSave = async () => { try { if (editingProfile) { await updateAuthorProfile(editingProfile.id, formData); toast.success('Author profile updated successfully'); } else { await createAuthorProfile(formData); toast.success('Author profile created successfully'); } setIsModalOpen(false); loadProfiles(); } catch (error: any) { toast.error(`Failed to save: ${error.message}`); } }; const handleDelete = async (id: number) => { if (!confirm('Are you sure you want to delete this author profile?')) return; try { await deleteAuthorProfile(id); toast.success('Author profile deleted successfully'); loadProfiles(); } catch (error: any) { toast.error(`Failed to delete: ${error.message}`); } }; const formFields: FormField[] = [ { name: 'name', label: 'Name', type: 'text', required: true }, { name: 'description', label: 'Description', type: 'textarea', required: false }, { name: 'tone', label: 'Tone', type: 'text', required: true }, { name: 'language', label: 'Language', type: 'text', required: true }, { name: 'is_active', label: 'Active', type: 'checkbox', required: false }, ]; // Thinker navigation tabs const thinkerTabs = [ { label: 'AI Instructions', path: '/thinker/prompts', icon: }, { label: 'Writing Voices', path: '/thinker/author-profiles', icon: }, { label: 'Content Strategies', path: '/thinker/strategies', icon: }, { label: 'Image Testing', path: '/thinker/image-testing', icon: }, ]; return (
, color: 'blue' }} navigation={} />
{loading ? (
Loading...
) : (
{profiles.map((profile) => (

{profile.name}

{profile.is_active ? 'Active' : 'Inactive'}

{profile.description}

Tone:{' '} {profile.tone}
Language:{' '} {profile.language}
))}
)} setIsModalOpen(false)} onSave={handleSave} title={editingProfile ? 'Edit Author Profile' : 'Create Author Profile'} fields={formFields} data={formData} onChange={setFormData} />
); }