feat(mui): migrate Warehouse Receipts (Příjmy) onto MUI kit
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
import { useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useAlert } from "../context/AlertContext";
|
||||
import { useAuth } from "../context/AuthContext";
|
||||
import Forbidden from "../components/Forbidden";
|
||||
import AdminDatePicker from "../components/AdminDatePicker";
|
||||
import { motion, AnimatePresence } from "framer-motion";
|
||||
import Pagination from "../components/Pagination";
|
||||
import { motion } from "framer-motion";
|
||||
import Box from "@mui/material/Box";
|
||||
import useDebounce from "../hooks/useDebounce";
|
||||
import { usePaginatedQuery } from "../hooks/usePaginatedQuery";
|
||||
|
||||
@@ -16,13 +14,31 @@ import {
|
||||
warehouseSupplierListOptions,
|
||||
type WarehouseReceipt,
|
||||
} from "../lib/queries/warehouse";
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
DataTable,
|
||||
Pagination,
|
||||
TextField,
|
||||
Select,
|
||||
DateField,
|
||||
StatusChip,
|
||||
PageHeader,
|
||||
FilterBar,
|
||||
EmptyState,
|
||||
LoadingState,
|
||||
type DataColumn,
|
||||
} from "../ui";
|
||||
|
||||
const PER_PAGE = 20;
|
||||
|
||||
const STATUS_BADGE: Record<string, string> = {
|
||||
DRAFT: "admin-badge-warning",
|
||||
CONFIRMED: "admin-badge-active",
|
||||
CANCELLED: "admin-badge-danger",
|
||||
const STATUS_COLOR: Record<
|
||||
string,
|
||||
"warning" | "success" | "error" | "info" | "default"
|
||||
> = {
|
||||
DRAFT: "warning",
|
||||
CONFIRMED: "success",
|
||||
CANCELLED: "error",
|
||||
};
|
||||
|
||||
const STATUS_LABEL: Record<string, string> = {
|
||||
@@ -31,8 +47,23 @@ const STATUS_LABEL: Record<string, string> = {
|
||||
CANCELLED: "Zrušeno",
|
||||
};
|
||||
|
||||
const PlusIcon = (
|
||||
<svg
|
||||
width="20"
|
||||
height="20"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
>
|
||||
<line x1="12" y1="5" x2="12" y2="19" />
|
||||
<line x1="5" y1="12" x2="19" y2="12" />
|
||||
</svg>
|
||||
);
|
||||
|
||||
export default function WarehouseReceipts() {
|
||||
const { hasPermission } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [page, setPage] = useState(1);
|
||||
const [search, setSearch] = useState("");
|
||||
@@ -60,16 +91,10 @@ export default function WarehouseReceipts() {
|
||||
}),
|
||||
);
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
if (!hasPermission("warehouse.view")) return <Forbidden />;
|
||||
|
||||
const canOperate = hasPermission("warehouse.operate");
|
||||
|
||||
const handleRowClick = (receipt: WarehouseReceipt) => {
|
||||
navigate(`/warehouse/receipts/${receipt.id}`);
|
||||
};
|
||||
|
||||
const resetFilters = () => {
|
||||
setSearch("");
|
||||
setStatusFilter("");
|
||||
@@ -79,252 +104,193 @@ export default function WarehouseReceipts() {
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const hasActiveFilters = statusFilter || supplierId || dateFrom || dateTo;
|
||||
const hasActiveFilters = !!(statusFilter || supplierId || dateFrom || dateTo);
|
||||
|
||||
if (isPending) {
|
||||
return (
|
||||
<div className="admin-loading">
|
||||
<div className="admin-spinner" />
|
||||
</div>
|
||||
);
|
||||
return <LoadingState />;
|
||||
}
|
||||
|
||||
const total = pagination?.total ?? items.length;
|
||||
const subtitle = `${total} ${
|
||||
total === 1 ? "doklad" : total >= 2 && total <= 4 ? "doklady" : "dokladů"
|
||||
}`;
|
||||
|
||||
const columns: DataColumn<WarehouseReceipt>[] = [
|
||||
{
|
||||
key: "receipt_number",
|
||||
header: "Číslo dokladu",
|
||||
width: "15%",
|
||||
mono: true,
|
||||
bold: true,
|
||||
render: (r) => r.receipt_number || "—",
|
||||
},
|
||||
{
|
||||
key: "supplier",
|
||||
header: "Dodavatel",
|
||||
width: "22%",
|
||||
render: (r) => r.supplier?.name || "—",
|
||||
},
|
||||
{
|
||||
key: "status",
|
||||
header: "Stav",
|
||||
width: "13%",
|
||||
render: (r) => (
|
||||
<StatusChip
|
||||
label={STATUS_LABEL[r.status] ?? r.status}
|
||||
color={STATUS_COLOR[r.status] ?? "default"}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "delivery_note_number",
|
||||
header: "Dodací list",
|
||||
width: "18%",
|
||||
mono: true,
|
||||
render: (r) => r.delivery_note_number || "—",
|
||||
},
|
||||
{
|
||||
key: "created_at",
|
||||
header: "Vytvořeno",
|
||||
width: "18%",
|
||||
mono: true,
|
||||
render: (r) => formatDate(r.created_at),
|
||||
},
|
||||
{
|
||||
key: "items_count",
|
||||
header: "Položek",
|
||||
width: "14%",
|
||||
mono: true,
|
||||
render: (r) => String(r._count?.items ?? 0),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Box>
|
||||
<motion.div
|
||||
className="admin-page-header"
|
||||
initial={{ opacity: 0, y: 12 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ duration: 0.25 }}
|
||||
>
|
||||
<div>
|
||||
<h1 className="admin-page-title">Příjmové doklady</h1>
|
||||
<p className="admin-page-subtitle">
|
||||
{pagination?.total ?? items.length}{" "}
|
||||
{pagination?.total === 1
|
||||
? "doklad"
|
||||
: pagination?.total !== undefined &&
|
||||
pagination.total >= 2 &&
|
||||
pagination.total <= 4
|
||||
? "doklady"
|
||||
: "dokladů"}
|
||||
</p>
|
||||
</div>
|
||||
<div className="admin-page-actions">
|
||||
{canOperate && (
|
||||
<button
|
||||
onClick={() => navigate("/warehouse/receipts/new")}
|
||||
className="admin-btn admin-btn-primary"
|
||||
>
|
||||
<svg
|
||||
width="20"
|
||||
height="20"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
<PageHeader
|
||||
title="Příjmové doklady"
|
||||
subtitle={subtitle}
|
||||
actions={
|
||||
canOperate ? (
|
||||
<Button
|
||||
startIcon={PlusIcon}
|
||||
onClick={() => navigate("/warehouse/receipts/new")}
|
||||
>
|
||||
<line x1="12" y1="5" x2="12" y2="19" />
|
||||
<line x1="5" y1="12" x2="19" y2="12" />
|
||||
</svg>
|
||||
Nový doklad
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
Nový doklad
|
||||
</Button>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
</motion.div>
|
||||
|
||||
<motion.div
|
||||
className="admin-card"
|
||||
initial={{ opacity: 0, y: 12 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ duration: 0.25, delay: 0.06 }}
|
||||
style={{ opacity: isFetching ? 0.6 : 1, transition: "opacity 0.2s" }}
|
||||
>
|
||||
<div className="admin-card-body">
|
||||
<div className="admin-search-bar mb-4">
|
||||
<div className="admin-search">
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<circle cx="11" cy="11" r="8" />
|
||||
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
||||
</svg>
|
||||
<input
|
||||
type="text"
|
||||
value={search}
|
||||
onChange={(e) => {
|
||||
setSearch(e.target.value);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder="Hledat podle čísla dokladu..."
|
||||
className="admin-form-input"
|
||||
/>
|
||||
</div>
|
||||
<select
|
||||
value={statusFilter}
|
||||
onChange={(e) => {
|
||||
setStatusFilter(e.target.value);
|
||||
setPage(1);
|
||||
}}
|
||||
className="admin-form-select"
|
||||
>
|
||||
<option value="">Všechny stavy</option>
|
||||
<option value="DRAFT">Návrh</option>
|
||||
<option value="CONFIRMED">Potvrzeno</option>
|
||||
<option value="CANCELLED">Zrušeno</option>
|
||||
</select>
|
||||
{suppliers.length > 0 && (
|
||||
<select
|
||||
value={supplierId}
|
||||
onChange={(e) => {
|
||||
setSupplierId(
|
||||
e.target.value === "" ? "" : Number(e.target.value),
|
||||
);
|
||||
setPage(1);
|
||||
}}
|
||||
className="admin-form-select"
|
||||
>
|
||||
<option value="">Všichni dodavatelé</option>
|
||||
{suppliers.map((s) => (
|
||||
<option key={s.id} value={s.id}>
|
||||
{s.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
)}
|
||||
<AdminDatePicker
|
||||
mode="date"
|
||||
value={dateFrom}
|
||||
<FilterBar>
|
||||
<Box sx={{ flex: "1 1 220px" }}>
|
||||
<TextField
|
||||
value={search}
|
||||
onChange={(e) => {
|
||||
setSearch(e.target.value);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder="Hledat podle čísla dokladu..."
|
||||
fullWidth
|
||||
/>
|
||||
</Box>
|
||||
<Box sx={{ flex: "0 0 160px" }}>
|
||||
<Select
|
||||
value={statusFilter}
|
||||
onChange={(val) => {
|
||||
setStatusFilter(val);
|
||||
setPage(1);
|
||||
}}
|
||||
options={[
|
||||
{ value: "", label: "Všechny stavy" },
|
||||
{ value: "DRAFT", label: "Návrh" },
|
||||
{ value: "CONFIRMED", label: "Potvrzeno" },
|
||||
{ value: "CANCELLED", label: "Zrušeno" },
|
||||
]}
|
||||
/>
|
||||
</Box>
|
||||
{suppliers.length > 0 && (
|
||||
<Box sx={{ flex: "0 0 200px" }}>
|
||||
<Select
|
||||
value={supplierId === "" ? "" : String(supplierId)}
|
||||
onChange={(val) => {
|
||||
setDateFrom(val);
|
||||
setSupplierId(val === "" ? "" : Number(val));
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder="Od"
|
||||
options={[
|
||||
{ value: "", label: "Všichni dodavatelé" },
|
||||
...suppliers.map((s) => ({
|
||||
value: String(s.id),
|
||||
label: s.name,
|
||||
})),
|
||||
]}
|
||||
/>
|
||||
<AdminDatePicker
|
||||
mode="date"
|
||||
value={dateTo}
|
||||
onChange={(val) => {
|
||||
setDateTo(val);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder="Do"
|
||||
/>
|
||||
{hasActiveFilters && (
|
||||
<button
|
||||
type="button"
|
||||
className="admin-btn admin-btn-secondary"
|
||||
onClick={resetFilters}
|
||||
style={{ whiteSpace: "nowrap" }}
|
||||
>
|
||||
Zrušit filtry
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</Box>
|
||||
)}
|
||||
<Box sx={{ flex: "0 0 150px" }}>
|
||||
<DateField
|
||||
value={dateFrom}
|
||||
onChange={(val) => {
|
||||
setDateFrom(val);
|
||||
setPage(1);
|
||||
}}
|
||||
label="Od"
|
||||
/>
|
||||
</Box>
|
||||
<Box sx={{ flex: "0 0 150px" }}>
|
||||
<DateField
|
||||
value={dateTo}
|
||||
onChange={(val) => {
|
||||
setDateTo(val);
|
||||
setPage(1);
|
||||
}}
|
||||
label="Do"
|
||||
/>
|
||||
</Box>
|
||||
{hasActiveFilters && (
|
||||
<Button variant="outlined" onClick={resetFilters}>
|
||||
Zrušit filtry
|
||||
</Button>
|
||||
)}
|
||||
</FilterBar>
|
||||
|
||||
<AnimatePresence mode="wait">
|
||||
<motion.div
|
||||
key={`${debouncedSearch}-${statusFilter}-${supplierId}-${dateFrom}-${dateTo}-${page}-${items.length}`}
|
||||
initial={{ opacity: 0, y: 6 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
exit={{ opacity: 0 }}
|
||||
transition={{ duration: 0.15 }}
|
||||
>
|
||||
{items.length === 0 && (
|
||||
<div className="admin-empty-state">
|
||||
<div className="admin-empty-icon">
|
||||
<svg
|
||||
width="28"
|
||||
height="28"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" />
|
||||
<polyline points="14 2 14 8 20 8" />
|
||||
<line x1="16" y1="13" x2="8" y2="13" />
|
||||
<line x1="16" y1="17" x2="8" y2="17" />
|
||||
</svg>
|
||||
</div>
|
||||
<p>
|
||||
{search || hasActiveFilters
|
||||
? "Žádné doklady pro zadaný filtr."
|
||||
: "Zatím nejsou žádné příjmové doklady."}
|
||||
</p>
|
||||
{canOperate && !search && !hasActiveFilters && (
|
||||
<button
|
||||
<Card sx={{ opacity: isFetching ? 0.6 : 1, transition: "opacity .2s" }}>
|
||||
<DataTable<WarehouseReceipt>
|
||||
columns={columns}
|
||||
rows={items}
|
||||
rowKey={(r) => r.id}
|
||||
onRowClick={(r) => navigate(`/warehouse/receipts/${r.id}`)}
|
||||
empty={
|
||||
search || hasActiveFilters ? (
|
||||
<EmptyState title="Žádné doklady pro zadaný filtr." />
|
||||
) : (
|
||||
<EmptyState
|
||||
title="Zatím nejsou žádné příjmové doklady."
|
||||
action={
|
||||
canOperate ? (
|
||||
<Button
|
||||
startIcon={PlusIcon}
|
||||
onClick={() => navigate("/warehouse/receipts/new")}
|
||||
className="admin-btn admin-btn-primary"
|
||||
>
|
||||
Vytvořit první doklad
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{items.length > 0 && (
|
||||
<div className="admin-table-responsive">
|
||||
<table className="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Číslo dokladu</th>
|
||||
<th >Dodavatel</th>
|
||||
<th>Stav</th>
|
||||
<th>Dodací list</th>
|
||||
<th>Vytvořeno</th>
|
||||
<th>Položek</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{items.map((receipt) => (
|
||||
<tr
|
||||
key={receipt.id}
|
||||
onClick={() => handleRowClick(receipt)}
|
||||
style={{ cursor: "pointer" }}
|
||||
>
|
||||
<td className="admin-mono fw-500">
|
||||
{receipt.receipt_number || "—"}
|
||||
</td>
|
||||
<td >
|
||||
{receipt.supplier?.name || "—"}
|
||||
</td>
|
||||
<td>
|
||||
<span
|
||||
className={`admin-badge ${STATUS_BADGE[receipt.status] ?? ""}`}
|
||||
>
|
||||
{STATUS_LABEL[receipt.status] ?? receipt.status}
|
||||
</span>
|
||||
</td>
|
||||
<td className="admin-mono">
|
||||
{receipt.delivery_note_number || "—"}
|
||||
</td>
|
||||
<td className="admin-mono">
|
||||
{formatDate(receipt.created_at)}
|
||||
</td>
|
||||
<td className="admin-mono">
|
||||
{receipt._count?.items ?? 0}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</motion.div>
|
||||
</AnimatePresence>
|
||||
|
||||
<Pagination pagination={pagination} onPageChange={setPage} />
|
||||
</div>
|
||||
</motion.div>
|
||||
</div>
|
||||
</Button>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Pagination
|
||||
page={page}
|
||||
pageCount={pagination?.total_pages ?? 1}
|
||||
onChange={setPage}
|
||||
/>
|
||||
</Card>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user