From 5b54c29a9f36eaac04e69d75e047a89ac7733662 Mon Sep 17 00:00:00 2001 From: tisachi Date: Fri, 23 Oct 2026 20:11:48 +0200 Subject: [PATCH] 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) --- app/src/App.tsx | 6 + app/src/api/queries.ts | 18 + app/src/api/types.ts | 15 + app/src/i18n/locales/en/gyms.json | 30 ++ app/src/i18n/locales/pl/gyms.json | 40 ++ app/src/pages/gyms/GymAnnouncementsPage.tsx | 234 +++++++++ app/src/pages/gyms/GymDetail.tsx | 500 +++++++------------- app/src/pages/gyms/GymEquipmentPage.tsx | 237 ++++++++++ app/src/pages/gyms/GymGalleryPage.tsx | 100 ++++ app/test/e2e/gym-gallery.spec.ts | 12 +- app/test/e2e/gyms.spec.ts | 58 ++- app/test/e2e/mock-api.ts | 22 + app/test/e2e/presence.spec.ts | 11 +- app/test/gym-detail.test.tsx | 222 +++++++++ 14 files changed, 1155 insertions(+), 350 deletions(-) create mode 100644 app/src/pages/gyms/GymAnnouncementsPage.tsx create mode 100644 app/src/pages/gyms/GymEquipmentPage.tsx create mode 100644 app/src/pages/gyms/GymGalleryPage.tsx create mode 100644 app/test/gym-detail.test.tsx diff --git a/app/src/App.tsx b/app/src/App.tsx index c560c9c..e13f54d 100644 --- a/app/src/App.tsx +++ b/app/src/App.tsx @@ -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() { } /> } /> } /> + } /> + } /> + } /> { + 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) { diff --git a/app/src/api/types.ts b/app/src/api/types.ts index 5ff90aa..951835b 100644 --- a/app/src/api/types.ts +++ b/app/src/api/types.ts @@ -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; diff --git a/app/src/i18n/locales/en/gyms.json b/app/src/i18n/locales/en/gyms.json index 74418d3..d538cde 100644 --- a/app/src/i18n/locales/en/gyms.json +++ b/app/src/i18n/locales/en/gyms.json @@ -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}}", diff --git a/app/src/i18n/locales/pl/gyms.json b/app/src/i18n/locales/pl/gyms.json index ef5b188..c0c647c 100644 --- a/app/src/i18n/locales/pl/gyms.json +++ b/app/src/i18n/locales/pl/gyms.json @@ -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}}", diff --git a/app/src/pages/gyms/GymAnnouncementsPage.tsx b/app/src/pages/gyms/GymAnnouncementsPage.tsx new file mode 100644 index 0000000..b9667aa --- /dev/null +++ b/app/src/pages/gyms/GymAnnouncementsPage.tsx @@ -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 ; + if (error || !gym) { + return ( + <> + + {t('detail.notFound')} + + ); + } + + return ( + <> + {/* HERO-LITE: nazwa siłowni (tytuł h1 należy do topbaru) */} +
+
+ + {gym.name} + +

{t('announcementsPage.subtitle')}

+
+ +
+ + + + + + + setComposerOpen(false)} + title={t('detail.modalAnnouncements')} + > + + + + ); +} + +/* 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 ; + if (announcements.length === 0) { + return ( +
+
+ ); + } + return ( +
+ {announcements.map((a) => ( +
+
+ {a.title} + {a.kind !== 'MANUAL' && ( + + {t('announcements.systemBadge')} + + )} + + {fmtDateTime(a.createdAt)} + +
+

{a.body}

+
+ ))} +
+ ); +} + +/* 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 ( +
+
+
+ {t('announcements.composerTitle')} +
+ setTitle(e.target.value)} + placeholder={t('announcements.titlePh')} + aria-label={t('announcements.titleAria')} + maxLength={120} + /> +