import React, { useState } from 'react'; import { useCreateMemory } from './hooks/useMemories'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from './ui/dialog'; import { Button } from './ui/button'; import { Textarea } from './ui/textarea'; import { Input } from './ui/input'; import { Label } from './ui/label'; import { AlertCircle, Loader2 } from 'lucide-react'; import { Alert, AlertDescription } from './ui/alert'; interface CreateMemoryModalProps { open: boolean; onClose: () => void; } export default function CreateMemoryModal({ open, onClose }: CreateMemoryModalProps) { const [content, setContent] = useState(''); const [tags, setTags] = useState(''); const createMemoryMutation = useCreateMemory(); const handleSuccess = () => { setContent(''); setTags(''); onClose(); }; const handleSubmit = async () => { if (!content.trim()) return; const payload = { content: content.trim(), ...(tags.trim() && { tags: tags .split(',') .map((t) => t.trim()) .filter(Boolean), }), metadata: { source: 'user' as const }, }; createMemoryMutation.mutate(payload, { onSuccess: handleSuccess, }); }; const handleClose = () => { if (!createMemoryMutation.isPending) { setContent(''); setTags(''); createMemoryMutation.reset(); onClose(); } }; return ( { if (!nextOpen) { handleClose(); } }} > Create Memory Memories are automatically included in every conversation to help Dexto remember your preferences and important information.
{createMemoryMutation.error && ( {createMemoryMutation.error instanceof Error ? createMemoryMutation.error.message : 'Failed to create memory'} )}