Admin: przeglad usera 1:1 z profilem apki (pasek 3 kafelkow bez Ostatniej wagi, podsumowanie Postepow z liczba cwiczen, dane osobowe jako kafelki z ikonami/tonowane miesnie/kafelki social, parametry ciala jako zakladki z pelna historia i postepem, usuniecie opisu Epley; dalej tylko do odczytu)
This commit is contained in:
@@ -8,16 +8,20 @@ import { cn } from '../../lib/utils';
|
||||
/* Page header: title + optional badge, actions on the right (stacks on mobile) */
|
||||
export function PageHeader({
|
||||
title,
|
||||
leading,
|
||||
badge,
|
||||
actions,
|
||||
}: {
|
||||
title: string;
|
||||
/** Element przed tytułem (np. awatar). */
|
||||
leading?: ReactNode;
|
||||
badge?: ReactNode;
|
||||
actions?: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 mb-5">
|
||||
<div className="flex items-center gap-3 flex-wrap">
|
||||
{leading}
|
||||
{/* `<h1>` należy do topbaru (tytuł strony) — nagłówek treści to `<h2>` */}
|
||||
<H2 className="mb-0">{title}</H2>
|
||||
{badge}
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
import type { Availability, DayAvailability } from '../api/types.js';
|
||||
|
||||
export const DAY_NAMES = ['Pon', 'Wt', 'Śr', 'Czw', 'Pt', 'Sob', 'Niedz'] as const;
|
||||
export const DAY_NAMES_FULL = ['Poniedziałek', 'Wtorek', 'Środa', 'Czwartek', 'Piątek', 'Sobota', 'Niedziela'] as const;
|
||||
export const DAY_NAMES_FULL = [
|
||||
'Poniedziałek',
|
||||
'Wtorek',
|
||||
'Środa',
|
||||
'Czwartek',
|
||||
'Piątek',
|
||||
'Sobota',
|
||||
'Niedziela',
|
||||
] as const;
|
||||
|
||||
/** 30-minute slots from 05:00 to 23:00. */
|
||||
export const TIME_SLOTS: string[] = (() => {
|
||||
@@ -30,14 +38,31 @@ export function normalizeAvailability(value: unknown): Availability {
|
||||
return emptyAvailability();
|
||||
}
|
||||
|
||||
/** Human-readable summary, e.g. "Pon 18:00–20:00, Wt 18:00–20:00". Empty string if none. */
|
||||
export function formatAvailability(value: unknown): string {
|
||||
/** Zakresy pogrupowane po dniach o tych samych godzinach, np. ["Pon–Pt 18:00–20:00"].
|
||||
Pusta tablica, gdy brak ustawionej dostępności. */
|
||||
export function formatAvailabilityParts(value: unknown): string[] {
|
||||
const arr = normalizeAvailability(value);
|
||||
const parts: string[] = [];
|
||||
arr.forEach((day, i) => {
|
||||
if (day) parts.push(`${DAY_NAMES[i]} ${day.start}–${day.end}`);
|
||||
});
|
||||
return parts.join(', ');
|
||||
let i = 0;
|
||||
while (i < 7) {
|
||||
const day = arr[i];
|
||||
if (!day) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
let j = i + 1;
|
||||
while (j < 7 && arr[j] && arr[j]!.start === day.start && arr[j]!.end === day.end) j++;
|
||||
const days = j - i > 1 ? `${DAY_NAMES[i]}–${DAY_NAMES[j - 1]}` : DAY_NAMES[i];
|
||||
parts.push(`${days} ${day.start}–${day.end}`);
|
||||
i = j;
|
||||
}
|
||||
return parts;
|
||||
}
|
||||
|
||||
/** Human-readable summary with consecutive same-time days grouped,
|
||||
e.g. "Pon–Pt 18:00–20:00, Sob 12:00–14:00". Empty string if none. */
|
||||
export function formatAvailability(value: unknown): string {
|
||||
return formatAvailabilityParts(value).join(', ');
|
||||
}
|
||||
|
||||
/** "18:00" -> "18", "21:30" -> "21:30" — forma skrócona do siatki tygodnia. */
|
||||
|
||||
@@ -20,6 +20,31 @@ export const MEASUREMENT_TYPES: MeasurementType[] = [
|
||||
|
||||
export const SIDE_LABELS: Record<Side, string> = { left: 'Lewy', right: 'Prawy' };
|
||||
|
||||
/* Rodzaj gramatyczny części ciała → poprawna fleksja przymiotnika strony. */
|
||||
const PART_GENDERS: Record<string, 'm' | 'f' | 'n' | 'p'> = {
|
||||
'Klatka piersiowa': 'f',
|
||||
Talia: 'f',
|
||||
Biodra: 'p',
|
||||
Kark: 'm',
|
||||
Biceps: 'm',
|
||||
Przedramię: 'n',
|
||||
Udo: 'n',
|
||||
Łydka: 'f',
|
||||
};
|
||||
|
||||
/** Etykiety strony zgodne z rodzajem części: `Udo` → `Lewe`/`Prawe`, `Talia` → `Lewa`/`Prawa`. */
|
||||
export function sideLabelsFor(part: string): Record<Side, string> {
|
||||
switch (PART_GENDERS[part]) {
|
||||
case 'f':
|
||||
return { left: 'Lewa', right: 'Prawa' };
|
||||
case 'n':
|
||||
case 'p':
|
||||
return { left: 'Lewe', right: 'Prawe' };
|
||||
default:
|
||||
return SIDE_LABELS;
|
||||
}
|
||||
}
|
||||
|
||||
export function measurementType(typeId: string): MeasurementType | undefined {
|
||||
return MEASUREMENT_TYPES.find((t) => t.id === typeId);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,18 @@ export const MUSCLE_NAMES: Record<string, string> = {
|
||||
calves: 'Łydki',
|
||||
};
|
||||
|
||||
export const MUSCLE_COLORS: Record<string, BadgeColor> = {
|
||||
chest: 'red',
|
||||
back: 'blue',
|
||||
legs: 'green',
|
||||
shoulders: 'yellow',
|
||||
biceps: 'blue',
|
||||
triceps: 'yellow',
|
||||
core: 'gray',
|
||||
glutes: 'red',
|
||||
forearms: 'gray',
|
||||
};
|
||||
|
||||
export const SESSION_STATUS: Record<
|
||||
HistorySession['status'],
|
||||
{ label: string; color: BadgeColor }
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { useEffect, useState, type ReactNode } from 'react';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { ChevronDown, Ruler, Scale, type LucideIcon } from 'lucide-react';
|
||||
import { Ruler, Scale, TrendingDown, TrendingUp, type LucideIcon } from 'lucide-react';
|
||||
import {
|
||||
LineChart,
|
||||
Line,
|
||||
Area,
|
||||
AreaChart,
|
||||
XAxis,
|
||||
YAxis,
|
||||
Tooltip,
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
CartesianGrid,
|
||||
} from 'recharts';
|
||||
import { useTopbar } from '../../topbar';
|
||||
import { MonthPickerCore } from '../../topbar/MonthPicker';
|
||||
import {
|
||||
BackButton,
|
||||
Button,
|
||||
@@ -21,12 +20,14 @@ import {
|
||||
H3,
|
||||
PageHeader,
|
||||
Skeleton,
|
||||
Tabs,
|
||||
} from '../../components/ui';
|
||||
import {
|
||||
MEASUREMENT_TYPES,
|
||||
SIDE_LABELS,
|
||||
bodyPartOf,
|
||||
detectBodyPart,
|
||||
sideLabelsFor,
|
||||
sideOf,
|
||||
type Side,
|
||||
} from '../../lib/body-measurements';
|
||||
@@ -41,6 +42,26 @@ const TOOLTIP_STYLE = {
|
||||
color: 'var(--text)',
|
||||
};
|
||||
|
||||
/* Wykresy: oś bez linii i kresek, drobny dimowany tick — tło siatki tylko poziome. */
|
||||
const AXIS_TICK = { fill: 'var(--text-dim)', fontSize: 12 };
|
||||
const CHART_MARGIN = { top: 8, right: 8, left: 0, bottom: 0 };
|
||||
|
||||
/* Kolor linii wg jednostki: waga = accent, obwody = info. */
|
||||
const unitStroke = (unit: PartGroup['unit']) => (unit === 'kg' ? 'var(--accent)' : 'var(--info)');
|
||||
/* Tooltip: wartość z jednostką, nazwa serii bez zmian (formatter zwraca parę [wartość, nazwa]). */
|
||||
const tooltipUnit =
|
||||
(unit: PartGroup['unit']) =>
|
||||
(value: number | string, name: string): [string, string] => [`${value} ${unit}`, name];
|
||||
|
||||
/* Punkty pomiarowe: pusty środek (karta pod spodem), ring w kolorze linii. */
|
||||
const lineDot = (stroke: string) => ({ r: 3, strokeWidth: 2, fill: 'var(--bg-card)', stroke });
|
||||
const lineActiveDot = (stroke: string) => ({
|
||||
r: 5,
|
||||
strokeWidth: 2,
|
||||
fill: 'var(--bg-card)',
|
||||
stroke,
|
||||
});
|
||||
|
||||
interface CircGroup {
|
||||
part: string;
|
||||
series: CircumferenceSeries[];
|
||||
@@ -70,168 +91,420 @@ function groupCircumferences(series: CircumferenceSeries[]): CircGroup[] {
|
||||
}));
|
||||
}
|
||||
|
||||
/** Wspólna oś dat dla obu stron: `[{ date, lewy, prawy }]` (brak pomiaru = null). */
|
||||
function mergedSideData(series: CircumferenceSeries[]) {
|
||||
const byDate = new Map<string, { date: string; lewy: number | null; prawy: number | null }>();
|
||||
for (const s of series) {
|
||||
const side = sideOf(s.name);
|
||||
if (side == null) continue;
|
||||
for (const p of s.points) {
|
||||
const entry = byDate.get(p.date) ?? { date: p.date, lewy: null, prawy: null };
|
||||
entry[side === 'left' ? 'lewy' : 'prawy'] = p.value;
|
||||
byDate.set(p.date, entry);
|
||||
}
|
||||
}
|
||||
return [...byDate.values()]
|
||||
.sort((a, b) => a.date.localeCompare(b.date))
|
||||
.map((e) => ({
|
||||
date: new Date(e.date).toLocaleDateString('pl-PL', { day: '2-digit', month: '2-digit' }),
|
||||
lewy: e.lewy,
|
||||
prawy: e.prawy,
|
||||
}));
|
||||
/* Grupa pomiaru w ujednoliconej postaci: waga i obwody jako jeden model (panel + wykres). */
|
||||
interface GroupPoint {
|
||||
id: string;
|
||||
value: number;
|
||||
date: string;
|
||||
side: Side | null;
|
||||
name: string;
|
||||
}
|
||||
|
||||
/* Karta pomiaru: nagłówek (ikona + H3 + najnowszy pomiar) + treść (wykres + lista). */
|
||||
function MeasurementCard({
|
||||
icon: Icon,
|
||||
title,
|
||||
latest,
|
||||
children,
|
||||
interface PartGroup {
|
||||
part: string;
|
||||
unit: 'kg' | 'cm';
|
||||
/** Wszystkie pomiary (pełna historia), rosnąco po dacie. */
|
||||
points: GroupPoint[];
|
||||
sidesPresent: Side[];
|
||||
}
|
||||
|
||||
/* Polski pluralis dla „pomiar”. */
|
||||
function pomN(n: number): string {
|
||||
if (n === 1) return '1 pomiar';
|
||||
if (n % 10 >= 2 && n % 10 <= 4 && !(n % 100 >= 12 && n % 100 <= 14)) return `${n} pomiary`;
|
||||
return `${n} pomiarów`;
|
||||
}
|
||||
|
||||
const WEIGHT_PART = 'Waga';
|
||||
|
||||
const fmtVal = (n: number) => n.toLocaleString('pl-PL', { maximumFractionDigits: 1 });
|
||||
const signed = (d: number) => `${d < 0 ? '−' : '+'}${fmtVal(Math.abs(d))}`;
|
||||
|
||||
/* Postęp części: zmiana najnowszego pomiaru od pierwszego; spadek wagi = dobry kierunek. */
|
||||
function progressOf(g: PartGroup): { text: string; className: string } | null {
|
||||
if (g.points.length < 2) return null;
|
||||
const d = g.points[g.points.length - 1].value - g.points[0].value;
|
||||
if (d === 0) return null;
|
||||
const className = g.unit === 'kg' ? (d < 0 ? 'text-accent-text' : 'text-warn') : 'text-ink';
|
||||
return { text: `${signed(d)} ${g.unit} od pierwszego`, className };
|
||||
}
|
||||
|
||||
/* Osobny div postępu wybranej części: kierunek zmiany + wynik (strony osobno, gdy łączone). */
|
||||
function ProgressCard({
|
||||
down,
|
||||
primary,
|
||||
primaryClass,
|
||||
sub,
|
||||
}: {
|
||||
icon: LucideIcon;
|
||||
title: string;
|
||||
latest?: ReactNode;
|
||||
children: ReactNode;
|
||||
down: boolean;
|
||||
primary: string;
|
||||
primaryClass: string;
|
||||
sub: string;
|
||||
}) {
|
||||
const Icon = down ? TrendingDown : TrendingUp;
|
||||
return (
|
||||
<Card>
|
||||
<div className="mb-3 flex flex-wrap items-center justify-between gap-2">
|
||||
<div className="flex items-center gap-2.5">
|
||||
<span className="grid h-8 w-8 place-items-center rounded-[10px] bg-accent/10 text-accent-text">
|
||||
<Icon className="h-4 w-4" />
|
||||
</span>
|
||||
<H3 className="mb-0">{title}</H3>
|
||||
<Card className="mb-4">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="grid h-9 w-9 flex-none place-items-center rounded-[10px] bg-input text-dim">
|
||||
<Icon className="h-4 w-4" />
|
||||
</span>
|
||||
<div className="min-w-0">
|
||||
<H3 className="mb-0.5">Postęp</H3>
|
||||
<p className={`text-[0.95rem] font-semibold tabular-nums ${primaryClass}`}>{primary}</p>
|
||||
<p className="text-[0.8125rem] text-dim">{sub}</p>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2">{latest}</div>
|
||||
</div>
|
||||
{children}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
interface MeasurementPoint {
|
||||
id: string;
|
||||
label: string;
|
||||
meta: string;
|
||||
/** Etykieta osi X: `17.10`; gdy historia przekracza rok — `17.10.26`. */
|
||||
function axisDateLabel(iso: string, withYear: boolean): string {
|
||||
return new Date(iso).toLocaleDateString('pl-PL', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
...(withYear ? { year: '2-digit' } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
/* Lista pomiarów: najnowsze N + „Pokaż więcej"; wiersz = wartość + data (+ strona). */
|
||||
function MeasurementList({
|
||||
/** Klucz dnia kalendarzowego (lokalnego) — jeden dzień to jedna kategoria osi X. */
|
||||
function dayKey(iso: string): string {
|
||||
const d = new Date(iso);
|
||||
return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dane wykresu: wiersze po dniach kalendarzowych — ten sam dzień mierzony
|
||||
* dwa razy (lub z obu stron) daje jeden punkt z osią X (ostatnia wartość dnia).
|
||||
*/
|
||||
function chartData(points: GroupPoint[]) {
|
||||
const rows = new Map<string, { day: string; date: string; value: number }>();
|
||||
for (const p of points) {
|
||||
const day = dayKey(p.date);
|
||||
const row = rows.get(day) ?? { day, date: p.date, value: p.value };
|
||||
row.date = p.date;
|
||||
row.value = p.value;
|
||||
rows.set(day, row);
|
||||
}
|
||||
return [...rows.values()];
|
||||
}
|
||||
|
||||
const SIDE_STROKE: Record<Side, string> = { left: 'var(--info)', right: 'var(--accent)' };
|
||||
|
||||
/* Pojedyncza seria: obszar z gradientem, oś X po dniach (pomiary z dnia w jednym punkcie). */
|
||||
function PartAreaChart({
|
||||
name,
|
||||
points,
|
||||
stroke,
|
||||
unit,
|
||||
withYear,
|
||||
height,
|
||||
}: {
|
||||
name: string;
|
||||
points: GroupPoint[];
|
||||
stroke: string;
|
||||
unit: 'kg' | 'cm';
|
||||
withYear: boolean;
|
||||
height: number;
|
||||
}) {
|
||||
const rows = chartData(points);
|
||||
const labelAt = (v: string | number) => {
|
||||
const row = rows.find((r) => r.day === String(v));
|
||||
return row ? axisDateLabel(row.date, withYear) : '';
|
||||
};
|
||||
const areaId = `bp-area-${encodeURIComponent(name)}`;
|
||||
return (
|
||||
<ResponsiveContainer width="100%" height={height}>
|
||||
<AreaChart data={rows} margin={CHART_MARGIN}>
|
||||
<defs>
|
||||
<linearGradient id={areaId} x1="0" y1="0" x2="0" y2="1">
|
||||
<stop offset="0%" stopColor={stroke} stopOpacity={0.25} />
|
||||
<stop offset="100%" stopColor={stroke} stopOpacity={0} />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<CartesianGrid stroke="var(--border)" vertical={false} />
|
||||
<XAxis
|
||||
dataKey="day"
|
||||
tickFormatter={labelAt}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickMargin={10}
|
||||
minTickGap={32}
|
||||
tick={AXIS_TICK}
|
||||
/>
|
||||
<YAxis
|
||||
width={44}
|
||||
tickLine={false}
|
||||
axisLine={false}
|
||||
tickMargin={8}
|
||||
domain={['auto', 'auto']}
|
||||
tick={AXIS_TICK}
|
||||
/>
|
||||
<Tooltip
|
||||
contentStyle={TOOLTIP_STYLE}
|
||||
formatter={tooltipUnit(unit)}
|
||||
labelFormatter={labelAt}
|
||||
/>
|
||||
<Area
|
||||
type="monotone"
|
||||
dataKey="value"
|
||||
name={name}
|
||||
stroke={stroke}
|
||||
strokeWidth={2}
|
||||
fill={`url(#${areaId})`}
|
||||
dot={lineDot(stroke)}
|
||||
activeDot={lineActiveDot(stroke)}
|
||||
/>
|
||||
</AreaChart>
|
||||
</ResponsiveContainer>
|
||||
);
|
||||
}
|
||||
|
||||
/* Panel wybranej części. Strony mierzone (lewy/prawy) = dwa niezależne divy,
|
||||
każdy z własnym nagłówkiem, postępem, wykresem i listą — lewy zawsze pierwszy. */
|
||||
function MeasurementPanel({
|
||||
group,
|
||||
icon: Icon,
|
||||
visible,
|
||||
onShowMore,
|
||||
}: {
|
||||
points: MeasurementPoint[];
|
||||
group: PartGroup;
|
||||
icon: LucideIcon;
|
||||
visible: number;
|
||||
onShowMore: () => void;
|
||||
}) {
|
||||
if (points.length === 0) return null;
|
||||
const sided = group.sidesPresent.length > 1;
|
||||
if (!sided) {
|
||||
return (
|
||||
<Card>
|
||||
<PartSection
|
||||
title={group.part}
|
||||
icon={Icon}
|
||||
unit={group.unit}
|
||||
points={group.points}
|
||||
stroke={unitStroke(group.unit)}
|
||||
chartName={group.part}
|
||||
visible={visible}
|
||||
onShowMore={onShowMore}
|
||||
/>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
const labels = sideLabelsFor(group.part);
|
||||
const unsidePoints = group.points.filter((p) => p.side == null);
|
||||
return (
|
||||
<div>
|
||||
{/* 3 najnowsze; duże ekrany: wiersz z poziomym scrollem, małe: kolumna */}
|
||||
<ul className="mt-3 flex flex-col gap-1.5 sm:flex-row sm:overflow-x-auto sm:pb-1">
|
||||
{points.slice(0, visible).map((p) => (
|
||||
<li
|
||||
key={p.id}
|
||||
className="border border-line bg-input rounded-xl px-3.5 py-2.5 text-[0.95rem] sm:w-44 sm:shrink-0"
|
||||
>
|
||||
<strong className="text-ink">{p.label}</strong>
|
||||
<div className="mt-0.5 text-[0.875rem] text-dim">{p.meta}</div>
|
||||
</li>
|
||||
<div className="flex flex-col gap-4">
|
||||
{(['left', 'right'] as Side[])
|
||||
.filter((s) => group.sidesPresent.includes(s))
|
||||
.map((s) => (
|
||||
<Card key={s}>
|
||||
<PartSection
|
||||
title={`${group.part} — ${labels[s].toLowerCase()}`}
|
||||
icon={Icon}
|
||||
unit={group.unit}
|
||||
points={group.points.filter((p) => p.side === s)}
|
||||
stroke={SIDE_STROKE[s]}
|
||||
chartName={labels[s].toLowerCase()}
|
||||
visible={visible}
|
||||
onShowMore={onShowMore}
|
||||
/>
|
||||
</Card>
|
||||
))}
|
||||
</ul>
|
||||
{points.length > visible && (
|
||||
<Button variant="ghost" size="sm" className="mt-2" onClick={onShowMore}>
|
||||
<ChevronDown className="w-4 h-4" />
|
||||
Pokaż więcej
|
||||
</Button>
|
||||
{unsidePoints.length > 0 && (
|
||||
<Card>
|
||||
<PartSection
|
||||
title={group.part}
|
||||
icon={Icon}
|
||||
unit={group.unit}
|
||||
points={unsidePoints}
|
||||
stroke={unitStroke(group.unit)}
|
||||
chartName={group.part}
|
||||
visible={visible}
|
||||
onShowMore={onShowMore}
|
||||
/>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/* Sekcja części/strony: nagłówek (nazwa + ostatni pomiar) + postęp + wykres historii + lista pomiarów.
|
||||
Tylko do odczytu — pomiary dodaje i usuwa wyłącznie użytkownik w aplikacji. */
|
||||
function PartSection({
|
||||
title,
|
||||
icon: Icon,
|
||||
unit,
|
||||
points,
|
||||
stroke,
|
||||
chartName,
|
||||
visible,
|
||||
onShowMore,
|
||||
}: {
|
||||
title: string;
|
||||
icon: LucideIcon;
|
||||
unit: 'kg' | 'cm';
|
||||
points: GroupPoint[];
|
||||
stroke: string;
|
||||
chartName: string;
|
||||
visible: number;
|
||||
onShowMore: () => void;
|
||||
}) {
|
||||
const latest = points[points.length - 1];
|
||||
// historia przekracza rok → oś X z rokiem (również przy przerwie >12 mies. w jednym roku)
|
||||
const withYear =
|
||||
new Date(points[points.length - 1].date).getTime() - new Date(points[0].date).getTime() >
|
||||
300 * 86_400_000;
|
||||
// postęp sekcji (dla strony: osobna, przy łączonej: per strona): zmiana od pierwszego pomiaru
|
||||
const prog = progressOf({ part: title, unit, points, sidesPresent: [] });
|
||||
const primary = prog?.text ?? 'bez zmian';
|
||||
const primaryClass = prog?.className ?? 'text-dim';
|
||||
const sub =
|
||||
points.length < 2
|
||||
? 'drugi pomiar pokaże zmianę'
|
||||
: `${pomN(points.length)} · pierwszy → ostatni`;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="mb-3 flex flex-wrap items-center justify-between gap-2">
|
||||
<div className="flex items-center gap-2.5">
|
||||
<span
|
||||
className="grid h-8 w-8 place-items-center rounded-[10px] bg-input"
|
||||
style={{ color: stroke }}
|
||||
>
|
||||
<Icon className="h-4 w-4" />
|
||||
</span>
|
||||
<H3 className="mb-0">{title}</H3>
|
||||
</div>
|
||||
<span className="flex flex-col items-end">
|
||||
<span className="flex items-baseline gap-2">
|
||||
<span className="font-display text-[1.35rem] font-bold leading-none tabular-nums">
|
||||
{latest.value} {unit}
|
||||
</span>
|
||||
<span className="text-[0.75rem] text-dim">{fmtDate(latest.date)}</span>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<ProgressCard
|
||||
down={prog != null && prog.text.startsWith('−')}
|
||||
primary={primary}
|
||||
primaryClass={primaryClass}
|
||||
sub={sub}
|
||||
/>
|
||||
|
||||
{points.length >= 2 ? (
|
||||
<PartAreaChart
|
||||
name={chartName}
|
||||
points={points}
|
||||
stroke={stroke}
|
||||
unit={unit}
|
||||
withYear={withYear}
|
||||
height={220}
|
||||
/>
|
||||
) : (
|
||||
<p className="text-dim">Za mało danych na wykres (min. 2 pomiary).</p>
|
||||
)}
|
||||
|
||||
{/* lista: najnowsze 3 + „Pokaż więcej" (kolejne 3); pełna historia w wykresie */}
|
||||
<div>
|
||||
<ul className="mt-3 flex flex-col gap-1.5 sm:flex-row sm:overflow-x-auto sm:pb-1">
|
||||
{[...points]
|
||||
.reverse()
|
||||
.slice(0, visible)
|
||||
.map((p) => {
|
||||
const sideLabel = p.side ? ` · ${SIDE_LABELS[p.side]}` : '';
|
||||
return (
|
||||
<li
|
||||
key={p.id}
|
||||
className="border border-line bg-input rounded-xl px-3.5 py-2.5 text-[0.95rem] sm:w-44 sm:shrink-0"
|
||||
>
|
||||
<strong className="text-ink">
|
||||
{p.value} {unit}
|
||||
</strong>
|
||||
<div className="mt-0.5 text-[0.875rem] text-dim">
|
||||
{fmtDate(p.date)}
|
||||
{sideLabel}
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
{points.length > visible && (
|
||||
<Button variant="ghost" size="sm" className="mt-2" onClick={onShowMore}>
|
||||
Pokaż więcej
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parametry ciała użytkownika (admin) — tylko do odczytu: wykresy i listy pomiarów.
|
||||
* Pomiary (waga, obwody) są w domenie read-only obok profilu — dodaje je wyłącznie
|
||||
* użytkownik w aplikacji. Układ wzorowany na `/profile/body-parameters`.
|
||||
* Parametry ciała użytkownika (admin) — tylko do odczyt: układ 1:1 z `/profile/body-parameters`
|
||||
* aplikacji (zakładki części z pełną historią, panel postępu, wykresy obszarowe, strony
|
||||
* osobno). Pomiary dodaje i usuwa wyłącznie użytkownik — brak kontrolek edycji.
|
||||
*/
|
||||
export default function UserBodyParameters() {
|
||||
const { id } = useParams();
|
||||
const { data: bp, isLoading: bpLoading, error: bpError } = useUserBodyParameters(id);
|
||||
|
||||
const [visible, setVisible] = useState<Record<string, number>>({});
|
||||
// miesiąc w topmenu: zawsze wybrany (domyślnie bieżący), jak w aplikacji;
|
||||
// strzałki i siatka skaczą tylko po miesiącach z danymi
|
||||
const [month, setMonth] = useState(() => {
|
||||
const d = new Date();
|
||||
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`;
|
||||
});
|
||||
|
||||
// miesiące z danymi (nowe → stare) — do selektora w topmenu
|
||||
const monthKeys = [
|
||||
...(bp?.weight ?? []).map((w) => w.date.slice(0, 7)),
|
||||
...(bp?.circumferences ?? []).flatMap((s) => s.points.map((p) => p.date.slice(0, 7))),
|
||||
];
|
||||
const availableMonths = [...new Set(monthKeys)].sort().reverse();
|
||||
const [selected, setSelected] = useState<string | null>(null);
|
||||
|
||||
useTopbar({
|
||||
title: 'Parametry ciała',
|
||||
back: id ? `/users/${id}` : '/users',
|
||||
dateFilter: (
|
||||
<MonthPickerCore month={month} setMonth={setMonth} availableMonths={availableMonths} />
|
||||
),
|
||||
filterActive: month !== '',
|
||||
});
|
||||
|
||||
// lista: 3 najnowsze + „Pokaż więcej" (kolejne 3); zmiana miesiąca resetuje
|
||||
// lista panelu: 3 najnowsze + „Pokaż więcej" (kolejne 3)
|
||||
const countFor = (key: string) => visible[key] ?? 3;
|
||||
const showMore = (key: string) => setVisible((v) => ({ ...v, [key]: (v[key] ?? 3) + 3 }));
|
||||
useEffect(() => setVisible({}), [month]);
|
||||
|
||||
// wybrany miesiąc bez danych → najnowszy miesiąc z danymi
|
||||
useEffect(() => {
|
||||
if (availableMonths.length > 0 && !availableMonths.includes(month)) {
|
||||
setMonth(availableMonths[0]);
|
||||
// pełna historia: waga + obwody jako jednolite grupy (bez filtra miesiąca)
|
||||
const groups = useMemo<PartGroup[]>(() => {
|
||||
const list: PartGroup[] = [];
|
||||
const weightPoints = [...(bp?.weight ?? [])].sort((a, b) => a.date.localeCompare(b.date));
|
||||
if (weightPoints.length > 0) {
|
||||
list.push({
|
||||
part: WEIGHT_PART,
|
||||
unit: 'kg',
|
||||
points: weightPoints.map((w) => ({
|
||||
id: w.id,
|
||||
value: w.value,
|
||||
date: w.date,
|
||||
side: null,
|
||||
name: 'wagi',
|
||||
})),
|
||||
sidesPresent: [],
|
||||
});
|
||||
}
|
||||
}, [availableMonths.join(','), month]);
|
||||
for (const g of groupCircumferences(bp?.circumferences ?? [])) {
|
||||
const points = g.series
|
||||
.flatMap((s) =>
|
||||
s.points.map((p) => ({
|
||||
id: p.id,
|
||||
value: p.value,
|
||||
date: p.date,
|
||||
side: sideOf(s.name),
|
||||
name: s.name,
|
||||
})),
|
||||
)
|
||||
.sort((a, b) => a.date.localeCompare(b.date));
|
||||
const sidesPresent = [
|
||||
...new Set(g.series.map((s) => sideOf(s.name)).filter((s): s is Side => s != null)),
|
||||
];
|
||||
list.push({
|
||||
part: g.part,
|
||||
unit: 'cm',
|
||||
points,
|
||||
sidesPresent,
|
||||
});
|
||||
}
|
||||
return list;
|
||||
}, [bp]);
|
||||
|
||||
// zakres: wybrany w topmenu miesiąc (YYYY-MM)
|
||||
const inMonth = (date: string) => date.startsWith(month);
|
||||
|
||||
const weightPoints = [...(bp?.weight ?? [])]
|
||||
.filter((w) => inMonth(w.date))
|
||||
.sort((a, b) => a.date.localeCompare(b.date));
|
||||
const weightData = weightPoints.map((w) => ({
|
||||
date: new Date(w.date).toLocaleDateString('pl-PL', { day: '2-digit', month: '2-digit' }),
|
||||
value: w.value,
|
||||
}));
|
||||
const latestWeight = weightPoints[weightPoints.length - 1];
|
||||
// delta wagi w wybranym miesiącu: ostatni pomiar − pierwszy (spadek = accent, wzrost = warn)
|
||||
const weightDelta =
|
||||
weightPoints.length >= 2
|
||||
? weightPoints[weightPoints.length - 1].value - weightPoints[0].value
|
||||
: null;
|
||||
|
||||
const circGroups = groupCircumferences(
|
||||
(bp?.circumferences ?? [])
|
||||
.map((s) => ({
|
||||
...s,
|
||||
points: s.points
|
||||
.filter((p) => inMonth(p.date))
|
||||
.sort((a, b) => a.date.localeCompare(b.date)),
|
||||
}))
|
||||
.filter((s) => s.points.length > 0),
|
||||
);
|
||||
// wybrana część odpada (brak danych) → pierwsza dostępna
|
||||
const active = groups.find((g) => g.part === selected) ?? groups[0];
|
||||
|
||||
if (bpLoading) {
|
||||
return (
|
||||
@@ -251,199 +524,29 @@ export default function UserBodyParameters() {
|
||||
|
||||
{bpError ? (
|
||||
<ErrorText>Błąd: {(bpError as Error).message}</ErrorText>
|
||||
) : active == null ? (
|
||||
<EmptyState
|
||||
icon={Scale}
|
||||
title="Brak pomiarów"
|
||||
description="Pomiary pojawią się tutaj, gdy użytkownik doda wagę lub obwód w aplikacji."
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<MeasurementCard
|
||||
icon={Scale}
|
||||
title="Waga"
|
||||
latest={
|
||||
latestWeight && (
|
||||
<span className="flex flex-col items-end">
|
||||
<span className="flex items-baseline gap-2">
|
||||
<span className="font-display text-[1.35rem] font-bold leading-none tabular-nums">
|
||||
{latestWeight.value} kg
|
||||
</span>
|
||||
<span className="text-[0.75rem] text-dim">· {fmtDate(latestWeight.date)}</span>
|
||||
</span>
|
||||
{weightDelta != null && weightDelta !== 0 && (
|
||||
<span
|
||||
className={`text-[0.75rem] font-semibold ${
|
||||
weightDelta < 0 ? 'text-accent-text' : 'text-warn'
|
||||
}`}
|
||||
>
|
||||
{weightDelta < 0 ? '−' : '+'}
|
||||
{Math.abs(weightDelta).toLocaleString('pl-PL')} kg w tym miesiącu
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
>
|
||||
{weightPoints.length === 0 ? (
|
||||
<EmptyState
|
||||
icon={Scale}
|
||||
title="Brak pomiarów wagi"
|
||||
description="Pomiary pojawią się tutaj, gdy użytkownik doda wagę w aplikacji."
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
{weightData.length >= 2 ? (
|
||||
<ResponsiveContainer width="100%" height={220}>
|
||||
<LineChart data={weightData}>
|
||||
<CartesianGrid stroke="var(--border)" />
|
||||
<XAxis dataKey="date" stroke="var(--text-dim)" />
|
||||
<YAxis stroke="var(--text-dim)" domain={['auto', 'auto']} />
|
||||
<Tooltip contentStyle={TOOLTIP_STYLE} />
|
||||
<Line
|
||||
type="monotone"
|
||||
dataKey="value"
|
||||
stroke="var(--accent)"
|
||||
strokeWidth={2}
|
||||
dot={false}
|
||||
/>
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
) : (
|
||||
<p className="text-dim">Za mało danych na wykres (min. 2 pomiary).</p>
|
||||
)}
|
||||
<MeasurementList
|
||||
points={[...weightPoints].reverse().map((p) => ({
|
||||
id: p.id,
|
||||
label: `${p.value} kg`,
|
||||
meta: fmtDate(p.date),
|
||||
}))}
|
||||
visible={countFor('weight')}
|
||||
onShowMore={() => showMore('weight')}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</MeasurementCard>
|
||||
{/* zakładki części: pełna nazwa (pasek jest przewijalny); szczegóły w panelu poniżej */}
|
||||
<Tabs
|
||||
tabs={groups.map((g) => ({ id: g.part, label: g.part }))}
|
||||
active={active.part}
|
||||
onChange={(id) => setSelected(id)}
|
||||
/>
|
||||
|
||||
{circGroups.length === 0 && (
|
||||
<MeasurementCard icon={Ruler} title="Obwody">
|
||||
<p className="text-dim">Brak pomiarów w wybranym miesiącu.</p>
|
||||
</MeasurementCard>
|
||||
)}
|
||||
{circGroups.map((g) => {
|
||||
const allPoints = g.series.flatMap((s) =>
|
||||
s.points.map((p) => ({ ...p, name: s.name, side: sideOf(s.name) })),
|
||||
);
|
||||
const latest = allPoints.reduce<(typeof allPoints)[number] | null>(
|
||||
(max, p) => (max == null || p.date > max.date ? p : max),
|
||||
null,
|
||||
);
|
||||
const sided = g.series.some((s) => sideOf(s.name) != null);
|
||||
const sidesPresent = [
|
||||
...new Set(g.series.map((s) => sideOf(s.name)).filter((s): s is Side => s != null)),
|
||||
];
|
||||
const sideData = mergedSideData(g.series);
|
||||
const chartReady = sided ? sideData.length >= 2 : g.series[0].points.length >= 2;
|
||||
|
||||
return (
|
||||
<MeasurementCard
|
||||
key={g.part}
|
||||
icon={Ruler}
|
||||
title={g.part}
|
||||
latest={
|
||||
latest && (
|
||||
<span className="flex items-baseline gap-2">
|
||||
<span className="font-display text-[1.35rem] font-bold leading-none tabular-nums">
|
||||
{latest.value} cm
|
||||
</span>
|
||||
<span className="text-[0.75rem] text-dim">
|
||||
{latest.side ? `${SIDE_LABELS[latest.side]} · ` : '· '}
|
||||
{fmtDate(latest.date)}
|
||||
</span>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
>
|
||||
{chartReady ? (
|
||||
<>
|
||||
<ResponsiveContainer width="100%" height={180}>
|
||||
{sided ? (
|
||||
<LineChart data={sideData}>
|
||||
<CartesianGrid stroke="var(--border)" />
|
||||
<XAxis dataKey="date" stroke="var(--text-dim)" />
|
||||
<YAxis stroke="var(--text-dim)" domain={['auto', 'auto']} />
|
||||
<Tooltip contentStyle={TOOLTIP_STYLE} />
|
||||
<Line
|
||||
type="monotone"
|
||||
dataKey="lewy"
|
||||
name="Lewy"
|
||||
stroke="var(--info)"
|
||||
strokeWidth={2}
|
||||
dot={false}
|
||||
connectNulls
|
||||
/>
|
||||
<Line
|
||||
type="monotone"
|
||||
dataKey="prawy"
|
||||
name="Prawy"
|
||||
stroke="var(--accent)"
|
||||
strokeWidth={2}
|
||||
dot={false}
|
||||
connectNulls
|
||||
/>
|
||||
</LineChart>
|
||||
) : (
|
||||
<LineChart
|
||||
data={g.series[0].points.map((p) => ({
|
||||
date: new Date(p.date).toLocaleDateString('pl-PL', {
|
||||
day: '2-digit',
|
||||
month: '2-digit',
|
||||
}),
|
||||
value: p.value,
|
||||
}))}
|
||||
>
|
||||
<CartesianGrid stroke="var(--border)" />
|
||||
<XAxis dataKey="date" stroke="var(--text-dim)" />
|
||||
<YAxis stroke="var(--text-dim)" domain={['auto', 'auto']} />
|
||||
<Tooltip contentStyle={TOOLTIP_STYLE} />
|
||||
<Line
|
||||
type="monotone"
|
||||
dataKey="value"
|
||||
stroke="var(--info)"
|
||||
strokeWidth={2}
|
||||
dot={false}
|
||||
/>
|
||||
</LineChart>
|
||||
)}
|
||||
</ResponsiveContainer>
|
||||
{sided && (
|
||||
<div className="mt-2 flex flex-wrap gap-4 text-[0.875rem] text-dim">
|
||||
{sidesPresent.includes('left') && (
|
||||
<span className="flex items-center gap-1.5">
|
||||
<span className="w-3 h-0.5 bg-info inline-block rounded-md" />
|
||||
Lewy
|
||||
</span>
|
||||
)}
|
||||
{sidesPresent.includes('right') && (
|
||||
<span className="flex items-center gap-1.5">
|
||||
<span className="w-3 h-0.5 bg-accent inline-block rounded-md" />
|
||||
Prawy
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<p className="text-dim">Za mało danych na wykres.</p>
|
||||
)}
|
||||
<MeasurementList
|
||||
points={[...allPoints]
|
||||
.sort((a, b) => b.date.localeCompare(a.date))
|
||||
.map((p) => ({
|
||||
id: p.id,
|
||||
label: `${p.value} cm`,
|
||||
meta: `${fmtDate(p.date)}${p.side ? ` · ${SIDE_LABELS[p.side]}` : ''}`,
|
||||
}))}
|
||||
visible={countFor(g.part)}
|
||||
onShowMore={() => showMore(g.part)}
|
||||
/>
|
||||
</MeasurementCard>
|
||||
);
|
||||
})}
|
||||
<div className="mt-4">
|
||||
<MeasurementPanel
|
||||
group={active}
|
||||
icon={active.part === WEIGHT_PART ? Scale : Ruler}
|
||||
visible={countFor(active.part)}
|
||||
onShowMore={() => showMore(active.part)}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
|
||||
@@ -14,8 +14,8 @@ import {
|
||||
import { fmtDate } from '../../lib/format';
|
||||
import { useUserClaims } from './user-queries';
|
||||
|
||||
const STATUS_BADGE: Record<string, { label: string; color: 'green' | 'gray' | 'red' }> = {
|
||||
PENDING: { label: 'Oczekuje', color: 'gray' },
|
||||
const STATUS_BADGE: Record<string, { label: string; color: 'green' | 'yellow' | 'red' }> = {
|
||||
PENDING: { label: 'Oczekuje', color: 'yellow' },
|
||||
APPROVED: { label: 'Zatwierdzony', color: 'green' },
|
||||
REJECTED: { label: 'Odrzucony', color: 'red' },
|
||||
};
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
useAdminUser,
|
||||
useUserBodyParameters,
|
||||
useUserClaims,
|
||||
useUserExerciseProgress,
|
||||
useUserHistory,
|
||||
useUserKillstreak,
|
||||
} from './user-queries';
|
||||
@@ -47,19 +48,15 @@ function sessionCountLabel(n: number) {
|
||||
return `${n} sesji`;
|
||||
}
|
||||
|
||||
/** Mini-statystyka: ikona + etykieta + wartość (+ meta). */
|
||||
/** Mini-statystyka: ikona + etykieta + wartość. */
|
||||
function MiniStat({
|
||||
icon: Icon,
|
||||
label,
|
||||
value,
|
||||
meta,
|
||||
valueClassName = '',
|
||||
}: {
|
||||
icon: LucideIcon;
|
||||
label: string;
|
||||
value: string;
|
||||
meta?: string;
|
||||
valueClassName?: string;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex items-center gap-3 rounded-xl border border-line bg-(image:--card-grad) px-3.5 py-3 shadow-card">
|
||||
@@ -68,12 +65,9 @@ function MiniStat({
|
||||
</span>
|
||||
<div className="min-w-0">
|
||||
<div className="text-[11px] font-bold uppercase tracking-[0.1em] text-dim">{label}</div>
|
||||
<div
|
||||
className={`truncate font-display text-[1.05rem] font-bold leading-tight tabular-nums ${valueClassName}`.trim()}
|
||||
>
|
||||
<div className="truncate font-display text-[1.05rem] font-bold leading-tight tabular-nums">
|
||||
{value}
|
||||
</div>
|
||||
{meta && <div className="truncate text-[0.75rem] text-dim">{meta}</div>}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -120,6 +114,7 @@ export default function UserDetail() {
|
||||
const { data: hist } = useUserHistory(id);
|
||||
const { data: ks } = useUserKillstreak(id);
|
||||
const { data: claimsData } = useUserClaims(id);
|
||||
const { data: progressData } = useUserExerciseProgress(id);
|
||||
const [confirmOpen, setConfirmOpen] = useState(false);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [removeError, setRemoveError] = useState('');
|
||||
@@ -163,11 +158,9 @@ export default function UserDetail() {
|
||||
const name = userDisplayName(user);
|
||||
const memberships = user.memberships ?? [];
|
||||
|
||||
// ostatnia waga + delta vs poprzedni pomiar (spadek = accent, wzrost = warn)
|
||||
// ostatnia waga (summary wiersza „Parametry ciała")
|
||||
const weightPoints = [...(bp?.weight ?? [])].sort((a, b) => a.date.localeCompare(b.date));
|
||||
const latestWeight = weightPoints[weightPoints.length - 1];
|
||||
const prevWeight = weightPoints[weightPoints.length - 2];
|
||||
const weightDelta = latestWeight && prevWeight ? latestWeight.value - prevWeight.value : null;
|
||||
const weightSummary = latestWeight
|
||||
? `${latestWeight.value} kg · ${fmtDate(latestWeight.date)}`
|
||||
: 'brak pomiarów';
|
||||
@@ -207,6 +200,18 @@ export default function UserDetail() {
|
||||
? `${pendingClaims} oczekujących`
|
||||
: `${claims.length} rozstrzygniętych`;
|
||||
|
||||
const progressCount = (progressData?.exercises ?? []).length;
|
||||
const progressSummary =
|
||||
progressCount > 0
|
||||
? `${progressCount} ${
|
||||
progressCount === 1
|
||||
? 'ćwiczenie'
|
||||
: progressCount < 5 && progressCount % 10 >= 2 && progressCount % 10 <= 4
|
||||
? 'ćwiczenia'
|
||||
: 'ćwiczeń'
|
||||
}`
|
||||
: 'brak danych';
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* md+ „Wstecz” w treści (telefon: „<” w topbarze) — jak na GymDetail i podstronach */}
|
||||
@@ -242,28 +247,9 @@ export default function UserDetail() {
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Pasek mini-statystyk: 2×2 na mobile, 4 w rzędzie na desktop */}
|
||||
<div className="mb-4 grid grid-cols-2 gap-3 sm:grid-cols-4">
|
||||
{/* Pasek mini-statystyk: 2 na mobile, 3 w rzędzie na desktop */}
|
||||
<div className="mb-4 grid grid-cols-2 gap-3 sm:grid-cols-3">
|
||||
<MiniStat icon={Flame} label="Killstreak" value={ks ? String(ks.killstreak) : '—'} />
|
||||
<MiniStat
|
||||
icon={Scale}
|
||||
label="Ostatnia waga"
|
||||
value={latestWeight ? `${latestWeight.value} kg` : '—'}
|
||||
meta={
|
||||
weightDelta != null && weightDelta !== 0
|
||||
? `${weightDelta > 0 ? '+' : '−'}${Math.abs(weightDelta).toLocaleString('pl-PL')} kg vs poprzedni`
|
||||
: latestWeight
|
||||
? fmtDate(latestWeight.date)
|
||||
: undefined
|
||||
}
|
||||
valueClassName={
|
||||
weightDelta != null && weightDelta !== 0
|
||||
? weightDelta < 0
|
||||
? 'text-accent-text'
|
||||
: 'text-warn'
|
||||
: ''
|
||||
}
|
||||
/>
|
||||
<MiniStat
|
||||
icon={Dumbbell}
|
||||
label="Objętość 7 dni"
|
||||
@@ -273,7 +259,6 @@ export default function UserDetail() {
|
||||
icon={History}
|
||||
label="Sesje"
|
||||
value={sessions.length > 0 ? String(sessions.length) : '—'}
|
||||
meta={lastSession ? `ostatnia ${fmtDate(lastSession)}` : undefined}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -312,7 +297,7 @@ export default function UserDetail() {
|
||||
to={`/users/${user.id}/progress`}
|
||||
title="Postępy"
|
||||
icon={TrendingUp}
|
||||
summary="1RM i objętość per ćwiczenie"
|
||||
summary={progressSummary}
|
||||
/>
|
||||
<SectionLink
|
||||
to={`/users/${user.id}/memberships`}
|
||||
|
||||
@@ -1,60 +1,237 @@
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import {
|
||||
ArrowRight,
|
||||
AtSign,
|
||||
Cake,
|
||||
Clock,
|
||||
Link2,
|
||||
Phone,
|
||||
Ruler,
|
||||
Sparkles,
|
||||
User,
|
||||
type LucideIcon,
|
||||
} from 'lucide-react';
|
||||
import { useTopbar } from '../../topbar';
|
||||
import { api } from '../../api/client';
|
||||
import type { FocusArea, FocusChain, User } from '../../api/types';
|
||||
import type {
|
||||
FocusArea,
|
||||
FocusChain,
|
||||
SocialMediaEntry,
|
||||
SocialMediaPlatform,
|
||||
User as UserT,
|
||||
} from '../../api/types';
|
||||
import {
|
||||
BackButton,
|
||||
Badge,
|
||||
Card,
|
||||
H3,
|
||||
Loading,
|
||||
PageHeader,
|
||||
SectionHeader,
|
||||
Skeleton,
|
||||
} from '../../components/ui';
|
||||
import { SOCIAL_MEDIA_LABELS } from '../../lib/labels';
|
||||
import { formatAvailability } from '../../lib/availability';
|
||||
import { Avatar } from '../../components/Avatar';
|
||||
import { MUSCLE_COLORS, MUSCLE_NAMES, SOCIAL_MEDIA_LABELS } from '../../lib/labels';
|
||||
import { formatAvailabilityParts } from '../../lib/availability';
|
||||
import { useAdminUser } from './user-queries';
|
||||
import { userDisplayName } from './UserDetail';
|
||||
|
||||
type MuscleTone = 'develop' | 'canDo' | 'difficult' | 'avoid';
|
||||
|
||||
/* 4 niezależne grupy mięśni. Ton = kolor badge'a + etykieta sekcji. */
|
||||
/* 4 niezależne grupy mięśni. Ton = kolor chipa/badge'a + etykieta sekcji. */
|
||||
const MUSCLE_TONES = {
|
||||
develop: {
|
||||
badge: 'green',
|
||||
text: 'text-accent-text',
|
||||
/* podświetlenie grupy w karcie ciągu (bg + border lewy + kolor tekstu) */
|
||||
tint: 'border-accent/40 bg-accent/10',
|
||||
dot: 'bg-accent',
|
||||
label: 'Co rozwija',
|
||||
chainPrefix: 'do rozwoju: ',
|
||||
},
|
||||
canDo: {
|
||||
badge: 'blue',
|
||||
text: 'text-info',
|
||||
tint: 'border-info/40 bg-info/10',
|
||||
dot: 'bg-info',
|
||||
label: 'Co potrafi',
|
||||
chainPrefix: '',
|
||||
},
|
||||
difficult: {
|
||||
badge: 'yellow',
|
||||
text: 'text-warn',
|
||||
tint: 'border-warn/40 bg-warn/10',
|
||||
dot: 'bg-warn',
|
||||
label: 'Co trudne',
|
||||
chainPrefix: '',
|
||||
},
|
||||
avoid: {
|
||||
badge: 'red',
|
||||
text: 'text-danger',
|
||||
tint: 'border-danger/40 bg-danger/10',
|
||||
dot: 'bg-danger',
|
||||
label: 'Co unikać',
|
||||
chainPrefix: 'unikamy: ',
|
||||
},
|
||||
} as const;
|
||||
|
||||
const MUSCLE_FIELD_BY_TONE: Record<MuscleTone, keyof User> = {
|
||||
const MUSCLE_FIELD_BY_TONE: Record<MuscleTone, keyof UserT> = {
|
||||
develop: 'developMuscles',
|
||||
canDo: 'canDoMuscles',
|
||||
difficult: 'difficultMuscles',
|
||||
avoid: 'avoidMuscles',
|
||||
};
|
||||
|
||||
/* Płytka informacyjna: ikona w tonie akcentu + etykieta + wartość (spójna z
|
||||
mini-statystykami przeglądu profilu). Puste wartości wyciszone. */
|
||||
function InfoTile({
|
||||
icon: Icon,
|
||||
label,
|
||||
value,
|
||||
}: {
|
||||
icon: LucideIcon;
|
||||
label: string;
|
||||
value: string;
|
||||
}) {
|
||||
const empty = value === '—';
|
||||
return (
|
||||
<div className="flex items-center gap-3 rounded-[10px] border border-line bg-input/40 px-3 py-2.5">
|
||||
<span className="grid h-9 w-9 shrink-0 place-items-center rounded-[10px] bg-accent/10 text-accent-text">
|
||||
<Icon className="h-4.5 w-4.5" />
|
||||
</span>
|
||||
<div className="min-w-0">
|
||||
<div className="text-[11px] font-bold uppercase tracking-[0.1em] text-dim">{label}</div>
|
||||
<div className={`truncate text-[0.95rem] font-semibold ${empty ? 'text-dim' : ''}`.trim()}>
|
||||
{value}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/* Płytki link społecznościowy: markowa kropka z inicjałem + nazwa + adres + strzałka. */
|
||||
const SOCIAL_BRAND: Record<SocialMediaPlatform, { color: string; initial: string }> = {
|
||||
INSTAGRAM: { color: 'linear-gradient(150deg,#f09433,#dc2743,#bc1888)', initial: 'i' },
|
||||
TIKTOK: { color: 'linear-gradient(150deg,#25f4ee,#000 60%,#fe2c55)', initial: 'T' },
|
||||
YOUTUBE: { color: 'linear-gradient(150deg,#ff5b4a,#c4302b)', initial: 'Y' },
|
||||
FACEBOOK: { color: 'linear-gradient(150deg,#5b8def,#1877f2)', initial: 'f' },
|
||||
X: { color: 'linear-gradient(150deg,#6b7280,#111)', initial: 'X' },
|
||||
OTHER: { color: 'linear-gradient(150deg,#8fa3b8,#5f7183)', initial: '·' },
|
||||
};
|
||||
|
||||
function hostOf(url: string): string {
|
||||
try {
|
||||
return new URL(url).hostname.replace(/^www\./, '');
|
||||
} catch {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
function SocialTile({ entry }: { entry: SocialMediaEntry }) {
|
||||
const label =
|
||||
entry.platform === 'OTHER' ? entry.label || 'Inne' : SOCIAL_MEDIA_LABELS[entry.platform];
|
||||
const brand = SOCIAL_BRAND[entry.platform];
|
||||
return (
|
||||
<a
|
||||
href={entry.url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
aria-label={label}
|
||||
className="group flex items-center gap-3 rounded-xl border border-line bg-input/40 px-3.5 py-3 transition-colors hover:border-accent/45 hover:bg-accent/[0.06]"
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className="grid h-9 w-9 shrink-0 place-items-center rounded-full text-[0.85rem] font-extrabold text-white shadow-[inset_0_1px_0_rgb(255_255_255/0.25)]"
|
||||
style={{ background: brand.color }}
|
||||
>
|
||||
{brand.initial}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-[0.95rem] font-semibold">{label}</span>
|
||||
<span className="block truncate text-[0.8125rem] text-dim">{hostOf(entry.url)}</span>
|
||||
</span>
|
||||
<ArrowRight className="h-4 w-4 shrink-0 text-dim transition-transform group-hover:translate-x-0.5 group-hover:text-accent-text" />
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
/* Ciąg przyczynowo-skutkowy: 4 kafelki w tonie grupy (kolor spójny z „Priorytety
|
||||
i wykluczenia”); puste tony wyciszone. Nazwy mięśni ujednolicone z resztą aplikacji. */
|
||||
function FocusChainCard({ chain }: { chain: FocusChain | undefined }) {
|
||||
return (
|
||||
<Card>
|
||||
<SectionHeader
|
||||
title={
|
||||
<span className="flex items-center gap-2">
|
||||
<Sparkles className="h-4.5 w-4.5 text-accent-text" />
|
||||
Ciąg przyczynowo-skutkowy
|
||||
</span>
|
||||
}
|
||||
description="Ćwiczenia z aktywnego planu w kontekście priorytetów i wykluczeń."
|
||||
/>
|
||||
{chain ? (
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
|
||||
{(Object.keys(MUSCLE_TONES) as MuscleTone[]).map((tone) => {
|
||||
const entries = chain[tone] ?? [];
|
||||
const t = MUSCLE_TONES[tone];
|
||||
return (
|
||||
<div
|
||||
key={tone}
|
||||
className={`rounded-xl border-l-[3px] border-y border-r px-4 py-3 ${
|
||||
entries.length > 0 ? t.tint : 'border-line bg-input/40'
|
||||
}`}
|
||||
>
|
||||
<div className="mb-2 flex items-center gap-2">
|
||||
<span
|
||||
className={`h-2 w-2 shrink-0 rounded-full ${
|
||||
entries.length > 0 ? t.dot : 'bg-dim/40'
|
||||
}`}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span
|
||||
className={`text-[11px] font-bold uppercase tracking-[0.1em] ${
|
||||
entries.length > 0 ? t.text : 'text-dim'
|
||||
}`}
|
||||
>
|
||||
{t.label}
|
||||
</span>
|
||||
</div>
|
||||
{entries.length === 0 ? (
|
||||
<span className="text-[0.875rem] text-dim">brak akcentów w planie</span>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{entries.map((e) => (
|
||||
<div key={e.muscle}>
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge color={MUSCLE_COLORS[e.muscle] ?? 'gray'}>
|
||||
{MUSCLE_NAMES[e.muscle] ?? e.name}
|
||||
</Badge>
|
||||
{(e.exercises ?? []).length > 0 && (
|
||||
<span className="text-[0.75rem] font-bold tabular-nums text-dim">
|
||||
{(e.exercises ?? []).length}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="mt-1 text-[0.875rem] text-dim">
|
||||
{(e.exercises ?? []).length > 0
|
||||
? `${t.chainPrefix}${(e.exercises ?? []).map((x) => x.name).join(', ')}`
|
||||
: 'brak w aktywnym planie'}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<Loading />
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
function InfoRow({ label, value }: { label: string; value: string }) {
|
||||
return (
|
||||
<div className="flex items-baseline justify-between gap-4 px-2 py-2.5">
|
||||
@@ -65,9 +242,11 @@ function InfoRow({ label, value }: { label: string; value: string }) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tylko do odczytu: dane osobowe, priorytety i konto.
|
||||
* Tylko do odczytu: układ 1:1 z podstroną `/profile/info` aplikacji (kafelki
|
||||
* z ikonami, tone'owane grupy mięśni, kafelki social, ciąg przyczynowo-skutkowy).
|
||||
* Profil (nick, telefon, wzrost, dostępność, mięśnie, social) edytuje wyłącznie
|
||||
* użytkownik w aplikacji; admin zmienia tożsamość/dostęp w wizardzie `/users/:id/edit`.
|
||||
* Karta „Konto” (e-mail, admin, data utworzenia) to dodatek admina.
|
||||
*/
|
||||
export default function UserInfo() {
|
||||
const { id } = useParams();
|
||||
@@ -99,14 +278,18 @@ export default function UserInfo() {
|
||||
);
|
||||
}
|
||||
|
||||
const name = userDisplayName(user);
|
||||
const availabilityParts = formatAvailabilityParts(user.availability);
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title={`Dane osobowe — ${userDisplayName(user)}`}
|
||||
title={`Dane osobowe — ${name}`}
|
||||
leading={<Avatar name={name} size={40} />}
|
||||
actions={<BackButton to={`/users/${user.id}`} />}
|
||||
/>
|
||||
|
||||
{/* Karta: konto (stan konta — edycja w wizardzie) */}
|
||||
{/* Karta: konto (stan konta — edycja w wizardzie); dodatek admina */}
|
||||
<Card>
|
||||
<SectionHeader title="Konto" />
|
||||
<div className="divide-y divide-line">
|
||||
@@ -116,43 +299,87 @@ export default function UserInfo() {
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* Karta: podstawowe dane */}
|
||||
{/* Karta 1: podstawowe dane — siatka płytek z ikonami + dostępność jako chipy */}
|
||||
<Card>
|
||||
<SectionHeader title="Podstawowe dane" />
|
||||
<div className="divide-y divide-line">
|
||||
<InfoRow label="Imię" value={user.firstName || '—'} />
|
||||
<InfoRow label="Nazwisko" value={user.lastName || '—'} />
|
||||
<InfoRow label="Wiek" value={user.age != null ? `${user.age} lat` : '—'} />
|
||||
<InfoRow label="Wzrost" value={user.heightCm != null ? `${user.heightCm} cm` : '—'} />
|
||||
<InfoRow label="Telefon" value={user.phone || '—'} />
|
||||
<InfoRow label="Nick" value={user.nickname || '—'} />
|
||||
<InfoRow label="Dostępność" value={formatAvailability(user.availability) || '—'} />
|
||||
<div className="grid grid-cols-1 gap-2.5 sm:grid-cols-2">
|
||||
<InfoTile icon={User} label="Imię" value={user.firstName || '—'} />
|
||||
<InfoTile icon={User} label="Nazwisko" value={user.lastName || '—'} />
|
||||
<InfoTile icon={Cake} label="Wiek" value={user.age != null ? `${user.age} lat` : '—'} />
|
||||
<InfoTile
|
||||
icon={Ruler}
|
||||
label="Wzrost"
|
||||
value={user.heightCm != null ? `${user.heightCm} cm` : '—'}
|
||||
/>
|
||||
<InfoTile icon={Phone} label="Telefon" value={user.phone || '—'} />
|
||||
<InfoTile icon={AtSign} label="Nick" value={user.nickname || '—'} />
|
||||
</div>
|
||||
<div className="mt-3 rounded-[10px] border border-line bg-input/40 px-3.5 py-3">
|
||||
<div className="mb-2 flex items-center gap-1.5 text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
|
||||
<Clock className="h-3.5 w-3.5" />
|
||||
Dostępność
|
||||
</div>
|
||||
{availabilityParts.length > 0 ? (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{availabilityParts.map((p) => (
|
||||
<Badge key={p} color="blue" className="font-semibold">
|
||||
{p}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-[0.875rem] text-dim">Brak ustawionej dostępności</span>
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* Karta: priorytety i wykluczenia (4 grupy mięśni) */}
|
||||
{/* Karta 2: priorytety i wykluczenia — 4 kafelki w tonie grupy */}
|
||||
<Card>
|
||||
<SectionHeader title="Priorytety i wykluczenia" />
|
||||
<div className="grid grid-cols-1 gap-x-4 gap-y-4 sm:grid-cols-2">
|
||||
<div className="grid grid-cols-1 gap-2.5 sm:grid-cols-2">
|
||||
{(Object.keys(MUSCLE_TONES) as MuscleTone[]).map((tone) => {
|
||||
const musclesList = (user[MUSCLE_FIELD_BY_TONE[tone]] as string[] | undefined) ?? [];
|
||||
const t = MUSCLE_TONES[tone];
|
||||
return (
|
||||
<div key={tone}>
|
||||
<div className="mb-1.5 text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
|
||||
{MUSCLE_TONES[tone].label}
|
||||
<div
|
||||
key={tone}
|
||||
className={`rounded-xl border-l-[3px] border-y border-r px-4 py-3 ${
|
||||
musclesList.length > 0 ? t.tint : 'border-line bg-input/40'
|
||||
}`}
|
||||
>
|
||||
<div className="mb-2 flex items-center gap-2">
|
||||
<span
|
||||
className={`h-2 w-2 shrink-0 rounded-full ${
|
||||
musclesList.length > 0 ? t.dot : 'bg-dim/40'
|
||||
}`}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span
|
||||
className={`text-[11px] font-bold uppercase tracking-[0.1em] ${
|
||||
musclesList.length > 0 ? t.text : 'text-dim'
|
||||
}`}
|
||||
>
|
||||
{t.label}
|
||||
</span>
|
||||
{musclesList.length > 0 && (
|
||||
<span className="ml-auto text-[11px] font-bold tabular-nums text-dim">
|
||||
{musclesList.length}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{musclesList.length > 0 ? (
|
||||
musclesList.map((m) => (
|
||||
<Badge
|
||||
key={m}
|
||||
color={MUSCLE_TONES[tone].badge as 'green' | 'blue' | 'yellow' | 'red'}
|
||||
color={t.badge as 'green' | 'blue' | 'yellow' | 'red'}
|
||||
className="bg-card/70"
|
||||
>
|
||||
{areaName(m)}
|
||||
</Badge>
|
||||
))
|
||||
) : (
|
||||
<span className="text-[0.875rem] text-dim">—</span>
|
||||
<span className="text-[0.875rem] text-dim">nic nie dodano</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
@@ -161,67 +388,24 @@ export default function UserInfo() {
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* Karta: social media */}
|
||||
{/* Karta 3: social media — kafelki linków z markową kropką i domeną */}
|
||||
<Card>
|
||||
<SectionHeader title="Social media" />
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{(user.socialMedia ?? []).length > 0 ? (
|
||||
(user.socialMedia ?? []).map((s, i) => (
|
||||
<a
|
||||
key={i}
|
||||
href={s.url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center rounded-full border border-line px-3 py-1.5 text-[0.875rem] font-semibold text-accent-text hover:underline"
|
||||
>
|
||||
{s.platform === 'OTHER' ? s.label || 'Inne' : SOCIAL_MEDIA_LABELS[s.platform]}
|
||||
</a>
|
||||
))
|
||||
) : (
|
||||
<span className="text-[0.875rem] text-dim">—</span>
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* Karta: ciąg przyczynowo-skutkowy (tylko odczyt) */}
|
||||
<Card>
|
||||
<SectionHeader
|
||||
title="Ciąg przyczynowo-skutkowy"
|
||||
description="Ćwiczenia z aktywnego planu w kontekście priorytetów i wykluczeń."
|
||||
/>
|
||||
{chain ? (
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 sm:gap-5">
|
||||
{(Object.keys(MUSCLE_TONES) as MuscleTone[]).map((tone) => {
|
||||
const entries = chain[tone] ?? [];
|
||||
return (
|
||||
<div key={tone}>
|
||||
<H3 className={`mb-2 ${MUSCLE_TONES[tone].text}`}>{MUSCLE_TONES[tone].label}</H3>
|
||||
{entries.length === 0 ? (
|
||||
<span className="text-[0.875rem] text-dim">—</span>
|
||||
) : (
|
||||
<div className="flex flex-col gap-2.5">
|
||||
{entries.map((en) => (
|
||||
<div key={en.muscle}>
|
||||
<div className="text-[0.95rem] font-semibold">{en.name}</div>
|
||||
<div className="mt-0.5 text-[0.875rem] text-dim">
|
||||
{(en.exercises ?? []).length > 0
|
||||
? `${MUSCLE_TONES[tone].chainPrefix}${(en.exercises ?? [])
|
||||
.map((x) => x.name)
|
||||
.join(', ')}`
|
||||
: 'brak w aktywnym planie'}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
{(user.socialMedia ?? []).length > 0 ? (
|
||||
<div className="grid grid-cols-1 gap-2.5 sm:grid-cols-2">
|
||||
{(user.socialMedia ?? []).map((s, i) => (
|
||||
<SocialTile key={i} entry={s} />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<Loading />
|
||||
<div className="flex items-center gap-3 rounded-xl border border-dashed border-line bg-input/40 px-4 py-4 text-[0.875rem] text-dim">
|
||||
<Link2 className="h-4 w-4 shrink-0" />
|
||||
Brak dodanych profili.
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
<FocusChainCard chain={chain} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,13 @@
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { TrendingUp } from 'lucide-react';
|
||||
import { useTopbar } from '../../topbar';
|
||||
import {
|
||||
BackButton,
|
||||
Card,
|
||||
EmptyState,
|
||||
ErrorText,
|
||||
Muted,
|
||||
PageHeader,
|
||||
Skeleton,
|
||||
} from '../../components/ui';
|
||||
import { BackButton, Card, EmptyState, ErrorText, PageHeader, Skeleton } from '../../components/ui';
|
||||
import ExerciseProgressCards from '../../components/ExerciseProgressCards';
|
||||
import { useUserExerciseProgress } from './user-queries';
|
||||
|
||||
/**
|
||||
* Postępy per ćwiczenie (1RM Epley + objętość) użytkownika — widok admina,
|
||||
* wzorowany na `/profile/progress` z aplikacji.
|
||||
* Postępy per ćwiczenie użytkownika — widok admina 1:1 z `/profile/progress`
|
||||
* z aplikacji (czyt. opis wzoru 1RM usunięty z obu stron).
|
||||
*/
|
||||
export default function UserProgress() {
|
||||
const { id } = useParams();
|
||||
@@ -38,10 +30,6 @@ export default function UserProgress() {
|
||||
<PageHeader title="Postępy" actions={<BackButton to={id ? `/users/${id}` : '/users'} />} />
|
||||
|
||||
<Card>
|
||||
<Muted className="text-[0.875rem]">
|
||||
1RM Epley: zaplanowane obciążenie × (1 + powtórzenia/30), maks. per sesja; objętość = Σ
|
||||
obciążenie × powtórzenia.
|
||||
</Muted>
|
||||
{error && <ErrorText>Błąd: {(error as Error).message}</ErrorText>}
|
||||
{!error && exercises.length === 0 && (
|
||||
<EmptyState
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { fireEvent, render, screen } 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';
|
||||
@@ -6,11 +6,25 @@ import UserBodyParameters from '../src/pages/users/UserBodyParameters';
|
||||
import { setAccessToken } from '../src/api/client';
|
||||
|
||||
const BP = {
|
||||
weight: [{ id: 'w1', value: 81.5, date: '2026-09-10T10:00:00.000Z' }],
|
||||
weight: [
|
||||
{ id: 'w1', value: 82, date: '2026-09-01T10:00:00.000Z' },
|
||||
{ id: 'w2', value: 81.5, date: '2026-09-10T10:00:00.000Z' },
|
||||
],
|
||||
circumferences: [
|
||||
{
|
||||
name: 'Biceps lewy',
|
||||
points: [{ id: 'c1', value: 35, date: '2026-09-09T10:00:00.000Z' }],
|
||||
points: [
|
||||
{ id: 'c1', value: 35, date: '2026-09-01T10:00:00.000Z' },
|
||||
{ id: 'c3', value: 36, date: '2026-09-20T10:00:00.000Z' },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Biceps prawy',
|
||||
points: [{ id: 'c2', value: 35.5, date: '2026-09-09T10:00:00.000Z' }],
|
||||
},
|
||||
{
|
||||
name: 'Klatka piersiowa',
|
||||
points: [{ id: 'c4', value: 100, date: '2026-09-05T10:00:00.000Z' }],
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -55,20 +69,81 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
describe('admin UserBodyParameters page', () => {
|
||||
it('pokazuje ostatnie pomiary wagi i obwodów', async () => {
|
||||
it('zakładki z pełną historią: waga + obwody grupowane po części (pełne nazwy)', async () => {
|
||||
mockFetchRoutes([['/body-parameters', () => BP]]);
|
||||
renderPage();
|
||||
|
||||
expect(
|
||||
await screen.findByRole('heading', { name: 'Parametry ciała', level: 2 }),
|
||||
).toBeInTheDocument();
|
||||
// karta Waga: najnowszy pomiar + wiersz listy
|
||||
|
||||
// zakładki części z pełnymi nazwami (bez skrótu „Przedr.”)
|
||||
expect(await screen.findByRole('button', { name: 'Waga' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Klatka piersiowa' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: 'Biceps' })).toBeInTheDocument();
|
||||
|
||||
// panel Wagi (pierwsza zakładka): najnowszy pomiar + postęp + pełna historia
|
||||
expect(screen.getByRole('heading', { name: 'Waga', level: 3 })).toBeInTheDocument();
|
||||
expect(screen.getAllByText('81.5 kg').length).toBeGreaterThan(0);
|
||||
expect(screen.getByText('Za mało danych na wykres (min. 2 pomiary).')).toBeInTheDocument();
|
||||
// karta obwodu grupowana po części ciała (Biceps lewy → karta „Biceps”)
|
||||
expect(screen.getByRole('heading', { name: 'Biceps' })).toBeInTheDocument();
|
||||
expect(screen.getAllByText('35 cm').length).toBeGreaterThan(0);
|
||||
expect(screen.getAllByText(/lewy/i).length).toBeGreaterThan(0);
|
||||
expect(screen.getByRole('heading', { name: 'Postęp' })).toBeInTheDocument();
|
||||
// separator dziesiętny bywa kropką lub przecinkiem zależnie od implementacji Intl
|
||||
expect(screen.getByText(/−0[.,]5 kg od pierwszego/)).toBeInTheDocument();
|
||||
// lista z pełnej historii (oba pomiary, nawet sprzed „bieżącego miesiąca”);
|
||||
// wartość i jednostka to osobne węzły tekstowe w kafelku listy
|
||||
const tiles = () =>
|
||||
Array.from(document.querySelectorAll('li')).map(
|
||||
(li) => (li.textContent ?? '').replace(/\s+/g, ' ').trim(),
|
||||
);
|
||||
expect(tiles().some((t) => t.startsWith('82 kg'))).toBe(true);
|
||||
});
|
||||
|
||||
it('strony mierzone jako dwa niezależne panele z własnym postępem', async () => {
|
||||
mockFetchRoutes([['/body-parameters', () => BP]]);
|
||||
renderPage();
|
||||
|
||||
const bicepsTab = await screen.findByRole('button', { name: 'Biceps' });
|
||||
fireEvent.click(bicepsTab);
|
||||
|
||||
// lewy zawsze pierwszy, potem prawy — każdy jako osobna karta
|
||||
expect(await screen.findByRole('heading', { name: 'Biceps — lewy' })).toBeInTheDocument();
|
||||
expect(screen.getByRole('heading', { name: 'Biceps — prawy' })).toBeInTheDocument();
|
||||
expect(screen.getAllByRole('heading', { name: 'Postęp' }).length).toBe(2);
|
||||
expect(screen.getAllByText('Za mało danych na wykres (min. 2 pomiary).').length).toBe(1);
|
||||
});
|
||||
|
||||
it('pokaż więcej odkrywa kolejne pomiary z historii', async () => {
|
||||
const many = {
|
||||
weight: Array.from({ length: 5 }, (_, i) => ({
|
||||
id: `w${i}`,
|
||||
value: 80 + i / 10,
|
||||
date: `2026-08-0${i + 1}T10:00:00.000Z`,
|
||||
})),
|
||||
circumferences: [],
|
||||
};
|
||||
mockFetchRoutes([['/body-parameters', () => many]]);
|
||||
renderPage();
|
||||
await screen.findByRole('heading', { name: 'Waga', level: 3 });
|
||||
|
||||
// domyślnie 3 najnowsze, gwóźdź programu: 4. pomiar ukryty do kliknięcia
|
||||
const tiles = () =>
|
||||
Array.from(document.querySelectorAll('li')).map(
|
||||
(li) => (li.textContent ?? '').replace(/\s+/g, ' ').trim(),
|
||||
);
|
||||
expect(tiles().some((t) => /^80[.,]1 kg/.test(t))).toBe(false);
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Pokaż więcej' }));
|
||||
expect(tiles().some((t) => /^80[.,]1 kg/.test(t))).toBe(true);
|
||||
});
|
||||
|
||||
it('pokazuje stan pusty, gdy użytkownik nie ma pomiarów', async () => {
|
||||
mockFetchRoutes([
|
||||
['/body-parameters', () => ({ weight: [], circumferences: [] })],
|
||||
]);
|
||||
renderPage();
|
||||
|
||||
expect(await screen.findByText('Brak pomiarów')).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText('Pomiary pojawią się tutaj, gdy użytkownik doda wagę lub obwód w aplikacji.'),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('jest tylko do odczytu — brak kontrolek dodawania i usuwania pomiarów', async () => {
|
||||
@@ -78,6 +153,7 @@ describe('admin UserBodyParameters page', () => {
|
||||
|
||||
expect(screen.queryByRole('button', { name: '+ Waga' })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: 'Dodaj wagę' })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole('button', { name: 'Dodaj pomiar' })).not.toBeInTheDocument();
|
||||
expect(screen.queryAllByRole('button', { name: /Usuń pomiar/ })).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -97,6 +97,7 @@ describe('admin UserDetail (przegląd profilu)', () => {
|
||||
['/body-parameters', () => ({ weight: [], circumferences: [] })],
|
||||
['/history', () => ({ sessions: [] })],
|
||||
['/claims', () => ({ claims: [] })],
|
||||
['/exercise-progress', () => ({ exercises: [] })],
|
||||
]);
|
||||
renderUserDetail();
|
||||
expect(await screen.findByText('Zablokowane')).toBeInTheDocument();
|
||||
@@ -121,6 +122,7 @@ describe('admin UserDetail (przegląd profilu)', () => {
|
||||
['/body-parameters', () => ({ weight: [], circumferences: [] })],
|
||||
['/history', () => ({ sessions: [] })],
|
||||
['/claims', () => ({ claims: [] })],
|
||||
['/exercise-progress', () => ({ exercises: [] })],
|
||||
]);
|
||||
renderUserDetail();
|
||||
expect(await screen.findByText(/Zawieszone do/)).toBeInTheDocument();
|
||||
@@ -139,6 +141,7 @@ describe('admin UserDetail (przegląd profilu)', () => {
|
||||
],
|
||||
['/history', () => ({ sessions: [] })],
|
||||
['/claims', () => ({ claims: [] })],
|
||||
['/exercise-progress', () => ({ exercises: [{ id: 'e1' }] })],
|
||||
]);
|
||||
renderUserDetail();
|
||||
|
||||
@@ -148,10 +151,16 @@ describe('admin UserDetail (przegląd profilu)', () => {
|
||||
expect(screen.getByText('@jano')).toBeInTheDocument();
|
||||
expect(screen.getByText('Admin')).toBeInTheDocument();
|
||||
|
||||
// mini-statystyki z endpointów
|
||||
// mini-statystyki z endpointów (pasek 3-kaflowy jak w aplikacji — bez „Ostatnia waga")
|
||||
expect(screen.getByText('Killstreak')).toBeInTheDocument();
|
||||
expect(screen.getByText('7')).toBeInTheDocument();
|
||||
expect(screen.getByText('81.5 kg')).toBeInTheDocument();
|
||||
expect(screen.getByText('Objętość 7 dni')).toBeInTheDocument();
|
||||
expect(screen.getByText('Sesje')).toBeInTheDocument();
|
||||
expect(screen.queryByText('Ostatnia waga')).not.toBeInTheDocument();
|
||||
// waga pozostaje w podsumowaniu wiersza „Parametry ciała”
|
||||
expect(screen.getByText('81.5 kg · 10.09.2026')).toBeInTheDocument();
|
||||
// podsumowanie Postępów = liczba ćwiczeń z endpointu
|
||||
expect(screen.getByRole('link', { name: /Postępy/ })).toHaveTextContent('1 ćwiczenie');
|
||||
|
||||
// wiersze sekcji prowadzące na podstrony
|
||||
for (const title of [
|
||||
@@ -176,6 +185,7 @@ describe('admin UserDetail (przegląd profilu)', () => {
|
||||
['/body-parameters', () => ({ weight: [], circumferences: [] })],
|
||||
['/history', () => ({ sessions: [] })],
|
||||
['/claims', () => ({ claims: [] })],
|
||||
['/exercise-progress', () => ({ exercises: [] })],
|
||||
]);
|
||||
renderUserDetail();
|
||||
const row = await screen.findByRole('link', { name: /Członkostwa w siłowniach/ });
|
||||
|
||||
@@ -47,7 +47,15 @@ const U1: User = {
|
||||
heightCm: 180,
|
||||
phone: '+48 500 100 200',
|
||||
isAdmin: true,
|
||||
availability: null,
|
||||
availability: [
|
||||
{ start: '18:00', end: '20:00' },
|
||||
{ start: '18:00', end: '20:00' },
|
||||
{ start: '18:00', end: '20:00' },
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
] as User['availability'],
|
||||
priorities: null,
|
||||
exclusions: null,
|
||||
developMuscles: ['chest'],
|
||||
@@ -120,6 +128,9 @@ describe('admin UserInfo page', () => {
|
||||
expect(screen.getByText('180 cm')).toBeInTheDocument();
|
||||
expect(screen.getByText('+48 500 100 200')).toBeInTheDocument();
|
||||
|
||||
// dostępność jako chipy z pogrupowanymi dniami (jak w aplikacji)
|
||||
expect(screen.getByText('Pon–Śr 18:00–20:00')).toBeInTheDocument();
|
||||
|
||||
// priorytety: nazwy mięśni rozwinięte z listy obszarów
|
||||
expect(screen.getAllByText('Co rozwija').length).toBeGreaterThan(0);
|
||||
expect(screen.getAllByText('Klatka piersiowa').length).toBeGreaterThan(0);
|
||||
|
||||
@@ -111,10 +111,14 @@ test('kliknięcie w użytkownika otwiera przegląd profilu (wzór z apki)', asyn
|
||||
await page.getByRole('link', { name: 'Użytkownicy' }).click();
|
||||
await page.getByRole('link', { name: 'Jan Kowalski' }).click();
|
||||
await expect(page).toHaveURL(/\/users\/user-1$/);
|
||||
// hero: e-mail + mini-statystyki + wiersze sekcji
|
||||
// hero: e-mail + mini-statystyki (pasek 3-kaflowy jak w apce) + wiersze sekcji
|
||||
await expect(page.getByText('jan@fitos.pl')).toBeVisible();
|
||||
await expect(page.getByText('Killstreak')).toBeVisible();
|
||||
await expect(page.getByText('81.5 kg', { exact: true })).toBeVisible();
|
||||
await expect(page.getByText('Objętość 7 dni')).toBeVisible();
|
||||
await expect(page.getByText('Sesje')).toBeVisible();
|
||||
await expect(page.getByText('Ostatnia waga')).toHaveCount(0);
|
||||
// waga pozostaje w podsumowaniu wiersza „Parametry ciała”
|
||||
await expect(page.getByText('81.5 kg ·')).toBeVisible();
|
||||
await expect(page.getByRole('link', { name: /Dane osobowe/ })).toBeVisible();
|
||||
await expect(page.getByRole('link', { name: /Parametry ciała/ })).toBeVisible();
|
||||
await expect(page.getByRole('link', { name: /Historia treningów/ })).toBeVisible();
|
||||
|
||||
@@ -2,6 +2,27 @@ import '@testing-library/jest-dom/vitest';
|
||||
import { afterEach } from 'vitest';
|
||||
import { cleanup } from '@testing-library/react';
|
||||
|
||||
// recharts (ResponsiveContainer) wymaga ResizeObserver, którego jsdom nie dostarcza.
|
||||
// Stub wywołuje callback z fikcyjnym rozmiarem — wykresy renderują się w stałym 800×600.
|
||||
class ResizeObserverStub {
|
||||
private cb: (entries: { contentRect: { width: number; height: number } }[]) => void;
|
||||
constructor(cb: (entries: { contentRect: { width: number; height: number } }[]) => void) {
|
||||
this.cb = cb;
|
||||
}
|
||||
observe() {
|
||||
this.cb([{ contentRect: { width: 800, height: 600 } }]);
|
||||
}
|
||||
unobserve() {}
|
||||
disconnect() {}
|
||||
}
|
||||
if (typeof globalThis.ResizeObserver === 'undefined') {
|
||||
Object.defineProperty(globalThis, 'ResizeObserver', {
|
||||
value: ResizeObserverStub,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
});
|
||||
}
|
||||
|
||||
// vitest runs with globals:false, so RTL auto-cleanup is not registered
|
||||
// automatically; clean the DOM after every test.
|
||||
afterEach(() => {
|
||||
|
||||
Reference in New Issue
Block a user