diff --git a/src/admin/pages/WarehouseInventoryForm.tsx b/src/admin/pages/WarehouseInventoryForm.tsx index 0c73737..37ae70a 100644 --- a/src/admin/pages/WarehouseInventoryForm.tsx +++ b/src/admin/pages/WarehouseInventoryForm.tsx @@ -1,18 +1,20 @@ -import { useState } from "react"; -import { useNavigate, Link } from "react-router-dom"; +import { useState, useId, useRef } from "react"; +import { useNavigate, Link as RouterLink } from "react-router-dom"; import { useQuery } from "@tanstack/react-query"; +import { motion } from "framer-motion"; +import Box from "@mui/material/Box"; +import Typography from "@mui/material/Typography"; +import IconButton from "@mui/material/IconButton"; import { useAlert } from "../context/AlertContext"; import { useAuth } from "../context/AuthContext"; import Forbidden from "../components/Forbidden"; -import { motion } from "framer-motion"; -import FormField from "../components/FormField"; import ItemPicker from "../components/warehouse/ItemPicker"; -import LocationSelect from "../components/warehouse/LocationSelect"; -import WarehouseMovementTable from "../components/warehouse/WarehouseMovementTable"; -import { warehouseLocationListOptions } from "../lib/queries/warehouse"; -import type { WarehouseLocation } from "../lib/queries/warehouse"; - +import { + warehouseLocationListOptions, + type WarehouseLocation, +} from "../lib/queries/warehouse"; import { useApiMutation } from "../lib/queries/mutations"; +import { Button, Card, TextField, Select, Field } from "../ui"; interface InventoryItem { key: string; @@ -21,22 +23,63 @@ interface InventoryItem { actual_qty: number; } -const defaultInventoryItem = () => ({ - item_id: null, - location_id: null, - actual_qty: 0, -}); +const BackIcon = ( + + + +); + +const RemoveIcon = ( + + + + +); + +const PlusIcon = ( + + + + +); export default function WarehouseInventoryForm() { const alert = useAlert(); const { hasPermission } = useAuth(); const navigate = useNavigate(); + const baseId = useId(); + const counterRef = useRef(0); + const nextKey = () => `${baseId}-item-${counterRef.current++}`; + const [items, setItems] = useState([]); const [notes, setNotes] = useState(""); const [saving, setSaving] = useState(false); - const { data: locations = [] } = useQuery(warehouseLocationListOptions()); + const { data: locations } = useQuery(warehouseLocationListOptions()); if (!hasPermission("warehouse.inventory")) return ; @@ -90,151 +133,171 @@ export default function WarehouseInventoryForm() { } }; + const addItem = () => { + setItems((prev) => [ + ...prev, + { key: nextKey(), item_id: null, location_id: null, actual_qty: 0 }, + ]); + }; + + const removeItem = (index: number) => { + setItems((prev) => prev.filter((_, i) => i !== index)); + }; + + const updateItem = ( + index: number, + field: keyof InventoryItem, + value: unknown, + ) => { + setItems((prev) => { + const updated = [...prev]; + updated[index] = { ...updated[index], [field]: value }; + return updated; + }); + }; + + const locationOptions = [ + { value: "", label: "-- bez lokace --" }, + ...(locations ?? []).map((loc: WarehouseLocation) => ({ + value: String(loc.id), + label: `${loc.code} - ${loc.name}`, + })), + ]; + return ( -
+ {/* Header */} -
- - + + - - - -
-

Nová inventura

-
-
-
- -
+ {BackIcon} + + Nová inventura +
+ + + + {/* Notes */} -
-

Základní údaje

- -