diff --git a/src/admin/pages/OffersTemplates.tsx b/src/admin/pages/OffersTemplates.tsx index 4f91c14..107fcca 100644 --- a/src/admin/pages/OffersTemplates.tsx +++ b/src/admin/pages/OffersTemplates.tsx @@ -1,11 +1,11 @@ -import { useState, useRef, type ReactNode } from "react"; +import { useState, useRef } from "react"; import { useQuery } from "@tanstack/react-query"; +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 { motion } from "framer-motion"; -import ConfirmModal from "../components/ConfirmModal"; -import FormModal from "../components/FormModal"; -import FormField from "../components/FormField"; import Forbidden from "../components/Forbidden"; import RichEditor from "../components/RichEditor"; import { @@ -16,8 +16,24 @@ import { type ScopeSection, } from "../lib/queries/offers"; import { useApiMutation } from "../lib/queries/mutations"; - import apiFetch from "../utils/api"; +import { + Button, + Card, + DataTable, + Modal, + ConfirmDialog, + Field, + TextField, + StatusChip, + PageHeader, + EmptyState, + LoadingState, + Tabs, + TabPanel, + type DataColumn, + type TabDef, +} from "../ui"; const API_BASE = "/api/admin"; @@ -33,45 +49,130 @@ interface ScopeForm { sections: ScopeSection[]; } +const PlusIcon = ( + + + + +); +const EditIcon = ( + + + + +); +const DeleteIcon = ( + + + + +); +const UpIcon = ( + + + +); +const DownIcon = ( + + + +); +const RemoveIcon = ( + + + + +); + export default function OffersTemplates() { const { hasPermission } = useAuth(); const [activeTab, setActiveTab] = useState<"items" | "scopes">("items"); if (!hasPermission("settings.templates")) return ; + const tabs: TabDef[] = [ + { value: "items", label: "Šablony položek" }, + { value: "scopes", label: "Šablony rozsahu" }, + ]; + return ( -
+ -
-

Šablony

-

- Šablony položek a rozsahu projektu -

-
+
-
- - -
+ + setActiveTab(v as "items" | "scopes")} + tabs={tabs} + /> + - {activeTab === "items" ? : } -
+ + + + + + + ); } @@ -169,183 +270,158 @@ function ItemTemplatesTab() { }; if (isPending) { - return ( -
-
-
- ); + return ; } - return ( - <> - -
-

- Šablony položek ({templates.length}) -

- -
-
- {templates.length === 0 ? ( -
-

Zatím žádné šablony položek.

-
- ) : ( -
- - - - - - - - - - - - {templates.map((t) => ( - - - - - - - - ))} - -
NázevPopisCenaKategorieAkce
{t.name} - {t.description || "—"} - {Number(t.default_price).toFixed(2)} - {t.category || "—"} - -
- - -
-
-
- )} -
-
+ {EditIcon} + + setDeleteConfirm({ show: true, template: t })} + aria-label="Smazat" + title="Smazat" + > + {DeleteIcon} + + + ), + }, + ]; + + return ( + + + + Šablony položek ({templates.length}) + + + + + + + columns={columns} + rows={templates} + rowKey={(t) => t.id} + empty={} + /> + {/* Item Template Modal */} - setShowModal(false)} onSubmit={handleSubmit} title={editingTemplate ? "Upravit šablonu" : "Nová šablona položky"} - submitLabel={editingTemplate ? "Uložit" : "Vytvořit"} + submitText={editingTemplate ? "Uložit" : "Vytvořit"} loading={saving} + maxWidth="md" > -
- - setForm((p) => ({ ...p, name: e.target.value }))} - className="admin-form-input" - /> - - -