mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 21:15:41 +00:00
fix(container-returns): dedupe company names in the return picker
freight.companies allows duplicate names, and Mantine v9 throws on duplicate Autocomplete option values, taking down the whole Container Returns page with a render error. Dedupes the option list by trimmed name. resolveId now returns an id only when exactly one company carries the name — an ambiguous name resolves to nothing, so the return keeps the typed company name rather than silently attaching to whichever duplicate happened to come first. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -16,11 +16,22 @@ export function useCompanyOptions() {
|
|||||||
|
|
||||||
const companies = data?.items ?? [];
|
const companies = data?.items ?? [];
|
||||||
|
|
||||||
|
// Company names are not unique — Mantine throws on duplicate option values,
|
||||||
|
// so the list is deduped by the trimmed name.
|
||||||
|
const names = [...new Set(companies.map((c) => c.name.trim()).filter(Boolean))];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
loading: isLoading,
|
loading: isLoading,
|
||||||
names: companies.map((c) => c.name),
|
names,
|
||||||
/** Exact (case-insensitive) name match → company id, else undefined. */
|
/**
|
||||||
resolveId: (name: string): string | undefined =>
|
* Name → company id, only when exactly one company carries that name. An
|
||||||
companies.find((c) => c.name.trim().toLowerCase() === name.trim().toLowerCase())?.id,
|
* ambiguous name resolves to nothing rather than to an arbitrary company:
|
||||||
|
* the container keeps the typed name and no wrong customer is attached.
|
||||||
|
*/
|
||||||
|
resolveId: (name: string): string | undefined => {
|
||||||
|
const key = name.trim().toLowerCase();
|
||||||
|
const matches = companies.filter((c) => c.name.trim().toLowerCase() === key);
|
||||||
|
return matches.length === 1 ? matches[0].id : undefined;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user