diff --git a/src/admin/pages/WarehouseItems.tsx b/src/admin/pages/WarehouseItems.tsx index 6e59f6c..136b39d 100644 --- a/src/admin/pages/WarehouseItems.tsx +++ b/src/admin/pages/WarehouseItems.tsx @@ -1,12 +1,10 @@ import { useState } from "react"; import { useQuery } from "@tanstack/react-query"; import { useNavigate } from "react-router-dom"; -import { useAlert } from "../context/AlertContext"; +import { motion } from "framer-motion"; +import Box from "@mui/material/Box"; import { useAuth } from "../context/AuthContext"; import Forbidden from "../components/Forbidden"; -import { motion, AnimatePresence } from "framer-motion"; -import Pagination from "../components/Pagination"; -import SortIcon from "../components/SortIcon"; import useTableSort from "../hooks/useTableSort"; import useDebounce from "../hooks/useDebounce"; import { usePaginatedQuery } from "../hooks/usePaginatedQuery"; @@ -17,11 +15,38 @@ import { warehouseCategoryListOptions, type WarehouseItem, } from "../lib/queries/warehouse"; +import { + Button, + Card, + DataTable, + Pagination, + TextField, + Select, + StatusChip, + PageHeader, + FilterBar, + EmptyState, + LoadingState, + type DataColumn, +} from "../ui"; const PER_PAGE = 20; +const PlusIcon = ( + + + + +); + export default function WarehouseItems() { - const alert = useAlert(); const { hasPermission } = useAuth(); const navigate = useNavigate(); @@ -30,7 +55,7 @@ export default function WarehouseItems() { const [categoryId, setCategoryId] = useState(""); const debouncedSearch = useDebounce(search, 300); - const { sort, order, handleSort, activeSort } = useTableSort("item_number"); + const { sort, order, handleSort } = useTableSort("item_number"); const { data: categories = [] } = useQuery(warehouseCategoryListOptions()); @@ -50,266 +75,174 @@ export default function WarehouseItems() { const canManage = hasPermission("warehouse.manage"); - const handleRowClick = (item: WarehouseItem) => { - navigate(`/warehouse/items/${item.id}`); - }; - if (isPending) { - return ( -
-
-
- ); + return ; } + const total = pagination?.total ?? items.length; + const subtitle = `${total} ${czechPlural(total, "položka", "položky", "položek")}`; + + const columns: DataColumn[] = [ + { + key: "item_number", + header: "Číslo", + width: "10%", + sortKey: "item_number", + mono: true, + render: (i) => i.item_number || "—", + }, + { + key: "name", + header: "Název", + width: "24%", + sortKey: "name", + bold: true, + render: (i) => i.name, + }, + { + key: "category", + header: "Kategorie", + width: "14%", + render: (i) => i.category?.name || "—", + }, + { + key: "unit", + header: "Jednotka", + width: "9%", + render: (i) => i.unit, + }, + { + key: "total_quantity", + header: "Množství", + width: "10%", + sortKey: "total_quantity", + mono: true, + render: (i) => String(i.total_quantity ?? 0), + }, + { + key: "available_quantity", + header: "K dispozici", + width: "10%", + mono: true, + render: (i) => String(i.available_quantity ?? 0), + }, + { + key: "stock_value", + header: "Hodnota", + width: "12%", + sortKey: "stock_value", + mono: true, + render: (i) => + i.stock_value != null + ? formatCurrency(i.stock_value, "CZK") + : "0,00 Kč", + }, + { + key: "status", + header: "Stav", + width: "11%", + render: (i) => + i.below_minimum ? ( + + ) : i.is_active ? ( + + ) : ( + + ), + }, + ]; + return ( -
+ -
-

Skladové položky

-

- {pagination?.total ?? items.length}{" "} - {czechPlural( - pagination?.total ?? items.length, - "položka", - "položky", - "položek", - )} -

-
-
- {canManage && ( - - )} -
+ Přidat položku + + ) : undefined + } + />
- -
-
-
- - - - - { - setSearch(e.target.value); - setPage(1); - }} - placeholder="Hledat podle názvu nebo čísla položky..." - className="admin-form-input" - /> -
- {categories.length > 0 && ( - - )} -
+ + + { + setSearch(e.target.value); + setPage(1); + }} + placeholder="Hledat podle názvu nebo čísla položky..." + fullWidth + /> + + {categories.length > 0 && ( + +