Silownie: /gyms - zakladka Dołącz z wyszukiwaniem i dołączaniem do siłowni, do których nie należę (lista REAL z /gyms/all, filtr w topbarze)
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
gymPhotoSrc,
|
||||
joinGym,
|
||||
rateGym,
|
||||
useAllGyms,
|
||||
useGyms,
|
||||
useGymInvitations,
|
||||
useMe,
|
||||
@@ -16,7 +17,18 @@ import {
|
||||
withdrawGymInvitation,
|
||||
} from '../../api/queries';
|
||||
import type { Gym, GymClaim, GymInvitation, VirtualGym } from '../../api/types';
|
||||
import { Badge, Button, Card, EmptyState, ErrorText, H3, ListRow, Loading, MetaItem, Tabs } from '../../components/ui';
|
||||
import {
|
||||
Badge,
|
||||
Button,
|
||||
Card,
|
||||
EmptyState,
|
||||
ErrorText,
|
||||
H3,
|
||||
ListRow,
|
||||
Loading,
|
||||
MetaItem,
|
||||
Tabs,
|
||||
} from '../../components/ui';
|
||||
import { useToast } from '../../components/toast';
|
||||
import { useListSearch } from '../../store/list-search';
|
||||
import { useTopbar } from '../../topbar';
|
||||
@@ -25,7 +37,7 @@ import GymCreateModal from '../../components/gyms/GymCreateModal';
|
||||
import ClaimModal from '../../components/gyms/ClaimModal';
|
||||
import InviteGymModal from '../../components/gyms/InviteGymModal';
|
||||
|
||||
type Tab = 'mine' | 'virtual';
|
||||
type Tab = 'mine' | 'join' | 'virtual';
|
||||
|
||||
function GymKindBadges({ gym }: { gym: { kind: string; isPrivate: boolean } }) {
|
||||
return (
|
||||
@@ -62,15 +74,22 @@ function GymCard({
|
||||
|
||||
return (
|
||||
<div
|
||||
data-slot="gym-card"
|
||||
className={`flex flex-col overflow-hidden rounded-xl border border-line bg-(image:--card-grad) shadow-card transition-all ${
|
||||
onClick ? 'cursor-pointer hover:-translate-y-0.5 hover:border-accent/55 hover:shadow-[var(--glow),var(--shadow)]' : ''
|
||||
onClick
|
||||
? 'cursor-pointer hover:-translate-y-0.5 hover:border-accent/55 hover:shadow-[var(--glow),var(--shadow)]'
|
||||
: ''
|
||||
}`}
|
||||
onClick={onClick}
|
||||
>
|
||||
{/* okładka: zdjęcie albo gradientowy placeholder z piktogramem */}
|
||||
<div className="relative grid h-28 place-items-center overflow-hidden sm:h-32">
|
||||
{cover ? (
|
||||
<img src={gymPhotoSrc(cover)} alt={gym.name} className="absolute inset-0 h-full w-full object-cover" />
|
||||
<img
|
||||
src={gymPhotoSrc(cover)}
|
||||
alt={gym.name}
|
||||
className="absolute inset-0 h-full w-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<div
|
||||
@@ -117,7 +136,11 @@ function GymCard({
|
||||
<div className="flex flex-wrap items-center gap-x-4 gap-y-1 text-dim text-[0.78rem]">
|
||||
<MetaItem icon={MapPin}>{gym.location || '—'}</MetaItem>
|
||||
<MetaItem icon={Users}>
|
||||
{memberCount != null ? `${memberCount} członków` : gym.capacity != null ? `${gym.capacity} miejsc` : '—'}
|
||||
{memberCount != null
|
||||
? `${memberCount} członków`
|
||||
: gym.capacity != null
|
||||
? `${gym.capacity} miejsc`
|
||||
: '—'}
|
||||
</MetaItem>
|
||||
<MetaItem icon={Dumbbell}>{gym.equipment.length} urządzeń</MetaItem>
|
||||
</div>
|
||||
@@ -154,7 +177,9 @@ function GymCard({
|
||||
style={{ width: `${rating}%` }}
|
||||
/>
|
||||
</div>
|
||||
<span className="text-[0.72rem] font-extrabold tabular-nums text-accent-text">{rating}%</span>
|
||||
<span className="text-[0.72rem] font-extrabold tabular-nums text-accent-text">
|
||||
{rating}%
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{children && <div className="mt-auto flex flex-col gap-2 pt-1">{children}</div>}
|
||||
@@ -166,7 +191,10 @@ function GymCard({
|
||||
/* Głosy „Polecam/Nie polecam” z licznikami (aria-pressed). */
|
||||
function VoteButtons({ gym, onRate }: { gym: VirtualGym; onRate: (vote: 'UP' | 'DOWN') => void }) {
|
||||
return (
|
||||
<div className="flex items-center gap-2" title="Czy ta wirtualna siłownia dobrze oddaje prawdziwą?">
|
||||
<div
|
||||
className="flex items-center gap-2"
|
||||
title="Czy ta wirtualna siłownia dobrze oddaje prawdziwą?"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Polecam: ${gym.name}`}
|
||||
@@ -300,14 +328,21 @@ function VirtualGymCard({
|
||||
{isOwner && !gym.isPrivate && gym.claimStatus === 'PENDING' && (
|
||||
<>
|
||||
<span className="text-[0.875rem] text-dim">Wniosek oczekuje na weryfikację</span>
|
||||
<Button size="sm" variant="secondary" onClick={() => void withdrawClaim()} disabled={busy}>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
onClick={() => void withdrawClaim()}
|
||||
disabled={busy}
|
||||
>
|
||||
Wycofaj
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
{isOwner && !gym.isPrivate && gym.claimStatus === 'REJECTED' && (
|
||||
<>
|
||||
<span className="text-[0.875rem] text-danger">Odrzucono{gym.rejectReason ? `: ${gym.rejectReason}` : ''}</span>
|
||||
<span className="text-[0.875rem] text-danger">
|
||||
Odrzucono{gym.rejectReason ? `: ${gym.rejectReason}` : ''}
|
||||
</span>
|
||||
<Button size="sm" variant="secondary" onClick={() => setClaimOpen(true)}>
|
||||
Złóż ponownie
|
||||
</Button>
|
||||
@@ -319,22 +354,36 @@ function VirtualGymCard({
|
||||
</Button>
|
||||
)}
|
||||
{gym.isPrivate && isOwner && (
|
||||
<ClaimStatusInline gym={gym} onResubmit={() => setClaimOpen(true)} onWithdraw={() => void withdrawClaim()} busy={busy} />
|
||||
<ClaimStatusInline
|
||||
gym={gym}
|
||||
onResubmit={() => setClaimOpen(true)}
|
||||
onWithdraw={() => void withdrawClaim()}
|
||||
busy={busy}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{gym.isPrivate && isOwner && sentInvitations.length > 0 && (
|
||||
<div className="mt-3 border-t border-line pt-3">
|
||||
<div className="mb-1.5 text-[11px] font-bold uppercase tracking-[0.1em] text-dim">Wysłane zaproszenia</div>
|
||||
<div className="mb-1.5 text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
|
||||
Wysłane zaproszenia
|
||||
</div>
|
||||
<div className="divide-y divide-line">
|
||||
{sentInvitations.map((inv) => {
|
||||
const name = [inv.user?.firstName, inv.user?.lastName].filter(Boolean).join(' ') || inv.user?.email || '—';
|
||||
const name =
|
||||
[inv.user?.firstName, inv.user?.lastName].filter(Boolean).join(' ') ||
|
||||
inv.user?.email ||
|
||||
'—';
|
||||
return (
|
||||
<ListRow
|
||||
key={inv.id}
|
||||
title={name}
|
||||
actions={
|
||||
<Button size="sm" variant="ghost" onClick={() => void withdrawInvitation(inv.id)}>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => void withdrawInvitation(inv.id)}
|
||||
>
|
||||
Wycofaj
|
||||
</Button>
|
||||
}
|
||||
@@ -398,23 +447,45 @@ function ClaimStatusInline({
|
||||
|
||||
export default function Gyms() {
|
||||
const navigate = useNavigate();
|
||||
const queryClient = useQueryClient();
|
||||
const { data: ownedData, isLoading: ownedLoading, error: ownedError } = useOwnedGyms();
|
||||
const { data: gymsData } = useGyms();
|
||||
const { data: allData, isLoading: allLoading, error: allError } = useAllGyms();
|
||||
const { data: virtualData, isLoading: virtualLoading, error: virtualError } = useVirtualGyms();
|
||||
const { data: invData } = useGymInvitations();
|
||||
const { data: claimsData } = useMyGymClaims();
|
||||
const { data: me } = useMe();
|
||||
const isAdmin = me?.user.isAdmin ?? false;
|
||||
const { push } = useToast();
|
||||
|
||||
const ownedGyms = ownedData?.gyms ?? [];
|
||||
const memberIds = new Set((gymsData?.gyms ?? []).map((g) => g.id));
|
||||
const ownerIds = new Set(ownedGyms.map((g) => g.id));
|
||||
// REAL siłownie, do których nie należę (zakładka „Dołącz”)
|
||||
const joinableGyms = (allData?.gyms ?? []).filter((g) => !memberIds.has(g.id));
|
||||
const virtualGyms = virtualData?.gyms ?? [];
|
||||
const sentGymInvitations = (invData?.invitations ?? []).filter((i) => i.direction === 'sent');
|
||||
const claimsByGym = new Map((claimsData?.claims ?? []).map((c) => [c.gymId, c]));
|
||||
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [inviteGym, setInviteGym] = useState<{ id: string; name: string } | null>(null);
|
||||
const [joinBusyId, setJoinBusyId] = useState<string | null>(null);
|
||||
|
||||
const join = async (g: Gym) => {
|
||||
setJoinBusyId(g.id);
|
||||
try {
|
||||
await joinGym(g.id);
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({ queryKey: ['gyms'] }),
|
||||
queryClient.invalidateQueries({ queryKey: ['gyms', 'all'] }),
|
||||
]);
|
||||
push(`Dołączono do siłowni: ${g.name}`, 'success');
|
||||
} catch (e) {
|
||||
push((e as Error).message, 'error');
|
||||
} finally {
|
||||
setJoinBusyId(null);
|
||||
}
|
||||
};
|
||||
|
||||
const [tab, setTab] = useState<Tab | null>(null);
|
||||
useEffect(() => {
|
||||
@@ -438,6 +509,7 @@ export default function Gyms() {
|
||||
!q || [g.name, g.location].filter(Boolean).some((s) => s!.toLowerCase().includes(q));
|
||||
|
||||
const filteredMine = ownedGyms.filter(matches);
|
||||
const filteredJoinable = joinableGyms.filter(matches);
|
||||
const filteredVirtual = virtualGyms.filter(matches);
|
||||
|
||||
return (
|
||||
@@ -446,6 +518,7 @@ export default function Gyms() {
|
||||
<Tabs
|
||||
tabs={[
|
||||
{ id: 'mine', label: 'Moje siłownie' },
|
||||
{ id: 'join', label: 'Dołącz' },
|
||||
{ id: 'virtual', label: 'Wirtualne' },
|
||||
]}
|
||||
active={tab ?? 'virtual'}
|
||||
@@ -488,7 +561,51 @@ export default function Gyms() {
|
||||
</div>
|
||||
<div className="grid grid-cols-1 gap-4 lg:grid-cols-2">
|
||||
{filteredMine.map((g) => (
|
||||
<GymCard key={g.id} gym={g} cover={g.coverPhoto} onClick={() => navigate(`/gyms/${g.id}`)} />
|
||||
<GymCard
|
||||
key={g.id}
|
||||
gym={g}
|
||||
cover={g.coverPhoto}
|
||||
onClick={() => navigate(`/gyms/${g.id}`)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{tab === 'join' && (
|
||||
<>
|
||||
{allLoading && <Loading />}
|
||||
{allError && <ErrorText>Błąd: {(allError as Error).message}</ErrorText>}
|
||||
{!allLoading && !allError && filteredJoinable.length === 0 && (
|
||||
<Card>
|
||||
<EmptyState
|
||||
icon={Building2}
|
||||
title={q ? 'Brak wyników' : 'Brak siłowni do dołączenia'}
|
||||
description={
|
||||
q
|
||||
? 'Brak wyników dla podanego zapytania.'
|
||||
: 'Należysz już do wszystkich dostępnych siłowni.'
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
)}
|
||||
{filteredJoinable.length > 0 && (
|
||||
<>
|
||||
<div className="mb-3 flex items-center gap-2.5">
|
||||
<H3 className="mb-0">Dołącz do siłowni</H3>
|
||||
<Badge color="gray">{filteredJoinable.length}</Badge>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 gap-4 lg:grid-cols-2">
|
||||
{filteredJoinable.map((g) => (
|
||||
// bez onClick na karcie — tap w „Dołącz” nie może jednocześnie otworzyć detalu
|
||||
// (nazwa pozostaje linkiem do /gyms/:id)
|
||||
<GymCard key={g.id} gym={g} cover={g.coverPhoto}>
|
||||
<Button size="sm" onClick={() => void join(g)} disabled={joinBusyId === g.id}>
|
||||
Dołącz
|
||||
</Button>
|
||||
</GymCard>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
@@ -505,7 +622,11 @@ export default function Gyms() {
|
||||
<EmptyState
|
||||
icon={Building2}
|
||||
title={q ? 'Brak wyników' : 'Brak wirtualnych siłowni'}
|
||||
description={q ? 'Brak wyników dla podanego zapytania.' : 'Zaglądaj tu, by oceniać odwzorowanie prawdziwych siłowni.'}
|
||||
description={
|
||||
q
|
||||
? 'Brak wyników dla podanego zapytania.'
|
||||
: 'Zaglądaj tu, by oceniać odwzorowanie prawdziwych siłowni.'
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
)}
|
||||
@@ -534,9 +655,7 @@ export default function Gyms() {
|
||||
)}
|
||||
|
||||
<GymCreateModal open={createOpen} onClose={() => setCreateOpen(false)} />
|
||||
{inviteGym && (
|
||||
<InviteGymModal open onClose={() => setInviteGym(null)} gym={inviteGym} />
|
||||
)}
|
||||
{inviteGym && <InviteGymModal open onClose={() => setInviteGym(null)} gym={inviteGym} />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,9 @@ async function loginToProfile(page: import('@playwright/test').Page) {
|
||||
await expect(page.getByRole('heading', { name: 'Profil — siłownie', exact: true })).toBeVisible();
|
||||
}
|
||||
|
||||
test('profil pokazuje siłownie użytkownika z rolą i sprzętem oraz listę do dołączenia', async ({ page }) => {
|
||||
test('profil pokazuje siłownie użytkownika z rolą i sprzętem oraz listę do dołączenia', async ({
|
||||
page,
|
||||
}) => {
|
||||
mockApi(page);
|
||||
await loginToProfile(page);
|
||||
|
||||
@@ -68,6 +70,42 @@ test('admin może stworzyć siłownię i dodać do niej sprzęt', async ({ page
|
||||
await expect(page.getByText('Sprzęt dodany')).toBeVisible();
|
||||
});
|
||||
|
||||
test('/gyms: zakładka Dołącz — wyszukiwanie i dołączanie do siłowni, do której nie należę', async ({
|
||||
page,
|
||||
}) => {
|
||||
mockApi(page);
|
||||
await page.goto('/login');
|
||||
await page.locator('input[type="email"]').fill('test@fitos.pl');
|
||||
await page.locator('input[type="password"]').fill('haslo123');
|
||||
await page.getByRole('button', { name: 'Zaloguj' }).click();
|
||||
await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
|
||||
|
||||
await page.getByRole('link', { name: 'Siłownie' }).click();
|
||||
await expect(page.getByRole('heading', { name: 'Siłownie', exact: true })).toBeVisible();
|
||||
|
||||
// zakładka „Dołącz”: REAL siłownie, do których nie należę (zakładka ≠ przycisk karty)
|
||||
await page.locator('[data-slot="tabs"]').getByRole('button', { name: 'Dołącz' }).click();
|
||||
await expect(page.getByText('Mega Gym')).toBeVisible();
|
||||
// moją siłownię (właściciel) w liście nie ma
|
||||
await expect(page.getByText('Żelazna Świątynia')).toHaveCount(0);
|
||||
|
||||
// wyszukiwarka w topbarze filtruje listę
|
||||
const searchbox = page.getByRole('searchbox', { name: 'Szukaj siłowni' });
|
||||
await searchbox.fill('mega');
|
||||
await expect(page.getByText('Mega Gym')).toBeVisible();
|
||||
await searchbox.fill('nieistniejąca');
|
||||
// exact: opis „Brak wyników dla podanego zapytania” zawiera ten sam podłańcuch
|
||||
await expect(page.getByRole('heading', { name: 'Brak wyników' })).toBeVisible();
|
||||
await searchbox.fill('');
|
||||
|
||||
// dołączenie (przycisk w karcie, nie zakładka)
|
||||
await page
|
||||
.locator('[data-slot="gym-card"]', { has: page.getByRole('link', { name: 'Mega Gym' }) })
|
||||
.getByRole('button', { name: 'Dołącz', exact: true })
|
||||
.click();
|
||||
await expect(page.getByText('Dołączono do siłowni: Mega Gym')).toBeVisible();
|
||||
});
|
||||
|
||||
test('właściciel ma menu „Siłownie" i zarządza swoją siłownią', async ({ page }) => {
|
||||
mockApi(page);
|
||||
await page.goto('/login');
|
||||
|
||||
@@ -62,7 +62,11 @@ test('wirtualne siłownie: dołączenie do publicznej', async ({ page }) => {
|
||||
await loginToGyms(page);
|
||||
await openVirtualTab(page);
|
||||
|
||||
await page.getByRole('button', { name: 'Dołącz' }).click();
|
||||
// przycisk w karcie (zakładka „Dołącz” ma tę samą nazwę)
|
||||
await page
|
||||
.locator('[data-slot="gym-card"]', { has: page.getByRole('link', { name: 'Wirtualna Alfa' }) })
|
||||
.getByRole('button', { name: 'Dołącz', exact: true })
|
||||
.click();
|
||||
await expect(page.getByText('Dołączono do siłowni: Wirtualna Alfa')).toBeVisible();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user