refactor(ui): single shared documentStatus map across offers/invoices/orders (fix issued color drift, add offers status chip)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -67,6 +67,11 @@ import {
|
||||
RichTextView,
|
||||
headerActionsSx,
|
||||
} from "../ui";
|
||||
import {
|
||||
INVOICE_STATUS,
|
||||
statusLabel,
|
||||
statusColor,
|
||||
} from "../lib/documentStatus";
|
||||
|
||||
const API_BASE = "/api/admin";
|
||||
|
||||
@@ -97,21 +102,6 @@ function addDaysLocalStr(days: number, base?: string): string {
|
||||
return `${result.getFullYear()}-${mm}-${dd}`;
|
||||
}
|
||||
|
||||
const STATUS_LABELS: Record<string, string> = {
|
||||
issued: "Vystavena",
|
||||
paid: "Zaplacena",
|
||||
overdue: "Po splatnosti",
|
||||
};
|
||||
|
||||
const STATUS_COLORS: Record<
|
||||
string,
|
||||
"default" | "success" | "error" | "warning" | "info"
|
||||
> = {
|
||||
issued: "info",
|
||||
paid: "success",
|
||||
overdue: "error",
|
||||
};
|
||||
|
||||
const TRANSITION_LABELS: Record<string, string> = { paid: "Zaplaceno" };
|
||||
|
||||
const BackIcon = (
|
||||
@@ -1141,8 +1131,8 @@ export default function InvoiceDetail() {
|
||||
Faktura {invoice.invoice_number}
|
||||
</Typography>
|
||||
<StatusChip
|
||||
label={STATUS_LABELS[invoice.status] || invoice.status}
|
||||
color={STATUS_COLORS[invoice.status] || "default"}
|
||||
label={statusLabel(INVOICE_STATUS, invoice.status)}
|
||||
color={statusColor(INVOICE_STATUS, invoice.status)}
|
||||
/>
|
||||
</Box>
|
||||
</Box>
|
||||
@@ -1658,8 +1648,8 @@ export default function InvoiceDetail() {
|
||||
Faktura {invoice.invoice_number}
|
||||
</Typography>
|
||||
<StatusChip
|
||||
label={STATUS_LABELS[invoice.status] || invoice.status}
|
||||
color={STATUS_COLORS[invoice.status] || "default"}
|
||||
label={statusLabel(INVOICE_STATUS, invoice.status)}
|
||||
color={statusColor(INVOICE_STATUS, invoice.status)}
|
||||
/>
|
||||
</Box>
|
||||
) : (
|
||||
@@ -2249,7 +2239,7 @@ export default function InvoiceDetail() {
|
||||
onClose={() => setStatusConfirm({ show: false, status: null })}
|
||||
onConfirm={handleStatusChange}
|
||||
title="Změnit stav faktury"
|
||||
message={`Opravdu chcete změnit stav faktury "${invoice.invoice_number}" na "${STATUS_LABELS[statusConfirm.status || ""]}"?`}
|
||||
message={`Opravdu chcete změnit stav faktury "${invoice.invoice_number}" na "${statusLabel(INVOICE_STATUS, statusConfirm.status)}"?`}
|
||||
confirmText={
|
||||
TRANSITION_LABELS[statusConfirm.status || ""] || "Potvrdit"
|
||||
}
|
||||
|
||||
@@ -45,6 +45,11 @@ import {
|
||||
type TabDef,
|
||||
type StatCardColor,
|
||||
} from "../ui";
|
||||
import {
|
||||
INVOICE_STATUS,
|
||||
statusLabel,
|
||||
statusColor,
|
||||
} from "../lib/documentStatus";
|
||||
|
||||
const ReceivedInvoices = lazy(() => import("./ReceivedInvoices"));
|
||||
const API_BASE = "/api/admin";
|
||||
@@ -86,21 +91,6 @@ function formatCzkWithDetail(
|
||||
return { value: formatMultiCurrency(amounts), detail: null };
|
||||
}
|
||||
|
||||
const STATUS_LABELS: Record<string, string> = {
|
||||
issued: "Vystavena",
|
||||
paid: "Zaplacena",
|
||||
overdue: "Po splatnosti",
|
||||
};
|
||||
|
||||
const STATUS_COLORS: Record<
|
||||
string,
|
||||
"default" | "success" | "warning" | "error"
|
||||
> = {
|
||||
issued: "warning",
|
||||
paid: "success",
|
||||
overdue: "error",
|
||||
};
|
||||
|
||||
const STATUS_FILTERS = [
|
||||
{ value: "", label: "Vše" },
|
||||
{ value: "issued", label: "Vystavené" },
|
||||
@@ -560,13 +550,13 @@ export default function Invoices() {
|
||||
render: (inv) =>
|
||||
inv.status === "paid" ? (
|
||||
<StatusChip
|
||||
label={STATUS_LABELS[inv.status]}
|
||||
color={STATUS_COLORS[inv.status] ?? "default"}
|
||||
label={statusLabel(INVOICE_STATUS, inv.status)}
|
||||
color={statusColor(INVOICE_STATUS, inv.status)}
|
||||
/>
|
||||
) : (
|
||||
<StatusChip
|
||||
label={STATUS_LABELS[inv.status] || inv.status}
|
||||
color={STATUS_COLORS[inv.status] ?? "default"}
|
||||
label={statusLabel(INVOICE_STATUS, inv.status)}
|
||||
color={statusColor(INVOICE_STATUS, inv.status)}
|
||||
onClick={() => toggleStatus(inv)}
|
||||
/>
|
||||
),
|
||||
|
||||
@@ -58,28 +58,14 @@ import {
|
||||
PageEnter,
|
||||
headerActionsSx,
|
||||
} from "../ui";
|
||||
import {
|
||||
ISSUED_ORDER_STATUS,
|
||||
statusLabel,
|
||||
statusColor,
|
||||
} from "../lib/documentStatus";
|
||||
|
||||
const API_BASE = "/api/admin";
|
||||
|
||||
const STATUS_LABELS: Record<string, string> = {
|
||||
draft: "Koncept",
|
||||
sent: "Odeslaná",
|
||||
confirmed: "Potvrzená",
|
||||
completed: "Dokončená",
|
||||
cancelled: "Stornovaná",
|
||||
};
|
||||
|
||||
const STATUS_COLORS: Record<
|
||||
string,
|
||||
"default" | "success" | "error" | "warning" | "info"
|
||||
> = {
|
||||
draft: "default",
|
||||
sent: "info",
|
||||
confirmed: "warning",
|
||||
completed: "success",
|
||||
cancelled: "error",
|
||||
};
|
||||
|
||||
// Labels for the buttons that trigger a status transition.
|
||||
const TRANSITION_LABELS: Record<string, string> = {
|
||||
sent: "Odeslat",
|
||||
@@ -862,8 +848,8 @@ export default function IssuedOrderDetail() {
|
||||
</Typography>
|
||||
{isEdit && (
|
||||
<StatusChip
|
||||
label={STATUS_LABELS[form.status] || form.status}
|
||||
color={STATUS_COLORS[form.status] || "default"}
|
||||
label={statusLabel(ISSUED_ORDER_STATUS, form.status)}
|
||||
color={statusColor(ISSUED_ORDER_STATUS, form.status)}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
@@ -1281,9 +1267,10 @@ export default function IssuedOrderDetail() {
|
||||
onClose={() => setStatusConfirm({ show: false, status: null })}
|
||||
onConfirm={handleStatusChange}
|
||||
title="Změnit stav objednávky"
|
||||
message={`Opravdu chcete změnit stav objednávky "${poNumber}" na "${
|
||||
STATUS_LABELS[statusConfirm.status || ""] || ""
|
||||
}"?`}
|
||||
message={`Opravdu chcete změnit stav objednávky "${poNumber}" na "${statusLabel(
|
||||
ISSUED_ORDER_STATUS,
|
||||
statusConfirm.status,
|
||||
)}"?`}
|
||||
confirmText={
|
||||
TRANSITION_LABELS[statusConfirm.status || ""] || "Potvrdit"
|
||||
}
|
||||
|
||||
@@ -28,32 +28,19 @@ import {
|
||||
LoadingState,
|
||||
type DataColumn,
|
||||
} from "../ui";
|
||||
import {
|
||||
ISSUED_ORDER_STATUS,
|
||||
statusLabel,
|
||||
statusColor,
|
||||
statusOptions,
|
||||
} from "../lib/documentStatus";
|
||||
|
||||
const API_BASE = "/api/admin";
|
||||
|
||||
const STATUS_LABELS: Record<string, string> = {
|
||||
draft: "Koncept",
|
||||
sent: "Odeslaná",
|
||||
confirmed: "Potvrzená",
|
||||
completed: "Dokončená",
|
||||
cancelled: "Stornovaná",
|
||||
};
|
||||
|
||||
const STATUS_COLORS: Record<
|
||||
string,
|
||||
"default" | "success" | "error" | "warning" | "info"
|
||||
> = {
|
||||
draft: "default",
|
||||
sent: "info",
|
||||
confirmed: "warning",
|
||||
completed: "success",
|
||||
cancelled: "error",
|
||||
};
|
||||
|
||||
const STATUS_OPTIONS = [
|
||||
{ value: "", label: "Všechny stavy" },
|
||||
...Object.entries(STATUS_LABELS).map(([value, label]) => ({ value, label })),
|
||||
];
|
||||
const STATUS_OPTIONS = statusOptions(ISSUED_ORDER_STATUS, {
|
||||
value: "",
|
||||
label: "Všechny stavy",
|
||||
});
|
||||
|
||||
const ViewIcon = (
|
||||
<svg
|
||||
@@ -224,8 +211,8 @@ export default function IssuedOrders({ month, year }: IssuedOrdersProps) {
|
||||
sortKey: "status",
|
||||
render: (o) => (
|
||||
<StatusChip
|
||||
label={STATUS_LABELS[o.status] || o.status}
|
||||
color={STATUS_COLORS[o.status] || "default"}
|
||||
label={statusLabel(ISSUED_ORDER_STATUS, o.status)}
|
||||
color={statusColor(ISSUED_ORDER_STATUS, o.status)}
|
||||
/>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -76,6 +76,7 @@ import {
|
||||
PageEnter,
|
||||
headerActionsSx,
|
||||
} from "../ui";
|
||||
import { OFFER_STATUS, statusLabel, statusColor } from "../lib/documentStatus";
|
||||
|
||||
const API_BASE = "/api/admin";
|
||||
const DRAFT_KEY = "boha_offer_draft";
|
||||
@@ -1124,10 +1125,17 @@ export default function OfferDetail() {
|
||||
<Typography variant="h4">
|
||||
{isEdit ? `Nabídka ${form.quotation_number}` : "Nová nabídka"}
|
||||
</Typography>
|
||||
{isInvalidated && (
|
||||
<StatusChip label="Zneplatněna" color="error" />
|
||||
)}
|
||||
{isCompleted && <StatusChip label="Dokončeno" color="success" />}
|
||||
{isEdit &&
|
||||
(isCompleted ? (
|
||||
// Completed is derived from the linked order, not the offer's
|
||||
// own status — surface it (success) over the base chip.
|
||||
<StatusChip label="Dokončená" color="success" />
|
||||
) : (
|
||||
<StatusChip
|
||||
label={statusLabel(OFFER_STATUS, offerStatus)}
|
||||
color={statusColor(OFFER_STATUS, offerStatus)}
|
||||
/>
|
||||
))}
|
||||
</Box>
|
||||
</Box>
|
||||
<Box sx={headerActionsSx}>
|
||||
|
||||
@@ -38,15 +38,19 @@ import {
|
||||
type DataColumn,
|
||||
type TabDef,
|
||||
} from "../ui";
|
||||
import { OFFER_STATUS, statusLabel, statusColor } from "../lib/documentStatus";
|
||||
|
||||
const API_BASE = "/api/admin";
|
||||
const DRAFT_KEY = "boha_offer_draft";
|
||||
|
||||
// Filter tabs cover only the real stored offer statuses (the `expired` entry
|
||||
// in OFFER_STATUS is a front-end-derived state, not a stored value).
|
||||
const STATUS_FILTERS = [
|
||||
{ value: "", label: "Vše" },
|
||||
{ value: "active", label: "Aktivní" },
|
||||
{ value: "ordered", label: "Objednaná" },
|
||||
{ value: "invalidated", label: "Zneplatněná" },
|
||||
...(["active", "ordered", "invalidated"] as const).map((value) => ({
|
||||
value,
|
||||
label: statusLabel(OFFER_STATUS, value),
|
||||
})),
|
||||
];
|
||||
|
||||
interface Quotation {
|
||||
@@ -497,7 +501,7 @@ export default function Offers() {
|
||||
{
|
||||
key: "customer_name",
|
||||
header: "Zákazník",
|
||||
width: "18%",
|
||||
width: "13%",
|
||||
render: (q) => q.customer_name || "—",
|
||||
},
|
||||
{
|
||||
@@ -511,22 +515,43 @@ export default function Offers() {
|
||||
{
|
||||
key: "valid_until",
|
||||
header: "Platnost",
|
||||
width: "11%",
|
||||
width: "10%",
|
||||
sortKey: "valid_until",
|
||||
mono: true,
|
||||
render: (q) => formatDate(q.valid_until),
|
||||
},
|
||||
{
|
||||
key: "status",
|
||||
header: "Stav",
|
||||
width: "10%",
|
||||
sortKey: "status",
|
||||
render: (q) => {
|
||||
// The offer's own status is `active`/`ordered`/`invalidated`. When its
|
||||
// linked order is completed, surface that as "Dokončená" (success) —
|
||||
// matching the OfferDetail header chip and the completed row tint.
|
||||
const completed =
|
||||
q.status !== "invalidated" && q.order_status === "dokoncena";
|
||||
return completed ? (
|
||||
<StatusChip label="Dokončená" color="success" />
|
||||
) : (
|
||||
<StatusChip
|
||||
label={statusLabel(OFFER_STATUS, q.status)}
|
||||
color={statusColor(OFFER_STATUS, q.status)}
|
||||
/>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "currency",
|
||||
header: "Měna",
|
||||
width: "8%",
|
||||
width: "7%",
|
||||
sortKey: "currency",
|
||||
render: (q) => <StatusChip label={q.currency} color="default" />,
|
||||
},
|
||||
{
|
||||
key: "total",
|
||||
header: "Celkem",
|
||||
width: "12%",
|
||||
width: "11%",
|
||||
align: "right",
|
||||
mono: true,
|
||||
bold: true,
|
||||
@@ -535,7 +560,7 @@ export default function Offers() {
|
||||
{
|
||||
key: "actions",
|
||||
header: "Akce",
|
||||
width: "16%",
|
||||
width: "15%",
|
||||
align: "right",
|
||||
render: (q) => {
|
||||
const isInvalidated = q.status === "invalidated";
|
||||
|
||||
@@ -34,26 +34,10 @@ import {
|
||||
LoadingState,
|
||||
type DataColumn,
|
||||
} from "../ui";
|
||||
import { ORDER_STATUS, statusLabel, statusColor } from "../lib/documentStatus";
|
||||
|
||||
const API_BASE = "/api/admin";
|
||||
|
||||
const STATUS_LABELS: Record<string, string> = {
|
||||
prijata: "Přijatá",
|
||||
v_realizaci: "V realizaci",
|
||||
dokoncena: "Dokončená",
|
||||
stornovana: "Stornována",
|
||||
};
|
||||
|
||||
const STATUS_COLORS: Record<
|
||||
string,
|
||||
"default" | "success" | "error" | "warning" | "info"
|
||||
> = {
|
||||
prijata: "info",
|
||||
v_realizaci: "warning",
|
||||
dokoncena: "success",
|
||||
stornovana: "error",
|
||||
};
|
||||
|
||||
interface Order {
|
||||
id: number;
|
||||
order_number: string;
|
||||
@@ -381,8 +365,8 @@ export default function OrdersReceived({
|
||||
sortKey: "status",
|
||||
render: (o) => (
|
||||
<StatusChip
|
||||
label={STATUS_LABELS[o.status] || o.status}
|
||||
color={STATUS_COLORS[o.status] || "default"}
|
||||
label={statusLabel(ORDER_STATUS, o.status)}
|
||||
color={statusColor(ORDER_STATUS, o.status)}
|
||||
/>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -42,17 +42,14 @@ import {
|
||||
type DataColumn,
|
||||
type StatCardColor,
|
||||
} from "../ui";
|
||||
import {
|
||||
RECEIVED_INVOICE_STATUS,
|
||||
statusLabel,
|
||||
statusColor,
|
||||
} from "../lib/documentStatus";
|
||||
|
||||
const API_BASE = "/api/admin";
|
||||
|
||||
const STATUS_LABELS: Record<string, string> = {
|
||||
unpaid: "Neuhrazena",
|
||||
paid: "Uhrazena",
|
||||
};
|
||||
const STATUS_COLORS: Record<string, "default" | "success" | "warning"> = {
|
||||
unpaid: "warning",
|
||||
paid: "success",
|
||||
};
|
||||
const DEFAULT_CURRENCIES = ["CZK", "EUR", "USD", "GBP"];
|
||||
const DEFAULT_VAT_RATES = [0, 10, 12, 15, 21];
|
||||
|
||||
@@ -604,13 +601,13 @@ export default function ReceivedInvoices({
|
||||
render: (inv) =>
|
||||
inv.status === "paid" ? (
|
||||
<StatusChip
|
||||
label={STATUS_LABELS[inv.status]}
|
||||
color={STATUS_COLORS[inv.status] ?? "default"}
|
||||
label={statusLabel(RECEIVED_INVOICE_STATUS, inv.status)}
|
||||
color={statusColor(RECEIVED_INVOICE_STATUS, inv.status)}
|
||||
/>
|
||||
) : (
|
||||
<StatusChip
|
||||
label={STATUS_LABELS[inv.status] || inv.status}
|
||||
color={STATUS_COLORS[inv.status] ?? "default"}
|
||||
label={statusLabel(RECEIVED_INVOICE_STATUS, inv.status)}
|
||||
color={statusColor(RECEIVED_INVOICE_STATUS, inv.status)}
|
||||
onClick={() => toggleStatus(inv)}
|
||||
/>
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user