/** * Presets - manage generation presets. */ import { useState, useEffect, useCallback } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { Button } from '@aime/wp-components'; import { trash, edit } from '@wordpress/icons'; import useApi from '../../../hooks/useApi'; import Card from '../../common/Card'; import EmptyState from '../../common/EmptyState'; import { SkeletonBlock } from '../../common/Skeleton'; import ConfirmModal from '../../common/ConfirmModal'; import { toast } from '../../common/Toast'; const TONES = [ { label: 'Professional', value: 'professional' }, { label: 'Casual', value: 'casual' }, { label: 'Friendly', value: 'friendly' }, { label: 'Authoritative', value: 'authoritative' }, { label: 'Humorous', value: 'humorous' }, { label: 'Formal', value: 'formal' }, { label: 'Conversational', value: 'conversational' }, ]; const STYLES = [ { label: 'Blog Post', value: 'blog_post' }, { label: 'How-To Guide', value: 'how_to' }, { label: 'Listicle', value: 'listicle' }, { label: 'Product Review', value: 'product_review' }, { label: 'Case Study', value: 'case_study' }, { label: 'Tutorial', value: 'tutorial' }, { label: 'Opinion Piece', value: 'opinion' }, { label: 'News Article', value: 'news' }, ]; const defaultPreset = { name: '', tone: 'professional', style: 'blog_post', language: 'en', word_count: 1000, prompt_template: '', system_instructions: '', }; const Presets = () => { const { get, post, put, del, loading } = useApi(); const [ presets, setPresets ] = useState( [] ); const [ editPreset, setEditPreset ] = useState( null ); const [ confirmDelete, setConfirmDelete ] = useState( null ); const fetchPresets = useCallback( async () => { try { const res = await get( '/content/presets' ); setPresets( res || [] ); } catch ( e ) { // silent } }, [ get ] ); useEffect( () => { fetchPresets(); }, [ fetchPresets ] ); const handleSave = async () => { try { if ( editPreset.id ) { await put( `/content/presets/${ editPreset.id }`, editPreset ); toast( __( 'Preset updated.', 'ai-marketing-expert' ) ); } else { await post( '/content/presets', editPreset ); toast( __( 'Preset created.', 'ai-marketing-expert' ) ); } setEditPreset( null ); fetchPresets(); } catch ( e ) { toast( e.message, 'error' ); } }; const handleDelete = async ( id ) => { try { await del( `/content/presets/${ id }` ); toast( __( 'Preset deleted.', 'ai-marketing-expert' ) ); setConfirmDelete( null ); fetchPresets(); } catch ( e ) { toast( e.message, 'error' ); } }; return (
{ preset.prompt_template }
) }