import React, { useState, useEffect } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { X } from 'lucide-react'; import { updateAsset } from '../../../services/assets-api'; import type { Asset } from '../../../types/assets'; interface EditAssetModalProps { isOpen: boolean; onClose: () => void; asset: Asset | null; onSuccess: () => void; } export const EditAssetModal: React.FC = ({ isOpen, onClose, asset, onSuccess }) => { const [editTitle, setEditTitle] = useState(''); const [editDescription, setEditDescription] = useState(''); const [editCategory, setEditCategory] = useState('Marketing'); const [editSubcategory, setEditSubcategory] = useState(''); const [editTags, setEditTags] = useState(''); const [editGithubUrl, setEditGithubUrl] = useState(''); const [editIsDownloadable, setEditIsDownloadable] = useState(true); const [isSavingEdit, setIsSavingEdit] = useState(false); useEffect(() => { if (asset) { setEditTitle(asset.title); setEditDescription(asset.description || ''); setEditCategory(asset.categoryId || 'Marketing'); setEditSubcategory(asset.subcategory || ''); setEditTags(asset.tags.join(', ')); setEditGithubUrl(asset.githubUrl || ''); setEditIsDownloadable(asset.isDownloadable); } }, [asset]); const handleEditSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!asset) return; setIsSavingEdit(true); try { await updateAsset(asset.id, { title: editTitle, description: editDescription, categoryId: editCategory, subcategory: editSubcategory, tags: editTags.split(',').map(t => t.trim()).filter(Boolean), githubUrl: editGithubUrl, isDownloadable: editIsDownloadable, }); onSuccess(); onClose(); } catch (err) { console.error('Failed to save asset details', err); } finally { setIsSavingEdit(false); } }; return ( {isOpen && asset && (

Edit Asset Details

setEditTitle(e.target.value)} required className="w-full bg-ink-50 border border-ink-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ink-900/10 text-ink-900 placeholder-ink-400" />
setEditSubcategory(e.target.value)} placeholder="e.g. Slide Deck" className="w-full bg-ink-50 border border-ink-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ink-900/10 text-ink-900 placeholder-ink-400" />