feat: implement inventory and pantry management views with CRUD functionality and user-friendly interfaces

This commit is contained in:
Nils-Johan Gynther
2026-04-21 14:43:18 +02:00
parent 82c3dc3fee
commit 81b63b3fdb
14 changed files with 352 additions and 59 deletions
+4 -2
View File
@@ -7,6 +7,7 @@ import { UNIT_OPTIONS } from '../../lib/units';
type Props = {
item: InventoryItem;
onUpdated?: () => void;
};
function toDateInputValue(value: string | null) {
@@ -44,7 +45,7 @@ const LOCATION_OPTIONS = [
{ value: 'Annat', label: 'Annat' },
];
export default function InventoryEditForm({ item }: Props) {
export default function InventoryEditForm({ item, onUpdated }: Props) {
const [isEditing, setIsEditing] = useState(false);
const [isPending, setIsPending] = useState(false);
const [error, setError] = useState<string | null>(null);
@@ -103,7 +104,8 @@ export default function InventoryEditForm({ item }: Props) {
throw new Error(data?.error || 'Kunde inte uppdatera');
}
setIsEditing(false);
router.refresh();
if (onUpdated) onUpdated();
else router.refresh();
} catch (err) {
setError(err instanceof Error ? err.message : 'Okänt fel');
} finally {