diff --git a/src/admin/pages/WarehouseItemDetail.tsx b/src/admin/pages/WarehouseItemDetail.tsx index 12ee1ea..e75ae97 100644 --- a/src/admin/pages/WarehouseItemDetail.tsx +++ b/src/admin/pages/WarehouseItemDetail.tsx @@ -1,11 +1,13 @@ import { useState, useEffect, useRef } from "react"; import { useQuery } from "@tanstack/react-query"; -import { useParams, useNavigate, Link } from "react-router-dom"; +import { useParams, useNavigate, Link as RouterLink } from "react-router-dom"; +import { motion } from "framer-motion"; +import Box from "@mui/material/Box"; +import Typography from "@mui/material/Typography"; +import MenuItem from "@mui/material/MenuItem"; 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 useModalLock from "../hooks/useModalLock"; import { formatCurrency, formatDate } from "../utils/formatters"; @@ -15,6 +17,20 @@ import { type WarehouseItem, } from "../lib/queries/warehouse"; import { useApiMutation } from "../lib/queries/mutations"; +import { + Button, + Card, + DataTable, + Field, + TextField, + Select, + StatCard, + EmptyState, + LoadingState, + PageHeader, + ConfirmDialog, + type DataColumn, +} from "../ui"; interface Batch { id: number; @@ -52,6 +68,35 @@ interface ItemForm { notes: string; } +const EditIcon = ( + + + + +); + +const BackIcon = ( + + + +); + export default function WarehouseItemDetail() { const { id } = useParams(); const alert = useAlert(); @@ -69,6 +114,7 @@ export default function WarehouseItemDetail() { notes: "", }); const [errors, setErrors] = useState>({}); + const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); const isNew = id === "new"; const itemQuery = useQuery(warehouseItemDetailOptions(id, !!id && !isNew)); @@ -176,425 +222,459 @@ export default function WarehouseItemDetail() { const saving = saveMutation.isPending; if (isPending && !isNew) { - return ( -
-
-
- ); + return ; } const batches: Batch[] = item?.batches ?? []; const locations: ItemLocation[] = item?.item_locations ?? []; + const title = isNew ? "Nová položka" : item ? item.name : "Detail položky"; + const subtitle = item?.item_number || undefined; + + // Edit / view mode action buttons + const headerActions = canManage ? ( + + {editing || isNew ? ( + <> + {!isNew && ( + + )} + + + ) : ( + <> + {item && ( + + )} + + + )} + + ) : undefined; + + // Batch table columns + const batchColumns: DataColumn[] = [ + { + key: "received_at", + header: "Datum příjmu", + width: "22%", + mono: true, + render: (b) => formatDate(b.received_at), + }, + { + key: "original_qty", + header: "Původní množství", + width: "20%", + mono: true, + render: (b) => String(Number(b.original_qty)), + }, + { + key: "quantity", + header: "Zůstatek", + width: "18%", + mono: true, + bold: true, + render: (b) => String(Number(b.quantity)), + }, + { + key: "unit_price", + header: "Cena za jednotku", + width: "20%", + mono: true, + render: (b) => formatCurrency(Number(b.unit_price), "CZK"), + }, + { + key: "value", + header: "Hodnota", + width: "20%", + mono: true, + render: (b) => + formatCurrency(Number(b.quantity) * Number(b.unit_price), "CZK"), + }, + ]; + + // Location table columns + const locationColumns: DataColumn[] = [ + { + key: "code", + header: "Kód", + width: "30%", + mono: true, + bold: true, + render: (l) => l.location?.code || "—", + }, + { + key: "name", + header: "Název", + width: "50%", + render: (l) => l.location?.name || "—", + }, + { + key: "quantity", + header: "Množství", + width: "20%", + mono: true, + bold: true, + render: (l) => String(Number(l.quantity)), + }, + ]; + return ( -
+ {/* Header */} -
- - - - - -
-

- {id === "new" - ? "Nová položka" - : item - ? item.name - : "Detail položky"} -

- {item?.item_number && ( -

{item.item_number}

- )} -
-
- {canManage && ( -
- {editing || isNew ? ( - <> - {!isNew && ( - - )} - - - ) : ( - <> - {item && ( - - )} - - - )} -
- )} + + + {headerActions} +
+ } + /> {/* Basic info */} -
-

Základní údaje

-
- {editing || id === "new" ? ( - <> -
- - { - updateForm("item_number", e.target.value); - setErrors((prev) => ({ ...prev, item_number: "" })); - }} - className="admin-form-input" - placeholder="Např. SKL-001" - /> - - - { - updateForm("name", e.target.value); - setErrors((prev) => ({ ...prev, name: "" })); - }} - className="admin-form-input" - placeholder="Název položky" - aria-invalid={!!errors.name} - /> - -
- -