From 6202890057c5f9ffe151a24d3d8ab5aa5fd8e86c Mon Sep 17 00:00:00 2001 From: tisachi Date: Fri, 23 Oct 2026 20:11:59 +0200 Subject: [PATCH] Admin: lustrzane kafelki Galeria/Urzadzenia/Ogloszenia na szczegole sirowni + podstrony przegladania (galeria, urzadzenia z mapa ciepla, ogloszenia); menu zwiniety do grupy Zarzadzaj (Wlasciciele i usuwanie w grupie, telemetria bytnosci zostaje na szczegole) --- admin/src/App.tsx | 6 + admin/src/api/queries.ts | 19 +- admin/src/api/types.ts | 15 + admin/src/i18n/locales/en/gyms.json | 30 ++ admin/src/i18n/locales/pl/gyms.json | 40 +++ admin/src/pages/gyms/GymAnnouncementsPage.tsx | 110 ++++++++ admin/src/pages/gyms/GymDetail.tsx | 263 ++++++++++-------- admin/src/pages/gyms/GymEquipmentPage.tsx | 220 +++++++++++++++ admin/src/pages/gyms/GymGalleryPage.tsx | 118 ++++++++ admin/test/GymDetail.test.tsx | 61 +++- admin/test/e2e/admin.spec.ts | 11 +- admin/test/e2e/gym-gallery.spec.ts | 9 +- 12 files changed, 760 insertions(+), 142 deletions(-) create mode 100644 admin/src/pages/gyms/GymAnnouncementsPage.tsx create mode 100644 admin/src/pages/gyms/GymEquipmentPage.tsx create mode 100644 admin/src/pages/gyms/GymGalleryPage.tsx diff --git a/admin/src/App.tsx b/admin/src/App.tsx index cfd4c59..0f65156 100644 --- a/admin/src/App.tsx +++ b/admin/src/App.tsx @@ -7,6 +7,9 @@ import Login from './pages/Login'; import GymsList from './pages/gyms/GymsList'; import GymForm from './pages/gyms/GymForm'; 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 UsersList from './pages/users/UsersList'; import UserForm from './pages/users/UserForm'; import UserDetail from './pages/users/UserDetail'; @@ -45,6 +48,9 @@ export default function App() { } /> } /> } /> + } /> + } /> + } /> } /> } /> } /> diff --git a/admin/src/api/queries.ts b/admin/src/api/queries.ts index 7eeec99..e185653 100644 --- a/admin/src/api/queries.ts +++ b/admin/src/api/queries.ts @@ -1,6 +1,6 @@ import { useQuery } from '@tanstack/react-query'; import { api } from './client'; -import type { User } from './types'; +import type { EquipmentUsageRow, User } from './types'; /** Bieżący użytkownik (admin) — profil + członkostwa, jak `useMe` w aplikacji. */ export function useMe() { @@ -15,3 +15,20 @@ export function useIsTrainer() { const { data } = useMe(); return (data?.memberships ?? []).some((m) => m.roles.includes('TRAINER')); } + +/** + * Mapa ciepła urządzeń (24 kafle godzinowe z okien bytności). `rangeDays`: 7/30/90, + * from liczony od teraz (jak telemetria bytności). + */ +export function useAdminGymEquipmentUsage(gymId: string | undefined, rangeDays: number) { + return useQuery({ + queryKey: ['admin-gym-equipment-usage', gymId, rangeDays], + queryFn: () => { + const from = new Date(Date.now() - rangeDays * 86_400_000).toISOString(); + return api<{ equipment: EquipmentUsageRow[] }>( + `/admin/gyms/${gymId}/equipment-usage?from=${encodeURIComponent(from)}`, + ); + }, + enabled: !!gymId, + }); +} diff --git a/admin/src/api/types.ts b/admin/src/api/types.ts index 1b1b4bf..dbbc2be 100644 --- a/admin/src/api/types.ts +++ b/admin/src/api/types.ts @@ -215,6 +215,21 @@ export interface GymPresenceStatsResponse { stats: GymPresenceStatsData; } +/** 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 /admin/gyms/:id/equipment-usage) — urządzenie + 24 kafle. */ +export interface EquipmentUsageRow { + equipmentId: string; + name: string; + nameEn: string | null; + cells: EquipmentUsageCell[]; + peak: number; +} + export type ClaimStatus = 'PENDING' | 'APPROVED' | 'REJECTED'; export interface GymClaimDocument { diff --git a/admin/src/i18n/locales/en/gyms.json b/admin/src/i18n/locales/en/gyms.json index 27d6480..0672061 100644 --- a/admin/src/i18n/locales/en/gyms.json +++ b/admin/src/i18n/locales/en/gyms.json @@ -74,6 +74,11 @@ "grantOwner": "Grant owner", "ownerRoleHint": "The owner manages the gym in the app: equipment, gallery and schedule.", "groupEdit": "Editing", + "groupManage": "Manage", + "tilePhotos_one": "{{count}} photo", + "tilePhotos_other": "{{count}} photos", + "tileAnnouncementsCount_one": "{{count}} announcement", + "tileAnnouncementsCount_other": "{{count}} announcements", "basicInfo": "Basic information", "groupGallery": "Gallery", "groupEquipment": "Equipment", @@ -84,6 +89,31 @@ "deleteGymDesc": "Delete this gym? Memberships will be removed, user plans will be kept.", "notFound": "Gym not found.", "gallerySection": "Photo gallery", + "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" + }, "equipmentDesc": "Machines and equipment available at this gym.", "hours": "Opening hours", "exceptions": "Exceptions", diff --git a/admin/src/i18n/locales/pl/gyms.json b/admin/src/i18n/locales/pl/gyms.json index d7f29bf..7c9796d 100644 --- a/admin/src/i18n/locales/pl/gyms.json +++ b/admin/src/i18n/locales/pl/gyms.json @@ -76,6 +76,15 @@ "grantOwner": "Nadaj właściciela", "ownerRoleHint": "Właściciel zarządza siłownią w aplikacji: urządzeniami, galerią i harmonogramem.", "groupEdit": "Edycja", + "groupManage": "Zarządzaj", + "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ń", "basicInfo": "Podstawowe informacje", "groupGallery": "Galeria", "groupEquipment": "Urządzenia", @@ -86,6 +95,37 @@ "deleteGymDesc": "Usunąć siłownię? Członkostwa zostaną usunięte, plany użytkowników zachowane.", "notFound": "Nie znaleziono siłowni.", "gallerySection": "Galeria zdjęć", + "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" + }, "equipmentDesc": "Maszyny i urządzenia dostępne w tej siłowni.", "hours": "Godziny otwarcia", "exceptions": "Wyjątki", diff --git a/admin/src/pages/gyms/GymAnnouncementsPage.tsx b/admin/src/pages/gyms/GymAnnouncementsPage.tsx new file mode 100644 index 0000000..9e19535 --- /dev/null +++ b/admin/src/pages/gyms/GymAnnouncementsPage.tsx @@ -0,0 +1,110 @@ +import { useState } from 'react'; +import { useParams } from 'react-router-dom'; +import { useTranslation } from 'react-i18next'; +import { useQuery } from '@tanstack/react-query'; +import { Megaphone } from 'lucide-react'; +import { api } from '../../api/client'; +import type { AdminAnnouncement, Gym } from '../../api/types'; +import { BackButton, Card, ErrorText, Loading, Modal, SectionHeader } from '../../components/ui'; +import { fmtDateTime } from '../../lib/format'; +import { useTopbar, type TopbarAction } from '../../topbar'; +import { GymAnnouncementsSection } from './GymDetail'; + +/* Podstrona ogłoszeń (read-only): lista; tworzenie/usuwanie modalem z sekcją + przeniesioną ze strony detalu (akcja „Nowe ogłoszenie” w menu). */ +export default function GymAnnouncementsPage() { + const { t } = useTranslation('gyms'); + const { id } = useParams(); + const { + data: gym, + isLoading, + error, + } = useQuery({ + queryKey: ['gym', id], + queryFn: () => api(`/admin/gyms/${id}`), + enabled: !!id, + }); + const { data: annData } = useQuery({ + queryKey: ['admin-announcements', id], + queryFn: () => + api<{ announcements: AdminAnnouncement[] }>( + `/admin/announcements?gymId=${encodeURIComponent(id ?? '')}`, + ), + enabled: !!id, + }); + const announcements = annData?.announcements ?? []; + + const [composerOpen, setComposerOpen] = useState(false); + + const actions: TopbarAction[] | undefined = gym + ? [{ label: t('announcementsPage.newAction'), onClick: () => setComposerOpen(true) }] + : undefined; + useTopbar({ title: t('announcementsPage.title'), back: `/gyms/${id}`, actions }); + + if (isLoading) return ; + if (error) + return ( + <> + + + {t('common:errorPrefix')} + {(error as Error).message} + + + ); + if (!gym) { + return ( + <> + + {t('notFound')} + + ); + } + + return ( + <> + {/* HERO-LITE: nazwa siłowni (tytuł h1 należy do topbaru) */} +
+
+ + {gym.name} + +

{t('announcementsPage.subtitle')}

+
+ +
+ + + + {announcements.length === 0 ? ( +
+
+ ) : ( +
+ {announcements.map((a) => ( +
+
+ {a.title} + + {fmtDateTime(a.createdAt)} + +
+

{a.body}

+
+ ))} +
+ )} +
+ + setComposerOpen(false)} + title={t('announcementsTitle')} + > + + + + ); +} diff --git a/admin/src/pages/gyms/GymDetail.tsx b/admin/src/pages/gyms/GymDetail.tsx index c125fbe..5f5a88d 100644 --- a/admin/src/pages/gyms/GymDetail.tsx +++ b/admin/src/pages/gyms/GymDetail.tsx @@ -1,5 +1,5 @@ import { useState } from 'react'; -import { useNavigate, useParams } from 'react-router-dom'; +import { Link, useNavigate, useParams } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { useQuery, useQueryClient } from '@tanstack/react-query'; import { @@ -8,16 +8,12 @@ import { Dumbbell, Image as ImageIcon, MapPin, - Megaphone, - Pencil, - QrCode, - ShieldCheck, + Settings, Star, Trash2, UserPlus, UserX, Users, - Wrench, X, } from 'lucide-react'; import { useTopbar, type TopbarCustomGroup } from '../../topbar'; @@ -71,7 +67,7 @@ import { normalizeAvailability, TIME_SLOTS, } from '../../lib/availability'; -import { fmtDate, fmtNumber } from '../../lib/format'; +import { fmtDate, fmtDateTime, fmtNumber } from '../../lib/format'; /* Godziny otwarcia w całym wierszu pod hero — lustrzany widok jak w apce (informacja kluczowa, więc nie w kolumnie bocznej). Pasek tygodnia wzorowany na kartach listy: @@ -265,54 +261,116 @@ function FragmentRow({ day, stats }: { day: number; stats: GymPresenceStatsRespo ); } -/* Mozaika galerii (odczyt): pierwsze zdjęcie duże, reszta siatką, „+N” na końcu — jak w apce. */ -function GalleryMosaic({ gym }: { gym: Gym }) { +/* Kafelek Galerii (tylko REAL): mini-mozaika 4 miniatur + licznik; klik → podstrona galerii. */ +function GalleryTile({ gym }: { gym: Gym }) { const { t } = useTranslation('gyms'); const photos = gym.photos ?? []; - if (photos.length === 0) { - return

{t('noPhotos')}

; - } - const [first, ...rest] = photos; + const preview = photos.slice(0, 4); return ( -
-
- + +
+ {preview.length === 0 ? ( +
+
+ ) : ( + preview.map((p) => ( +
+ +
+ )) + )}
- {rest.slice(0, 3).map((p) => ( -
- -
- ))} - {rest.length > 3 && ( -
- {t('photosMore', { count: rest.length - 3 })} -
- )} -
+
+ + {t('gallerySection')} + + + {t('tilePhotos', { count: photos.length })} + +
+ ); } -/* Kafle urządzeń (odczyt) — jak w apce; zarządzanie w modalu z grupy „Urządzenia”. */ -function EquipmentTiles({ gym }: { gym: Gym }) { - const { t } = useTranslation('gyms'); - const { i18n } = useTranslation(); - if (gym.equipment.length === 0) { - return

{t('noEquipment')}

; - } +/* Kafelek Urządzeń: nazwy pierwszych instancji + licznik; klik → podstrona urządzeń. */ +function EquipmentTile({ gym }: { gym: Gym }) { + const { t, i18n } = useTranslation('gyms'); + const preview = gym.equipment.slice(0, 4); return ( -
- {gym.equipment.map((e) => ( -
- {formatGymEquipment(e, i18n.language)} -
- ))} -
+ +
+ {preview.length === 0 ? ( +
+
+ ) : ( + preview.map((e) => ( + + {formatGymEquipment(e, i18n.language)} + + )) + )} +
+
+ + {t('groupEquipment')} + + + {t('common:counters.devices', { count: gym.equipment.length })} + +
+ + ); +} + +/* 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 } = useQuery({ + queryKey: ['admin-announcements', gymId], + queryFn: () => + api<{ announcements: AdminAnnouncement[] }>( + `/admin/announcements?gymId=${encodeURIComponent(gymId)}`, + ), + }); + const announcements = data?.announcements ?? []; + const latest = announcements[0]; + return ( + +
+ {latest ? ( + <> + {latest.title} + + {fmtDateTime(latest.createdAt)} + + + ) : ( + {t('noAnnouncements')} + )} +
+
+ + {t('groupAnnouncements')} + + + {t('tileAnnouncementsCount', { count: announcements.length })} + +
+ ); } @@ -716,10 +774,7 @@ export default function GymDetail() { }); const [editOpen, setEditOpen] = useState(false); - const [galleryOpen, setGalleryOpen] = useState(false); - const [equipmentOpen, setEquipmentOpen] = useState(false); const [ownersOpen, setOwnersOpen] = useState(false); - const [announcementsOpen, setAnnouncementsOpen] = useState(false); const [qrOpen, setQrOpen] = useState(false); const [presenceRange, setPresenceRange] = useState(30); const [confirmOpen, setConfirmOpen] = useState(false); @@ -745,49 +800,31 @@ export default function GymDetail() { } }; - // Operacje admina pogrupowane tematycznie w menu kontekstowym (topbar) — jak w apce; - // dodatkowo grupa „Właściciele” (niedostępna dla zwykłych userów). + // Operacje admina w JEDNEJ grupie „Zarządzaj” (jak w apce): modale pozostają na stronie, + // Galeria/Urządzenia/Ogłoszenia prowadzą do podstron (read-only z akcją edycji w menu). const groups: TopbarCustomGroup[] | undefined = gym ? [ { - id: 'edit', - label: t('groupEdit'), - icon: Pencil, - actions: [{ label: t('basicInfo'), onClick: () => setEditOpen(true) }], - }, - ...(gym.kind === 'REAL' - ? [ - { - id: 'gallery', - label: t('groupGallery'), - icon: ImageIcon, - actions: [{ label: t('groupGallery'), onClick: () => setGalleryOpen(true) }], - } as TopbarCustomGroup, - { - id: 'qr', - label: t('presence.qrGroup'), - icon: QrCode, - actions: [{ label: t('presence.qrAction'), onClick: () => setQrOpen(true) }], - } as TopbarCustomGroup, - ] - : []), - { - id: 'equipment', - label: t('groupEquipment'), - icon: Wrench, - actions: [{ label: t('groupEquipment'), onClick: () => setEquipmentOpen(true) }], - }, - { - id: 'owners', - label: t('groupOwners'), - icon: ShieldCheck, - actions: [{ label: t('groupOwners'), onClick: () => setOwnersOpen(true) }], - }, - { - id: 'announcements', - label: t('groupAnnouncements'), - icon: Megaphone, - actions: [{ label: t('announceOnBehalf'), onClick: () => setAnnouncementsOpen(true) }], + id: 'manage', + label: t('groupManage'), + icon: Settings, + actions: [ + { label: t('basicInfo'), onClick: () => setEditOpen(true) }, + ...(gym.kind === 'REAL' + ? [ + { label: t('groupGallery'), to: `/gyms/${gym.id}/gallery` }, + { label: t('presence.qrAction'), onClick: () => setQrOpen(true) }, + ] + : []), + { label: t('groupEquipment'), to: `/gyms/${gym.id}/equipment` }, + { label: t('groupAnnouncements'), to: `/gyms/${gym.id}/announcements` }, + { label: t('groupOwners'), onClick: () => setOwnersOpen(true) }, + { + label: t('deleteGym'), + variant: 'danger', + onClick: () => setConfirmOpen(true), + }, + ], }, ] : undefined; @@ -818,7 +855,6 @@ export default function GymDetail() { ], } : {}), - actions: [{ label: t('deleteGym'), variant: 'danger', onClick: () => setConfirmOpen(true) }], }); if (isLoading) return ; @@ -914,19 +950,18 @@ export default function GymDetail() { {/* GODZINY: cały wiersz bezpośrednio pod hero (jak w apce) */} - {/* DWIE KOLUMNY (widok odczytu identyczny jak w apce; edycja w grupach menu) */} + {/* DWIE KOLUMNY: kafelki sekcji (klik → podstrony) + karta danych */}
- {gym.kind === 'REAL' && ( - - - - - )} - - - - +
+ {gym.kind === 'REAL' && } + + +
@@ -990,27 +1025,9 @@ export default function GymDetail() {
- setGalleryOpen(false)} title={t('manageGallery')}> - void invalidate()} /> - - setEquipmentOpen(false)} - title={t('manageEquipment')} - className="sm:max-w-2xl" - > - void invalidate()} /> - setOwnersOpen(false)} title={t('manageOwners')}> void invalidate()} /> - setAnnouncementsOpen(false)} - title={t('announcementsTitle')} - > - - {gym.kind === 'REAL' && ( void }) { +export function EquipmentSection({ gym, onChanged }: { gym: Gym; onChanged: () => void }) { const { t } = useTranslation('gyms'); const { i18n } = useTranslation(); const { data: eqData, isLoading } = useQuery({ @@ -1431,7 +1448,7 @@ async function uploadGymPhotos(gymId: string, files: File[]): Promise { return api(`/gyms/${gymId}/photos`, { method: 'POST', body: form }); } -function GallerySection({ gym, onChanged }: { gym: Gym; onChanged: () => void }) { +export function GallerySection({ gym, onChanged }: { gym: Gym; onChanged: () => void }) { const { t } = useTranslation('gyms'); const photos = gym.photos ?? []; const [error, setError] = useState(''); diff --git a/admin/src/pages/gyms/GymEquipmentPage.tsx b/admin/src/pages/gyms/GymEquipmentPage.tsx new file mode 100644 index 0000000..0986fbe --- /dev/null +++ b/admin/src/pages/gyms/GymEquipmentPage.tsx @@ -0,0 +1,220 @@ +import { useState } from 'react'; +import { useParams } from 'react-router-dom'; +import { useTranslation } from 'react-i18next'; +import { useQuery, useQueryClient } from '@tanstack/react-query'; +import { Dumbbell } from 'lucide-react'; +import { api } from '../../api/client'; +import { useAdminGymEquipmentUsage } from '../../api/queries'; +import type { EquipmentUsageRow, Gym } from '../../api/types'; +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 './GymDetail'; + +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. */ +function EquipmentUsageHeatmap({ gymId, rangeDays }: { gymId: string; rangeDays: number }) { + const { t, i18n } = useTranslation('gyms'); + const { data, isLoading } = useAdminGymEquipmentUsage(gymId, rangeDays); + const rows = data?.equipment ?? []; + + return ( + + + {isLoading ? ( + + ) : rows.length === 0 ? ( +

{t('equipmentPage.usage.noData')}

+ ) : ( +
+
+ + {Array.from({ length: 24 }, (_, hour) => ( + + {hour % 3 === 0 ? String(hour).padStart(2, '0') : ''} + + ))} + {rows.map((row) => ( + + ))} +
+
+ )} +
+ ); +} + +function HeatmapRow({ row, label }: { row: EquipmentUsageRow; label: string }) { + const { t } = useTranslation('gyms'); + return ( + <> + + {label} + + {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 ( + 0 + ? `color-mix(in srgb, var(--accent) ${Math.round(18 + intensity * 82)}%, var(--bg-input))` + : 'var(--bg-input)', + }} + /> + ); + })} + + ); +} + +/* Podstrona urządzeń (read-only): lista instancji + mapa ciepła (REAL); + edycja modalem EquipmentSection (akcja „Edytuj urządzenia” w menu). */ +export default function GymEquipmentPage() { + const { t, i18n } = useTranslation('gyms'); + const { id } = useParams(); + const queryClient = useQueryClient(); + const { + data: gym, + isLoading, + error, + } = useQuery({ + queryKey: ['gym', id], + queryFn: () => api(`/admin/gyms/${id}`), + enabled: !!id, + }); + + const [rangeDays, setRangeDays] = useState(30); + const [editOpen, setEditOpen] = useState(false); + + const actions: TopbarAction[] | undefined = gym + ? [{ label: t('equipmentPage.editAction'), onClick: () => setEditOpen(true) }] + : undefined; + const rangeFilter = ( + + ); + useTopbar({ + title: t('equipmentPage.title'), + back: `/gyms/${id}`, + actions, + ...(gym?.kind === 'REAL' ? { filters: [rangeFilter], filterActive: rangeDays !== 30 } : {}), + }); + + if (isLoading) return ; + if (error) + return ( + <> + + + {t('common:errorPrefix')} + {(error as Error).message} + + + ); + if (!gym) { + return ( + <> + + {t('notFound')} + + ); + } + + const equipment = gym.equipment; + return ( + <> + {/* HERO-LITE: nazwa siłowni + licznik urządzeń (tytuł h1 należy do topbaru) */} +
+
+ + {gym.name} + +

+ {t('common:counters.devices', { count: equipment.length })} +

+
+ +
+ +
+ + + {equipment.length === 0 ? ( +
+
+ ) : ( +
+ {equipment.map((e) => ( +
+ {formatGymEquipment(e, i18n.language)} +
+ ))} +
+ )} +
+
+ + {gym.kind === 'REAL' && } + + setEditOpen(false)} + title={t('manageEquipment')} + className="sm:max-w-2xl" + > + { + void queryClient.invalidateQueries({ queryKey: ['gym', id] }); + }} + /> + + + ); +} diff --git a/admin/src/pages/gyms/GymGalleryPage.tsx b/admin/src/pages/gyms/GymGalleryPage.tsx new file mode 100644 index 0000000..3f8aac6 --- /dev/null +++ b/admin/src/pages/gyms/GymGalleryPage.tsx @@ -0,0 +1,118 @@ +import { useState } from 'react'; +import { useParams } from 'react-router-dom'; +import { useTranslation } from 'react-i18next'; +import { useQuery, useQueryClient } from '@tanstack/react-query'; +import { Image as ImageIcon } from 'lucide-react'; +import { api } from '../../api/client'; +import type { Gym, 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 { GallerySection } from './GymDetail'; + +/* Podstrona galerii (read-only): pełna siatka zdjęć + podgląd; edycja modalem + GallerySection (akcja „Edytuj zdjęcia” w menu). */ +export default function GymGalleryPage() { + const { t } = useTranslation('gyms'); + const { id } = useParams(); + const queryClient = useQueryClient(); + const { + data: gym, + isLoading, + error, + } = useQuery({ + queryKey: ['gym', id], + queryFn: () => api(`/admin/gyms/${id}`), + enabled: !!id, + }); + + const [editOpen, setEditOpen] = useState(false); + const [preview, setPreview] = useState(null); + + const actions: TopbarAction[] | undefined = gym + ? [{ label: t('galleryPage.editAction'), onClick: () => setEditOpen(true) }] + : undefined; + useTopbar({ title: t('galleryPage.title'), back: `/gyms/${id}`, actions }); + + if (isLoading) return ; + if (error) + return ( + <> + + + {t('common:errorPrefix')} + {(error as Error).message} + + + ); + if (!gym) { + return ( + <> + + {t('notFound')} + + ); + } + + const photos = gym.photos ?? []; + return ( + <> + {/* HERO-LITE: nazwa siłowni + licznik zdjęć (tytuł h1 należy do topbaru) */} +
+
+ + {gym.name} + +

+ {t('galleryPage.photosCount', { count: photos.length })} +

+
+ +
+ + + + {photos.length === 0 ? ( +
+
+ ) : ( +
+ {photos.map((p) => ( + + ))} +
+ )} +
+ + setPreview(null)} title={t('galleryPage.title')}> + {preview && ( + + )} + + + setEditOpen(false)} title={t('manageGallery')}> + { + void queryClient.invalidateQueries({ queryKey: ['gym', id] }); + }} + /> + + + ); +} diff --git a/admin/test/GymDetail.test.tsx b/admin/test/GymDetail.test.tsx index 71772c3..5123127 100644 --- a/admin/test/GymDetail.test.tsx +++ b/admin/test/GymDetail.test.tsx @@ -3,6 +3,7 @@ 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 GymEquipmentPage from '../src/pages/gyms/GymEquipmentPage'; import { setAccessToken } from '../src/api/client'; import { useTopbarStore } from '../src/topbar/store'; import { Topbar } from '../src/topbar'; @@ -102,6 +103,20 @@ function stubGymFetch(options: { gym?: Gym; calls?: Call[] } = {}) { }, }); if (url.includes('/admin/users')) return jsonResponse(200, { users: [U1] }); + if (url.includes('/admin/announcements')) + return jsonResponse(200, { announcements: [] }); + if (url.includes('/equipment-usage')) + return jsonResponse(200, { + equipment: [ + { + equipmentId: 'eq-2', + name: 'hantle', + nameEn: null, + cells: [{ hour: 18, count: 3 }], + peak: 3, + }, + ], + }); if (url.endsWith('/admin/gyms/g1/equipment') && method === 'POST') { return jsonResponse(200, { gym: G1_EQ, @@ -131,14 +146,15 @@ function actionButton(label: string): HTMLElement { return btn; } -function renderGymDetail() { +function renderGymDetail(initialPath = '/gyms/g1') { const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } }); return render( - + } /> + } /> , @@ -154,7 +170,7 @@ afterEach(() => { }); describe('admin GymDetail page', () => { - it('shows read-only details, owners and top-menu groups (app parity)', async () => { + it('pokazuje szczegóły odczytu, kafelki sekcji i pojedynczą grupę menu „Zarządzaj”', async () => { stubGymFetch(); renderGymDetail(); expect(await screen.findByRole('heading', { name: 'Gym A' })).toBeInTheDocument(); @@ -165,25 +181,44 @@ describe('admin GymDetail page', () => { expect(screen.getByText('12 członków')).toBeInTheDocument(); expect(screen.getByText('Anna Kowalska')).toBeInTheDocument(); - // menu kontekstowe: grupy Edycja/Galeria/Urządzenia + admin-only Właściciele + Ogłoszenia + // kafelki sekcji prowadzą do podstron (galeria/urządzenia/ogłoszenia) + expect(screen.getByRole('link', { name: /Galeria zdjęć/ })).toBeInTheDocument(); + expect(screen.getByRole('link', { name: /Urządzenia/ })).toBeInTheDocument(); + expect(screen.getByRole('link', { name: /Ogłoszenia/ })).toBeInTheDocument(); + + // menu kontekstowe: JEDNA grupa „Zarządzaj” z akcjami strony (admin: + Właściciele) const config = useTopbarStore.getState().config; - expect(config?.groups?.map((g) => g.id)).toEqual([ - 'edit', - 'gallery', - 'qr', - 'equipment', - 'owners', - 'announcements', + expect(config?.groups?.map((g) => g.id)).toEqual(['manage']); + expect(config?.groups?.[0]?.actions?.map((a) => a.label)).toEqual([ + 'Podstawowe informacje', + 'Galeria', + 'Kod QR', + 'Urządzenia', + 'Ogłoszenia', + 'Właściciele', + 'Usuń siłownię', ]); - expect(config?.actions?.some((a) => a.label === 'Usuń siłownię')).toBe(true); + expect(config?.groups?.[0]?.actions?.find((a) => a.label === 'Galeria')?.to).toBe( + '/gyms/g1/gallery', + ); + expect(config?.groups?.[0]?.actions?.find((a) => a.label === 'Urządzenia')?.to).toBe( + '/gyms/g1/equipment', + ); + expect(config?.groups?.[0]?.actions?.find((a) => a.label === 'Ogłoszenia')?.to).toBe( + '/gyms/g1/announcements', + ); }); - it('manages equipment in a modal opened from the „Urządzenia” group', async () => { + it('podstrona urządzeń: mapa ciepła godzinowa + edycja modalem z menu', async () => { const calls = stubGymFetch({ gym: G1_EQ }); renderGymDetail(); expect(await screen.findByRole('heading', { name: 'Gym A' })).toBeInTheDocument(); fireEvent.click(actionButton('Urządzenia')); + expect(await screen.findByText('Korzystanie z urządzeń (godziny)')).toBeInTheDocument(); + expect(await screen.findByTitle('18:00 — 3 użycia')).toBeInTheDocument(); + + fireEvent.click(actionButton('Edytuj urządzenia')); const dialog = await screen.findByRole('dialog'); // select pokazuje cały katalog — sprzęt już dodany jest oznaczony bieżącą ilością diff --git a/admin/test/e2e/admin.spec.ts b/admin/test/e2e/admin.spec.ts index 975c53f..7402e2f 100644 --- a/admin/test/e2e/admin.spec.ts +++ b/admin/test/e2e/admin.spec.ts @@ -42,8 +42,10 @@ test('ponowne dodanie tego samego typu tworzy osobną instancję (bez inkrementa await expect(page).toHaveURL(/\/gyms\/gym-1$/); await expect(page.getByText('Dywan ×3')).toBeVisible(); - // zarządzanie urządzeniami w modalu z grupy „Urządzenia" menu kontekstowego - await page.locator('button[data-slot="button"]', { hasText: 'Urządzenia' }).click(); + // akcja „Urządzenia" (grupa inline na lg+) → podstrona urządzeń; edycja modalem z menu + await page.getByRole('button', { name: 'Urządzenia' }).click(); + await expect(page).toHaveURL(/\/gyms\/gym-1\/equipment$/); + await page.getByRole('button', { name: 'Edytuj urządzenia' }).click(); const addReq = page.waitForRequest( (req) => req.url().endsWith('/admin/gyms/gym-1/equipment') && req.method() === 'POST', ); @@ -61,7 +63,10 @@ test('dodanie urządzenia z własnymi parametrami wysyła spec w POST', async ({ mockApi(page, { gyms: { gyms: [TEST_GYM] } }); await loginAsAdmin(page); await page.getByRole('link', { name: 'Fit Factory' }).click(); - await page.locator('button[data-slot="button"]', { hasText: 'Urządzenia' }).click(); + // akcja „Urządzenia" → podstrona urządzeń; edycja modalem z menu + await page.getByRole('button', { name: 'Urządzenia' }).click(); + await expect(page).toHaveURL(/\/gyms\/gym-1\/equipment$/); + await page.getByRole('button', { name: 'Edytuj urządzenia' }).click(); const addReq = page.waitForRequest( (req) => req.url().endsWith('/admin/gyms/gym-1/equipment') && req.method() === 'POST', diff --git a/admin/test/e2e/gym-gallery.spec.ts b/admin/test/e2e/gym-gallery.spec.ts index ce257c2..b3fe366 100644 --- a/admin/test/e2e/gym-gallery.spec.ts +++ b/admin/test/e2e/gym-gallery.spec.ts @@ -20,10 +20,15 @@ test('admin zarządza galerią zdjęć siłowni REAL (upload/okładka/usuwanie)' await loginAsAdmin(page); await page.getByRole('link', { name: 'Fit Factory' }).click(); await expect(page).toHaveURL(/\/gyms\/gym-1$/); + await expect(page.getByRole('link', { name: /Galeria zdjęć/ })).toBeVisible(); + + // kafelek galerii → podstrona galerii (read-only) + await page.getByRole('link', { name: /Galeria zdjęć/ }).click(); + await expect(page).toHaveURL(/\/gyms\/gym-1\/gallery$/); await expect(page.getByRole('heading', { name: 'Galeria zdjęć' })).toBeVisible(); - // zarządzanie galerią ukryte w grupie „Galeria" menu kontekstowego — otwórz modal - await page.locator('button[data-slot="button"]', { hasText: 'Galeria' }).click(); + // zarządzanie galerią: modal z akcji menu (grupa inline na lg+ → „Edytuj zdjęcia") + await page.getByRole('button', { name: 'Edytuj zdjęcia' }).click(); // start: 2 zdjęcia, pierwsze jest okładką const removeBtn = page.getByRole('button', { name: 'Usuń zdjęcie' });