feat: implement inventory and pantry management views with CRUD functionality and user-friendly interfaces
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user