fix: show real Weeztix company trade names, not GUID-as-name

Merge nested company objects, prefer trade_name over name, skip UUID-like
labels; Alpine falls back to stored company_name when API label is junk.

Made-with: Cursor
This commit is contained in:
2026-04-05 10:48:04 +02:00
parent 70c1d25ad4
commit 977e09d8ac
2 changed files with 115 additions and 11 deletions

View File

@@ -916,17 +916,35 @@ document.addEventListener('alpine:init', () => {
this.syncCouponName();
},
/** Prefer API/display name; avoid showing raw GUID when a label exists. */
/** Prefer human-readable label; skip API "names" that are just the GUID / UUID. */
companyLabel(c) {
if (!c || typeof c.guid !== 'string') {
return '';
}
const n = c.name;
if (typeof n === 'string' && n.trim() !== '') {
return n.trim();
const g = c.guid;
const isBadLabel = (s) => {
const t = typeof s === 'string' ? s.trim() : '';
return (
t === '' ||
t.toLowerCase() === g.toLowerCase() ||
this.stringLooksLikeUuid(t)
);
};
const fromApi = typeof c.name === 'string' ? c.name : '';
if (!isBadLabel(fromApi)) {
return fromApi.trim();
}
if (this.companyGuid === g && !isBadLabel(this.companyName)) {
return String(this.companyName).trim();
}
return c.guid;
return g;
},
stringLooksLikeUuid(s) {
return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/.test(
String(s),
);
},
}));
});