feat(orders): invoices-style landing — month selector + Vydane-first tabs, content-only tab bodies
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,7 @@ import { useAlert } from "../context/AlertContext";
|
||||
import { useAuth } from "../context/AuthContext";
|
||||
import Forbidden from "../components/Forbidden";
|
||||
import apiFetch from "../utils/api";
|
||||
import { formatCurrency, formatDate, czechPlural } from "../utils/formatters";
|
||||
import { formatCurrency, formatDate } from "../utils/formatters";
|
||||
import useTableSort from "../hooks/useTableSort";
|
||||
import useDebounce from "../hooks/useDebounce";
|
||||
import { usePaginatedQuery } from "../hooks/usePaginatedQuery";
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
import { offerCustomersOptions } from "../lib/queries/offers";
|
||||
import { useApiMutation } from "../lib/queries/mutations";
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
DataTable,
|
||||
Pagination,
|
||||
@@ -30,8 +29,6 @@ import {
|
||||
StatusChip,
|
||||
CheckboxField,
|
||||
FileUpload,
|
||||
PageHeader,
|
||||
PageEnter,
|
||||
FilterBar,
|
||||
EmptyState,
|
||||
LoadingState,
|
||||
@@ -70,19 +67,6 @@ interface Order {
|
||||
invoice_id?: number;
|
||||
}
|
||||
|
||||
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 ViewIcon = (
|
||||
<svg
|
||||
width="18"
|
||||
@@ -151,7 +135,19 @@ const DeleteIcon = (
|
||||
</svg>
|
||||
);
|
||||
|
||||
export default function OrdersReceived() {
|
||||
interface OrdersReceivedProps {
|
||||
month: number;
|
||||
year: number;
|
||||
createOpen: boolean;
|
||||
setCreateOpen: (open: boolean) => void;
|
||||
}
|
||||
|
||||
export default function OrdersReceived({
|
||||
month,
|
||||
year,
|
||||
createOpen,
|
||||
setCreateOpen,
|
||||
}: OrdersReceivedProps) {
|
||||
const alert = useAlert();
|
||||
const { hasPermission } = useAuth();
|
||||
|
||||
@@ -180,7 +176,6 @@ export default function OrdersReceived() {
|
||||
},
|
||||
});
|
||||
|
||||
const [showCreate, setShowCreate] = useState(false);
|
||||
const [createForm, setCreateForm] = useState({
|
||||
customer_id: "",
|
||||
customer_order_number: "",
|
||||
@@ -201,14 +196,15 @@ export default function OrdersReceived() {
|
||||
|
||||
const customersQuery = useQuery({
|
||||
...offerCustomersOptions(),
|
||||
enabled: showCreate,
|
||||
enabled: createOpen,
|
||||
});
|
||||
const nextNumberQuery = useQuery({
|
||||
...orderNextNumberOptions(),
|
||||
enabled: showCreate,
|
||||
enabled: createOpen,
|
||||
});
|
||||
|
||||
const openCreate = () => {
|
||||
const closeCreate = () => {
|
||||
setCreateOpen(false);
|
||||
setCreateForm({
|
||||
customer_id: "",
|
||||
customer_order_number: "",
|
||||
@@ -223,7 +219,6 @@ export default function OrdersReceived() {
|
||||
quantity: "1",
|
||||
});
|
||||
setOrderAttachment(null);
|
||||
setShowCreate(true);
|
||||
};
|
||||
|
||||
const handleCreate = async () => {
|
||||
@@ -283,7 +278,7 @@ export default function OrdersReceived() {
|
||||
const response = await apiFetch(`${API_BASE}/orders`, fetchOptions);
|
||||
const result = await response.json();
|
||||
if (result.success) {
|
||||
setShowCreate(false);
|
||||
closeCreate();
|
||||
alert.success(result.message || "Objednávka byla vytvořena");
|
||||
await queryClient.invalidateQueries({ queryKey: ["orders"] });
|
||||
await queryClient.invalidateQueries({ queryKey: ["projects"] });
|
||||
@@ -306,7 +301,14 @@ export default function OrdersReceived() {
|
||||
isPending,
|
||||
isFetching,
|
||||
} = usePaginatedQuery<Order>(
|
||||
orderListOptions({ search: debouncedSearch, sort, order, page }),
|
||||
orderListOptions({
|
||||
search: debouncedSearch,
|
||||
sort,
|
||||
order,
|
||||
page,
|
||||
month,
|
||||
year,
|
||||
}),
|
||||
);
|
||||
|
||||
if (!hasPermission("orders.view")) return <Forbidden />;
|
||||
@@ -327,14 +329,6 @@ export default function OrdersReceived() {
|
||||
return <LoadingState />;
|
||||
}
|
||||
|
||||
const total = pagination?.total ?? orders.length;
|
||||
const subtitle = `${total} ${czechPlural(
|
||||
total,
|
||||
"objednávka",
|
||||
"objednávky",
|
||||
"objednávek",
|
||||
)}`;
|
||||
|
||||
const columns: DataColumn<Order>[] = [
|
||||
{
|
||||
key: "order_number",
|
||||
@@ -463,19 +457,7 @@ export default function OrdersReceived() {
|
||||
];
|
||||
|
||||
return (
|
||||
<PageEnter>
|
||||
<PageHeader
|
||||
title="Objednávky"
|
||||
subtitle={subtitle}
|
||||
actions={
|
||||
hasPermission("orders.create") ? (
|
||||
<Button startIcon={PlusIcon} onClick={openCreate}>
|
||||
Vytvořit objednávku
|
||||
</Button>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
|
||||
<>
|
||||
<FilterBar>
|
||||
<Box sx={{ flex: "1 1 320px" }}>
|
||||
<TextField
|
||||
@@ -537,8 +519,8 @@ export default function OrdersReceived() {
|
||||
</ConfirmDialog>
|
||||
|
||||
<Modal
|
||||
isOpen={showCreate}
|
||||
onClose={() => setShowCreate(false)}
|
||||
isOpen={createOpen}
|
||||
onClose={closeCreate}
|
||||
onSubmit={handleCreate}
|
||||
title="Vytvořit objednávku bez nabídky"
|
||||
subtitle={`Číslo objednávky: ${
|
||||
@@ -699,6 +681,6 @@ export default function OrdersReceived() {
|
||||
onChange={(v) => setCreateForm({ ...createForm, create_project: v })}
|
||||
/>
|
||||
</Modal>
|
||||
</PageEnter>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user