From 702943fdc67ea8863e2f35693be275140fbca013 Mon Sep 17 00:00:00 2001 From: tisachi Date: Sat, 17 Oct 2026 09:25:27 +0200 Subject: [PATCH] Admin: topbar podstron usera = 'Profil [nazwa]' jak w apce (tytul sekcji tylko w h2 w tresci, koniec dublowania naglowka) --- admin/src/pages/users/UserBodyParameters.tsx | 7 +++++-- admin/src/pages/users/UserClaims.tsx | 10 ++++++++-- admin/src/pages/users/UserHistory.tsx | 7 +++++-- admin/src/pages/users/UserInfo.tsx | 5 +++-- admin/src/pages/users/UserMemberships.tsx | 7 ++++++- admin/src/pages/users/UserProgress.tsx | 10 ++++++++-- admin/test/UserInfo.test.tsx | 6 ++++-- admin/test/e2e/admin.spec.ts | 17 +++++++++++++++++ 8 files changed, 56 insertions(+), 13 deletions(-) diff --git a/admin/src/pages/users/UserBodyParameters.tsx b/admin/src/pages/users/UserBodyParameters.tsx index 4b78bc2..17ea290 100644 --- a/admin/src/pages/users/UserBodyParameters.tsx +++ b/admin/src/pages/users/UserBodyParameters.tsx @@ -33,7 +33,8 @@ import { } from '../../lib/body-measurements'; import { fmtDate } from '../../lib/format'; import type { CircumferenceSeries } from '../../api/types'; -import { useUserBodyParameters } from './user-queries'; +import { useAdminUser, useUserBodyParameters } from './user-queries'; +import { userDisplayName } from './UserDetail'; const TOOLTIP_STYLE = { background: 'var(--bg-card)', @@ -446,13 +447,15 @@ function PartSection({ */ export default function UserBodyParameters() { const { id } = useParams(); + const { user } = useAdminUser(id); const { data: bp, isLoading: bpLoading, error: bpError } = useUserBodyParameters(id); const [visible, setVisible] = useState>({}); const [selected, setSelected] = useState(null); useTopbar({ - title: 'Parametry ciała', + // topbar = rodzic („Profil [nazwa]”), nazwa podstrony w PageHeader poniżej (h2) + title: user ? `Profil ${userDisplayName(user)}` : 'Profil', back: id ? `/users/${id}` : '/users', }); diff --git a/admin/src/pages/users/UserClaims.tsx b/admin/src/pages/users/UserClaims.tsx index 924fda8..fcad24e 100644 --- a/admin/src/pages/users/UserClaims.tsx +++ b/admin/src/pages/users/UserClaims.tsx @@ -12,7 +12,8 @@ import { Skeleton, } from '../../components/ui'; import { fmtDate } from '../../lib/format'; -import { useUserClaims } from './user-queries'; +import { useAdminUser, useUserClaims } from './user-queries'; +import { userDisplayName } from './UserDetail'; const STATUS_BADGE: Record = { PENDING: { label: 'Oczekuje', color: 'yellow' }, @@ -26,7 +27,12 @@ const STATUS_BADGE: Record areas.find((a) => a.muscle === muscle)?.name ?? muscle; useTopbar({ - title: 'Dane osobowe', + // topbar = rodzic („Profil [nazwa]”), nazwa podstrony w PageHeader poniżej (h2) + title: user ? `Profil ${userDisplayName(user)}` : 'Profil', back: id ? `/users/${id}` : '/users', }); @@ -284,7 +285,7 @@ export default function UserInfo() { return ( <> } actions={} /> diff --git a/admin/src/pages/users/UserMemberships.tsx b/admin/src/pages/users/UserMemberships.tsx index edc0855..31708ff 100644 --- a/admin/src/pages/users/UserMemberships.tsx +++ b/admin/src/pages/users/UserMemberships.tsx @@ -13,6 +13,7 @@ import { Skeleton, } from '../../components/ui'; import { useAdminUser } from './user-queries'; +import { userDisplayName } from './UserDetail'; /** * Członkostwa użytkownika w siłowniach (admin): tylko do odczytu. @@ -24,7 +25,11 @@ export default function UserMemberships() { const { id } = useParams(); const { user, isLoading, error } = useAdminUser(id); - useTopbar({ title: 'Członkostwa w siłowniach', back: id ? `/users/${id}` : '/users' }); + // topbar = rodzic („Profil [nazwa]”), nazwa podstrony w PageHeader poniżej (h2) + useTopbar({ + title: user ? `Profil ${userDisplayName(user)}` : 'Profil', + back: id ? `/users/${id}` : '/users', + }); if (isLoading) { return ( diff --git a/admin/src/pages/users/UserProgress.tsx b/admin/src/pages/users/UserProgress.tsx index 0c9b7e7..1ec6ff8 100644 --- a/admin/src/pages/users/UserProgress.tsx +++ b/admin/src/pages/users/UserProgress.tsx @@ -3,7 +3,8 @@ import { TrendingUp } from 'lucide-react'; import { useTopbar } from '../../topbar'; import { BackButton, Card, EmptyState, ErrorText, PageHeader, Skeleton } from '../../components/ui'; import ExerciseProgressCards from '../../components/ExerciseProgressCards'; -import { useUserExerciseProgress } from './user-queries'; +import { useAdminUser, useUserExerciseProgress } from './user-queries'; +import { userDisplayName } from './UserDetail'; /** * Postępy per ćwiczenie użytkownika — widok admina 1:1 z `/profile/progress` @@ -11,7 +12,12 @@ import { useUserExerciseProgress } from './user-queries'; */ export default function UserProgress() { const { id } = useParams(); - useTopbar({ title: 'Postępy', back: id ? `/users/${id}` : '/users' }); + const { user } = useAdminUser(id); + useTopbar({ + // topbar = rodzic („Profil [nazwa]”), nazwa podstrony w PageHeader poniżej (h2) + title: user ? `Profil ${userDisplayName(user)}` : 'Profil', + back: id ? `/users/${id}` : '/users', + }); const { data, isLoading, error } = useUserExerciseProgress(id); if (isLoading) { diff --git a/admin/test/UserInfo.test.tsx b/admin/test/UserInfo.test.tsx index 399289e..42238da 100644 --- a/admin/test/UserInfo.test.tsx +++ b/admin/test/UserInfo.test.tsx @@ -119,7 +119,9 @@ describe('admin UserInfo page', () => { defaultRoutes(); renderUserInfo(); - expect(await screen.findByRole('heading', { name: 'Dane osobowe — jano' })).toBeInTheDocument(); + expect( + await screen.findByRole('heading', { name: 'Dane osobowe', level: 2 }), + ).toBeInTheDocument(); // karta „Konto” (dodatek admina) + dane adresowe expect(screen.getByText('Konto')).toBeInTheDocument(); @@ -149,7 +151,7 @@ describe('admin UserInfo page', () => { it('jest wyłącznie do odczytu — brak kontrolek edycji', async () => { defaultRoutes(); renderUserInfo(); - await screen.findByRole('heading', { name: 'Dane osobowe — jano' }); + await screen.findByRole('heading', { name: 'Dane osobowe', level: 2 }); expect(screen.queryAllByRole('button', { name: 'Edytuj' })).toHaveLength(0); expect(screen.queryByRole('button', { name: 'Zapisz' })).not.toBeInTheDocument(); diff --git a/admin/test/e2e/admin.spec.ts b/admin/test/e2e/admin.spec.ts index 151ebb5..9746fa3 100644 --- a/admin/test/e2e/admin.spec.ts +++ b/admin/test/e2e/admin.spec.ts @@ -311,6 +311,23 @@ test('parametry ciała tylko do odczytu — brak kontrolek dodawania/usuwania po await expect(page.getByRole('heading', { level: 2, name: 'Parametry ciała' })).toBeVisible(); }); +test('podstrony usera: topbar = Profil [nazwa], nazwa sekcji dopiero w treści (bez dubla)', async ({ + page, +}) => { + mockApi(page, { gyms: { gyms: [TEST_GYM] }, users: { users: [TEST_USER] } }); + await loginAsAdmin(page); + await page.getByRole('link', { name: 'Użytkownicy' }).click(); + await page.getByRole('link', { name: 'Jan Kowalski' }).click(); + await page.getByRole('link', { name: /Historia treningów/ }).click(); + await expect(page).toHaveURL(/\/users\/user-1\/history$/); + + // topbar pokazuje rodzica z nazwą usera, a pod nim dopiero nazwę sekcji + await expect(page.getByRole('heading', { level: 1, name: 'Profil Jan Kowalski' })).toBeVisible(); + await expect(page.getByRole('heading', { level: 2, name: 'Historia treningów' })).toBeVisible(); + // ten sam tekst nie może dublować się w dwóch nagłówkach + await expect(page.getByRole('heading', { name: 'Historia treningów' })).toHaveCount(1); +}); + test('kreator edycji: zapis bez zmian członkostw wysyła tylko PATCH konta', async ({ page }) => { mockApi(page, { gyms: { gyms: [TEST_GYM, TEST_GYM_2] }, users: { users: [TEST_USER] } }); await loginAsAdmin(page);