diff --git a/app/src/pages/trainees/Trainees.tsx b/app/src/pages/trainees/Trainees.tsx index 8b0e1fb..edc4d79 100644 --- a/app/src/pages/trainees/Trainees.tsx +++ b/app/src/pages/trainees/Trainees.tsx @@ -25,6 +25,7 @@ import { ProgressBar, Select, Skeleton, + Tabs, } from '../../components/ui'; import { Avatar } from '../../components/Avatar'; import { useToast } from '../../components/toast'; @@ -113,6 +114,7 @@ export default function Trainees() { const [sortKey, setSortKey] = useState('none'); const [sortOpen, setSortOpen] = useState(false); const [groupByGym, setGroupByGym] = useState(false); + const [activeGymTab, setActiveGymTab] = useState(null); const [firstName, setFirstName] = useState(''); const [lastName, setLastName] = useState(''); const [searching, setSearching] = useState(false); @@ -256,6 +258,8 @@ export default function Trainees() { if (other.length > 0) groups.push({ id: 'other', name: 'Inne', trainees: other }); return groups; }, [filtered, trainerGymIds]); + // aktywna zakładka siłowni (domyślnie pierwsza grupa; fallback gdy grupa zniknie np. po wyszukiwarce) + const activeGroup = gymGroups.find((g) => g.id === activeGymTab) ?? gymGroups[0]; const invite = async (candidate: UserSearchResult) => { try { @@ -378,28 +382,36 @@ export default function Trainees() { )} {!isLoading && !error && filtered.length > 0 && ( - groupByGym ? ( -
- {gymGroups.map((g) => ( -
-
-

{g.name}

- {g.trainees.length} + groupByGym && activeGroup ? ( + <> + {/* lista siłowni (tylko te z podopiecznymi) jako zakładki — łatwiej się odnaleźć */} + {gymGroups.length > 1 && ( +
+ ({ id: g.id, label: g.name }))} + active={activeGroup.id} + onChange={setActiveGymTab} + /> +
+ )} +
+
+

{activeGroup.name}

+ {activeGroup.trainees.length} +
+ +
+ {activeGroup.trainees.map((t) => ( + navigate(`/trainees/${t.user.id}`)} + /> + ))}
- -
- {g.trainees.map((t) => ( - navigate(`/trainees/${t.user.id}`)} - /> - ))} -
-
-
- ))} -
+ +
+ ) : (
diff --git a/app/test/trainees.test.tsx b/app/test/trainees.test.tsx index 9c692b6..fe306b5 100644 --- a/app/test/trainees.test.tsx +++ b/app/test/trainees.test.tsx @@ -429,18 +429,31 @@ describe('Trainees — lista i szczegóły', () => { await user.click(screen.getByRole('button', { name: 'Grupuj wg siłowni' })); - // grupy: Żelazna Świątynia (Anna, Tomek), Mega Gym (Tomek), Inne (Piotr, Zofia) - expect(screen.getByRole('heading', { name: 'Żelazna Świątynia' })).toBeInTheDocument(); + // zakładki = lista siłowni z podopiecznymi (siłownie alfabetycznie, „Inne” na końcu) + expect(screen.getByRole('button', { name: 'Inne' })).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Mega Gym' })).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Żelazna Świątynia' })).toBeInTheDocument(); + // domyślnie pierwsza zakładka (Mega Gym) — tylko jej wiersze expect(screen.getByRole('heading', { name: 'Mega Gym' })).toBeInTheDocument(); - expect(screen.getByRole('heading', { name: 'Inne' })).toBeInTheDocument(); - // Tomek trenowany w obu siłowniach — w obu grupach; reszta po jednej - expect(screen.getAllByText('Tomek Kowalczyk')).toHaveLength(2); - expect(screen.getAllByText('Anna Nowak')).toHaveLength(1); - expect(screen.getAllByText('Piotr Kowal')).toHaveLength(1); + expect(screen.getByText('Tomek Kowalczyk')).toBeInTheDocument(); + expect(screen.queryByText('Anna Nowak')).not.toBeInTheDocument(); - // wyłączenie wraca do listy płaskiej + // przełączenie na siłownię — Anna + Tomek (Tomek trenowany w obu siłowniach) + await user.click(screen.getByRole('button', { name: 'Żelazna Świątynia' })); + expect(screen.getByRole('heading', { name: 'Żelazna Świątynia' })).toBeInTheDocument(); + expect(screen.getByText('Anna Nowak')).toBeInTheDocument(); + expect(screen.getAllByText('Tomek Kowalczyk')).toHaveLength(1); + + // „Inne” — Piotr i Zofia + await user.click(screen.getByRole('button', { name: 'Inne' })); + expect(screen.getByRole('heading', { name: 'Inne' })).toBeInTheDocument(); + expect(screen.getByText('Piotr Kowal')).toBeInTheDocument(); + expect(screen.queryByText('Anna Nowak')).not.toBeInTheDocument(); + + // wyłączenie wraca do listy płaskiej (wszyscy, Tomek raz) await user.click(screen.getByRole('button', { name: 'Grupuj wg siłowni' })); expect(screen.queryByRole('heading', { name: 'Mega Gym' })).not.toBeInTheDocument(); + expect(screen.getByText('Anna Nowak')).toBeInTheDocument(); expect(screen.getAllByText('Tomek Kowalczyk')).toHaveLength(1); });