"use client"; import React, { useState } from 'react'; import * as Dialog from '@radix-ui/react-dialog'; import { X, Save, AlertCircle } from 'lucide-react'; interface SaveTemplateModalProps { isOpen: boolean; onClose: () => void; onSave: (templateData: { title: string; description: string; tags: string[]; }) => void; } const SaveTemplateModal: React.FC = ({ isOpen, onClose, onSave }) => { const [title, setTitle] = useState(''); const [description, setDescription] = useState(''); const [tagInput, setTagInput] = useState(''); const [tags, setTags] = useState([]); const [errors, setErrors] = useState<{ [key: string]: string }>({}); const validateForm = () => { const newErrors: { [key: string]: string } = {}; if (!title.trim()) { newErrors.title = 'Title is required'; } if (!description.trim()) { newErrors.description = 'Description is required'; } setErrors(newErrors); return Object.keys(newErrors).length === 0; }; const handleAddTag = () => { const newTag = tagInput.trim(); if (newTag && !tags.includes(newTag)) { setTags([...tags, newTag]); setTagInput(''); } }; const handleRemoveTag = (tagToRemove: string) => { setTags(tags.filter(tag => tag !== tagToRemove)); }; const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === 'Enter') { e.preventDefault(); handleAddTag(); } }; const handleSave = () => { if (validateForm()) { onSave({ title: title.trim(), description: description.trim(), tags }); handleClose(); } }; const handleClose = () => { setTitle(''); setDescription(''); setTagInput(''); setTags([]); setErrors({}); onClose(); }; return ( {/* Header */}
Save as Template

Create a reusable template from your current design

{/* Form */}
{/* Title */}
setTitle(e.target.value)} placeholder="e.g., E-commerce Order Flow" className={`w-full px-3 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent ${ errors.title ? 'border-red-300' : 'border-gray-300' }`} /> {errors.title && (
{errors.title}
)}
{/* Description */}