From 248fa0bc9b71da368d265f8d122281edce6841c7 Mon Sep 17 00:00:00 2001 From: tisachi Date: Thu, 29 Oct 2026 21:44:51 +0100 Subject: [PATCH] =?UTF-8?q?Admin:=20konsola=20u=C5=BCytkownika=20od=20nowa?= =?UTF-8?q?=20=E2=80=94=20status,=20cz=C5=82onkostwa=20z=20menu=20r=C3=B3l?= =?UTF-8?q?,=20logi=20konta=20z=20podstron=C4=85;=20usuni=C4=99cie=20podst?= =?UTF-8?q?ron=20treningowych=20(wsp=C3=B3=C5=82dzielone=20menu=20cz=C5=82?= =?UTF-8?q?onkostwa=20z=20konsol=C4=85=20si=C5=82owni)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/src/App.tsx | 14 +- .../src/components/ExerciseProgressCards.tsx | 185 ------ admin/src/components/HistoryTable.tsx | 202 ------ .../src/components/MembershipActionsModal.tsx | 137 ++++ admin/src/components/ui/content.tsx | 31 +- admin/src/i18n/locales/en/gyms.json | 3 +- admin/src/i18n/locales/en/users.json | 105 +-- admin/src/i18n/locales/pl/gyms.json | 3 +- admin/src/i18n/locales/pl/users.json | 95 +-- admin/src/lib/useMeasurementLabels.ts | 20 - admin/src/pages/gyms/GymDetail.tsx | 155 +---- admin/src/pages/users/UserBodyParameters.tsx | 607 ------------------ admin/src/pages/users/UserClaims.tsx | 110 ---- admin/src/pages/users/UserDetail.tsx | 522 +++++++-------- admin/src/pages/users/UserHistory.tsx | 89 --- admin/src/pages/users/UserInfo.tsx | 436 ------------- admin/src/pages/users/UserLogsPage.tsx | 84 +++ admin/src/pages/users/UserMemberships.tsx | 88 --- admin/src/pages/users/UserProgress.tsx | 61 -- admin/src/pages/users/user-queries.ts | 51 +- admin/test/UserBodyParameters.test.tsx | 165 ----- admin/test/UserDetail.test.tsx | 203 +++--- admin/test/UserInfo.test.tsx | 160 ----- admin/test/UserLogsPage.test.tsx | 120 ++++ admin/test/UserMemberships.test.tsx | 110 ---- admin/test/e2e/admin.spec.ts | 146 ++--- admin/test/e2e/mock-api.ts | 65 +- 27 files changed, 836 insertions(+), 3131 deletions(-) delete mode 100644 admin/src/components/ExerciseProgressCards.tsx delete mode 100644 admin/src/components/HistoryTable.tsx create mode 100644 admin/src/components/MembershipActionsModal.tsx delete mode 100644 admin/src/lib/useMeasurementLabels.ts delete mode 100644 admin/src/pages/users/UserBodyParameters.tsx delete mode 100644 admin/src/pages/users/UserClaims.tsx delete mode 100644 admin/src/pages/users/UserHistory.tsx delete mode 100644 admin/src/pages/users/UserInfo.tsx create mode 100644 admin/src/pages/users/UserLogsPage.tsx delete mode 100644 admin/src/pages/users/UserMemberships.tsx delete mode 100644 admin/src/pages/users/UserProgress.tsx delete mode 100644 admin/test/UserBodyParameters.test.tsx delete mode 100644 admin/test/UserInfo.test.tsx create mode 100644 admin/test/UserLogsPage.test.tsx delete mode 100644 admin/test/UserMemberships.test.tsx diff --git a/admin/src/App.tsx b/admin/src/App.tsx index 2336941..91be7d0 100644 --- a/admin/src/App.tsx +++ b/admin/src/App.tsx @@ -15,12 +15,7 @@ import GymLogsPage from './pages/gyms/GymLogsPage'; import UsersList from './pages/users/UsersList'; import UserForm from './pages/users/UserForm'; import UserDetail from './pages/users/UserDetail'; -import UserInfo from './pages/users/UserInfo'; -import UserBodyParameters from './pages/users/UserBodyParameters'; -import UserHistory from './pages/users/UserHistory'; -import UserProgress from './pages/users/UserProgress'; -import UserMemberships from './pages/users/UserMemberships'; -import UserClaims from './pages/users/UserClaims'; +import UserLogsPage from './pages/users/UserLogsPage'; import FocusAreas from './pages/catalog/FocusAreas'; import Exercises from './pages/catalog/Exercises'; import EquipmentCatalog from './pages/catalog/Equipment'; @@ -59,12 +54,7 @@ export default function App() { } /> } /> } /> - } /> - } /> - } /> - } /> - } /> - } /> + } /> } /> } /> } /> diff --git a/admin/src/components/ExerciseProgressCards.tsx b/admin/src/components/ExerciseProgressCards.tsx deleted file mode 100644 index 97737f0..0000000 --- a/admin/src/components/ExerciseProgressCards.tsx +++ /dev/null @@ -1,185 +0,0 @@ -import { useState } from 'react'; -import { useTranslation } from 'react-i18next'; -import { ChevronDown, ChevronUp, TrendingDown, TrendingUp } from 'lucide-react'; -import { - Bar, - BarChart, - CartesianGrid, - Line, - LineChart, - ResponsiveContainer, - Tooltip, - XAxis, - YAxis, -} from 'recharts'; -import type { ExerciseProgress } from '../api/types'; -import { resolveLocaleTag } from '../i18n/language'; -import { fmtDate, fmtVolume } from '../lib/format'; -import { localizedName } from '../lib/localizedName'; -import { muscleName } from '../lib/labels'; -import { Badge, Tabs } from './ui'; - -const TOOLTIP_STYLE = { - background: 'var(--bg-card)', - border: '1px solid var(--border)', - borderRadius: 12, - color: 'var(--text)', -}; - -/** - * Lista postępów per ćwiczenie: wiersz (nazwa + 1RM + delta + objętość + PR), - * tap rozwija kartę z zakładkami 1RM/Objętość i jednym wykresem (renderowany - * tylko dla aktywnej zakładki — unik ostrzeżeń recharts/ResizeObserver). - * Współdzielone z detalem podopiecznego (spójnie). - */ -export default function ExerciseProgressCards({ exercises }: { exercises: ExerciseProgress[] }) { - const { t, i18n } = useTranslation(); - const [openId, setOpenId] = useState(null); - // aktywna zakładka per ćwiczenie (domyślnie 1RM) - const [tabs, setTabs] = useState>({}); - - return ( -
- {exercises.map((ex) => { - const last = ex.points[ex.points.length - 1]; - const prev = ex.points[ex.points.length - 2]; - const oneRmDelta = - last?.oneRm != null && prev?.oneRm != null ? last.oneRm - prev.oneRm : null; - const maxOneRm = ex.points.reduce( - (max, p) => (p.oneRm != null && p.oneRm > max ? p.oneRm : max), - 0, - ); - const isPr = last?.oneRm != null && last.oneRm === maxOneRm && ex.points.length > 1; - const open = openId === ex.exerciseId; - const tab = tabs[ex.exerciseId] ?? 'onerm'; - const setTab = (t: 'onerm' | 'volume') => setTabs((m) => ({ ...m, [ex.exerciseId]: t })); - return ( -
- {/* Wiersz: nazwa + mięsień (meta) + 1RM + delta + objętość + PR */} - - {/* Rozwinięta karta: zakładki 1RM/Objętość + jeden wykres */} - {open && ( -
- setTab(id as 'onerm' | 'volume')} - /> - {tab === 'onerm' ? : } -
- )} -
- ); - })} -
- ); -} - -function OneRmChart({ ex }: { ex: ExerciseProgress }) { - const { t } = useTranslation(); - const oneRmPoints = ex.points.filter((p) => p.oneRm != null); - if (oneRmPoints.length < 2) { - return

{t('progress.notEnough1rm')}

; - } - return ( -
- - ({ date: fmtDate(p.date), oneRm: p.oneRm }))}> - - - - - - - -
- ); -} - -function VolumeChart({ ex }: { ex: ExerciseProgress }) { - const { t } = useTranslation(); - const volumePoints = ex.points.filter((p) => p.volumeKg != null); - if (volumePoints.length < 1) { - return

{t('progress.noVolumeData')}

; - } - return ( -
- - ({ date: fmtDate(p.date), volumeKg: p.volumeKg }))}> - - - - - - - -
- ); -} diff --git a/admin/src/components/HistoryTable.tsx b/admin/src/components/HistoryTable.tsx deleted file mode 100644 index 12ffc68..0000000 --- a/admin/src/components/HistoryTable.tsx +++ /dev/null @@ -1,202 +0,0 @@ -import { useState } from 'react'; -import { useTranslation } from 'react-i18next'; -import { ChevronDown, ChevronUp, MessageSquare } from 'lucide-react'; -import type { HistorySession } from '../api/types'; -import { fmtDate, fmtDuration, fmtVolume } from '../lib/format'; -import { localizedName } from '../lib/localizedName'; -import { muscleName, SESSION_STATUS } from '../lib/labels'; -import { Badge } from './ui'; - -interface HistoryTableProps { - sessions: HistorySession[]; - /** Sesja otwarta od razu (np. po kliknięciu linku). */ - initialOpenSessionId?: string; -} - -/** - * Historia sesji tylko do odczytu: plan vs. wykonanie per seria + komentarze przy ćwiczeniach. - * Port odpowiednika z aplikacji (`app/src/components/HistoryTable`) bez dodawania komentarzy. - */ -export default function HistoryTable({ sessions, initialOpenSessionId }: HistoryTableProps) { - const { t, i18n } = useTranslation(); - const [openSession, setOpenSession] = useState(initialOpenSessionId ?? null); - - return ( -
- {sessions.map((s) => { - const st = SESSION_STATUS[s.status]; - const open = openSession === s.id; - const plannedTotal = s.exercises.reduce( - (n, ex) => n + ex.sets.filter((set) => set.planned).length, - 0, - ); - const plannedDone = s.exercises.reduce( - (n, ex) => n + ex.sets.filter((set) => set.planned && set.reps != null).length, - 0, - ); - // Serie wykonane ponad plan (bez planowanego odpowiednika) z zapisanymi powtórzeniami. - const extraSets = s.exercises.reduce( - (n, ex) => n + ex.sets.filter((set) => set.planned == null && set.reps != null).length, - 0, - ); - // Deficyt = niewyrobione serie normowe (bonus nie wchodzi w normę). - const deficit = plannedTotal - plannedDone; - // Objętość = Σ obciążenie × powtórzenia; seria bez planowanego obciążenia = masa ciała z profilu. - const volume = s.exercises - .flatMap((ex) => ex.sets) - .reduce( - (sum, set) => - set.reps != null ? sum + (set.planned?.loadKg ?? s.bodyKg ?? 0) * set.reps : sum, - 0, - ); - const duration = s.endedAt ? fmtDuration(s.startedAt, s.endedAt) : null; - return ( -
- - {open && ( -
- {s.exercises.length === 0 && ( -

{t('history.noExercises')}

- )} - {s.exercises.length > 0 && ( -
- {s.exercises.map((ex) => ( -
-
-
- - {localizedName(ex, i18n.language)} - - {ex.isExtra && {t('history.added')}} -
- - {muscleName(ex.muscle) || ex.muscle} - -
-
- {ex.sets.map((set) => ( -
-
- - S{set.index + 1} - - {set.planned && set.reps == null ? ( - - {t('history.notDone')} - - ) : ( - - {set.reps ?? '—'} - - {t('history.repsUnit')} - - - )} -
- {(set.planned || set.rir != null || set.difficulty != null) && ( -
- {set.planned && ( - - {t('history.planPrefix')} - {set.planned.reps ?? '—'} - {set.planned.loadKg != null - ? `/${set.planned.loadKg} kg` - : `/${t('history.bodyweight')}`} - {set.planned.restSec != null - ? `/${set.planned.restSec} s` - : ''} - - )} - {set.rir != null && RIR {set.rir}} - {set.difficulty != null && ( - - {t('history.difficultyWord', { n: set.difficulty })} - - )} -
- )} - {set.note && ( -
- - {set.note} -
- )} -
- ))} -
- {ex.comments.length > 0 && ( -
- {ex.comments.map((c) => ( -
-
- {c.authorName} - · {fmtDate(c.createdAt)} -
{c.body}
-
-
- ))} -
- )} -
- ))} -
- )} -
- )} -
- ); - })} -
- ); -} diff --git a/admin/src/components/MembershipActionsModal.tsx b/admin/src/components/MembershipActionsModal.tsx new file mode 100644 index 0000000..b651345 --- /dev/null +++ b/admin/src/components/MembershipActionsModal.tsx @@ -0,0 +1,137 @@ +import { useState } from 'react'; +import { Link } from 'react-router-dom'; +import { useTranslation } from 'react-i18next'; +import { api } from '../api/client'; +import type { GymRole } from '../api/types'; +import { GymRolePicker } from './GymRolePicker'; +import { Button, ErrorText, Field, Modal, Muted, Textarea } from './ui'; +import { GYM_ROLE_ORDER } from '../lib/roles'; + +/** + * Wspólne menu członkostwa (konsola siłowni + profil usera): pełna lista ról (PATCH) + * oraz wyrzucenie z siłowni z wymagalnym powodem (DELETE + audyt membership.deleted). + */ +export function MembershipActionsModal({ + userId, + titleName, + gymId, + roles: initialRoles, + showProfileLink = true, + onClose, + onChanged, +}: { + userId: string; + titleName: string; + gymId: string; + roles: string[]; + showProfileLink?: boolean; + onClose: () => void; + onChanged: () => void; +}) { + const { t } = useTranslation('gyms'); + const [roles, setRoles] = useState( + GYM_ROLE_ORDER.filter((r) => initialRoles.includes(r)), + ); + const [reason, setReason] = useState(''); + const [busy, setBusy] = useState<'' | 'roles' | 'remove'>(''); + const [error, setError] = useState(''); + + const saveRoles = async () => { + if (roles.length === 0) return; + setError(''); + setBusy('roles'); + try { + await api(`/admin/users/${userId}/memberships/${gymId}`, { + method: 'PATCH', + body: { roles }, + }); + onChanged(); + onClose(); + } catch (err) { + setError(err instanceof Error ? err.message : t('common:error')); + } finally { + setBusy(''); + } + }; + + const remove = async () => { + const trimmed = reason.trim(); + if (trimmed.length < 3) return; + setError(''); + setBusy('remove'); + try { + await api(`/admin/users/${userId}/memberships/${gymId}`, { + method: 'DELETE', + body: { reason: trimmed }, + }); + onChanged(); + onClose(); + } catch (err) { + setError(err instanceof Error ? err.message : t('common:error')); + } finally { + setBusy(''); + } + }; + + return ( + +
+ {t('memberMenuDesc')} + {showProfileLink && ( + + {t('memberProfileLink')} + + )} +
+ +
+ {t('memberRolesTitle')} +
+ +
+ +
+ +
+ +
+ {t('removeMemberTitle')} +
+

{t('removeMemberDesc')}

+ +