refactor(ui): shared searchable CustomerPicker across offers/invoices/issued-orders

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
BOHA
2026-06-09 16:42:24 +02:00
parent 20177e8f87
commit e868ecf769
5 changed files with 132 additions and 286 deletions

View File

@@ -56,6 +56,7 @@ import {
ConfirmDialog,
LoadingState,
PageEnter,
CustomerPicker,
headerActionsSx,
} from "../ui";
import {
@@ -690,12 +691,11 @@ export default function IssuedOrderDetail() {
});
};
const selectCustomer = (val: string) => {
const cid = val ? Number(val) : null;
const c = customers.find((x: Customer) => x.id === cid);
const selectCustomer = (id: number | null) => {
const c = id != null ? customers.find((x: Customer) => x.id === id) : null;
setForm((prev) => ({
...prev,
customer_id: cid,
customer_id: id,
customer_name: c?.name || "",
}));
setErrors((prev) => ({ ...prev, customer_id: "" }));
@@ -956,19 +956,13 @@ export default function IssuedOrderDetail() {
}}
>
<Field label="Dodavatel" error={errors.customer_id} required>
<Select
value={form.customer_id ? String(form.customer_id) : ""}
<CustomerPicker
customers={customers}
value={form.customer_id}
onChange={selectCustomer}
disabled={!editable}
options={[
{ value: "", label: "— Vyberte dodavatele —" },
...customers.map((c: Customer) => ({
value: String(c.id),
label: c.company_id
? `${c.name} (${c.company_id})`
: c.name,
})),
]}
error={errors.customer_id}
placeholder="Vyberte dodavatele…"
/>
</Field>
<Field label="Datum objednávky" error={errors.order_date} required>