import React, { useState } from 'react'; import { Modal } from '../ui/Modal'; import { useUIStore } from '../../stores/uiStore'; import { useSpaceStore } from '../../stores/spaceStore'; export function CreateCategoryModal() { const [name, setName] = useState(''); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); const activeModal = useUIStore((s) => s.activeModal); const closeModal = useUIStore((s) => s.closeModal); const createCategory = useSpaceStore((s) => s.createCategory); const currentSpaceId = useSpaceStore((s) => s.currentSpaceId); const isOpen = activeModal === 'createCategory'; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); if (!name.trim()) { setError('Category name is required'); return; } if (!currentSpaceId) { setError('No space selected'); return; } setIsLoading(true); try { await createCategory(currentSpaceId, name.trim()); closeModal(); setName(''); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to create category'); } finally { setIsLoading(false); } }; return (
{error && (
{error}
)}
setName(e.target.value)} className="input-standard w-full" placeholder="new-category" autoFocus />
); }