Files
tfm_ainventory/frontend/components/CategoryCreationModal.tsx
Daniel Bedeleanu c0232bb2f1 refactor: remove all bold font weights from UI/UX (291 replacements)
Replace font-bold, font-black, and font-semibold with font-normal throughout:
- 26 component files
- 1 CSS utility file (globals.css)
- 291 total occurrences

Text hierarchy now maintained through font-size differences only.
All tests passing (291/291).

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-04-19 18:28:23 +03:00

136 lines
4.7 KiB
TypeScript

'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<string | null>(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 (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40">
<div className="bg-surface border border-slate-800 rounded-lg shadow-xl max-w-sm w-full mx-4">
<div className="flex items-center justify-between p-6 border-b border-slate-800">
<div className="flex items-center gap-3">
<div className="p-2 bg-primary/10 rounded-lg text-primary">
<Tag size={20} />
</div>
<h2 className="text-lg font-normal text-white">New Category</h2>
</div>
<button
onClick={onClose}
disabled={loading}
className="p-1 text-muted hover:text-secondary rounded focus-visible:ring-2 focus-visible:ring-primary focus-visible:outline-none disabled:opacity-50"
aria-label="Close"
>
<X size={20} />
</button>
</div>
<form onSubmit={handleSubmit} className="p-6 space-y-4">
<div>
<label className="text-sm font-normal text-secondary">Name</label>
<input
type="text"
value={name}
onChange={(e) => {
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:text-muted focus:outline-none focus-visible:ring-2 focus-visible:ring-primary"
disabled={loading}
autoFocus
/>
</div>
<div>
<label className="text-sm font-normal text-secondary">Description (optional)</label>
<input
type="text"
value={description}
onChange={(e) => 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:text-muted focus:outline-none focus-visible:ring-2 focus-visible:ring-primary"
disabled={loading}
/>
</div>
{error && (
<div className="p-3 bg-rose-500/10 border border-rose-500/20 rounded">
<p className="text-sm text-rose-400">{error}</p>
</div>
)}
<div className="flex gap-2 pt-2">
<button
type="button"
onClick={onClose}
disabled={loading}
className="flex-1 px-4 py-2.5 text-secondary bg-slate-800 border border-slate-700 rounded font-normal hover:bg-slate-700 transition-colors disabled:opacity-50 focus-visible:ring-2 focus-visible:ring-primary focus-visible:outline-none"
>
Cancel
</button>
<button
type="submit"
disabled={loading || !name.trim()}
className="flex-1 px-4 py-2.5 bg-primary text-white rounded font-normal hover:bg-blue-600 transition-colors disabled:opacity-50 flex items-center justify-center gap-2 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-slate-900 focus-visible:ring-primary focus-visible:outline-none"
>
{loading ? (
<>
<Loader2 size={16} className="animate-spin" />
Creating...
</>
) : (
'Create'
)}
</button>
</div>
</form>
</div>
</div>
);
}