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:
@@ -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),
|
||||
);
|
||||
},
|
||||
}));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user