Silownie: kafelki Galeria/Urzadzenia/Ogloszenia na szczegole zamiast pelnych sekcji + podstrony przegladania (galeria z preview, urzadzenia z mapa ciepla godzinowa i filtrem 7/30/90, ogloszenia); menu kontekstowe zwiniety do jednej grupy Zarzadzaj (edycje przez modale istniejacych sekcji)
This commit is contained in:
@@ -20,6 +20,9 @@ import ProfileProgress from './pages/profile/ProfileProgress';
|
||||
import ProfileClaims from './pages/profile/ProfileClaims';
|
||||
import Gyms from './pages/gyms/Gyms';
|
||||
import GymDetail from './pages/gyms/GymDetail';
|
||||
import GymGalleryPage from './pages/gyms/GymGalleryPage';
|
||||
import GymEquipmentPage from './pages/gyms/GymEquipmentPage';
|
||||
import GymAnnouncementsPage from './pages/gyms/GymAnnouncementsPage';
|
||||
import GymCheckIn from './pages/gyms/GymCheckIn';
|
||||
import Trainees from './pages/trainees/Trainees';
|
||||
import TraineeDetail from './pages/trainees/TraineeDetail';
|
||||
@@ -69,6 +72,9 @@ export default function App() {
|
||||
<Route path="/gyms" element={<Gyms />} />
|
||||
<Route path="/gyms/:id" element={<GymDetail />} />
|
||||
<Route path="/gyms/:id/checkin" element={<GymCheckIn />} />
|
||||
<Route path="/gyms/:id/gallery" element={<GymGalleryPage />} />
|
||||
<Route path="/gyms/:id/equipment" element={<GymEquipmentPage />} />
|
||||
<Route path="/gyms/:id/announcements" element={<GymAnnouncementsPage />} />
|
||||
<Route
|
||||
path="/trainees"
|
||||
element={
|
||||
|
||||
@@ -14,6 +14,7 @@ import type {
|
||||
GymAnnouncement,
|
||||
ExerciseComment,
|
||||
ExerciseProgress,
|
||||
EquipmentUsageRow,
|
||||
FocusArea,
|
||||
FocusChain,
|
||||
HistorySession,
|
||||
@@ -141,6 +142,23 @@ export function useGymDetail(id: string | undefined) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Mapa ciepła urządzeń (24 kafle godzinowe z okien bytności). `rangeDays`: 7/30/90,
|
||||
* from liczony od teraz (jak telemetria bytności w adminie).
|
||||
*/
|
||||
export function useGymEquipmentUsage(gymId: string | undefined, rangeDays: number) {
|
||||
return useQuery({
|
||||
queryKey: ['gym-equipment-usage', gymId, rangeDays],
|
||||
queryFn: () => {
|
||||
const from = new Date(Date.now() - rangeDays * 86_400_000).toISOString();
|
||||
return api<{ equipment: EquipmentUsageRow[] }>(
|
||||
`/gyms/${gymId}/equipment-usage?from=${encodeURIComponent(from)}`,
|
||||
);
|
||||
},
|
||||
enabled: !!gymId,
|
||||
});
|
||||
}
|
||||
|
||||
// ---------- bytność (check-in, live occupancy) ----------
|
||||
/** Aktywna bytność zalogowanego — podstawa przycisków „Idę ćwiczyć / Wychodzę / Wciąż tu jestem". */
|
||||
export function useActivePresence(refetchIntervalMs?: number) {
|
||||
|
||||
@@ -115,6 +115,21 @@ export interface GymEquipment {
|
||||
|
||||
export type GymKind = 'VIRTUAL' | 'REAL';
|
||||
|
||||
/** Kafel godzinowy mapy ciepła urządzeń (0–23, godzina lokalna serwera). */
|
||||
export interface EquipmentUsageCell {
|
||||
hour: number;
|
||||
count: number;
|
||||
}
|
||||
|
||||
/** Wiersz mapy ciepła urządzeń (GET /gyms/:id/equipment-usage) — urządzenie + 24 kafle. */
|
||||
export interface EquipmentUsageRow {
|
||||
equipmentId: string;
|
||||
name: string;
|
||||
nameEn: string | null;
|
||||
cells: EquipmentUsageCell[];
|
||||
peak: number;
|
||||
}
|
||||
|
||||
/** Zdjęcie w galerii siłowni REAL. `url` = ścieżka względna API (dopełnij `API_BASE`). */
|
||||
export interface GymPhoto {
|
||||
id: string;
|
||||
|
||||
@@ -71,6 +71,10 @@
|
||||
"photoMore": "+{{count}} more",
|
||||
"noEquipment": "No equipment.",
|
||||
"photosAria": "Photos: {{name}}",
|
||||
"tilePhotos_one": "{{count}} photo",
|
||||
"tilePhotos_other": "{{count}} photos",
|
||||
"tileAnnouncementsCount_one": "{{count}} announcement",
|
||||
"tileAnnouncementsCount_other": "{{count}} announcements",
|
||||
"places": "{{count}} places",
|
||||
"chipVirtual": "Virtual",
|
||||
"chipPrivate": "Private",
|
||||
@@ -88,6 +92,7 @@
|
||||
"dataCountry": "Country",
|
||||
"dataLocation": "Location",
|
||||
"groupEdit": "Editing",
|
||||
"groupManage": "Manage",
|
||||
"groupGallery": "Gallery",
|
||||
"groupEquipment": "Equipment",
|
||||
"groupAnnouncements": "Announcements",
|
||||
@@ -216,6 +221,31 @@
|
||||
"confirmTitle": "Remove photo",
|
||||
"confirmText": "Are you sure you want to remove this photo?"
|
||||
},
|
||||
"galleryPage": {
|
||||
"title": "Gallery",
|
||||
"editAction": "Edit photos",
|
||||
"photosCount_one": "{{count}} photo",
|
||||
"photosCount_other": "{{count}} photos",
|
||||
"previewAria": "Zoom photo"
|
||||
},
|
||||
"equipmentPage": {
|
||||
"title": "Equipment",
|
||||
"editAction": "Edit equipment",
|
||||
"usage": {
|
||||
"title": "Equipment usage (by hour)",
|
||||
"noData": "No usage data for this period.",
|
||||
"hourCellTitle_one": "{{hour}}:00 — {{count}} use",
|
||||
"hourCellTitle_other": "{{hour}}:00 — {{count}} uses",
|
||||
"rangeAria": "Heatmap range",
|
||||
"rangeDays_one": "{{count}} day",
|
||||
"rangeDays_other": "{{count}} days"
|
||||
}
|
||||
},
|
||||
"announcementsPage": {
|
||||
"title": "Announcements",
|
||||
"subtitle": "Updates from gym managers",
|
||||
"newAction": "New announcement"
|
||||
},
|
||||
"invite": {
|
||||
"toastOk": "Invited: {{name}}",
|
||||
"title": "Invite user: {{name}}",
|
||||
|
||||
@@ -71,6 +71,14 @@
|
||||
"photoMore": "+{{count}} zdjęć",
|
||||
"noEquipment": "Brak urządzeń.",
|
||||
"photosAria": "Zdjęcia: {{name}}",
|
||||
"tilePhotos_one": "{{count}} zdjęcie",
|
||||
"tilePhotos_few": "{{count}} zdjęcia",
|
||||
"tilePhotos_many": "{{count}} zdjęć",
|
||||
"tilePhotos_other": "{{count}} zdjęć",
|
||||
"tileAnnouncementsCount_one": "{{count}} ogłoszenie",
|
||||
"tileAnnouncementsCount_few": "{{count}} ogłoszenia",
|
||||
"tileAnnouncementsCount_many": "{{count}} ogłoszeń",
|
||||
"tileAnnouncementsCount_other": "{{count}} ogłoszeń",
|
||||
"places": "{{count}} miejsc",
|
||||
"chipVirtual": "Wirtualna",
|
||||
"chipPrivate": "Prywatna",
|
||||
@@ -88,6 +96,7 @@
|
||||
"dataCountry": "Kraj",
|
||||
"dataLocation": "Lokalizacja",
|
||||
"groupEdit": "Edycja",
|
||||
"groupManage": "Zarządzaj",
|
||||
"groupGallery": "Galeria",
|
||||
"groupEquipment": "Urządzenia",
|
||||
"groupAnnouncements": "Ogłoszenia",
|
||||
@@ -216,6 +225,37 @@
|
||||
"confirmTitle": "Usuń zdjęcie",
|
||||
"confirmText": "Czy na pewno chcesz usunąć to zdjęcie?"
|
||||
},
|
||||
"galleryPage": {
|
||||
"title": "Galeria",
|
||||
"editAction": "Edytuj zdjęcia",
|
||||
"photosCount_one": "{{count}} zdjęcie",
|
||||
"photosCount_few": "{{count}} zdjęcia",
|
||||
"photosCount_many": "{{count}} zdjęć",
|
||||
"photosCount_other": "{{count}} zdjęć",
|
||||
"previewAria": "Powiększ zdjęcie"
|
||||
},
|
||||
"equipmentPage": {
|
||||
"title": "Urządzenia",
|
||||
"editAction": "Edytuj urządzenia",
|
||||
"usage": {
|
||||
"title": "Korzystanie z urządzeń (godziny)",
|
||||
"noData": "Brak danych o korzystaniu w tym okresie.",
|
||||
"hourCellTitle_one": "{{hour}}:00 — {{count}} użycie",
|
||||
"hourCellTitle_few": "{{hour}}:00 — {{count}} użycia",
|
||||
"hourCellTitle_many": "{{hour}}:00 — {{count}} użyć",
|
||||
"hourCellTitle_other": "{{hour}}:00 — {{count}} użyć",
|
||||
"rangeAria": "Zakres mapy ciepła",
|
||||
"rangeDays_one": "{{count}} dzień",
|
||||
"rangeDays_few": "{{count}} dni",
|
||||
"rangeDays_many": "{{count}} dni",
|
||||
"rangeDays_other": "{{count}} dni"
|
||||
}
|
||||
},
|
||||
"announcementsPage": {
|
||||
"title": "Ogłoszenia",
|
||||
"subtitle": "Aktualności od zarządzających siłownią",
|
||||
"newAction": "Nowe ogłoszenie"
|
||||
},
|
||||
"invite": {
|
||||
"toastOk": "Zaproszono: {{name}}",
|
||||
"title": "Zaproś usera: {{name}}",
|
||||
|
||||
234
app/src/pages/gyms/GymAnnouncementsPage.tsx
Normal file
234
app/src/pages/gyms/GymAnnouncementsPage.tsx
Normal file
@@ -0,0 +1,234 @@
|
||||
import { useState } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { Megaphone } from 'lucide-react';
|
||||
import {
|
||||
createGymAnnouncement,
|
||||
deleteGymAnnouncement,
|
||||
useGymAnnouncements,
|
||||
useGymDetail,
|
||||
} from '../../api/queries';
|
||||
import { fmtDateTime } from '../../lib/format';
|
||||
import {
|
||||
BackButton,
|
||||
Button,
|
||||
Card,
|
||||
ErrorText,
|
||||
Input,
|
||||
Loading,
|
||||
Modal,
|
||||
SectionHeader,
|
||||
Textarea,
|
||||
} from '../../components/ui';
|
||||
import { useToast } from '../../components/toast';
|
||||
import { useTopbar, type TopbarAction } from '../../topbar';
|
||||
|
||||
/* Podstrona ogłoszeń (read-only): lista; tworzenie/usuwanie w modalu z sekcją
|
||||
przeniesioną ze strony detalu (akcja „Nowe ogłoszenie" w menu, tylko dla zarządzających). */
|
||||
export default function GymAnnouncementsPage() {
|
||||
const { id } = useParams();
|
||||
const { t } = useTranslation('gyms');
|
||||
const { data: detail, isLoading, error } = useGymDetail(id);
|
||||
const gym = detail?.gym;
|
||||
const canManage = (detail?.isAdmin ?? false) || (detail?.roles ?? []).includes('OWNER');
|
||||
|
||||
const [composerOpen, setComposerOpen] = useState(false);
|
||||
|
||||
const actions: TopbarAction[] | undefined =
|
||||
gym && canManage
|
||||
? [{ label: t('announcementsPage.newAction'), onClick: () => setComposerOpen(true) }]
|
||||
: undefined;
|
||||
useTopbar({ title: t('announcementsPage.title'), back: `/gyms/${id}`, actions });
|
||||
|
||||
if (isLoading) return <Loading />;
|
||||
if (error || !gym) {
|
||||
return (
|
||||
<>
|
||||
<BackButton to={`/gyms/${id}`} className="mb-4" />
|
||||
<ErrorText>{t('detail.notFound')}</ErrorText>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* HERO-LITE: nazwa siłowni (tytuł h1 należy do topbaru) */}
|
||||
<div className="mb-5 flex flex-wrap items-end justify-between gap-3">
|
||||
<div>
|
||||
<span className="font-display text-[1.35rem] font-bold tracking-[-0.02em]">
|
||||
{gym.name}
|
||||
</span>
|
||||
<p className="mt-0.5 text-[0.85rem] text-dim">{t('announcementsPage.subtitle')}</p>
|
||||
</div>
|
||||
<BackButton to={`/gyms/${id}`} />
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<SectionHeader title={t('detail.groupAnnouncements')} />
|
||||
<AnnouncementsList gymId={gym.id} />
|
||||
</Card>
|
||||
|
||||
<Modal
|
||||
open={composerOpen}
|
||||
onClose={() => setComposerOpen(false)}
|
||||
title={t('detail.modalAnnouncements')}
|
||||
>
|
||||
<AnnouncementsManageSection gymId={gym.id} />
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/* Lista tylko do odczytu (treść podstrony). */
|
||||
function AnnouncementsList({ gymId }: { gymId: string }) {
|
||||
const { t } = useTranslation('gyms');
|
||||
const { data, isLoading } = useGymAnnouncements(gymId);
|
||||
const announcements = data?.announcements ?? [];
|
||||
|
||||
if (isLoading) return <Loading />;
|
||||
if (announcements.length === 0) {
|
||||
return (
|
||||
<div className="flex flex-col items-center gap-2 py-10 text-dim">
|
||||
<Megaphone className="h-6 w-6" aria-hidden="true" />
|
||||
<p className="text-[0.875rem]">{t('announcements.empty')}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className="flex flex-col gap-2">
|
||||
{announcements.map((a) => (
|
||||
<div key={a.id} className="rounded-[10px] border border-line bg-card/50 px-3 py-2.5">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="min-w-0 flex-1 truncate text-[0.9rem] font-bold">{a.title}</span>
|
||||
{a.kind !== 'MANUAL' && (
|
||||
<span className="shrink-0 rounded-full bg-dim/13 px-2 py-0.5 text-[0.65rem] font-extrabold uppercase tracking-wide text-dim">
|
||||
{t('announcements.systemBadge')}
|
||||
</span>
|
||||
)}
|
||||
<span className="shrink-0 text-[0.72rem] tabular-nums text-dim">
|
||||
{fmtDateTime(a.createdAt)}
|
||||
</span>
|
||||
</div>
|
||||
<p className="mt-1 whitespace-pre-wrap text-dim text-[0.8125rem]">{a.body}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/* Sekcja zarządzania (lista + tworzenie + usuwanie ręcznych) — przeniesiona z GymDetail. */
|
||||
function AnnouncementsManageSection({ gymId }: { gymId: string }) {
|
||||
const queryClient = useQueryClient();
|
||||
const { push } = useToast();
|
||||
const { t } = useTranslation('gyms');
|
||||
const { data, isLoading } = useGymAnnouncements(gymId);
|
||||
const announcements = data?.announcements ?? [];
|
||||
const [title, setTitle] = useState('');
|
||||
const [body, setBody] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const invalidate = async () => {
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({ queryKey: ['gym-announcements', gymId] }),
|
||||
queryClient.invalidateQueries({ queryKey: ['feed'] }),
|
||||
]);
|
||||
};
|
||||
|
||||
const add = async () => {
|
||||
setBusy(true);
|
||||
try {
|
||||
await createGymAnnouncement(gymId, { title, body });
|
||||
await invalidate();
|
||||
push(t('announcements.toastPublished'), 'success');
|
||||
setTitle('');
|
||||
setBody('');
|
||||
} catch (err) {
|
||||
push((err as Error).message, 'error');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const remove = async (id: string) => {
|
||||
try {
|
||||
await deleteGymAnnouncement(gymId, id);
|
||||
await invalidate();
|
||||
push(t('announcements.toastRemoved'), 'success');
|
||||
} catch (err) {
|
||||
push((err as Error).message, 'error');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="rounded-xl border border-line bg-input/40 p-3.5">
|
||||
<div className="mb-2.5 text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
|
||||
{t('announcements.composerTitle')}
|
||||
</div>
|
||||
<Input
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
placeholder={t('announcements.titlePh')}
|
||||
aria-label={t('announcements.titleAria')}
|
||||
maxLength={120}
|
||||
/>
|
||||
<Textarea
|
||||
value={body}
|
||||
onChange={(e) => setBody(e.target.value)}
|
||||
placeholder={t('announcements.bodyPh')}
|
||||
aria-label={t('announcements.bodyAria')}
|
||||
maxLength={2000}
|
||||
rows={3}
|
||||
className="mt-2.5"
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
className="mt-2.5"
|
||||
onClick={() => void add()}
|
||||
disabled={busy || !title.trim() || !body.trim()}
|
||||
>
|
||||
{busy ? t('announcements.publishing') : t('announcements.publish')}
|
||||
</Button>
|
||||
</div>
|
||||
<div className="mt-4">
|
||||
{isLoading ? (
|
||||
<Loading />
|
||||
) : announcements.length === 0 ? (
|
||||
<p className="text-[0.875rem] text-dim">{t('announcements.empty')}</p>
|
||||
) : (
|
||||
<div className="flex flex-col gap-2">
|
||||
{announcements.map((a) => (
|
||||
<div key={a.id} className="rounded-[10px] border border-line bg-card/50 px-3 py-2.5">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="min-w-0 flex-1 truncate text-[0.9rem] font-bold">{a.title}</span>
|
||||
{a.kind !== 'MANUAL' && (
|
||||
<span className="shrink-0 rounded-full bg-dim/13 px-2 py-0.5 text-[0.65rem] font-extrabold uppercase tracking-wide text-dim">
|
||||
{t('announcements.systemBadge')}
|
||||
</span>
|
||||
)}
|
||||
<span className="shrink-0 text-[0.72rem] tabular-nums text-dim">
|
||||
{fmtDateTime(a.createdAt)}
|
||||
</span>
|
||||
</div>
|
||||
<p className="mt-1 whitespace-pre-wrap text-dim text-[0.8125rem]">{a.body}</p>
|
||||
{a.kind === 'MANUAL' && (
|
||||
<div className="mt-2">
|
||||
<Button
|
||||
variant="danger"
|
||||
size="sm"
|
||||
type="button"
|
||||
onClick={() => void remove(a.id)}
|
||||
>
|
||||
{t('common:remove')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -7,21 +7,15 @@ import {
|
||||
CalendarX,
|
||||
Dumbbell,
|
||||
Image as ImageIcon,
|
||||
Megaphone,
|
||||
MapPin,
|
||||
Pencil,
|
||||
QrCode,
|
||||
UserPlus,
|
||||
Settings,
|
||||
Users,
|
||||
Wrench,
|
||||
} from 'lucide-react';
|
||||
import {
|
||||
checkIn,
|
||||
checkOutPresence,
|
||||
createGymAnnouncement,
|
||||
createGymException,
|
||||
deleteGym,
|
||||
deleteGymAnnouncement,
|
||||
deleteGymException,
|
||||
useActivePresence,
|
||||
useGymAnnouncements,
|
||||
@@ -32,9 +26,8 @@ import {
|
||||
withdrawGymClaim,
|
||||
withdrawGymInvitation,
|
||||
} from '../../api/queries';
|
||||
import type { Gym, GymEquipment, GymException } from '../../api/types';
|
||||
import type { Gym, GymException } from '../../api/types';
|
||||
import { fmtDate, fmtDateTime } from '../../lib/format';
|
||||
import { localizedName } from '../../lib/localizedName';
|
||||
import { formatGymEquipment } from '../../lib/equipment';
|
||||
import {
|
||||
BackButton,
|
||||
@@ -48,7 +41,6 @@ import {
|
||||
Modal,
|
||||
SectionHeader,
|
||||
Select,
|
||||
Textarea,
|
||||
} from '../../components/ui';
|
||||
import { useToast } from '../../components/toast';
|
||||
import { Avatar } from '../../components/Avatar';
|
||||
@@ -63,9 +55,8 @@ import {
|
||||
} from '../../lib/availability';
|
||||
import ClaimModal from '../../components/gyms/ClaimModal';
|
||||
import InviteGymModal from '../../components/gyms/InviteGymModal';
|
||||
import GymGallery from '../../components/gyms/GymGallery';
|
||||
import GymQrModal from '../../components/gyms/GymQrModal';
|
||||
import { EquipmentSection, GymEditForm } from './GymSections';
|
||||
import { GymEditForm } from './GymSections';
|
||||
|
||||
/* Godziny otwarcia w całym wierszu pod hero (informacja kluczowa — nie w bocznej kolumnie).
|
||||
Pasek tygodnia wzorowany na kartach z /gyms: siedem dni, „dziś” wyróżnione, dni otwarte
|
||||
@@ -152,107 +143,123 @@ function HoursBand({ gym }: { gym: Gym }) {
|
||||
);
|
||||
}
|
||||
|
||||
/* Mozaika galerii (read-only): pierwsze zdjęcie duże, reszta siatką, „+N” na końcu. */
|
||||
function GalleryMosaic({ gym }: { gym: Gym & { photos: { id: string; url: string }[] } }) {
|
||||
/* Kafel Galerii (tylko REAL): mini-mozaika 4 miniatur + licznik; klik → podstrona galerii. */
|
||||
function GalleryTile({ gym }: { gym: Gym & { photos: { id: string; url: string }[] } }) {
|
||||
const { t } = useTranslation('gyms');
|
||||
const photos = gym.photos;
|
||||
if (photos.length === 0) {
|
||||
return <p className="text-[0.875rem] text-dim">{t('gallery.empty')}</p>;
|
||||
}
|
||||
const [first, ...rest] = photos;
|
||||
const preview = gym.photos.slice(0, 4);
|
||||
return (
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
<div className="relative col-span-2 row-span-2 overflow-hidden rounded-[10px] border border-line bg-input">
|
||||
<AuthImage src={first.url} alt={gym.name} className="h-full w-full object-cover" />
|
||||
<Link
|
||||
to={`/gyms/${gym.id}/gallery`}
|
||||
className="flex flex-col rounded-2xl border border-line bg-card p-3 transition-colors hover:border-accent/55"
|
||||
>
|
||||
<div className="grid h-20 grid-cols-4 gap-1.5">
|
||||
{preview.length === 0 ? (
|
||||
<div className="col-span-4 grid place-items-center rounded-[10px] border border-dashed border-line bg-input/50 text-dim">
|
||||
<ImageIcon className="h-5 w-5" aria-hidden="true" />
|
||||
</div>
|
||||
) : (
|
||||
preview.map((p) => (
|
||||
<div key={p.id} className="overflow-hidden rounded-[8px] border border-line bg-input">
|
||||
<AuthImage src={p.url} alt={gym.name} className="h-full w-full object-cover" />
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
{rest.slice(0, 3).map((p) => (
|
||||
<div
|
||||
key={p.id}
|
||||
className="relative overflow-hidden rounded-[10px] border border-line bg-input"
|
||||
>
|
||||
<AuthImage src={p.url} alt={gym.name} className="h-full min-h-20 w-full object-cover" />
|
||||
</div>
|
||||
))}
|
||||
{rest.length > 3 && (
|
||||
<div className="grid place-items-center rounded-[10px] border border-line bg-input text-[0.8rem] font-extrabold text-accent-text">
|
||||
{t('detail.photoMore', { count: rest.length - 3 })}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="mt-2.5 flex items-center justify-between gap-2">
|
||||
<span className="min-w-0 truncate font-display text-[0.9rem] font-bold">
|
||||
{t('detail.galleryTitle')}
|
||||
</span>
|
||||
<span className="shrink-0 text-[0.72rem] font-semibold tabular-nums text-dim">
|
||||
{t('detail.tilePhotos', { count: gym.photos.length })}
|
||||
</span>
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
/* Kafle urządzeń (read-only): specyfikacja efektywna + miniatura zdjęcia; klik = podgląd zdjęć. */
|
||||
function EquipmentTiles({ gym }: { gym: Gym }) {
|
||||
const [preview, setPreview] = useState<GymEquipment | null>(null);
|
||||
const { i18n } = useTranslation();
|
||||
const { t } = useTranslation('gyms');
|
||||
if (gym.equipment.length === 0) {
|
||||
return <p className="text-[0.875rem] text-dim">{t('detail.noEquipment')}</p>;
|
||||
}
|
||||
const photos = preview?.photos ?? [];
|
||||
/* Kafelek Urządzeń: miniatury pierwszych instancji (zdjęcie lub ikona) + licznik; klik → podstrona. */
|
||||
function EquipmentTile({ gym }: { gym: Gym }) {
|
||||
const { t, i18n } = useTranslation('gyms');
|
||||
const preview = gym.equipment.slice(0, 4);
|
||||
return (
|
||||
<>
|
||||
<div className="grid grid-cols-1 gap-2 sm:grid-cols-2">
|
||||
{gym.equipment.map((e) => {
|
||||
const hasPhotos = (e.photos?.length ?? 0) > 0;
|
||||
const content = (
|
||||
<>
|
||||
{hasPhotos ? (
|
||||
<Link
|
||||
to={`/gyms/${gym.id}/equipment`}
|
||||
className="flex flex-col rounded-2xl border border-line bg-card p-3 transition-colors hover:border-accent/55"
|
||||
>
|
||||
<div className="grid h-20 grid-cols-4 items-center gap-1.5">
|
||||
{preview.length === 0 ? (
|
||||
<div className="col-span-4 grid place-items-center rounded-[10px] border border-dashed border-line bg-input/50 text-dim">
|
||||
<Dumbbell className="h-5 w-5" aria-hidden="true" />
|
||||
</div>
|
||||
) : (
|
||||
preview.map((e) => {
|
||||
const photo = e.photos?.[0];
|
||||
return photo ? (
|
||||
<div
|
||||
key={e.id}
|
||||
className="h-full overflow-hidden rounded-[8px] border border-line bg-input"
|
||||
>
|
||||
<AuthImage
|
||||
src={e.photos![0].url}
|
||||
alt={localizedName(e.equipment, i18n.language)}
|
||||
className="h-9 w-9 shrink-0 rounded-[8px] border border-line object-cover"
|
||||
src={photo.url}
|
||||
alt={formatGymEquipment(e, i18n.language)}
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<Dumbbell className="h-4 w-4 shrink-0 text-dim" aria-hidden="true" />
|
||||
)}
|
||||
<span className="min-w-0 truncate">{formatGymEquipment(e, i18n.language)}</span>
|
||||
</>
|
||||
);
|
||||
return hasPhotos ? (
|
||||
<button
|
||||
key={e.id}
|
||||
type="button"
|
||||
onClick={() => setPreview(e)}
|
||||
aria-label={t('detail.photosAria', {
|
||||
name: localizedName(e.equipment, i18n.language),
|
||||
})}
|
||||
className="flex cursor-pointer items-center gap-2 rounded-[10px] border border-line bg-card/50 px-3 py-2.5 text-left text-[0.85rem] font-semibold hover:border-accent/55"
|
||||
>
|
||||
{content}
|
||||
</button>
|
||||
) : (
|
||||
<div
|
||||
key={e.id}
|
||||
className="flex items-center gap-2 rounded-[10px] border border-line bg-card/50 px-3 py-2.5 text-[0.85rem] font-semibold"
|
||||
>
|
||||
{content}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
key={e.id}
|
||||
className="grid h-full place-items-center rounded-[8px] border border-line bg-input/50 text-dim"
|
||||
>
|
||||
<Dumbbell className="h-4 w-4" aria-hidden="true" />
|
||||
</div>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
<Modal
|
||||
open={preview != null}
|
||||
onClose={() => setPreview(null)}
|
||||
title={
|
||||
preview
|
||||
? t('detail.photosAria', { name: localizedName(preview.equipment, i18n.language) })
|
||||
: ''
|
||||
}
|
||||
>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
{photos.map((p) => (
|
||||
<AuthImage
|
||||
key={p.id}
|
||||
src={p.url}
|
||||
alt={preview ? localizedName(preview.equipment, i18n.language) : ''}
|
||||
className="w-full rounded-[10px] border border-line object-cover"
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</Modal>
|
||||
</>
|
||||
<div className="mt-2.5 flex items-center justify-between gap-2">
|
||||
<span className="min-w-0 truncate font-display text-[0.9rem] font-bold">
|
||||
{t('detail.equipmentTitle')}
|
||||
</span>
|
||||
<span className="shrink-0 text-[0.72rem] font-semibold tabular-nums text-dim">
|
||||
{t('common:counters.devices', { count: gym.equipment.length })}
|
||||
</span>
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
/* Kafelek Ogłoszeń: najnowsze ogłoszenie (tytuł + data) lub pusty stan + licznik; klik → podstrona. */
|
||||
function AnnouncementsTile({ gymId }: { gymId: string }) {
|
||||
const { t } = useTranslation('gyms');
|
||||
const { data } = useGymAnnouncements(gymId);
|
||||
const announcements = data?.announcements ?? [];
|
||||
const latest = announcements[0];
|
||||
return (
|
||||
<Link
|
||||
to={`/gyms/${gymId}/announcements`}
|
||||
className="flex flex-col rounded-2xl border border-line bg-card p-3 transition-colors hover:border-accent/55"
|
||||
>
|
||||
<div className="flex h-20 flex-col justify-center rounded-[10px] border border-line bg-input/40 px-3 py-2">
|
||||
{latest ? (
|
||||
<>
|
||||
<span className="truncate text-[0.85rem] font-bold">{latest.title}</span>
|
||||
<span className="mt-0.5 text-[0.72rem] tabular-nums text-dim">
|
||||
{fmtDateTime(latest.createdAt)}
|
||||
</span>
|
||||
</>
|
||||
) : (
|
||||
<span className="text-[0.8125rem] text-dim">{t('announcements.empty')}</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="mt-2.5 flex items-center justify-between gap-2">
|
||||
<span className="min-w-0 truncate font-display text-[0.9rem] font-bold">
|
||||
{t('detail.groupAnnouncements')}
|
||||
</span>
|
||||
<span className="shrink-0 text-[0.72rem] font-semibold tabular-nums text-dim">
|
||||
{t('detail.tileAnnouncementsCount', { count: announcements.length })}
|
||||
</span>
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -451,7 +458,6 @@ export default function GymDetail() {
|
||||
const { data: presenceData } = useActivePresence();
|
||||
const gym = data?.gym;
|
||||
const presence = presenceData?.presence ?? null;
|
||||
const canManage = (data?.isAdmin ?? false) || (data?.roles ?? []).includes('OWNER');
|
||||
const isOwner = (data?.roles ?? []).includes('OWNER');
|
||||
const claim = (claimsData?.claims ?? []).find((c) => c.gymId === id) ?? null;
|
||||
|
||||
@@ -462,9 +468,6 @@ export default function GymDetail() {
|
||||
const [claimOpen, setClaimOpen] = useState(false);
|
||||
const [claimBusy, setClaimBusy] = useState(false);
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [galleryOpen, setGalleryOpen] = useState(false);
|
||||
const [equipmentOpen, setEquipmentOpen] = useState(false);
|
||||
const [announcementsOpen, setAnnouncementsOpen] = useState(false);
|
||||
const [qrOpen, setQrOpen] = useState(false);
|
||||
const [presenceBusy, setPresenceBusy] = useState(false);
|
||||
|
||||
@@ -535,94 +538,61 @@ export default function GymDetail() {
|
||||
}
|
||||
};
|
||||
|
||||
// Operacje właściciela pogrupowane tematycznie w menu kontekstowym (topbar).
|
||||
// Operacje właściciela: JEDNA grupa „Zarządzaj” (topbar). Pozycje Galeria/Urządzenia/
|
||||
// Ogłoszenia nawigują na podstrony (świadome dublowanie z kafelkami — decyzja product);
|
||||
// Informacje/QR/Zaproszenia/Usuń otwierają modale na tej stronie.
|
||||
const groups: TopbarCustomGroup[] | undefined =
|
||||
gym && isOwner
|
||||
? [
|
||||
{
|
||||
id: 'edit',
|
||||
label: t('detail.groupEdit'),
|
||||
icon: Pencil,
|
||||
actions: [{ label: t('detail.actionInfo'), onClick: () => setEditOpen(true) }],
|
||||
},
|
||||
...(gym.kind === 'REAL'
|
||||
? [
|
||||
{
|
||||
id: 'gallery',
|
||||
label: t('detail.groupGallery'),
|
||||
icon: ImageIcon,
|
||||
actions: [
|
||||
{ label: t('detail.groupGallery'), onClick: () => setGalleryOpen(true) },
|
||||
],
|
||||
} as TopbarCustomGroup,
|
||||
]
|
||||
: []),
|
||||
...(gym.kind === 'REAL'
|
||||
? [
|
||||
{
|
||||
id: 'qr',
|
||||
label: tp('qr.group'),
|
||||
icon: QrCode,
|
||||
actions: [{ label: tp('qr.action'), onClick: () => setQrOpen(true) }],
|
||||
} as TopbarCustomGroup,
|
||||
]
|
||||
: []),
|
||||
{
|
||||
id: 'equipment',
|
||||
label: t('detail.groupEquipment'),
|
||||
icon: Wrench,
|
||||
actions: [{ label: t('detail.groupEquipment'), onClick: () => setEquipmentOpen(true) }],
|
||||
},
|
||||
{
|
||||
id: 'announcements',
|
||||
label: t('detail.groupAnnouncements'),
|
||||
icon: Megaphone,
|
||||
id: 'manage',
|
||||
label: t('detail.groupManage'),
|
||||
icon: Settings,
|
||||
actions: [
|
||||
{ label: t('detail.groupAnnouncements'), onClick: () => setAnnouncementsOpen(true) },
|
||||
{ label: t('detail.actionInfo'), onClick: () => setEditOpen(true) },
|
||||
...(gym.kind === 'REAL'
|
||||
? [
|
||||
{
|
||||
label: t('detail.groupGallery'),
|
||||
to: `/gyms/${gym.id}/gallery`,
|
||||
},
|
||||
{ label: tp('qr.action'), onClick: () => setQrOpen(true) },
|
||||
]
|
||||
: []),
|
||||
{ label: t('detail.groupEquipment'), to: `/gyms/${gym.id}/equipment` },
|
||||
{ label: t('detail.groupAnnouncements'), to: `/gyms/${gym.id}/announcements` },
|
||||
...(gym.kind === 'VIRTUAL' && gym.isPrivate
|
||||
? [{ label: t('detail.actionInvite'), onClick: () => setInviteOpen(true) }]
|
||||
: []),
|
||||
{
|
||||
label: t('detail.actionDelete'),
|
||||
variant: 'danger',
|
||||
onClick: () => setConfirmOpen(true),
|
||||
},
|
||||
],
|
||||
},
|
||||
...(gym.kind === 'VIRTUAL' && gym.isPrivate
|
||||
? [
|
||||
{
|
||||
id: 'invite',
|
||||
label: t('detail.groupInvites'),
|
||||
icon: UserPlus,
|
||||
actions: [
|
||||
{ label: t('detail.actionInvite'), onClick: () => setInviteOpen(true) },
|
||||
],
|
||||
} as TopbarCustomGroup,
|
||||
]
|
||||
: []),
|
||||
]
|
||||
: undefined;
|
||||
|
||||
// Spoza grupy: claim/wycofanie wniosku (VIRTUAL) — reszta operacji właściciela w „Zarządzaj”.
|
||||
const ownerActions: TopbarAction[] | undefined =
|
||||
gym && isOwner
|
||||
? [
|
||||
...(gym.kind === 'VIRTUAL'
|
||||
? claim
|
||||
? ([
|
||||
{
|
||||
label: t('detail.actionWithdrawClaim'),
|
||||
variant: 'secondary',
|
||||
disabled: claimBusy,
|
||||
onClick: () => void withdrawClaim(),
|
||||
},
|
||||
] as TopbarAction[])
|
||||
: ([
|
||||
{
|
||||
label: t('detail.actionClaimVerify'),
|
||||
variant: 'secondary',
|
||||
onClick: () => setClaimOpen(true),
|
||||
},
|
||||
] as TopbarAction[])
|
||||
: []),
|
||||
{
|
||||
label: t('detail.actionDelete'),
|
||||
variant: 'danger',
|
||||
onClick: () => setConfirmOpen(true),
|
||||
},
|
||||
]
|
||||
gym && isOwner && gym.kind === 'VIRTUAL'
|
||||
? claim
|
||||
? [
|
||||
{
|
||||
label: t('detail.actionWithdrawClaim'),
|
||||
variant: 'secondary',
|
||||
disabled: claimBusy,
|
||||
onClick: () => void withdrawClaim(),
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
label: t('detail.actionClaimVerify'),
|
||||
variant: 'secondary',
|
||||
onClick: () => setClaimOpen(true),
|
||||
},
|
||||
]
|
||||
: undefined;
|
||||
|
||||
// Meldunek bytności (REAL) — akcje dla każdego użytkownika siłowni.
|
||||
@@ -769,22 +739,18 @@ export default function GymDetail() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* DWIE KOLUMNY */}
|
||||
{/* DWIE KOLUMNY: kafelki sekcji (klik → podstrony) + karta danych */}
|
||||
<div className="grid grid-cols-1 items-start gap-4 lg:grid-cols-[1.5fr_1fr]">
|
||||
<div className="flex min-w-0 flex-col gap-4">
|
||||
{gym.kind === 'REAL' && (
|
||||
<Card>
|
||||
<SectionHeader title={t('detail.galleryTitle')} />
|
||||
<GalleryMosaic gym={gym} />
|
||||
</Card>
|
||||
)}
|
||||
<Card>
|
||||
<SectionHeader
|
||||
title={t('detail.equipmentTitle')}
|
||||
description={t('detail.equipmentDesc')}
|
||||
/>
|
||||
<EquipmentTiles gym={gym} />
|
||||
</Card>
|
||||
<div
|
||||
className={`grid grid-cols-1 gap-3 ${
|
||||
gym.kind === 'REAL' ? 'sm:grid-cols-3' : 'sm:grid-cols-2'
|
||||
}`}
|
||||
>
|
||||
{gym.kind === 'REAL' && <GalleryTile gym={gym} />}
|
||||
<EquipmentTile gym={gym} />
|
||||
<AnnouncementsTile gymId={gym.id} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex min-w-0 flex-col gap-4">
|
||||
@@ -849,28 +815,6 @@ export default function GymDetail() {
|
||||
<ExceptionsBlock gymId={gym.id} canManage={isOwner} />
|
||||
</div>
|
||||
</Modal>
|
||||
<Modal
|
||||
open={galleryOpen}
|
||||
onClose={() => setGalleryOpen(false)}
|
||||
title={t('detail.modalGallery')}
|
||||
>
|
||||
<GymGallery gym={gym} canManage={canManage} onChanged={() => {}} />
|
||||
</Modal>
|
||||
<Modal
|
||||
wide
|
||||
open={equipmentOpen}
|
||||
onClose={() => setEquipmentOpen(false)}
|
||||
title={t('detail.modalEquipment')}
|
||||
>
|
||||
<EquipmentSection key={gym.id} gym={gym} />
|
||||
</Modal>
|
||||
<Modal
|
||||
open={announcementsOpen}
|
||||
onClose={() => setAnnouncementsOpen(false)}
|
||||
title={t('detail.modalAnnouncements')}
|
||||
>
|
||||
<AnnouncementsSection gymId={gym.id} />
|
||||
</Modal>
|
||||
{gym.kind === 'REAL' && isOwner && (
|
||||
<GymQrModal
|
||||
open={qrOpen}
|
||||
@@ -910,122 +854,6 @@ export default function GymDetail() {
|
||||
);
|
||||
}
|
||||
|
||||
/* Ogłoszenia (lista + tworzenie + usuwanie ręcznych). */
|
||||
function AnnouncementsSection({ gymId }: { gymId: string }) {
|
||||
const queryClient = useQueryClient();
|
||||
const { push } = useToast();
|
||||
const { t } = useTranslation('gyms');
|
||||
const { data, isLoading } = useGymAnnouncements(gymId);
|
||||
const announcements = data?.announcements ?? [];
|
||||
const [title, setTitle] = useState('');
|
||||
const [body, setBody] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const invalidate = async () => {
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({ queryKey: ['gym-announcements', gymId] }),
|
||||
queryClient.invalidateQueries({ queryKey: ['feed'] }),
|
||||
]);
|
||||
};
|
||||
|
||||
const add = async () => {
|
||||
setBusy(true);
|
||||
try {
|
||||
await createGymAnnouncement(gymId, { title, body });
|
||||
await invalidate();
|
||||
push(t('announcements.toastPublished'), 'success');
|
||||
setTitle('');
|
||||
setBody('');
|
||||
} catch (err) {
|
||||
push((err as Error).message, 'error');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const remove = async (id: string) => {
|
||||
try {
|
||||
await deleteGymAnnouncement(gymId, id);
|
||||
await invalidate();
|
||||
push(t('announcements.toastRemoved'), 'success');
|
||||
} catch (err) {
|
||||
push((err as Error).message, 'error');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="rounded-xl border border-line bg-input/40 p-3.5">
|
||||
<div className="mb-2.5 text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
|
||||
{t('announcements.composerTitle')}
|
||||
</div>
|
||||
<Input
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
placeholder={t('announcements.titlePh')}
|
||||
aria-label={t('announcements.titleAria')}
|
||||
maxLength={120}
|
||||
/>
|
||||
<Textarea
|
||||
value={body}
|
||||
onChange={(e) => setBody(e.target.value)}
|
||||
placeholder={t('announcements.bodyPh')}
|
||||
aria-label={t('announcements.bodyAria')}
|
||||
maxLength={2000}
|
||||
rows={3}
|
||||
className="mt-2.5"
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
className="mt-2.5"
|
||||
onClick={() => void add()}
|
||||
disabled={busy || !title.trim() || !body.trim()}
|
||||
>
|
||||
{busy ? t('announcements.publishing') : t('announcements.publish')}
|
||||
</Button>
|
||||
</div>
|
||||
<div className="mt-4">
|
||||
{isLoading ? (
|
||||
<Loading />
|
||||
) : announcements.length === 0 ? (
|
||||
<p className="text-[0.875rem] text-dim">{t('announcements.empty')}</p>
|
||||
) : (
|
||||
<div className="flex flex-col gap-2">
|
||||
{announcements.map((a) => (
|
||||
<div key={a.id} className="rounded-[10px] border border-line bg-card/50 px-3 py-2.5">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="min-w-0 flex-1 truncate text-[0.9rem] font-bold">{a.title}</span>
|
||||
{a.kind !== 'MANUAL' && (
|
||||
<span className="shrink-0 rounded-full bg-dim/13 px-2 py-0.5 text-[0.65rem] font-extrabold uppercase tracking-wide text-dim">
|
||||
{t('announcements.systemBadge')}
|
||||
</span>
|
||||
)}
|
||||
<span className="shrink-0 text-[0.72rem] tabular-nums text-dim">
|
||||
{fmtDateTime(a.createdAt)}
|
||||
</span>
|
||||
</div>
|
||||
<p className="mt-1 whitespace-pre-wrap text-dim text-[0.8125rem]">{a.body}</p>
|
||||
{a.kind === 'MANUAL' && (
|
||||
<div className="mt-2">
|
||||
<Button
|
||||
variant="danger"
|
||||
size="sm"
|
||||
type="button"
|
||||
onClick={() => void remove(a.id)}
|
||||
>
|
||||
{t('common:remove')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/* Zaproszenia do prywatnej siłowni (lista + wycofywanie). */
|
||||
function GymInvitationsSection({ gym }: { gym: Gym }) {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
237
app/src/pages/gyms/GymEquipmentPage.tsx
Normal file
237
app/src/pages/gyms/GymEquipmentPage.tsx
Normal file
@@ -0,0 +1,237 @@
|
||||
import { useState } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Dumbbell } from 'lucide-react';
|
||||
import { useGymDetail, useGymEquipmentUsage } from '../../api/queries';
|
||||
import type { EquipmentUsageRow, GymEquipment } from '../../api/types';
|
||||
import { AuthImage } from '../../components/AuthImage';
|
||||
import {
|
||||
BackButton,
|
||||
Card,
|
||||
ErrorText,
|
||||
Loading,
|
||||
Modal,
|
||||
SectionHeader,
|
||||
Select,
|
||||
} from '../../components/ui';
|
||||
import { useTopbar, type TopbarAction } from '../../topbar';
|
||||
import { formatGymEquipment } from '../../lib/equipment';
|
||||
import { localizedName } from '../../lib/localizedName';
|
||||
import { EquipmentSection } from './GymSections';
|
||||
|
||||
const RANGE_OPTIONS = [7, 30, 90];
|
||||
|
||||
/* Mapa ciepła urządzeń: wiersz = urządzenie z katalogu, 24 kafle godzinowe
|
||||
(natężenie ~ udział w szczycie), styl jak heatmapa bytności w panelu admina. */
|
||||
function EquipmentUsageHeatmap({ gymId, rangeDays }: { gymId: string; rangeDays: number }) {
|
||||
const { t, i18n } = useTranslation('gyms');
|
||||
const { data, isLoading } = useGymEquipmentUsage(gymId, rangeDays);
|
||||
const rows = data?.equipment ?? [];
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<SectionHeader title={t('equipmentPage.usage.title')} />
|
||||
{isLoading ? (
|
||||
<Loading />
|
||||
) : rows.length === 0 ? (
|
||||
<p className="text-[0.875rem] text-dim">{t('equipmentPage.usage.noData')}</p>
|
||||
) : (
|
||||
<div className="overflow-x-auto">
|
||||
<div
|
||||
className="grid min-w-[34rem] gap-[3px]"
|
||||
style={{ gridTemplateColumns: 'minmax(7rem, 11rem) repeat(24, minmax(0, 1fr))' }}
|
||||
>
|
||||
<span />
|
||||
{Array.from({ length: 24 }, (_, hour) => (
|
||||
<span
|
||||
key={hour}
|
||||
className="text-center text-[0.6rem] font-bold tabular-nums text-dim"
|
||||
>
|
||||
{hour % 3 === 0 ? String(hour).padStart(2, '0') : ''}
|
||||
</span>
|
||||
))}
|
||||
{rows.map((row) => (
|
||||
<HeatmapRow
|
||||
key={row.equipmentId}
|
||||
row={row}
|
||||
label={localizedName(row, i18n.language)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
function HeatmapRow({ row, label }: { row: EquipmentUsageRow; label: string }) {
|
||||
const { t } = useTranslation('gyms');
|
||||
return (
|
||||
<>
|
||||
<span className="flex min-w-0 items-center pr-1 text-[0.68rem] font-semibold text-dim">
|
||||
<span className="truncate">{label}</span>
|
||||
</span>
|
||||
{Array.from({ length: 24 }, (_, hour) => {
|
||||
const cell = row.cells.find((c) => c.hour === hour);
|
||||
const count = cell?.count ?? 0;
|
||||
const intensity = row.peak > 0 ? count / row.peak : 0;
|
||||
return (
|
||||
<span
|
||||
key={hour}
|
||||
title={t('equipmentPage.usage.hourCellTitle', {
|
||||
hour: String(hour).padStart(2, '0'),
|
||||
count,
|
||||
})}
|
||||
className="aspect-square rounded-[2px] border border-line/40"
|
||||
style={{
|
||||
background:
|
||||
intensity > 0
|
||||
? `color-mix(in srgb, var(--accent) ${Math.round(18 + intensity * 82)}%, var(--bg-input))`
|
||||
: 'var(--bg-input)',
|
||||
}}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/* Podstrona urządzeń (read-only): kafle instancji + podgląd zdjęć + mapa ciepła;
|
||||
edycja przez modal z istniejącym komponentem EquipmentSection (akcja w menu). */
|
||||
export default function GymEquipmentPage() {
|
||||
const { id } = useParams();
|
||||
const { t, i18n } = useTranslation('gyms');
|
||||
const { data, isLoading, error } = useGymDetail(id);
|
||||
const gym = data?.gym;
|
||||
const canManage = (data?.isAdmin ?? false) || (data?.roles ?? []).includes('OWNER');
|
||||
|
||||
const [rangeDays, setRangeDays] = useState(30);
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [preview, setPreview] = useState<GymEquipment | null>(null);
|
||||
|
||||
const actions: TopbarAction[] | undefined =
|
||||
gym && canManage
|
||||
? [{ label: t('equipmentPage.editAction'), onClick: () => setEditOpen(true) }]
|
||||
: undefined;
|
||||
const rangeFilter = (
|
||||
<Select
|
||||
size="sm"
|
||||
value={rangeDays}
|
||||
onChange={(e) => setRangeDays(Number(e.target.value))}
|
||||
aria-label={t('equipmentPage.usage.rangeAria')}
|
||||
>
|
||||
{RANGE_OPTIONS.map((d) => (
|
||||
<option key={d} value={d}>
|
||||
{t('equipmentPage.usage.rangeDays', { count: d })}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
);
|
||||
useTopbar({
|
||||
title: t('equipmentPage.title'),
|
||||
back: `/gyms/${id}`,
|
||||
actions,
|
||||
...(gym?.kind === 'REAL' ? { filters: [rangeFilter], filterActive: rangeDays !== 30 } : {}),
|
||||
});
|
||||
|
||||
if (isLoading) return <Loading />;
|
||||
if (error || !gym) {
|
||||
return (
|
||||
<>
|
||||
<BackButton to={`/gyms/${id}`} className="mb-4" />
|
||||
<ErrorText>{t('detail.notFound')}</ErrorText>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const equipment = gym.equipment;
|
||||
const photos = preview?.photos ?? [];
|
||||
return (
|
||||
<>
|
||||
{/* HERO-LITE: nazwa siłowni + licznik urządzeń (tytuł h1 należy do topbaru) */}
|
||||
<div className="mb-5 flex flex-wrap items-end justify-between gap-3">
|
||||
<div>
|
||||
<span className="font-display text-[1.35rem] font-bold tracking-[-0.02em]">
|
||||
{gym.name}
|
||||
</span>
|
||||
<p className="mt-0.5 text-[0.85rem] tabular-nums text-dim">
|
||||
{t('common:counters.devices', { count: equipment.length })}
|
||||
</p>
|
||||
</div>
|
||||
<BackButton to={`/gyms/${id}`} />
|
||||
</div>
|
||||
|
||||
<div className="mb-4">
|
||||
<Card>
|
||||
<SectionHeader
|
||||
title={t('detail.equipmentTitle')}
|
||||
description={t('detail.equipmentDesc')}
|
||||
/>
|
||||
{equipment.length === 0 ? (
|
||||
<div className="flex flex-col items-center gap-2 py-10 text-dim">
|
||||
<Dumbbell className="h-6 w-6" aria-hidden="true" />
|
||||
<p className="text-[0.875rem]">{t('detail.noEquipment')}</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 gap-2 sm:grid-cols-2">
|
||||
{equipment.map((e) => (
|
||||
<button
|
||||
key={e.id}
|
||||
type="button"
|
||||
onClick={() => setPreview(e)}
|
||||
aria-label={t('detail.photosAria', {
|
||||
name: localizedName(e.equipment, i18n.language),
|
||||
})}
|
||||
className="flex cursor-pointer items-center gap-2 rounded-[10px] border border-line bg-card/50 px-3 py-2.5 text-left text-[0.85rem] font-semibold hover:border-accent/55"
|
||||
>
|
||||
{(e.photos?.length ?? 0) > 0 ? (
|
||||
<AuthImage
|
||||
src={e.photos![0].url}
|
||||
alt={localizedName(e.equipment, i18n.language)}
|
||||
className="h-9 w-9 shrink-0 rounded-[8px] border border-line object-cover"
|
||||
/>
|
||||
) : (
|
||||
<Dumbbell className="h-4 w-4 shrink-0 text-dim" aria-hidden="true" />
|
||||
)}
|
||||
<span className="min-w-0 truncate">{formatGymEquipment(e, i18n.language)}</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{gym.kind === 'REAL' && <EquipmentUsageHeatmap gymId={gym.id} rangeDays={rangeDays} />}
|
||||
|
||||
<Modal
|
||||
open={preview != null}
|
||||
onClose={() => setPreview(null)}
|
||||
title={t('detail.equipmentTitle')}
|
||||
>
|
||||
{photos.length === 0 ? (
|
||||
<p className="text-[0.875rem] text-dim">{t('gallery.empty')}</p>
|
||||
) : (
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
{photos.map((p) => (
|
||||
<AuthImage
|
||||
key={p.id}
|
||||
src={p.url}
|
||||
alt={preview ? localizedName(preview.equipment, i18n.language) : ''}
|
||||
className="w-full rounded-[10px] border border-line object-cover"
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
wide
|
||||
open={editOpen}
|
||||
onClose={() => setEditOpen(false)}
|
||||
title={t('detail.modalEquipment')}
|
||||
>
|
||||
<EquipmentSection key={gym.id} gym={gym} />
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
100
app/src/pages/gyms/GymGalleryPage.tsx
Normal file
100
app/src/pages/gyms/GymGalleryPage.tsx
Normal file
@@ -0,0 +1,100 @@
|
||||
import { useState } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Image as ImageIcon } from 'lucide-react';
|
||||
import { useGymDetail } from '../../api/queries';
|
||||
import type { GymPhoto } from '../../api/types';
|
||||
import { AuthImage } from '../../components/AuthImage';
|
||||
import { BackButton, Card, ErrorText, Loading, Modal, SectionHeader } from '../../components/ui';
|
||||
import { useTopbar, type TopbarAction } from '../../topbar';
|
||||
import GymGallery from '../../components/gyms/GymGallery';
|
||||
|
||||
/* Podstrona galerii (read-only): pełna siatka zdjęć + podgląd w modalu;
|
||||
edycja przez modal z istniejącym komponentem GymGallery (akcja w menu). */
|
||||
export default function GymGalleryPage() {
|
||||
const { id } = useParams();
|
||||
const { t } = useTranslation('gyms');
|
||||
const { data, isLoading, error } = useGymDetail(id);
|
||||
const gym = data?.gym;
|
||||
const canManage = (data?.isAdmin ?? false) || (data?.roles ?? []).includes('OWNER');
|
||||
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [preview, setPreview] = useState<GymPhoto | null>(null);
|
||||
|
||||
const actions: TopbarAction[] | undefined =
|
||||
gym && canManage
|
||||
? [{ label: t('galleryPage.editAction'), onClick: () => setEditOpen(true) }]
|
||||
: undefined;
|
||||
useTopbar({ title: t('galleryPage.title'), back: `/gyms/${id}`, actions });
|
||||
|
||||
if (isLoading) return <Loading />;
|
||||
if (error || !gym) {
|
||||
return (
|
||||
<>
|
||||
<BackButton to={`/gyms/${id}`} className="mb-4" />
|
||||
<ErrorText>{t('detail.notFound')}</ErrorText>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const photos = gym.photos ?? [];
|
||||
return (
|
||||
<>
|
||||
{/* HERO-LITE: nazwa siłowni + licznik zdjęć (tytuł h1 należy do topbaru) */}
|
||||
<div className="mb-5 flex flex-wrap items-end justify-between gap-3">
|
||||
<div>
|
||||
<span className="font-display text-[1.35rem] font-bold tracking-[-0.02em]">
|
||||
{gym.name}
|
||||
</span>
|
||||
<p className="mt-0.5 text-[0.85rem] tabular-nums text-dim">
|
||||
{t('galleryPage.photosCount', { count: photos.length })}
|
||||
</p>
|
||||
</div>
|
||||
<BackButton to={`/gyms/${id}`} />
|
||||
</div>
|
||||
|
||||
<Card>
|
||||
<SectionHeader title={t('detail.galleryTitle')} />
|
||||
{photos.length === 0 ? (
|
||||
<div className="flex flex-col items-center gap-2 py-10 text-dim">
|
||||
<ImageIcon className="h-6 w-6" aria-hidden="true" />
|
||||
<p className="text-[0.875rem]">{t('gallery.empty')}</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-2 gap-2 sm:grid-cols-3 lg:grid-cols-4">
|
||||
{photos.map((p) => (
|
||||
<button
|
||||
key={p.id}
|
||||
type="button"
|
||||
onClick={() => setPreview(p)}
|
||||
aria-label={t('galleryPage.previewAria')}
|
||||
className="overflow-hidden rounded-[10px] border border-line bg-input transition-colors hover:border-accent/55"
|
||||
>
|
||||
<AuthImage src={p.url} alt={gym.name} className="h-32 w-full object-cover" />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
<Modal open={preview != null} onClose={() => setPreview(null)} title={t('galleryPage.title')}>
|
||||
{preview && (
|
||||
<AuthImage
|
||||
src={preview.url}
|
||||
alt={gym.name}
|
||||
className="max-h-[70vh] w-full rounded-[10px] border border-line object-contain"
|
||||
/>
|
||||
)}
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
wide
|
||||
open={editOpen}
|
||||
onClose={() => setEditOpen(false)}
|
||||
title={t('detail.modalGallery')}
|
||||
>
|
||||
<GymGallery gym={gym} canManage={canManage} onChanged={() => {}} />
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -13,7 +13,6 @@ async function openOwnedGymDetail(page: import('@playwright/test').Page) {
|
||||
await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
|
||||
await page.getByRole('link', { name: 'Siłownie' }).click();
|
||||
await page.getByRole('link', { name: 'Żelazna Świątynia' }).click();
|
||||
await expect(page.getByRole('heading', { name: 'Galeria zdjęć' })).toBeVisible();
|
||||
}
|
||||
|
||||
test('właściciel zarządza galerią zdjęć siłowni REAL (upload/okładka/usuwanie)', async ({ page }) => {
|
||||
@@ -21,8 +20,15 @@ test('właściciel zarządza galerią zdjęć siłowni REAL (upload/okładka/usu
|
||||
mockApi(page);
|
||||
await openOwnedGymDetail(page);
|
||||
|
||||
// zarządzanie galerią otwierane z menu kontekstowego (grupa „Galeria”)
|
||||
await page.locator('button[data-slot="button"]', { hasText: 'Galeria' }).click();
|
||||
// kafelek galerii na stronie detalu → podstrona galerii
|
||||
await expect(page.getByRole('link', { name: /Galeria zdjęć/ })).toBeVisible();
|
||||
await page.getByRole('link', { name: /Galeria zdjęć/ }).click();
|
||||
await expect(page.getByRole('heading', { name: 'Galeria', exact: true })).toBeVisible();
|
||||
// start: 2 zdjęcia w siatce podstrony
|
||||
await expect(page.getByRole('button', { name: 'Powiększ zdjęcie' })).toHaveCount(2);
|
||||
|
||||
// zarządzanie galerią: modal z akcji menu (grupa inline na lg+ → „Edytuj zdjęcia”)
|
||||
await page.getByRole('button', { name: 'Edytuj zdjęcia' }).click();
|
||||
const dialog = page.getByRole('dialog');
|
||||
|
||||
// start: 2 zdjęcia, pierwsze jest okładką
|
||||
|
||||
@@ -100,7 +100,8 @@ test('właściciel ma menu „Siłownie" i zarządza swoją siłownią', async (
|
||||
|
||||
// open the gym detail
|
||||
await page.getByRole('link', { name: 'Żelazna Świątynia' }).click();
|
||||
await expect(page.getByRole('heading', { name: 'Urządzenia' })).toBeVisible();
|
||||
await expect(page.getByRole('link', { name: /Urządzenia/ })).toBeVisible();
|
||||
await expect(page.getByRole('link', { name: /Galeria zdjęć/ })).toBeVisible();
|
||||
// pasek godzin w całym wierszu pod hero: godziny siłowni + wyjątek harmonogramu
|
||||
await expect(page.getByText('06:00–22:00')).toBeVisible();
|
||||
await expect(page.getByText('Wyjątki', { exact: true })).toBeVisible();
|
||||
@@ -111,7 +112,7 @@ test('właściciel ma menu „Siłownie" i zarządza swoją siłownią', async (
|
||||
await expect(page.getByText('Mokotowska 12A')).toBeVisible();
|
||||
await expect(page.getByText('00-900 Warszawa')).toBeVisible();
|
||||
|
||||
// wyjątek dodawany z menu kontekstowego (grupa „Edycja” → modal „Informacje”)
|
||||
// wyjątek dodawany z menu kontekstowego (grupa „Zarządzaj” inline na lg+ → modal „Informacje”)
|
||||
await page.getByRole('button', { name: 'Informacje' }).click();
|
||||
const excDialog = page.getByRole('dialog');
|
||||
await excDialog.locator('input[type="date"]').fill('2026-09-01');
|
||||
@@ -129,11 +130,13 @@ test('ponowne dodanie tego samego typu tworzy osobną instancję urządzenia', a
|
||||
|
||||
await page.getByRole('link', { name: 'Siłownie' }).click();
|
||||
await page.getByRole('link', { name: 'Żelazna Świątynia' }).click();
|
||||
await expect(page.getByRole('heading', { name: 'Urządzenia' })).toBeVisible();
|
||||
// kafelek urządzeń → podstrona z listą instancji + mapa ciepła
|
||||
await page.getByRole('link', { name: /Urządzenia/ }).click();
|
||||
await expect(page.getByText('Korzystanie z urządzeń (godziny)')).toBeVisible();
|
||||
await expect(page.getByText('Hantle ×2 · 2.5–25 kg', { exact: true })).toBeVisible();
|
||||
|
||||
// zarządzanie sprzętem z menu kontekstowego (grupa „Urządzenia” → modal)
|
||||
await page.locator('button[data-slot="button"]', { hasText: 'Urządzenia' }).click();
|
||||
// zarządzanie sprzętem: modal z akcji menu (grupa inline na lg+ → „Edytuj urządzenia”)
|
||||
await page.getByRole('button', { name: 'Edytuj urządzenia' }).click();
|
||||
const dialog = page.getByRole('dialog');
|
||||
// każde dodanie = NOWA instancja z własnymi parametrami (bez inkrementacji ilości)
|
||||
await dialog.getByLabel('Dodaj urządzenie').selectOption('eq-2');
|
||||
@@ -154,7 +157,9 @@ test('właściciel może zmienić ilość instancji urządzenia', async ({ page
|
||||
|
||||
await page.getByRole('link', { name: 'Siłownie' }).click();
|
||||
await page.getByRole('link', { name: 'Żelazna Świątynia' }).click();
|
||||
await page.locator('button[data-slot="button"]', { hasText: 'Urządzenia' }).click();
|
||||
// kafelek urządzeń → podstrona; edycja modalem z akcji menu (inline na lg+)
|
||||
await page.getByRole('link', { name: /Urządzenia/ }).click();
|
||||
await page.getByRole('button', { name: 'Edytuj urządzenia' }).click();
|
||||
const dialog = page.getByRole('dialog');
|
||||
|
||||
await dialog.getByLabel('Ilość: Sztanga').fill('4');
|
||||
@@ -172,7 +177,9 @@ test('właściciel może nadać instancji własne parametry (nadpisanie speca)',
|
||||
|
||||
await page.getByRole('link', { name: 'Siłownie' }).click();
|
||||
await page.getByRole('link', { name: 'Żelazna Świątynia' }).click();
|
||||
await page.locator('button[data-slot="button"]', { hasText: 'Urządzenia' }).click();
|
||||
// kafelek urządzeń → podstrona; edycja modalem z akcji menu (inline na lg+)
|
||||
await page.getByRole('link', { name: /Urządzenia/ }).click();
|
||||
await page.getByRole('button', { name: 'Edytuj urządzenia' }).click();
|
||||
const dialog = page.getByRole('dialog');
|
||||
|
||||
// panel edycji instancji Hantle: własny zakres 5–5 kg = ciężar stały „5 kg”
|
||||
@@ -193,7 +200,9 @@ test('właściciel może dodać zdjęcie do urządzenia', async ({ page }) => {
|
||||
|
||||
await page.getByRole('link', { name: 'Siłownie' }).click();
|
||||
await page.getByRole('link', { name: 'Żelazna Świątynia' }).click();
|
||||
await page.locator('button[data-slot="button"]', { hasText: 'Urządzenia' }).click();
|
||||
// kafelek urządzeń → podstrona; edycja modalem z akcji menu (inline na lg+)
|
||||
await page.getByRole('link', { name: /Urządzenia/ }).click();
|
||||
await page.getByRole('button', { name: 'Edytuj urządzenia' }).click();
|
||||
const dialog = page.getByRole('dialog');
|
||||
|
||||
const png = Buffer.from(
|
||||
@@ -213,3 +222,36 @@ test('właściciel może dodać zdjęcie do urządzenia', async ({ page }) => {
|
||||
await dialog.getByRole('button', { name: 'Edytuj Sztanga' }).click();
|
||||
await expect(dialog.getByText('Zdjęcia (1/5)')).toBeVisible();
|
||||
});
|
||||
|
||||
test('podstrona urządzeń: mapa ciepła godzinowa z filtra okresu', async ({ page }) => {
|
||||
mockApi(page, {
|
||||
equipmentUsage: {
|
||||
equipment: [
|
||||
{
|
||||
equipmentId: 'eq-2',
|
||||
name: 'Hantle',
|
||||
nameEn: null,
|
||||
cells: [{ hour: 18, count: 5 }],
|
||||
peak: 5,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
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 page.getByRole('link', { name: 'Żelazna Świątynia' }).click();
|
||||
await page.getByRole('link', { name: /Urządzenia/ }).click();
|
||||
|
||||
// wiersz urządzenia + kafel godzinowy z licznikiem w title
|
||||
await expect(page.getByText('Korzystanie z urządzeń (godziny)')).toBeVisible();
|
||||
await expect(page.getByTitle('18:00 — 5 użyć')).toBeVisible();
|
||||
|
||||
// filtr okresu w topbarze (grupa filtrów inline na lg+)
|
||||
await page.getByRole('combobox', { name: 'Zakres mapy ciepła' }).selectOption('7');
|
||||
await expect(page.getByTitle('18:00 — 5 użyć')).toBeVisible();
|
||||
});
|
||||
|
||||
@@ -910,6 +910,10 @@ export interface MockApiOptions {
|
||||
presenceHistory?: unknown;
|
||||
/** Ciało GET /me/presence/stats (domyślnie: puste statystyki). */
|
||||
presenceStats?: unknown;
|
||||
/** Ciało GET /gyms/:id/announcements (domyślnie: puste; canManage z właściciela). */
|
||||
gymAnnouncements?: unknown;
|
||||
/** Ciało GET /gyms/:id/equipment-usage (domyślnie: brak wierszy). */
|
||||
equipmentUsage?: { equipment: unknown[] };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -940,6 +944,8 @@ export function mockApi(page: Page, opts: MockApiOptions = {}) {
|
||||
presence,
|
||||
presenceHistory,
|
||||
presenceStats,
|
||||
gymAnnouncements,
|
||||
equipmentUsage,
|
||||
} = opts;
|
||||
|
||||
// Stateful: bytność (check-in) — aktywna obecność + zamknięte wizyty; occupancy liczy się z niej.
|
||||
@@ -1370,6 +1376,22 @@ export function mockApi(page: Page, opts: MockApiOptions = {}) {
|
||||
route.fulfill({ status: 200, contentType: 'application/json', body: gymDetailBody() }),
|
||||
);
|
||||
|
||||
// ---------- ogłoszenia siłowni + mapa ciepła urządzeń (podstrony) ----------
|
||||
page.route('**/api/v1/gyms/*/announcements', (route) =>
|
||||
route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify(gymAnnouncements ?? { announcements: [], canManage: false }),
|
||||
}),
|
||||
);
|
||||
page.route('**/api/v1/gyms/*/equipment-usage*', (route) =>
|
||||
route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify(equipmentUsage ?? { equipment: [] }),
|
||||
}),
|
||||
);
|
||||
|
||||
// POST /gyms/gym-1/photos — upload (multipart, pole `photos`).
|
||||
page.route('**/api/v1/gyms/*/photos', (route) => {
|
||||
const req = route.request();
|
||||
|
||||
@@ -3,6 +3,11 @@ import { mockApi, TEST_DAY, TEST_SESSION, TEST_USER } from './mock-api';
|
||||
|
||||
/* Bytność na siłowni: QR check-in, live occupancy, modal rozpoczęcia treningu, historia wizyt. */
|
||||
|
||||
// świeże znaczniki czasu — inaczej globalny modal keep-alive (>PROMPT_AFTER_MS bezczynności)
|
||||
// otwiera się nad stroną i blokuje kliknięcia w akcje
|
||||
const freshIso = (minutesAgo = 0) =>
|
||||
new Date(Date.now() - minutesAgo * 60_000).toISOString();
|
||||
|
||||
const GYM1_PRESENCE = {
|
||||
id: 'presence-1',
|
||||
gymId: 'gym-1',
|
||||
@@ -10,8 +15,8 @@ const GYM1_PRESENCE = {
|
||||
gymCapacity: 50,
|
||||
status: 'ACTIVE',
|
||||
source: 'MANUAL',
|
||||
checkedInAt: '2026-10-23T17:05:00.000Z',
|
||||
lastActivityAt: '2026-10-23T17:05:00.000Z',
|
||||
checkedInAt: freshIso(10),
|
||||
lastActivityAt: freshIso(0),
|
||||
closedAt: null,
|
||||
};
|
||||
|
||||
@@ -98,7 +103,7 @@ test('modal kodu QR właściciela pokazuje kod i link do strony check-inu', asyn
|
||||
await login(page);
|
||||
await openGymDetail(page);
|
||||
|
||||
// akcja „Kod QR” grupy „QR” w menu kontekstowym (desktop = inline; tylko REAL + OWNER)
|
||||
// akcja „Kod QR” grupy „Zarządzaj” (inline na lg+; tylko REAL + OWNER)
|
||||
await page.getByRole('button', { name: 'Kod QR' }).click();
|
||||
|
||||
const dialog = page.getByRole('dialog');
|
||||
|
||||
222
app/test/gym-detail.test.tsx
Normal file
222
app/test/gym-detail.test.tsx
Normal file
@@ -0,0 +1,222 @@
|
||||
import { render, screen, fireEvent, within } from '@testing-library/react';
|
||||
import { MemoryRouter, Route, Routes } from 'react-router-dom';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import GymDetail from '../src/pages/gyms/GymDetail';
|
||||
import GymGalleryPage from '../src/pages/gyms/GymGalleryPage';
|
||||
import GymEquipmentPage from '../src/pages/gyms/GymEquipmentPage';
|
||||
import GymAnnouncementsPage from '../src/pages/gyms/GymAnnouncementsPage';
|
||||
import { setAccessToken } from '../src/api/client';
|
||||
import { useTopbarStore } from '../src/topbar/store';
|
||||
import { Topbar } from '../src/topbar';
|
||||
import type { Gym, GymAnnouncement } from '../src/api/types';
|
||||
|
||||
const PHOTOS = [
|
||||
{ id: 'p1', url: 'uploads/p1.jpg', order: 0, createdAt: '2026-01-01T00:00:00.000Z' },
|
||||
];
|
||||
|
||||
const EQ_INST = {
|
||||
id: 'ge-1',
|
||||
gymId: 'g1',
|
||||
equipmentId: 'eq-1',
|
||||
quantity: 2,
|
||||
spec: null,
|
||||
equipment: {
|
||||
id: 'eq-1',
|
||||
name: 'hantle',
|
||||
nameEn: 'dumbbells',
|
||||
kind: 'DUMBBELL',
|
||||
spec: { minKg: 2.5, maxKg: 25 },
|
||||
description: null,
|
||||
},
|
||||
};
|
||||
|
||||
const GYM_REAL: Gym = {
|
||||
id: 'g1',
|
||||
name: 'Gym A',
|
||||
location: 'Polna 4, 00-001 Warszawa',
|
||||
availability: null,
|
||||
capacity: 50,
|
||||
kind: 'REAL',
|
||||
isPrivate: false,
|
||||
equipment: [EQ_INST],
|
||||
coverPhoto: 'uploads/p1.jpg',
|
||||
};
|
||||
|
||||
const GYM_VIRTUAL: Gym = {
|
||||
...GYM_REAL,
|
||||
kind: 'VIRTUAL',
|
||||
isPrivate: false,
|
||||
equipment: [EQ_INST],
|
||||
coverPhoto: null,
|
||||
};
|
||||
|
||||
const ANNOUNCEMENT: GymAnnouncement = {
|
||||
id: 'a1',
|
||||
kind: 'MANUAL',
|
||||
title: 'Awarida klimatyzacji',
|
||||
body: 'Klimatyzacja nie działa.',
|
||||
createdAt: '2026-01-05T00:00:00.000Z',
|
||||
};
|
||||
|
||||
function jsonResponse(status: number, body: unknown) {
|
||||
return new Response(JSON.stringify(body), {
|
||||
status,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
/** Wspólny mock: detal siłowni, ogłoszenia, mapa ciepła, bytność, wnioski/zaproszenia. */
|
||||
function stubGymFetch(options: { gym?: Gym; roles?: string[]; announcements?: GymAnnouncement[] } = {}) {
|
||||
const gym = options.gym ?? GYM_REAL;
|
||||
const roles = options.roles ?? ['OWNER'];
|
||||
const announcements = options.announcements ?? [ANNOUNCEMENT];
|
||||
const fetchMock = vi.fn(async (input: RequestInfo | URL) => {
|
||||
const url = String(input);
|
||||
if (url.includes('/announcements'))
|
||||
return jsonResponse(200, { announcements, canManage: true });
|
||||
if (url.includes('/equipment-usage'))
|
||||
return jsonResponse(200, {
|
||||
equipment: [
|
||||
{
|
||||
equipmentId: 'eq-1',
|
||||
name: 'hantle',
|
||||
nameEn: 'dumbbells',
|
||||
cells: [{ hour: 18, count: 3 }],
|
||||
peak: 3,
|
||||
},
|
||||
],
|
||||
});
|
||||
if (url.includes('/me/presence')) return jsonResponse(200, { presence: null });
|
||||
if (url.includes('/exceptions')) return jsonResponse(200, { exceptions: [] });
|
||||
if (url.includes('/gyms/claims')) return jsonResponse(200, { claims: [] });
|
||||
if (url.includes('/gyms/invitations')) return jsonResponse(200, { invitations: [] });
|
||||
if (url.includes('/gyms/g1'))
|
||||
return jsonResponse(200, { gym: { ...gym, photos: PHOTOS }, roles, isAdmin: false });
|
||||
throw new Error(`Unexpected fetch: ${url}`);
|
||||
});
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
return fetchMock;
|
||||
}
|
||||
|
||||
/** Akcja w topbarze (przycisk z panelu grupy/akcji). */
|
||||
function actionButton(label: string): HTMLElement {
|
||||
const btn = Array.from(document.querySelectorAll('button[data-slot="button"]')).find(
|
||||
(b) => b.textContent?.trim() === label,
|
||||
);
|
||||
if (!btn) throw new Error(`Brak akcji w menu: ${label}`);
|
||||
return btn;
|
||||
}
|
||||
|
||||
function renderGym(initialPath = '/gyms/g1') {
|
||||
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
||||
return render(
|
||||
<MemoryRouter initialEntries={[initialPath]}>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<Topbar />
|
||||
<Routes>
|
||||
<Route path="/gyms/:id" element={<GymDetail />} />
|
||||
<Route path="/gyms/:id/gallery" element={<GymGalleryPage />} />
|
||||
<Route path="/gyms/:id/equipment" element={<GymEquipmentPage />} />
|
||||
<Route path="/gyms/:id/announcements" element={<GymAnnouncementsPage />} />
|
||||
</Routes>
|
||||
</QueryClientProvider>
|
||||
</MemoryRouter>,
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
setAccessToken('tok');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
describe('app GymDetail — kafelki i menu „Zarządzaj”', () => {
|
||||
it('REAL: trzy kafelki sekcji i jedna grupa menu z akcjami', async () => {
|
||||
stubGymFetch();
|
||||
renderGym();
|
||||
expect(await screen.findByRole('heading', { name: 'Gym A' })).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByRole('link', { name: /Galeria zdjęć/ })).toHaveAttribute(
|
||||
'href',
|
||||
'/gyms/g1/gallery',
|
||||
);
|
||||
expect(screen.getByRole('link', { name: /Urządzenia/ })).toHaveAttribute(
|
||||
'href',
|
||||
'/gyms/g1/equipment',
|
||||
);
|
||||
expect(screen.getByRole('link', { name: /Ogłoszenia/ })).toHaveAttribute(
|
||||
'href',
|
||||
'/gyms/g1/announcements',
|
||||
);
|
||||
|
||||
const config = useTopbarStore.getState().config;
|
||||
expect(config?.groups?.map((g) => g.id)).toEqual(['manage']);
|
||||
expect(config?.groups?.[0]?.actions?.map((a) => a.label)).toEqual([
|
||||
'Informacje',
|
||||
'Galeria',
|
||||
'Kod QR',
|
||||
'Urządzenia',
|
||||
'Ogłoszenia',
|
||||
'Usuń siłownię',
|
||||
]);
|
||||
});
|
||||
|
||||
it('VIRTUAL: brak kafelka galerii i brak akcji QR/Galeria w menu', async () => {
|
||||
stubGymFetch({ gym: GYM_VIRTUAL });
|
||||
renderGym();
|
||||
expect(await screen.findByRole('heading', { name: 'Gym A' })).toBeInTheDocument();
|
||||
|
||||
expect(screen.queryByRole('link', { name: /Galeria zdjęć/ })).not.toBeInTheDocument();
|
||||
expect(screen.getByRole('link', { name: /Urządzenia/ })).toBeInTheDocument();
|
||||
expect(screen.getByRole('link', { name: /Ogłoszenia/ })).toBeInTheDocument();
|
||||
|
||||
const config = useTopbarStore.getState().config;
|
||||
expect(config?.groups?.[0]?.actions?.map((a) => a.label)).toEqual([
|
||||
'Informacje',
|
||||
'Urządzenia',
|
||||
'Ogłoszenia',
|
||||
'Usuń siłownię',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('app podstrony sekcji siłowni', () => {
|
||||
it('podstrona urządzeń: lista instancji + mapa ciepła godzinowa', async () => {
|
||||
stubGymFetch();
|
||||
renderGym('/gyms/g1/equipment');
|
||||
|
||||
expect(await screen.findByText('Korzystanie z urządzeń (godziny)')).toBeInTheDocument();
|
||||
expect(await screen.findByTitle('18:00 — 3 użycia')).toBeInTheDocument();
|
||||
// właściciel: akcja edycji w menu (modal z EquipmentSection)
|
||||
expect(actionButton('Edytuj urządzenia')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('podstrona urządzeń bez uprawnień: brak akcji edycji', async () => {
|
||||
stubGymFetch({ roles: ['MEMBER'] });
|
||||
renderGym('/gyms/g1/equipment');
|
||||
expect(await screen.findByText('Korzystanie z urządzeń (godziny)')).toBeInTheDocument();
|
||||
expect(() => actionButton('Edytuj urządzenia')).toThrow();
|
||||
});
|
||||
|
||||
it('podstrona ogłoszeń: lista read-only; właściciel otwiera modal tworzenia', async () => {
|
||||
stubGymFetch();
|
||||
renderGym('/gyms/g1/announcements');
|
||||
|
||||
expect(await screen.findByText('Awarida klimatyzacji')).toBeInTheDocument();
|
||||
fireEvent.click(actionButton('Nowe ogłoszenie'));
|
||||
const dialog = await screen.findByRole('dialog');
|
||||
expect(within(dialog).getByRole('button', { name: 'Opublikuj' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('podstrona galerii: siatka zdjęć i akcja edycji dla właściciela', async () => {
|
||||
stubGymFetch();
|
||||
renderGym('/gyms/g1/gallery');
|
||||
|
||||
expect(await screen.findByRole('button', { name: 'Powiększ zdjęcie' })).toBeInTheDocument();
|
||||
fireEvent.click(actionButton('Edytuj zdjęcia'));
|
||||
expect(await screen.findByRole('dialog')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user