diff --git a/src/admin/pages/WarehouseSuppliers.tsx b/src/admin/pages/WarehouseSuppliers.tsx
index 5302722..4f7f83f 100644
--- a/src/admin/pages/WarehouseSuppliers.tsx
+++ b/src/admin/pages/WarehouseSuppliers.tsx
@@ -1,20 +1,34 @@
import { useState } from "react";
+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, AnimatePresence } from "framer-motion";
-import ConfirmModal from "../components/ConfirmModal";
-import FormModal from "../components/FormModal";
-import Pagination from "../components/Pagination";
import useDebounce from "../hooks/useDebounce";
import { usePaginatedQuery } from "../hooks/usePaginatedQuery";
-
-import FormField from "../components/FormField";
import {
warehouseSupplierListOptions,
type WarehouseSupplier,
} from "../lib/queries/warehouse";
import { useApiMutation } from "../lib/queries/mutations";
+import {
+ Button,
+ Card,
+ DataTable,
+ Pagination,
+ Modal,
+ ConfirmDialog,
+ Field,
+ TextField,
+ StatusChip,
+ PageHeader,
+ FilterBar,
+ EmptyState,
+ LoadingState,
+ type DataColumn,
+} from "../ui";
const API_BASE = "/api/admin/warehouse/suppliers";
@@ -31,6 +45,50 @@ interface SupplierForm {
const PER_PAGE = 20;
+const PlusIcon = (
+
+);
+const EditIcon = (
+
+);
+const DeleteIcon = (
+
+);
+
export default function WarehouseSuppliers() {
const alert = useAlert();
const { hasPermission } = useAuth();
@@ -191,347 +249,261 @@ export default function WarehouseSuppliers() {
};
if (isPending) {
- return (
-
- );
+ return ;
}
+ const total = pagination?.total ?? suppliers.length;
+ const subtitle = `${total} ${
+ total === 1
+ ? "dodavatel"
+ : total >= 2 && total <= 4
+ ? "dodavatelé"
+ : "dodavatelů"
+ }`;
+
+ const columns: DataColumn[] = [
+ {
+ key: "name",
+ header: "Název",
+ width: "20%",
+ bold: true,
+ render: (s) => s.name,
+ },
+ {
+ key: "ico",
+ header: "IČO",
+ width: "11%",
+ mono: true,
+ render: (s) => s.ico || "—",
+ },
+ {
+ key: "dic",
+ header: "DIČ",
+ width: "11%",
+ mono: true,
+ render: (s) => s.dic || "—",
+ },
+ {
+ key: "contact_person",
+ header: "Kontaktní osoba",
+ width: "16%",
+ render: (s) => s.contact_person || "—",
+ },
+ {
+ key: "email",
+ header: "E-mail",
+ width: "16%",
+ render: (s) => s.email || "—",
+ },
+ {
+ key: "phone",
+ header: "Telefon",
+ width: "12%",
+ mono: true,
+ render: (s) => s.phone || "—",
+ },
+ {
+ key: "status",
+ header: "Stav",
+ width: "8%",
+ render: (s) => (
+ toggleActive(s)}
+ />
+ ),
+ },
+ {
+ key: "actions",
+ header: "Akce",
+ width: "10%",
+ align: "right",
+ render: (s) => (
+
+ openEditModal(s)}
+ aria-label="Upravit"
+ title="Upravit"
+ >
+ {EditIcon}
+
+ setDeactivateConfirm({ show: true, supplier: s })}
+ aria-label={s.is_active ? "Deaktivovat" : "Smazat"}
+ title={s.is_active ? "Deaktivovat" : "Smazat"}
+ >
+ {DeleteIcon}
+
+
+ ),
+ },
+ ];
+
return (
-
+
-
-
Dodavatelé
-
- {pagination?.total ?? suppliers.length}{" "}
- {pagination?.total === 1
- ? "dodavatel"
- : pagination?.total !== undefined &&
- pagination.total >= 2 &&
- pagination.total <= 4
- ? "dodavatelé"
- : "dodavatelů"}
-
-
-
-
-
+
+ Přidat dodavatele
+
+ }
+ />
-
-
-
-
-
- {
- setSearch(e.target.value);
- setPage(1);
- }}
- placeholder="Hledat dodavatele..."
- className="admin-form-input"
- />
-
-
+
+
+ {
+ setSearch(e.target.value);
+ setPage(1);
+ }}
+ placeholder="Hledat dodavatele..."
+ fullWidth
+ />
+
+
-
-
- {suppliers.length === 0 && !search && (
-
-
-
Zatím nejsou žádní dodavatelé.
-
-
- )}
- {suppliers.length === 0 && search && (
-
-
Žádní dodavatelé pro "{search}".
-
- )}
- {suppliers.length > 0 && (
-
-
-
-
- | Název |
- IČO |
- DIČ |
- Kontaktní osoba |
- E-mail |
- Telefon |
- Stav |
- Akce |
-
-
-
- {suppliers.map((supplier) => (
-
- | {supplier.name} |
- {supplier.ico || "—"} |
- {supplier.dic || "—"} |
- {supplier.contact_person || "—"} |
- {supplier.email || "—"} |
-
- {supplier.phone || "—"}
- |
-
-
- |
-
-
-
-
-
- |
-
- ))}
-
-
-
- )}
-
-
-
-
-
-
+
+ }
+ />
+ )
+ }
+ />
+
+
{/* Add/Edit Modal */}
- setShowModal(false)}
onSubmit={handleSubmit}
title={editingSupplier ? "Upravit dodavatele" : "Přidat dodavatele"}
loading={saving}
>
-
-
- {
- setForm({ ...form, name: e.target.value });
- setErrors((prev) => ({ ...prev, name: "" }));
- }}
- className="admin-form-input"
- placeholder="Název dodavatele"
- aria-invalid={!!errors.name}
+
+ {
+ setForm({ ...form, name: e.target.value });
+ setErrors((prev) => ({ ...prev, name: "" }));
+ }}
+ placeholder="Název dodavatele"
+ />
+
+
+
+
+ setForm({ ...form, ico: e.target.value })}
+ placeholder="12345678"
/>
-
-
-
-
- setForm({ ...form, ico: e.target.value })}
- className="admin-form-input"
- placeholder="12345678"
- />
-
-
-
- setForm({ ...form, dic: e.target.value })}
- className="admin-form-input"
- placeholder="CZ12345678"
- />
-
-
-
-
-
-
- setForm({
- ...form,
- contact_person: e.target.value,
- })
- }
- className="admin-form-input"
- placeholder="Jan Novák"
- />
-
-
-
- setForm({ ...form, email: e.target.value })}
- className="admin-form-input"
- placeholder="info@firma.cz"
- />
-
-
-
-
-
- setForm({ ...form, phone: e.target.value })}
- className="admin-form-input"
- placeholder="+420 123 456 789"
- />
-
-
-
-
-
+
+
-
-
-
-
+
+
+ setForm({ ...form, email: e.target.value })}
+ placeholder="info@firma.cz"
+ />
+
+
+
+
+ setForm({ ...form, phone: e.target.value })}
+ placeholder="+420 123 456 789"
+ />
+
+
+
+ setForm({ ...form, address: e.target.value })}
+ placeholder="Ulice, město, PSČ"
+ />
+
+
+
+ setForm({ ...form, notes: e.target.value })}
+ placeholder="Volitelné poznámky"
+ />
+
+
{/* Deactivate/Delete Confirmation */}
-
setDeactivateConfirm({ show: false, supplier: null })}
onConfirm={handleDeactivate}
@@ -551,7 +523,8 @@ export default function WarehouseSuppliers() {
deactivateConfirm.supplier?.is_active ? "Deaktivovat" : "Smazat"
}
confirmVariant="danger"
+ loading={deleteMutation.isPending}
/>
-
+
);
}