Admin: lista siłowni przebudowana na karte z aplikacji (cover, meta z ikonami, siatka tygodnia)
This commit is contained in:
@@ -38,3 +38,14 @@ export function formatAvailability(value: unknown): string {
|
||||
});
|
||||
return parts.join(', ');
|
||||
}
|
||||
|
||||
/** "18:00" -> "18", "21:30" -> "21:30" — forma skrócona do siatki tygodnia. */
|
||||
export function shortTime(t: string): string {
|
||||
const [h, m] = t.split(':');
|
||||
return m === '00' ? h : t;
|
||||
}
|
||||
|
||||
/** Zwarty zakres dnia do siatki tygodnia, np. "18–21:30". */
|
||||
export function formatDayRange(day: DayAvailability): string {
|
||||
return `${shortTime(day.start)}–${shortTime(day.end)}`;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,121 @@
|
||||
import { useEffect } from 'react';
|
||||
import { Link, useNavigate } from 'react-router-dom';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { Clock, MapPin, Plus, Users, Building2, Dumbbell } from 'lucide-react';
|
||||
import { MapPin, Plus, Users, Building2, Dumbbell } from 'lucide-react';
|
||||
import { api } from '../../api/client';
|
||||
import type { Gym } from '../../api/types';
|
||||
import { Badge, Card, EmptyState, ErrorText, Loading, MetaItem } from '../../components/ui';
|
||||
import { formatAvailability } from '../../lib/availability';
|
||||
import { Badge, Card, EmptyState, ErrorText, H3, Loading, MetaItem } from '../../components/ui';
|
||||
import { DAY_NAMES, formatDayRange, normalizeAvailability } from '../../lib/availability';
|
||||
import { useListSearch } from '../../store/list-search';
|
||||
import { useTopbar } from '../../topbar';
|
||||
import { AuthImage } from '../../components/AuthImage';
|
||||
|
||||
/* Karta siłowni 1:1 z widokiem z aplikacji (app/src/pages/gyms/Gyms.tsx):
|
||||
cover z badge'ami i „Otwórz →”, nazwa, meta z ikonami, pasek tygodnia z wyróżnionym „dziś”. */
|
||||
function GymCard({ gym }: { gym: Gym }) {
|
||||
const navigate = useNavigate();
|
||||
const availability = normalizeAvailability(gym.availability);
|
||||
const todayIdx = (new Date().getDay() + 6) % 7;
|
||||
const members = gym._count?.memberships ?? 0;
|
||||
|
||||
return (
|
||||
<div
|
||||
data-slot="gym-card"
|
||||
className="flex cursor-pointer flex-col overflow-hidden rounded-xl border border-line bg-(image:--card-grad) shadow-card transition-all hover:-translate-y-0.5 hover:border-accent/55 hover:shadow-[var(--glow),var(--shadow)]"
|
||||
onClick={() => navigate(`/gyms/${gym.id}`)}
|
||||
>
|
||||
{/* okładka: zdjęcie albo gradientowy placeholder z piktogramem */}
|
||||
<div className="relative grid h-28 place-items-center overflow-hidden sm:h-32">
|
||||
{gym.coverPhoto ? (
|
||||
<AuthImage
|
||||
src={gym.coverPhoto}
|
||||
alt={gym.name}
|
||||
className="absolute inset-0 h-full w-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className="absolute inset-0"
|
||||
style={{
|
||||
background:
|
||||
'linear-gradient(140deg, color-mix(in srgb, var(--accent) 26%, var(--bg-input)), color-mix(in srgb, var(--line) 60%, var(--bg-input)) 55%, var(--bg-input))',
|
||||
}}
|
||||
/>
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className="absolute inset-0 opacity-60"
|
||||
style={{
|
||||
background:
|
||||
'repeating-linear-gradient(45deg, color-mix(in srgb, var(--text) 4%, transparent) 0 2px, transparent 2px 14px)',
|
||||
}}
|
||||
/>
|
||||
<Dumbbell className="relative h-8 w-8 text-ink/25" />
|
||||
</>
|
||||
)}
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className="absolute inset-0 bg-[linear-gradient(180deg,transparent_55%,rgb(0_0_0/0.45))]"
|
||||
/>
|
||||
<div className="absolute left-2.5 top-2.5 flex flex-wrap gap-1.5">
|
||||
{gym.kind === 'VIRTUAL' && <Badge color="blue">Wirtualna</Badge>}
|
||||
{gym.isPrivate && <Badge color="gray">Prywatna</Badge>}
|
||||
</div>
|
||||
<span className="absolute bottom-2.5 right-2.5 inline-flex items-center gap-1.5 rounded-full bg-black/35 px-2.5 py-1 text-[0.7rem] font-bold text-white backdrop-blur-sm">
|
||||
Otwórz →
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-1 flex-col gap-2.5 p-4">
|
||||
<Link
|
||||
to={`/gyms/${gym.id}`}
|
||||
className="min-w-0 truncate text-[1.02rem] font-bold hover:text-accent-text"
|
||||
>
|
||||
{gym.name}
|
||||
</Link>
|
||||
<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}>
|
||||
{gym.capacity != null ? `${members}/${gym.capacity} członków` : `${members} członków`}
|
||||
</MetaItem>
|
||||
<MetaItem icon={Dumbbell}>{gym.equipment.length} urządzeń</MetaItem>
|
||||
</div>
|
||||
<div className="grid grid-cols-7 gap-0.5">
|
||||
{availability.map((day, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className={`min-w-0 rounded-[10px] px-0 py-1.5 text-center ${day ? 'bg-accent/10' : 'bg-input/50'} ${
|
||||
i === todayIdx ? 'outline outline-1 outline-accent/50' : ''
|
||||
}`}
|
||||
>
|
||||
<div
|
||||
className={`truncate text-[0.6rem] font-semibold uppercase tracking-wide ${
|
||||
day ? 'text-accent-text' : 'text-dim/60'
|
||||
}`}
|
||||
>
|
||||
{DAY_NAMES[i]}
|
||||
</div>
|
||||
<div
|
||||
className={`whitespace-nowrap text-[0.65rem] tabular-nums tracking-tight ${
|
||||
day ? 'text-ink' : 'text-dim/50'
|
||||
}`}
|
||||
>
|
||||
{day ? formatDayRange(day) : '—'}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function GymsList() {
|
||||
useTopbar({
|
||||
title: 'Siłownie',
|
||||
search: 'gyms',
|
||||
actions: [{ label: 'Nowa siłownia', to: '/gyms/new', icon: Plus }],
|
||||
});
|
||||
const navigate = useNavigate();
|
||||
const { data, isLoading, error } = useQuery({
|
||||
queryKey: ['gyms'],
|
||||
queryFn: () => api<{ gyms: Gym[] }>('/admin/gyms'),
|
||||
@@ -42,75 +141,25 @@ export default function GymsList() {
|
||||
{isLoading && <Loading />}
|
||||
{error && <ErrorText>Błąd: {(error as Error).message}</ErrorText>}
|
||||
|
||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||
{filtered.map((g) => (
|
||||
<div
|
||||
key={g.id}
|
||||
className="cursor-pointer overflow-hidden rounded-[10px] border border-line bg-(image:--card-grad) shadow-card transition-all hover:border-accent/55"
|
||||
onClick={() => navigate(`/gyms/${g.id}`)}
|
||||
>
|
||||
{g.coverPhoto ? (
|
||||
<AuthImage
|
||||
src={g.coverPhoto}
|
||||
alt={g.name}
|
||||
className="h-28 w-full object-cover sm:h-32"
|
||||
/>
|
||||
) : (
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className="relative grid h-20 place-items-center overflow-hidden sm:h-24"
|
||||
style={{
|
||||
background:
|
||||
'linear-gradient(140deg, color-mix(in srgb, var(--accent) 22%, var(--bg-input)), color-mix(in srgb, var(--line) 55%, var(--bg-input)) 55%, var(--bg-input))',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="absolute inset-0 opacity-60"
|
||||
style={{
|
||||
background:
|
||||
'repeating-linear-gradient(45deg, color-mix(in srgb, var(--text) 4%, transparent) 0 2px, transparent 2px 14px)',
|
||||
}}
|
||||
/>
|
||||
<Dumbbell className="relative h-7 w-7 text-ink/25" />
|
||||
</div>
|
||||
)}
|
||||
<div className="p-5 sm:p-6">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<Link
|
||||
to={`/gyms/${g.id}`}
|
||||
className="text-[1.05rem] font-semibold hover:text-accent-text"
|
||||
>
|
||||
{g.name}
|
||||
</Link>
|
||||
<Badge color={g.kind === 'VIRTUAL' ? 'blue' : 'gray'}>
|
||||
{g.kind === 'VIRTUAL' ? 'Wirtualna' : 'Realna'}
|
||||
</Badge>
|
||||
{g.isPrivate && <Badge color="gray">Prywatna</Badge>}
|
||||
</div>
|
||||
<div className="mt-1">
|
||||
<MetaItem icon={MapPin}>{g.location || '—'}</MetaItem>
|
||||
</div>
|
||||
</div>
|
||||
<Badge color="gray">{g._count?.memberships ?? 0} członk.</Badge>
|
||||
</div>
|
||||
<div className="mt-3 flex flex-wrap gap-x-4 gap-y-1">
|
||||
<MetaItem icon={Clock}>{formatAvailability(g.availability) || '—'}</MetaItem>
|
||||
<MetaItem icon={Users}>
|
||||
{g.capacity != null ? `${g.capacity} miejsc` : '—'}
|
||||
</MetaItem>
|
||||
</div>
|
||||
</div>
|
||||
{!isLoading && !error && filtered.length > 0 && (
|
||||
<>
|
||||
<div className="mb-3 flex items-center gap-2.5">
|
||||
<H3 className="mb-0">Wszystkie siłownie</H3>
|
||||
<Badge color="gray">{filtered.length}</Badge>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="grid grid-cols-1 gap-4 lg:grid-cols-2">
|
||||
{filtered.map((g) => (
|
||||
<GymCard key={g.id} gym={g} />
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{!isLoading && !error && filtered.length === 0 && (
|
||||
<Card>
|
||||
<EmptyState
|
||||
icon={Building2}
|
||||
title="Brak siłowni"
|
||||
title={query ? 'Brak wyników' : 'Brak siłowni'}
|
||||
description={
|
||||
query
|
||||
? 'Brak wyników dla podanego zapytania.'
|
||||
|
||||
@@ -69,7 +69,7 @@ describe('admin GymsList page', () => {
|
||||
renderGyms();
|
||||
expect(await screen.findByText('Gym A')).toBeInTheDocument();
|
||||
expect(screen.getByText('Warszawa')).toBeInTheDocument();
|
||||
expect(screen.getByText('12 członk.')).toBeInTheDocument();
|
||||
expect(screen.getByText('12/50 członków')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('clicking a gym opens the detail page', async () => {
|
||||
|
||||
Reference in New Issue
Block a user