From 0dbe78bfe6952dc94e9ee5d5687d582962fcd27f Mon Sep 17 00:00:00 2001 From: BOHA Date: Sat, 6 Jun 2026 23:28:30 +0200 Subject: [PATCH] feat(mui): migrate Warehouse Categories (Kategorie) onto MUI kit Replace legacy admin-* CSS, FormModal, ConfirmModal, FormField, and framer-motion wrappers with PageHeader, Card, DataTable, Modal, ConfirmDialog, Field, TextField, EmptyState, LoadingState, and MUI IconButton. All data logic preserved verbatim. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/admin/pages/WarehouseCategories.tsx | 377 ++++++++++++------------ 1 file changed, 185 insertions(+), 192 deletions(-) diff --git a/src/admin/pages/WarehouseCategories.tsx b/src/admin/pages/WarehouseCategories.tsx index f1baf7e..2006bcc 100644 --- a/src/admin/pages/WarehouseCategories.tsx +++ b/src/admin/pages/WarehouseCategories.tsx @@ -1,18 +1,28 @@ import { useState } from "react"; import { useQuery } from "@tanstack/react-query"; +import Box from "@mui/material/Box"; +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 ConfirmModal from "../components/ConfirmModal"; -import FormModal from "../components/FormModal"; - -import FormField from "../components/FormField"; import { warehouseCategoryListOptions, type WarehouseCategory, } from "../lib/queries/warehouse"; import { useApiMutation } from "../lib/queries/mutations"; +import { + Button, + Card, + DataTable, + Modal, + ConfirmDialog, + Field, + TextField, + PageHeader, + EmptyState, + LoadingState, + type DataColumn, +} from "../ui"; const API_BASE = "/api/admin/warehouse/categories"; @@ -22,6 +32,50 @@ interface CategoryForm { sort_order: number; } +const PlusIcon = ( + + + + +); +const EditIcon = ( + + + + +); +const DeleteIcon = ( + + + + +); + export default function WarehouseCategories() { const alert = useAlert(); const { hasPermission } = useAuth(); @@ -121,207 +175,145 @@ export default function WarehouseCategories() { }; if (isPending) { - return ( -
-
-
- ); + return ; } - return ( -
- -
-

Kategorie skladu

-
-
- -
-
+ const total = categories.length; + const subtitle = `${total} ${ + total === 1 + ? "kategorie" + : total >= 2 && total <= 4 + ? "kategorie" + : "kategorií" + }`; - -
- {categories.length === 0 && ( -
-
- - - -
-

Zatím nejsou žádné kategorie.

- -
- )} - {categories.length > 0 && ( -
- - - - - - - - - - - {categories.map((category) => ( - - - - - - - ))} - -
NázevPopisPořadíAkce
{category.name}{category.description || "—"}{category.sort_order} -
- - -
-
-
- )} -
-
+ const columns: DataColumn[] = [ + { + key: "name", + header: "Název", + width: "35%", + bold: true, + render: (c) => c.name, + }, + { + key: "description", + header: "Popis", + width: "40%", + render: (c) => c.description || "—", + }, + { + key: "sort_order", + header: "Pořadí", + width: "15%", + mono: true, + render: (c) => String(c.sort_order), + }, + { + key: "actions", + header: "Akce", + width: "10%", + align: "right", + render: (c) => ( + + openEditModal(c)} + aria-label="Upravit" + title="Upravit" + > + {EditIcon} + + setDeleteConfirm({ show: true, category: c })} + aria-label="Smazat" + title="Smazat" + > + {DeleteIcon} + + + ), + }, + ]; + + return ( + + + Přidat kategorii + + } + /> + + + + columns={columns} + rows={categories} + rowKey={(c) => c.id} + empty={ + + Přidat první kategorii + + } + /> + } + /> + {/* Add/Edit Modal */} - setShowModal(false)} onSubmit={handleSubmit} title={editingCategory ? "Upravit kategorii" : "Přidat kategorii"} loading={saving} > -
- - { - setForm({ ...form, name: e.target.value }); - setErrors((prev) => ({ ...prev, name: "" })); - }} - className="admin-form-input" - placeholder="Název kategorie" - aria-invalid={!!errors.name} - /> - + + { + setForm({ ...form, name: e.target.value }); + setErrors((prev) => ({ ...prev, name: "" })); + }} + placeholder="Název kategorie" + /> + - -