diff --git a/app/src/pages/trainees/Trainees.tsx b/app/src/pages/trainees/Trainees.tsx index fb80c70..dceb558 100644 --- a/app/src/pages/trainees/Trainees.tsx +++ b/app/src/pages/trainees/Trainees.tsx @@ -1,7 +1,7 @@ import { useEffect, useMemo, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { useQueryClient } from '@tanstack/react-query'; -import { Flame, Plus, Users } from 'lucide-react'; +import { ChevronDown, Flame, Plus, Users } from 'lucide-react'; import { sendInvitation, useIsTrainer, @@ -30,6 +30,14 @@ import { useToast } from '../../components/toast'; import { useListSearch } from '../../store/list-search'; import { useTopbar } from '../../topbar'; +const SORT_OPTIONS = [ + { id: 'flags', label: 'Flagi' }, + { id: 'killstreak', label: 'Killstreak' }, + { id: 'name', label: 'Nazwa' }, + { id: 'lastSession', label: 'Ostatnia sesja' }, +] as const; +type SortKey = (typeof SORT_OPTIONS)[number]['id']; + /* Wiersz podopiecznego: avatar + nazwa + siłownie + killstreak, aktywny plan (pasek), ostatnia sesja + flagi. Cały wiersz to przycisk. */ function TraineeCard({ trainee, onOpen }: { trainee: Trainee; onOpen: () => void }) { @@ -100,7 +108,8 @@ export default function Trainees() { const trainerGyms = (meData?.memberships ?? []).filter((m) => m.roles.includes('TRAINER')); const [gymId, setGymId] = useState(''); - const [sortKey, setSortKey] = useState<'flags' | 'killstreak' | 'name' | 'lastSession'>('flags'); + const [sortKey, setSortKey] = useState('flags'); + const [sortOpen, setSortOpen] = useState(false); const [firstName, setFirstName] = useState(''); const [lastName, setLastName] = useState(''); const [searching, setSearching] = useState(false); @@ -110,29 +119,42 @@ export default function Trainees() { title: 'Podopieczni', search: 'trainees', filters: [ -
- {( - [ - { id: 'flags', label: 'Flagi' }, - { id: 'killstreak', label: 'Killstreak' }, - { id: 'name', label: 'Nazwa' }, - { id: 'lastSession', label: 'Ostatnia sesja' }, - ] as const - ).map((s) => ( - - ))} + /* sortowanie: przycisk „Sortuj” + rozwijany select (kompaktowo w grupie filtrów) */ +
+ Sortuj + + {sortOpen && ( + <> +
setSortOpen(false)} /> +
+ {SORT_OPTIONS.map((s) => ( + + ))} +
+ + )}
, ], filterActive: sortKey !== 'flags', diff --git a/app/test/trainees.test.tsx b/app/test/trainees.test.tsx index 9803990..58df61f 100644 --- a/app/test/trainees.test.tsx +++ b/app/test/trainees.test.tsx @@ -353,7 +353,7 @@ describe('Trainees — lista i szczegóły', () => { expect(screen.getByText('Anna Nowak')).toBeInTheDocument(); }); - it('chipy sortowania zmieniają kolejność listy (flagi/killstreak/nazwa/ostatnia sesja)', async () => { + it('select sortowania w topmenu zmienia kolejność listy (flagi/killstreak/nazwa/ostatnia sesja)', async () => { mockApi(); const user = userEvent.setup(); renderApp(); @@ -366,20 +366,25 @@ describe('Trainees — lista i szczegóły', () => { Array.from(document.querySelectorAll('button')) .filter((b) => NAMES.some((n) => b.textContent?.includes(n))) .map((b) => NAMES.find((n) => b.textContent!.includes(n))!); + // wybór opcji sortowania: otwórz dropdown „Sortuj” i kliknij opcję + const pickSort = async (option: string) => { + await user.click(screen.getByRole('button', { name: 'Sortuj podopiecznych' })); + await user.click(await screen.findByRole('button', { name: option })); + }; // domyślnie: najpierw flagi (Anna 1 > Piotr/Zofia 0; remis po nazwie) expect(rowOrder()).toEqual(['Anna Nowak', 'Piotr Kowal', 'Zofia Wiśniewska']); - await user.click(screen.getByRole('button', { name: 'Killstreak' })); + await pickSort('Killstreak'); expect(rowOrder()).toEqual(['Zofia Wiśniewska', 'Anna Nowak', 'Piotr Kowal']); - await user.click(screen.getByRole('button', { name: 'Nazwa' })); + await pickSort('Nazwa'); expect(rowOrder()).toEqual(['Anna Nowak', 'Piotr Kowal', 'Zofia Wiśniewska']); - await user.click(screen.getByRole('button', { name: 'Ostatnia sesja' })); + await pickSort('Ostatnia sesja'); expect(rowOrder()).toEqual(['Zofia Wiśniewska', 'Anna Nowak', 'Piotr Kowal']); - await user.click(screen.getByRole('button', { name: 'Flagi' })); + await pickSort('Flagi'); expect(rowOrder()).toEqual(['Anna Nowak', 'Piotr Kowal', 'Zofia Wiśniewska']); });