Admin: topbar podstron usera = 'Profil [nazwa]' jak w apce (tytul sekcji tylko w h2 w tresci, koniec dublowania naglowka)

This commit is contained in:
tisachi
2026-10-17 09:25:27 +02:00
parent b2978151c4
commit 702943fdc6
8 changed files with 56 additions and 13 deletions

View File

@@ -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<Record<string, number>>({});
const [selected, setSelected] = useState<string | null>(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',
});

View File

@@ -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<string, { label: string; color: 'green' | 'yellow' | 'red' }> = {
PENDING: { label: 'Oczekuje', color: 'yellow' },
@@ -26,7 +27,12 @@ const STATUS_BADGE: Record<string, { label: string; color: 'green' | 'yellow' |
*/
export default function UserClaims() {
const { id } = useParams();
useTopbar({ title: 'Wnioski', 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 } = useUserClaims(id);
if (isLoading) {

View File

@@ -4,7 +4,8 @@ import { History } from 'lucide-react';
import { useTopbar } from '../../topbar';
import { MonthPickerCore } from '../../topbar/MonthPicker';
import { BackButton, Card, EmptyState, ErrorText, PageHeader, Skeleton } from '../../components/ui';
import { useUserHistory } from './user-queries';
import { useAdminUser, useUserHistory } from './user-queries';
import { userDisplayName } from './UserDetail';
import HistoryTable from '../../components/HistoryTable';
/**
@@ -13,6 +14,7 @@ import HistoryTable from '../../components/HistoryTable';
*/
export default function UserHistory() {
const { id } = useParams();
const { user } = useAdminUser(id);
const [params] = useSearchParams();
const initialOpenSessionId = params.get('session') ?? undefined;
const [month, setMonth] = useState('');
@@ -28,7 +30,8 @@ export default function UserHistory() {
.reverse();
useTopbar({
title: 'Historia treningów',
// topbar = rodzic („Profil [nazwa]”), nazwa podstrony w PageHeader poniżej (h2)
title: user ? `Profil ${userDisplayName(user)}` : 'Profil',
back: id ? `/users/${id}` : '/users',
dateFilter: (
<MonthPickerCore

View File

@@ -264,7 +264,8 @@ export default function UserInfo() {
const areaName = (muscle: string) => 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 (
<>
<PageHeader
title={`Dane osobowe — ${name}`}
title="Dane osobowe"
leading={<Avatar name={name} size={40} />}
actions={<BackButton to={`/users/${user.id}`} />}
/>

View File

@@ -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 (

View File

@@ -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) {

View File

@@ -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();

View File

@@ -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);