feat(mui): migrate Warehouse Locations (Lokace) onto MUI kit
Replace legacy admin-* CSS, hand-rolled AnimatePresence modal, ConfirmModal, FormField, and useModalLock with PageHeader, Card, DataTable (rowInactive), Modal, ConfirmDialog, Field, TextField, StatusChip (clickable toggle), EmptyState, LoadingState, and MUI IconButton. All four mutations + ["warehouse"] invalidation and is_active toggle preserved verbatim. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,18 +1,29 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import IconButton from "@mui/material/IconButton";
|
||||||
import { useAlert } from "../context/AlertContext";
|
import { useAlert } from "../context/AlertContext";
|
||||||
import { useAuth } from "../context/AuthContext";
|
import { useAuth } from "../context/AuthContext";
|
||||||
import Forbidden from "../components/Forbidden";
|
import Forbidden from "../components/Forbidden";
|
||||||
import { motion, AnimatePresence } from "framer-motion";
|
|
||||||
import ConfirmModal from "../components/ConfirmModal";
|
|
||||||
import useModalLock from "../hooks/useModalLock";
|
|
||||||
|
|
||||||
import FormField from "../components/FormField";
|
|
||||||
import {
|
import {
|
||||||
warehouseLocationListOptions,
|
warehouseLocationListOptions,
|
||||||
type WarehouseLocation,
|
type WarehouseLocation,
|
||||||
} from "../lib/queries/warehouse";
|
} from "../lib/queries/warehouse";
|
||||||
import { useApiMutation } from "../lib/queries/mutations";
|
import { useApiMutation } from "../lib/queries/mutations";
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
DataTable,
|
||||||
|
Modal,
|
||||||
|
ConfirmDialog,
|
||||||
|
Field,
|
||||||
|
TextField,
|
||||||
|
StatusChip,
|
||||||
|
PageHeader,
|
||||||
|
EmptyState,
|
||||||
|
LoadingState,
|
||||||
|
type DataColumn,
|
||||||
|
} from "../ui";
|
||||||
|
|
||||||
const API_BASE = "/api/admin/warehouse/locations";
|
const API_BASE = "/api/admin/warehouse/locations";
|
||||||
|
|
||||||
@@ -22,6 +33,50 @@ interface LocationForm {
|
|||||||
description: string;
|
description: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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>
|
||||||
|
);
|
||||||
|
const EditIcon = (
|
||||||
|
<svg
|
||||||
|
width="18"
|
||||||
|
height="18"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="2"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
>
|
||||||
|
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7" />
|
||||||
|
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z" />
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
const DeleteIcon = (
|
||||||
|
<svg
|
||||||
|
width="18"
|
||||||
|
height="18"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="2"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
>
|
||||||
|
<polyline points="3 6 5 6 21 6" />
|
||||||
|
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
|
||||||
export default function WarehouseLocations() {
|
export default function WarehouseLocations() {
|
||||||
const alert = useAlert();
|
const alert = useAlert();
|
||||||
const { hasPermission } = useAuth();
|
const { hasPermission } = useAuth();
|
||||||
@@ -96,8 +151,6 @@ export default function WarehouseLocations() {
|
|||||||
invalidate: ["warehouse"],
|
invalidate: ["warehouse"],
|
||||||
});
|
});
|
||||||
|
|
||||||
useModalLock(showModal);
|
|
||||||
|
|
||||||
if (!hasPermission("warehouse.manage")) return <Forbidden />;
|
if (!hasPermission("warehouse.manage")) return <Forbidden />;
|
||||||
|
|
||||||
const openCreateModal = () => {
|
const openCreateModal = () => {
|
||||||
@@ -175,272 +228,166 @@ export default function WarehouseLocations() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (isPending) {
|
if (isPending) {
|
||||||
return (
|
return <LoadingState />;
|
||||||
<div className="admin-loading">
|
|
||||||
<div className="admin-spinner" />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
const total = locations.length;
|
||||||
<div>
|
const subtitle = `${total} ${
|
||||||
<motion.div
|
total === 1
|
||||||
className="admin-page-header"
|
? "umístění"
|
||||||
initial={{ opacity: 0, y: 12 }}
|
: total >= 2 && total <= 4
|
||||||
animate={{ opacity: 1, y: 0 }}
|
? "umístění"
|
||||||
transition={{ duration: 0.25 }}
|
: "umístění"
|
||||||
>
|
}`;
|
||||||
<div>
|
|
||||||
<h1 className="admin-page-title">Umístění skladu</h1>
|
|
||||||
</div>
|
|
||||||
<div className="admin-page-actions">
|
|
||||||
<button
|
|
||||||
onClick={openCreateModal}
|
|
||||||
className="admin-btn admin-btn-primary"
|
|
||||||
>
|
|
||||||
<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>
|
|
||||||
Přidat umístění
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</motion.div>
|
|
||||||
|
|
||||||
<motion.div
|
const columns: DataColumn<WarehouseLocation>[] = [
|
||||||
className="admin-card"
|
{
|
||||||
initial={{ opacity: 0, y: 12 }}
|
key: "code",
|
||||||
animate={{ opacity: 1, y: 0 }}
|
header: "Kód",
|
||||||
transition={{ duration: 0.25, delay: 0.06 }}
|
width: "15%",
|
||||||
>
|
mono: true,
|
||||||
<div className="admin-card-body">
|
bold: true,
|
||||||
{locations.length === 0 && (
|
render: (l) => l.code,
|
||||||
<div className="admin-empty-state">
|
},
|
||||||
<div className="admin-empty-icon">
|
{
|
||||||
<svg
|
key: "name",
|
||||||
width="28"
|
header: "Název",
|
||||||
height="28"
|
width: "25%",
|
||||||
viewBox="0 0 24 24"
|
render: (l) => l.name,
|
||||||
fill="none"
|
},
|
||||||
stroke="currentColor"
|
{
|
||||||
strokeWidth="1.5"
|
key: "description",
|
||||||
strokeLinecap="round"
|
header: "Popis",
|
||||||
strokeLinejoin="round"
|
width: "35%",
|
||||||
>
|
render: (l) => l.description || "—",
|
||||||
<path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z" />
|
},
|
||||||
<circle cx="12" cy="10" r="3" />
|
{
|
||||||
</svg>
|
key: "status",
|
||||||
</div>
|
header: "Stav",
|
||||||
<p>Zatím nejsou žádná umístění.</p>
|
width: "15%",
|
||||||
<button
|
render: (l) => (
|
||||||
onClick={openCreateModal}
|
<StatusChip
|
||||||
className="admin-btn admin-btn-primary"
|
label={l.is_active ? "Aktivní" : "Neaktivní"}
|
||||||
>
|
color={l.is_active ? "success" : "default"}
|
||||||
Přidat první umístění
|
onClick={() => toggleActive(l)}
|
||||||
</button>
|
/>
|
||||||
</div>
|
),
|
||||||
)}
|
},
|
||||||
{locations.length > 0 && (
|
{
|
||||||
<div className="admin-table-responsive">
|
key: "actions",
|
||||||
<table className="admin-table">
|
header: "Akce",
|
||||||
<thead>
|
width: "10%",
|
||||||
<tr>
|
align: "right",
|
||||||
<th>Kód</th>
|
render: (l) => (
|
||||||
<th>Název</th>
|
<Box sx={{ display: "flex", gap: 0.5, justifyContent: "flex-end" }}>
|
||||||
<th>Popis</th>
|
<IconButton
|
||||||
<th>Stav</th>
|
size="small"
|
||||||
<th>Akce</th>
|
onClick={() => openEditModal(l)}
|
||||||
</tr>
|
aria-label="Upravit"
|
||||||
</thead>
|
title="Upravit"
|
||||||
<tbody>
|
>
|
||||||
{locations.map((location) => (
|
{EditIcon}
|
||||||
<tr
|
</IconButton>
|
||||||
key={location.id}
|
<IconButton
|
||||||
className={
|
size="small"
|
||||||
!location.is_active ? "admin-table-row-inactive" : ""
|
color="error"
|
||||||
}
|
onClick={() => setDeleteConfirm({ show: true, location: l })}
|
||||||
>
|
aria-label="Smazat"
|
||||||
<td className="admin-mono fw-500">{location.code}</td>
|
title="Smazat"
|
||||||
<td>{location.name}</td>
|
>
|
||||||
<td>{location.description || "—"}</td>
|
{DeleteIcon}
|
||||||
<td>
|
</IconButton>
|
||||||
<button
|
</Box>
|
||||||
onClick={() => toggleActive(location)}
|
),
|
||||||
className={`admin-badge ${location.is_active ? "admin-badge-active" : "admin-badge-inactive"}`}
|
},
|
||||||
>
|
];
|
||||||
{location.is_active ? "Aktivní" : "Neaktivní"}
|
|
||||||
</button>
|
return (
|
||||||
</td>
|
<Box>
|
||||||
<td>
|
<PageHeader
|
||||||
<div className="admin-table-actions">
|
title="Umístění skladu"
|
||||||
<button
|
subtitle={subtitle}
|
||||||
onClick={() => openEditModal(location)}
|
actions={
|
||||||
className="admin-btn-icon"
|
<Button startIcon={PlusIcon} onClick={openCreateModal}>
|
||||||
title="Upravit"
|
Přidat umístění
|
||||||
aria-label="Upravit"
|
</Button>
|
||||||
>
|
}
|
||||||
<svg
|
/>
|
||||||
width="18"
|
|
||||||
height="18"
|
<Card>
|
||||||
viewBox="0 0 24 24"
|
<DataTable<WarehouseLocation>
|
||||||
fill="none"
|
columns={columns}
|
||||||
stroke="currentColor"
|
rows={locations}
|
||||||
strokeWidth="2"
|
rowKey={(l) => l.id}
|
||||||
strokeLinecap="round"
|
rowInactive={(l) => !l.is_active}
|
||||||
strokeLinejoin="round"
|
empty={
|
||||||
>
|
<EmptyState
|
||||||
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7" />
|
title="Zatím nejsou žádná umístění."
|
||||||
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z" />
|
action={
|
||||||
</svg>
|
<Button startIcon={PlusIcon} onClick={openCreateModal}>
|
||||||
</button>
|
Přidat první umístění
|
||||||
<button
|
</Button>
|
||||||
onClick={() =>
|
}
|
||||||
setDeleteConfirm({ show: true, location })
|
/>
|
||||||
}
|
}
|
||||||
className="admin-btn-icon danger"
|
/>
|
||||||
title="Smazat"
|
</Card>
|
||||||
aria-label="Smazat"
|
|
||||||
>
|
|
||||||
<svg
|
|
||||||
width="18"
|
|
||||||
height="18"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
fill="none"
|
|
||||||
stroke="currentColor"
|
|
||||||
strokeWidth="2"
|
|
||||||
strokeLinecap="round"
|
|
||||||
strokeLinejoin="round"
|
|
||||||
>
|
|
||||||
<polyline points="3 6 5 6 21 6" />
|
|
||||||
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</motion.div>
|
|
||||||
|
|
||||||
{/* Add/Edit Modal */}
|
{/* Add/Edit Modal */}
|
||||||
<AnimatePresence>
|
<Modal
|
||||||
{showModal && (
|
isOpen={showModal}
|
||||||
<motion.div
|
onClose={() => setShowModal(false)}
|
||||||
className="admin-modal-overlay"
|
onSubmit={handleSubmit}
|
||||||
initial={{ opacity: 0 }}
|
title={editingLocation ? "Upravit umístění" : "Přidat umístění"}
|
||||||
animate={{ opacity: 1 }}
|
loading={
|
||||||
exit={{ opacity: 0 }}
|
createLocationMutation.isPending || updateLocationMutation.isPending
|
||||||
transition={{ duration: 0.2 }}
|
}
|
||||||
>
|
>
|
||||||
<div
|
<Box
|
||||||
className="admin-modal-backdrop"
|
sx={{
|
||||||
onClick={() => setShowModal(false)}
|
display: "grid",
|
||||||
|
gridTemplateColumns: { xs: "1fr", sm: "1fr 1fr" },
|
||||||
|
gap: 2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Field label="Kód" required error={errors.code}>
|
||||||
|
<TextField
|
||||||
|
value={form.code}
|
||||||
|
error={!!errors.code}
|
||||||
|
onChange={(e) => {
|
||||||
|
setForm({ ...form, code: e.target.value.toUpperCase() });
|
||||||
|
setErrors((prev) => ({ ...prev, code: "" }));
|
||||||
|
}}
|
||||||
|
placeholder="A-01"
|
||||||
/>
|
/>
|
||||||
<motion.div
|
</Field>
|
||||||
className="admin-modal"
|
|
||||||
initial={{ opacity: 0, scale: 0.95, y: 20 }}
|
|
||||||
animate={{ opacity: 1, scale: 1, y: 0 }}
|
|
||||||
exit={{ opacity: 0, scale: 0.95, y: 20 }}
|
|
||||||
transition={{ duration: 0.2 }}
|
|
||||||
>
|
|
||||||
<div className="admin-modal-header">
|
|
||||||
<h2 className="admin-modal-title">
|
|
||||||
{editingLocation ? "Upravit umístění" : "Přidat umístění"}
|
|
||||||
</h2>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="admin-modal-body">
|
<Field label="Název" required error={errors.name}>
|
||||||
<div className="admin-form">
|
<TextField
|
||||||
<div className="admin-form-row">
|
value={form.name}
|
||||||
<FormField label="Kód" error={errors.code} required>
|
error={!!errors.name}
|
||||||
<input
|
onChange={(e) => {
|
||||||
type="text"
|
setForm({ ...form, name: e.target.value });
|
||||||
value={form.code}
|
setErrors((prev) => ({ ...prev, name: "" }));
|
||||||
onChange={(e) => {
|
}}
|
||||||
setForm({
|
placeholder="Regál A, polička 1"
|
||||||
...form,
|
/>
|
||||||
code: e.target.value.toUpperCase(),
|
</Field>
|
||||||
});
|
</Box>
|
||||||
setErrors((prev) => ({
|
|
||||||
...prev,
|
|
||||||
code: "",
|
|
||||||
}));
|
|
||||||
}}
|
|
||||||
className="admin-form-input"
|
|
||||||
placeholder="A-01"
|
|
||||||
aria-invalid={!!errors.code}
|
|
||||||
/>
|
|
||||||
</FormField>
|
|
||||||
|
|
||||||
<FormField label="Název" error={errors.name} required>
|
<Field label="Popis">
|
||||||
<input
|
<TextField
|
||||||
type="text"
|
multiline
|
||||||
value={form.name}
|
minRows={3}
|
||||||
onChange={(e) => {
|
value={form.description}
|
||||||
setForm({ ...form, name: e.target.value });
|
onChange={(e) => setForm({ ...form, description: e.target.value })}
|
||||||
setErrors((prev) => ({
|
placeholder="Volitelný popis umístění"
|
||||||
...prev,
|
/>
|
||||||
name: "",
|
</Field>
|
||||||
}));
|
</Modal>
|
||||||
}}
|
|
||||||
className="admin-form-input"
|
|
||||||
placeholder="Regál A, polička 1"
|
|
||||||
aria-invalid={!!errors.name}
|
|
||||||
/>
|
|
||||||
</FormField>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<FormField label="Popis">
|
|
||||||
<textarea
|
|
||||||
value={form.description}
|
|
||||||
onChange={(e) =>
|
|
||||||
setForm({
|
|
||||||
...form,
|
|
||||||
description: e.target.value,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
className="admin-form-input"
|
|
||||||
rows={3}
|
|
||||||
placeholder="Volitelný popis umístění"
|
|
||||||
/>
|
|
||||||
</FormField>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="admin-modal-footer">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => setShowModal(false)}
|
|
||||||
className="admin-btn admin-btn-secondary"
|
|
||||||
>
|
|
||||||
Zrušit
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={handleSubmit}
|
|
||||||
className="admin-btn admin-btn-primary"
|
|
||||||
>
|
|
||||||
Uložit
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</motion.div>
|
|
||||||
</motion.div>
|
|
||||||
)}
|
|
||||||
</AnimatePresence>
|
|
||||||
|
|
||||||
{/* Delete Confirmation */}
|
{/* Delete Confirmation */}
|
||||||
<ConfirmModal
|
<ConfirmDialog
|
||||||
isOpen={deleteConfirm.show}
|
isOpen={deleteConfirm.show}
|
||||||
onClose={() => setDeleteConfirm({ show: false, location: null })}
|
onClose={() => setDeleteConfirm({ show: false, location: null })}
|
||||||
onConfirm={handleDelete}
|
onConfirm={handleDelete}
|
||||||
@@ -454,6 +401,6 @@ export default function WarehouseLocations() {
|
|||||||
confirmVariant="danger"
|
confirmVariant="danger"
|
||||||
loading={deleteMutation.isPending}
|
loading={deleteMutation.isPending}
|
||||||
/>
|
/>
|
||||||
</div>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user