diff --git a/src/admin/pages/Orders.tsx b/src/admin/pages/Orders.tsx
index cbecfe4..8a649c8 100644
--- a/src/admin/pages/Orders.tsx
+++ b/src/admin/pages/Orders.tsx
@@ -1,16 +1,23 @@
import { useState } from "react";
+import { useQuery } from "@tanstack/react-query";
import { useAlert } from "../context/AlertContext";
import { useAuth } from "../context/AuthContext";
import { Link } from "react-router-dom";
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 { formatCurrency, formatDate, czechPlural } from "../utils/formatters";
import SortIcon from "../components/SortIcon";
import useTableSort from "../hooks/useTableSort";
import { usePaginatedQuery } from "../hooks/usePaginatedQuery";
-import { orderListOptions } from "../lib/queries/orders";
+import {
+ orderListOptions,
+ orderNextNumberOptions,
+} from "../lib/queries/orders";
+import { offerCustomersOptions } from "../lib/queries/offers";
import { useApiMutation } from "../lib/queries/mutations";
import Pagination from "../components/Pagination";
@@ -71,6 +78,77 @@ export default function Orders() {
},
});
+ const [showCreate, setShowCreate] = useState(false);
+ const [createForm, setCreateForm] = useState({
+ customer_id: "",
+ customer_order_number: "",
+ currency: "CZK",
+ vat_rate: "21",
+ apply_vat: true,
+ scope_title: "",
+ scope_description: "",
+ notes: "",
+ create_project: true,
+ });
+ const [creating, setCreating] = useState(false);
+
+ const customersQuery = useQuery({
+ ...offerCustomersOptions(),
+ enabled: showCreate,
+ });
+ const nextNumberQuery = useQuery({
+ ...orderNextNumberOptions(),
+ enabled: showCreate,
+ });
+
+ // The payload normalises customer_id: "" → null. CreateOrderSchema's
+ // customer_id coercion does NOT special-case "", so a raw "" would become
+ // Number("") = 0 and hit a foreign-key violation.
+ type OrderCreatePayload = Omit
+ Číslo objednávky:{" "} + + {nextNumberQuery.data?.number ?? + nextNumberQuery.data?.next_number ?? + "…"} + {" "} + (přiděleno automaticky) +
+