-
-
+
+
+ {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' });