fix(ui): name the account by its display name

The dashboard greeting, the Insights greeting, the top bar and the
sidebar read the username, so a display name set on the profile card
reached the reports but none of the surfaces that address the account.
They now read one helper that returns the display name when set and
falls back to the username otherwise.

Refs #1309
This commit is contained in:
Marc-André Bombeck committed 2026-11-01 00:56:24 +01:00
1 parent 022c6de0b5
commit 1c4bcce6c7
7 files changed
+73 -17

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
import { describe, expect, it } from "vitest";
import { accountName } from "../account-name";
describe("accountName", () => {
it("names the account by its display name when one is set", () => {
expect(accountName({ username: "jdoe", displayName: "Jane" })).toBe("Jane");
});
it("trims the display name it shows", () => {
expect(accountName({ username: "jdoe", displayName: " Jane " })).toBe(
"Jane",
);
});
it("falls back to the username when the display name is empty or absent", () => {
expect(accountName({ username: "jdoe", displayName: " " })).toBe("jdoe");
expect(accountName({ username: "jdoe", displayName: null })).toBe("jdoe");
expect(accountName({ username: "jdoe" })).toBe("jdoe");
});
});
+13
View File
@@ -0,0 +1,13 @@
/**
* The name the app shows and addresses an account by: the display name when
* one is set, the username otherwise. Greetings, the top bar and the sidebar
* all read it here, so the display name edited on the profile card reaches
* every surface that names the account.
*/
export function accountName(user: {
username: string;
displayName?: string | null;
}): string {
const displayName = user.displayName?.trim();
return displayName ? displayName : user.username;
}