Admin: podglad tablicy sirowni (ranking, agregaty, ekwiwalenty i rekordy 1RM tylko do odczytu)
This commit is contained in:
@@ -7,6 +7,7 @@ import Login from './pages/Login';
|
||||
import GymsList from './pages/gyms/GymsList';
|
||||
import GymForm from './pages/gyms/GymForm';
|
||||
import GymDetail from './pages/gyms/GymDetail';
|
||||
import GymBoard from './pages/gyms/GymBoard';
|
||||
import GymGalleryPage from './pages/gyms/GymGalleryPage';
|
||||
import GymEquipmentPage from './pages/gyms/GymEquipmentPage';
|
||||
import GymAnnouncementsPage from './pages/gyms/GymAnnouncementsPage';
|
||||
@@ -48,6 +49,7 @@ export default function App() {
|
||||
<Route path="/gyms" element={<GymsList />} />
|
||||
<Route path="/gyms/new" element={<GymForm />} />
|
||||
<Route path="/gyms/:id" element={<GymDetail />} />
|
||||
<Route path="/gyms/:id/board" element={<GymBoard />} />
|
||||
<Route path="/gyms/:id/gallery" element={<GymGalleryPage />} />
|
||||
<Route path="/gyms/:id/equipment" element={<GymEquipmentPage />} />
|
||||
<Route path="/gyms/:id/announcements" element={<GymAnnouncementsPage />} />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { api } from './client';
|
||||
import type { EquipmentUsageRow, User } from './types';
|
||||
import type { EquipmentUsageRow, GymBoardData, User } from './types';
|
||||
|
||||
/** Bieżący użytkownik (admin) — profil + członkostwa, jak `useMe` w aplikacji. */
|
||||
export function useMe() {
|
||||
@@ -32,3 +32,15 @@ export function useAdminGymEquipmentUsage(gymId: string | undefined, rangeDays:
|
||||
enabled: !!gymId,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Tablica statystyk siłowni (GET /gyms/:id/board, tylko REAL) — te same dane co
|
||||
* w apce; admin ma dostęp do endpointa, widok w panelu jest read-only (bez opt-in).
|
||||
*/
|
||||
export function useGymBoard(gymId: string | undefined, rangeDays: number) {
|
||||
return useQuery({
|
||||
queryKey: ['gym-board', gymId, rangeDays],
|
||||
queryFn: () => api<GymBoardData>(`/gyms/${gymId}/board?range=${rangeDays}`),
|
||||
enabled: !!gymId,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -215,6 +215,50 @@ export interface GymPresenceStatsResponse {
|
||||
stats: GymPresenceStatsData;
|
||||
}
|
||||
|
||||
/** Wiersz rankingu tablicy (GET /gyms/:id/board) — skuteczne sesje w zakresie. */
|
||||
export interface GymBoardRankRow {
|
||||
userId: string;
|
||||
nickname: string | null;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
sessions: number;
|
||||
tonnageKg: number;
|
||||
days: number;
|
||||
}
|
||||
|
||||
/** Autor rekordu 1RM (atrybucja tylko po opt-in; null = anonim). */
|
||||
export interface GymBoardAuthor {
|
||||
nickname: string | null;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
}
|
||||
|
||||
/** Rekord 1RM (Epley) z całej historii. */
|
||||
export interface GymBoardRecord {
|
||||
exerciseId: string;
|
||||
name: string;
|
||||
nameEn: string | null;
|
||||
muscle: string;
|
||||
oneRm: number;
|
||||
date: string;
|
||||
author: GymBoardAuthor | null;
|
||||
}
|
||||
|
||||
/** Odpowiedź tablicy statystyk siłowni (tylko REAL); w adminie widok read-only. */
|
||||
export interface GymBoardData {
|
||||
gym: { id: string; name: string };
|
||||
myStatsOptIn: boolean | null;
|
||||
rangeDays: number;
|
||||
ranking: GymBoardRankRow[];
|
||||
aggregate: {
|
||||
tonnageKg: number;
|
||||
sessions: number;
|
||||
uniqueExercisers: number;
|
||||
muscles: { muscle: string; sets: number; volumeKg: number }[];
|
||||
};
|
||||
records: GymBoardRecord[];
|
||||
}
|
||||
|
||||
/** Kafel godzinowy mapy ciepła urządzeń (0–23, godzina lokalna serwera). */
|
||||
export interface EquipmentUsageCell {
|
||||
hour: number;
|
||||
|
||||
56
admin/src/components/stats/MuscleSplit.tsx
Normal file
56
admin/src/components/stats/MuscleSplit.tsx
Normal file
@@ -0,0 +1,56 @@
|
||||
import { Badge } from '../ui';
|
||||
import { fmtVolume } from '../../lib/format';
|
||||
import { MUSCLE_COLORS, muscleName, setCountLabel } from '../../lib/labels';
|
||||
|
||||
// Paleta segmentów paska partii (kolory dekoracyjne, stałe niezależnie od motywu).
|
||||
export const MUSCLE_PALETTE = ['#ff6b4a', '#63b3e4', '#e8b04a', '#4ec97f', '#a78bfa', '#5eead4'];
|
||||
|
||||
export interface MuscleSplitRow {
|
||||
muscle: string;
|
||||
sets: number;
|
||||
volumeKg: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rozbicie na partie ciała: pasek udziału serii + legenda (badge partii,
|
||||
* liczba serii, tonaż). Lustrzany komponent aplikacji (tablica siłowni).
|
||||
*/
|
||||
export function MuscleSplit({
|
||||
muscles,
|
||||
ariaLabel,
|
||||
}: {
|
||||
muscles: MuscleSplitRow[];
|
||||
ariaLabel: string;
|
||||
}) {
|
||||
const muscleTotal = muscles.reduce((n, m) => n + m.sets, 0);
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div
|
||||
className="flex h-3 w-full overflow-hidden rounded-full bg-input"
|
||||
role="img"
|
||||
aria-label={ariaLabel}
|
||||
>
|
||||
{muscles.map((m, i) => (
|
||||
<div
|
||||
key={m.muscle}
|
||||
title={`${muscleName(m.muscle)} · ${setCountLabel(m.sets)}`}
|
||||
style={{
|
||||
width: `${(m.sets / (muscleTotal || 1)) * 100}%`,
|
||||
background: MUSCLE_PALETTE[i % MUSCLE_PALETTE.length],
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<ul className="space-y-2">
|
||||
{muscles.map((m) => (
|
||||
<li key={m.muscle} className="flex items-center gap-3 text-[0.875rem]">
|
||||
<Badge color={MUSCLE_COLORS[m.muscle] ?? 'gray'}>{muscleName(m.muscle)}</Badge>
|
||||
<span className="ml-auto shrink-0 tabular-nums text-dim">
|
||||
{setCountLabel(m.sets)} · {fmtVolume(m.volumeKg)}
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -183,6 +183,27 @@
|
||||
"qrCopy": "Copy link",
|
||||
"qrCopied": "Copied"
|
||||
},
|
||||
"board": {
|
||||
"title": "Board",
|
||||
"tileHint": "Ranking and records",
|
||||
"rangeAria": "Board range",
|
||||
"rangeDays_one": "{{count}} day",
|
||||
"rangeDays_other": "{{count}} days",
|
||||
"rankingTitle": "Training ranking",
|
||||
"emptyRanking": "No information",
|
||||
"aggregateTitle": "Gym aggregate",
|
||||
"aggTonnage": "Tonnage",
|
||||
"aggSessions": "Sessions",
|
||||
"aggExercisers": "Exercisers",
|
||||
"equivElephants": "African elephant (6 t)",
|
||||
"equivBus": "city bus (12.5 t)",
|
||||
"equivCar": "car (1.5 t)",
|
||||
"musclesTitle": "Muscle groups of the gym",
|
||||
"emptyMuscles": "No sets in this period.",
|
||||
"recordsTitle": "1RM records",
|
||||
"emptyRecords": "No measurable records.",
|
||||
"anon": "anonymous"
|
||||
},
|
||||
"stats": {
|
||||
"cellTitle_one": "{{day}}, {{hour}}:00 — {{count}} visit",
|
||||
"cellTitle_other": "{{day}}, {{hour}}:00 — {{count}} visits"
|
||||
|
||||
@@ -195,6 +195,29 @@
|
||||
"qrCopy": "Kopiuj link",
|
||||
"qrCopied": "Skopiowano"
|
||||
},
|
||||
"board": {
|
||||
"title": "Tablica",
|
||||
"tileHint": "Ranking i rekordy",
|
||||
"rangeAria": "Zakres tablicy",
|
||||
"rangeDays_one": "{{count}} dzień",
|
||||
"rangeDays_few": "{{count}} dni",
|
||||
"rangeDays_many": "{{count}} dni",
|
||||
"rangeDays_other": "{{count}} dni",
|
||||
"rankingTitle": "Ranking treningów",
|
||||
"emptyRanking": "Brak informacji",
|
||||
"aggregateTitle": "Zbiorowość siłowni",
|
||||
"aggTonnage": "Tonaż",
|
||||
"aggSessions": "Sesje",
|
||||
"aggExercisers": "Ćwiczący",
|
||||
"equivElephants": "słoń afrykański (6 t)",
|
||||
"equivBus": "autobus (12,5 t)",
|
||||
"equivCar": "samochód osobowy (1,5 t)",
|
||||
"musclesTitle": "Partie ciała siłowni",
|
||||
"emptyMuscles": "Brak serii w tym okresie.",
|
||||
"recordsTitle": "Rekordy 1RM",
|
||||
"emptyRecords": "Brak mierzalnych rekordów.",
|
||||
"anon": "anonim"
|
||||
},
|
||||
"stats": {
|
||||
"cellTitle_one": "{{day}}, {{hour}}:00 — {{count}} wizyta",
|
||||
"cellTitle_few": "{{day}}, {{hour}}:00 — {{count}} wizyty",
|
||||
|
||||
@@ -90,6 +90,11 @@ export function fmtVolume(kg: number): string {
|
||||
return `${Math.round(kg).toLocaleString(currentTag())} kg`;
|
||||
}
|
||||
|
||||
/** Obciążenie w kg do wyświetlania: 62.5 → „62,5” (Intl, max 2 miejsca po przecinku). */
|
||||
export function fmtLoadKg(kg: number): string {
|
||||
return kg.toLocaleString(currentTag(), { maximumFractionDigits: 2 });
|
||||
}
|
||||
|
||||
/** Czas trwania sesji: „45 min”, „1 h 30 min”. */
|
||||
export function fmtDuration(startIso: string, endIso: string): string {
|
||||
const min = Math.round((new Date(endIso).getTime() - new Date(startIso).getTime()) / 60000);
|
||||
|
||||
@@ -7,6 +7,10 @@ export function muscleName(muscle: string): string {
|
||||
return i18n.exists(key) ? i18n.t(key) : muscle;
|
||||
}
|
||||
|
||||
export function setCountLabel(n: number): string {
|
||||
return i18n.t('counters.setCount', { count: n });
|
||||
}
|
||||
|
||||
export const MUSCLE_COLORS: Record<string, BadgeColor> = {
|
||||
chest: 'red',
|
||||
back: 'blue',
|
||||
|
||||
16
admin/src/lib/stats-equiv.ts
Normal file
16
admin/src/lib/stats-equiv.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Przyjęte masy jednostek do ekwiwalentów tonażu (kg) — lustrzana tabela
|
||||
* aplikacji (klucze etykiet zostają w i18n poszczególnych pakietów nazw).
|
||||
*/
|
||||
export const EQUIV_UNITS = [
|
||||
{ id: 'elephants', kg: 6000 },
|
||||
{ id: 'bus', kg: 12500 },
|
||||
{ id: 'car', kg: 1500 },
|
||||
] as const;
|
||||
|
||||
export type EquivUnitId = (typeof EQUIV_UNITS)[number]['id'];
|
||||
|
||||
/** Ile sztuk jednostki mieści się w podanym tonażu (zaokrąglenie). */
|
||||
export function equivCount(tonnageKg: number, kg: number): number {
|
||||
return Math.round(tonnageKg / kg);
|
||||
}
|
||||
216
admin/src/pages/gyms/GymBoard.tsx
Normal file
216
admin/src/pages/gyms/GymBoard.tsx
Normal file
@@ -0,0 +1,216 @@
|
||||
import { useState } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useGymBoard } from '../../api/queries';
|
||||
import type { GymBoardRecord } from '../../api/types';
|
||||
import { MuscleSplit } from '../../components/stats/MuscleSplit';
|
||||
import {
|
||||
BackButton,
|
||||
Badge,
|
||||
Card,
|
||||
ErrorText,
|
||||
Loading,
|
||||
PageHeader,
|
||||
SectionHeader,
|
||||
Select,
|
||||
} from '../../components/ui';
|
||||
import { Avatar } from '../../components/Avatar';
|
||||
import { displayName, fmtDate, fmtLoadKg, fmtVolume } from '../../lib/format';
|
||||
import { localizedName } from '../../lib/localizedName';
|
||||
import { MUSCLE_COLORS, muscleName } from '../../lib/labels';
|
||||
import { EQUIV_UNITS, equivCount, type EquivUnitId } from '../../lib/stats-equiv';
|
||||
import { useTopbar } from '../../topbar';
|
||||
|
||||
const RANGE_OPTIONS = [7, 30, 90];
|
||||
|
||||
// Etykiety ekwiwalentów (wspólne masy jednostek w lib/stats-equiv).
|
||||
const EQUIV_LABELS: Record<EquivUnitId, string> = {
|
||||
elephants: 'board.equivElephants',
|
||||
bus: 'board.equivBus',
|
||||
car: 'board.equivCar',
|
||||
};
|
||||
|
||||
/* KPI: etykieta + duża wartość tabelaryczna (wzorzec statystyk siłowni). */
|
||||
function Kpi({ label, value }: { label: string; value: string | number }) {
|
||||
return (
|
||||
<Card className="p-3.5">
|
||||
<div className="text-[0.72rem] font-bold uppercase tracking-[0.08em] text-dim">{label}</div>
|
||||
<div className="mt-1 font-display text-[1.35rem] font-bold tabular-nums">{value}</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
/* Wiersz rekordu 1RM: nazwa ćwiczenia + partia + autor (lub „anonim") + wartość. */
|
||||
function RecordRow({ record, index }: { record: GymBoardRecord; index: number }) {
|
||||
const { t, i18n } = useTranslation('gyms');
|
||||
const authorName = record.author ? displayName(record.author, t('board.anon')) : t('board.anon');
|
||||
return (
|
||||
<div className="flex items-center gap-3 py-2.5">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<strong className="truncate text-[0.925rem]">
|
||||
{index + 1}. {localizedName(record, i18n.language)}
|
||||
</strong>
|
||||
<Badge color={MUSCLE_COLORS[record.muscle] ?? 'gray'}>
|
||||
{muscleName(record.muscle) || record.muscle}
|
||||
</Badge>
|
||||
</div>
|
||||
<div className="text-[0.78rem] text-dim">
|
||||
{authorName} · {fmtDate(record.date)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="shrink-0 font-display text-[1.1rem] font-bold tabular-nums">
|
||||
{fmtLoadKg(record.oneRm)} kg
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tablica statystyk siłowni REAL w panelu admina (`/gyms/:id/board`) — te same
|
||||
* dane co w apce: anonimowe agregaty wszystkich ćwiczących + ranking skutecznych
|
||||
* sesji i rekordy 1RM (nick tylko członków z opt-in). Panel jest tutaj
|
||||
* wyłącznie odczytowy: brak przełącznika zgody i trybu TV.
|
||||
*/
|
||||
export default function GymBoard() {
|
||||
const { id } = useParams();
|
||||
const { t } = useTranslation('gyms');
|
||||
const [rangeDays, setRangeDays] = useState(30);
|
||||
const { data, isLoading, error } = useGymBoard(id, rangeDays);
|
||||
|
||||
useTopbar({
|
||||
// topbar = rodzic (lista siłowni); nazwa podstrony w PageHeader poniżej (h2)
|
||||
title: t('common:nav.gyms'),
|
||||
back: `/gyms/${id}`,
|
||||
filters: [
|
||||
<Select
|
||||
key="range"
|
||||
size="sm"
|
||||
value={String(rangeDays)}
|
||||
onChange={(e) => setRangeDays(Number(e.target.value))}
|
||||
aria-label={t('board.rangeAria')}
|
||||
>
|
||||
{RANGE_OPTIONS.map((d) => (
|
||||
<option key={d} value={String(d)}>
|
||||
{t('board.rangeDays', { count: d })}
|
||||
</option>
|
||||
))}
|
||||
</Select>,
|
||||
],
|
||||
filterActive: rangeDays !== 30,
|
||||
});
|
||||
|
||||
if (isLoading) return <Loading />;
|
||||
if (error || !data) {
|
||||
return (
|
||||
<>
|
||||
<BackButton to={`/gyms/${id}`} className="mb-4" />
|
||||
<ErrorText>
|
||||
{t('common:errorPrefix')}
|
||||
{(error as Error).message}
|
||||
</ErrorText>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const { aggregate, ranking, records } = data;
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* jeden wiersz: „Tablica" + nazwa siłowni (badge) + wstecz */}
|
||||
<PageHeader
|
||||
title={t('board.title')}
|
||||
badge={
|
||||
<span className="min-w-0 truncate font-display text-[1.05rem] font-semibold tracking-[-0.02em] text-dim">
|
||||
{data.gym.name}
|
||||
</span>
|
||||
}
|
||||
actions={<BackButton to={`/gyms/${id}`} />}
|
||||
/>
|
||||
|
||||
{/* RANKING: skuteczne sesje w zakresie (nick po opt-in członka) */}
|
||||
<Card>
|
||||
<SectionHeader title={t('board.rankingTitle')} />
|
||||
{ranking.length === 0 ? (
|
||||
<p className="text-[0.875rem] text-dim">{t('board.emptyRanking')}</p>
|
||||
) : (
|
||||
<ol className="divide-y divide-line">
|
||||
{ranking.map((row, i) => {
|
||||
const name = displayName(row);
|
||||
return (
|
||||
<li key={row.userId} className="flex items-center gap-3 py-2.5">
|
||||
<span
|
||||
className={`grid w-5 shrink-0 place-items-center font-display text-[0.9rem] font-bold tabular-nums ${
|
||||
i === 0 ? 'text-accent-text' : 'text-dim'
|
||||
}`}
|
||||
>
|
||||
{i + 1}
|
||||
</span>
|
||||
<Avatar name={name} />
|
||||
<span className="min-w-0 flex-1 truncate text-[0.925rem] font-semibold">
|
||||
{name}
|
||||
</span>
|
||||
<span className="shrink-0 text-[0.78rem] tabular-nums text-dim">
|
||||
{fmtVolume(row.tonnageKg)} ·{' '}
|
||||
{t('common:counters.daysCount', { count: row.days })}
|
||||
</span>
|
||||
<span className="shrink-0 font-display text-[1.1rem] font-bold tabular-nums">
|
||||
{t('common:counters.sessions', { count: row.sessions })}
|
||||
</span>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ol>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
{/* ZBIOROWOŚĆ: anonimowe agregaty wszystkich ćwiczących + ekwiwalenty tonażu */}
|
||||
<Card>
|
||||
<SectionHeader title={t('board.aggregateTitle')} />
|
||||
<div className="grid grid-cols-2 gap-3 sm:grid-cols-3">
|
||||
<Kpi label={t('board.aggTonnage')} value={fmtVolume(aggregate.tonnageKg)} />
|
||||
<Kpi label={t('board.aggSessions')} value={aggregate.sessions} />
|
||||
<Kpi label={t('board.aggExercisers')} value={aggregate.uniqueExercisers} />
|
||||
</div>
|
||||
<div className="mt-4 divide-y divide-line">
|
||||
{EQUIV_UNITS.map((u) => {
|
||||
const count = equivCount(aggregate.tonnageKg, u.kg);
|
||||
return (
|
||||
<div
|
||||
key={u.id}
|
||||
className="flex items-center justify-between gap-3 py-2 text-[0.875rem]"
|
||||
>
|
||||
<span className="text-dim">{t(EQUIV_LABELS[u.id], { count })}</span>
|
||||
<span className="shrink-0 font-display font-bold tabular-nums">× {count}</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* PARTIE CIAŁA: serie i tonaż wg partii pierwotnej (współdzielony pasek + legenda) */}
|
||||
<Card>
|
||||
<SectionHeader title={t('board.musclesTitle')} />
|
||||
{aggregate.muscles.length === 0 ? (
|
||||
<p className="text-[0.875rem] text-dim">{t('board.emptyMuscles')}</p>
|
||||
) : (
|
||||
<MuscleSplit muscles={aggregate.muscles} ariaLabel={t('board.musclesTitle')} />
|
||||
)}
|
||||
</Card>
|
||||
|
||||
{/* REKORDY 1RM: Epley z całej historii; autor tylko gdy wyraził zgodę */}
|
||||
<Card>
|
||||
<SectionHeader title={t('board.recordsTitle')} />
|
||||
{records.length === 0 ? (
|
||||
<p className="text-[0.875rem] text-dim">{t('board.emptyRecords')}</p>
|
||||
) : (
|
||||
<div className="divide-y divide-line">
|
||||
{records.map((r, i) => (
|
||||
<RecordRow key={r.exerciseId} record={r} index={i} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
Settings,
|
||||
Star,
|
||||
Trash2,
|
||||
Trophy,
|
||||
UserPlus,
|
||||
UserX,
|
||||
Users,
|
||||
@@ -248,6 +249,29 @@ function PresenceRow({
|
||||
);
|
||||
}
|
||||
|
||||
/* Kafelek Tablicy statystyk (tylko REAL): klik → podstrona tablicy (odczyt). */
|
||||
function BoardTile({ gymId }: { gymId: string }) {
|
||||
const { t } = useTranslation('gyms');
|
||||
return (
|
||||
<Link
|
||||
to={`/gyms/${gymId}/board`}
|
||||
className="flex flex-col rounded-2xl border border-line bg-card p-3 transition-colors hover:border-accent/55"
|
||||
>
|
||||
<div className="grid h-28 place-items-center rounded-[10px] border border-dashed border-line bg-input/50 text-dim">
|
||||
<Trophy className="h-5 w-5" aria-hidden="true" />
|
||||
</div>
|
||||
<div className="mt-2.5 flex items-center justify-between gap-2">
|
||||
<span className="min-w-0 truncate font-display text-[0.9rem] font-bold">
|
||||
{t('board.title')}
|
||||
</span>
|
||||
<span className="shrink-0 text-[0.72rem] font-semibold text-dim">
|
||||
{t('board.tileHint')}
|
||||
</span>
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
/* Kafelek Galerii (tylko REAL): mini-mozaika 4 miniatur + licznik; klik → podstrona galerii. */
|
||||
function GalleryTile({ gym }: { gym: Gym }) {
|
||||
const { t } = useTranslation('gyms');
|
||||
@@ -940,6 +964,8 @@ export default function GymDetail() {
|
||||
</div>
|
||||
|
||||
<div className="flex min-w-0 flex-col gap-4">
|
||||
{/* Tablica nad Bytnością: kafelek prowadzi na podstronę tablicy (odczyt) */}
|
||||
{gym.kind === 'REAL' && <BoardTile gymId={gym.id} />}
|
||||
{gym.kind === 'REAL' && (
|
||||
<Card>
|
||||
<SectionHeader title={t('presence.title')} />
|
||||
|
||||
158
admin/test/GymBoard.test.tsx
Normal file
158
admin/test/GymBoard.test.tsx
Normal file
@@ -0,0 +1,158 @@
|
||||
import { render, screen, fireEvent, waitFor, within } from '@testing-library/react';
|
||||
import { MemoryRouter, Route, Routes } from 'react-router-dom';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import GymBoard from '../src/pages/gyms/GymBoard';
|
||||
import { Topbar } from '../src/topbar';
|
||||
import { setAccessToken } from '../src/api/client';
|
||||
import type { GymBoardData } from '../src/api/types';
|
||||
|
||||
type Call = { url: string };
|
||||
|
||||
function jsonResponse(status: number, body: unknown) {
|
||||
return new Response(JSON.stringify(body), {
|
||||
status,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
function boardBody(rangeDays: number): GymBoardData {
|
||||
return {
|
||||
gym: { id: 'g1', name: 'Gym A' },
|
||||
myStatsOptIn: null,
|
||||
rangeDays,
|
||||
ranking: [
|
||||
{
|
||||
userId: 'u-ala',
|
||||
nickname: 'żelazka',
|
||||
firstName: 'Ala',
|
||||
lastName: 'Nowak',
|
||||
sessions: 8,
|
||||
tonnageKg: 18200,
|
||||
days: 6,
|
||||
},
|
||||
{
|
||||
userId: 'u-bob',
|
||||
nickname: null,
|
||||
firstName: 'Bob',
|
||||
lastName: 'Kowal',
|
||||
sessions: 5,
|
||||
tonnageKg: 11000,
|
||||
days: 4,
|
||||
},
|
||||
],
|
||||
aggregate: {
|
||||
tonnageKg: 42000,
|
||||
sessions: 24,
|
||||
uniqueExercisers: 9,
|
||||
muscles: [
|
||||
{ muscle: 'legs', sets: 40, volumeKg: 21000 },
|
||||
{ muscle: 'chest', sets: 25, volumeKg: 9500 },
|
||||
],
|
||||
},
|
||||
records: [
|
||||
{
|
||||
exerciseId: 'e-squat',
|
||||
name: 'Przysiady',
|
||||
nameEn: 'Squat',
|
||||
muscle: 'legs',
|
||||
oneRm: 140,
|
||||
date: '2026-09-12T16:00:00.000Z',
|
||||
author: { nickname: 'żelazka', firstName: 'Ala', lastName: 'Nowak' },
|
||||
},
|
||||
{
|
||||
exerciseId: 'e-bench',
|
||||
name: 'Wyciskanie leżąc',
|
||||
nameEn: 'Bench press',
|
||||
muscle: 'chest',
|
||||
oneRm: 100,
|
||||
date: '2026-08-30T16:00:00.000Z',
|
||||
author: null,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
function stubBoardFetch(calls: Call[]) {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn(async (input: RequestInfo | URL) => {
|
||||
const url = String(input);
|
||||
calls.push({ url });
|
||||
const range = Number(url.match(/board\?range=(\d+)/)?.[1] ?? 30);
|
||||
if (url.includes('/gyms/g1/board')) return jsonResponse(200, boardBody(range));
|
||||
throw new Error(`Unexpected fetch: ${url}`);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
function renderBoard(path = '/gyms/g1/board') {
|
||||
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
||||
return render(
|
||||
<MemoryRouter initialEntries={[path]}>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<Topbar />
|
||||
<Routes>
|
||||
<Route path="/gyms/:id" element={<div>detail</div>} />
|
||||
<Route path="/gyms/:id/board" element={<GymBoard />} />
|
||||
</Routes>
|
||||
</QueryClientProvider>
|
||||
</MemoryRouter>,
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
setAccessToken('admin-tok');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
describe('admin GymBoard — tablica siłowni (odczyt)', () => {
|
||||
it('renders ranking, anonymous aggregates with equivalents and 1RM records', async () => {
|
||||
stubBoardFetch([]);
|
||||
renderBoard();
|
||||
|
||||
// jeden wiersz nagłówka: h2 „Tablica" + nazwa siłowni
|
||||
expect(await screen.findByRole('heading', { name: 'Tablica', level: 2 })).toBeInTheDocument();
|
||||
expect(screen.getByText('Gym A')).toBeInTheDocument();
|
||||
|
||||
// ranking: nick z opt-in + nazwa bez nicka
|
||||
const ranking = screen
|
||||
.getByText('Ranking treningów')
|
||||
.closest('[data-slot="card"]') as HTMLElement;
|
||||
expect(within(ranking).getByText('żelazka')).toBeInTheDocument();
|
||||
expect(within(ranking).getByText('Bob Kowal')).toBeInTheDocument();
|
||||
|
||||
// zbiorowość anonimowa: tonaż 42 t + ekwiwalenty
|
||||
const aggregate = screen
|
||||
.getByText('Zbiorowość siłowni')
|
||||
.closest('[data-slot="card"]') as HTMLElement;
|
||||
expect(screen.getByText('42 t')).toBeInTheDocument();
|
||||
expect(screen.getByText('słoń afrykański (6 t)')).toBeInTheDocument();
|
||||
|
||||
// partie ciała: serie + tonaż
|
||||
expect(screen.getByText('40 serii · 21 t')).toBeInTheDocument();
|
||||
|
||||
// rekordy: autor z opt-in po nicku, brak autora jako „anonim"
|
||||
expect(screen.getByText('140 kg')).toBeInTheDocument();
|
||||
expect(screen.getByText(/anonim ·/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('panel jest read-only: brak przełącznika zgody; filtr zakresu refetchuje tablicę', async () => {
|
||||
const calls: Call[] = [];
|
||||
stubBoardFetch(calls);
|
||||
renderBoard();
|
||||
|
||||
// w panelu admina nie ma opt-in nicka (to decyzja członka w apce)
|
||||
expect(screen.queryByRole('switch')).not.toBeInTheDocument();
|
||||
|
||||
const select = screen.getByRole('combobox', { name: 'Zakres tablicy' });
|
||||
expect(select).toHaveValue('30');
|
||||
fireEvent.change(select, { target: { value: '7' } });
|
||||
await waitFor(() =>
|
||||
expect(calls.some((c) => c.url.includes('board?range=7'))).toBe(true),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -176,10 +176,16 @@ describe('admin GymDetail page', () => {
|
||||
// hero bez chipa miasta i karty „Dane" — zostają liczniki członków/urządzeń
|
||||
expect(screen.getByText('12 członków')).toBeInTheDocument();
|
||||
|
||||
// kafelki sekcji prowadzą do podstron (galeria/urządzenia/ogłoszenia)
|
||||
// kafelki sekcji prowadzą do podstron (galeria/urządzenia/ogłoszenia + tablica nad bytnością)
|
||||
expect(screen.getByRole('link', { name: /Galeria zdjęć/ })).toBeInTheDocument();
|
||||
expect(screen.getByRole('link', { name: /Urządzenia/ })).toBeInTheDocument();
|
||||
expect(screen.getByRole('link', { name: /Ogłoszenia/ })).toBeInTheDocument();
|
||||
const boardTile = screen.getByRole('link', { name: /Tablica/ });
|
||||
expect(boardTile).toHaveAttribute('href', '/gyms/g1/board');
|
||||
const presenceHeading = await screen.findByText('Bytność');
|
||||
expect(
|
||||
boardTile.compareDocumentPosition(presenceHeading) & Node.DOCUMENT_POSITION_FOLLOWING,
|
||||
).toBeTruthy();
|
||||
|
||||
// menu kontekstowe: JEDNA grupa „Zarządzaj” z akcjami strony (admin: + Właściciele)
|
||||
const config = useTopbarStore.getState().config;
|
||||
|
||||
Reference in New Issue
Block a user