'use client'; import { useState } from 'react'; import { X, Loader2, Tag } from 'lucide-react'; import { inventoryApi } from '@/lib/api'; import { toast } from 'react-hot-toast'; interface CategoryCreationModalProps { show: boolean; onClose: () => void; onCategoryCreated: () => void; } export default function CategoryCreationModal({ show, onClose, onCategoryCreated }: CategoryCreationModalProps) { const [name, setName] = useState(''); const [description, setDescription] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); if (!show) return null; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!name.trim()) { setError('Category name is required'); return; } setLoading(true); setError(null); try { await inventoryApi.createCategory({ name: name.trim(), description: description.trim() || undefined }); toast.success('Category added'); setName(''); setDescription(''); onCategoryCreated(); onClose(); } catch (err: any) { setError(err?.response?.data?.detail || 'Failed to create category'); } finally { setLoading(false); } }; return (

New Category

{ setName(e.target.value); setError(null); }} placeholder="e.g., Electronics" className="w-full mt-2 px-3 py-2.5 bg-slate-800 border border-slate-700 rounded text-white placeholder-slate-500 focus:outline-none focus-visible:ring-2 focus-visible:ring-primary" disabled={loading} autoFocus />
setDescription(e.target.value)} placeholder="Brief category description" className="w-full mt-2 px-3 py-2.5 bg-slate-800 border border-slate-700 rounded text-white placeholder-slate-500 focus:outline-none focus-visible:ring-2 focus-visible:ring-primary" disabled={loading} />
{error && (

{error}

)}
); }