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)
This commit is contained in:
@@ -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() {
|
||||
<Route path="/gyms" element={<GymsList />} />
|
||||
<Route path="/gyms/new" element={<GymForm />} />
|
||||
<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 />} />
|
||||
<Route path="/users" element={<UsersList />} />
|
||||
<Route path="/users/new" element={<UserForm />} />
|
||||
<Route path="/users/:id" element={<UserDetail />} />
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
110
admin/src/pages/gyms/GymAnnouncementsPage.tsx
Normal file
110
admin/src/pages/gyms/GymAnnouncementsPage.tsx
Normal file
@@ -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<Gym>(`/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 <Loading />;
|
||||
if (error)
|
||||
return (
|
||||
<>
|
||||
<BackButton to={`/gyms/${id}`} className="mb-4" />
|
||||
<ErrorText>
|
||||
{t('common:errorPrefix')}
|
||||
{(error as Error).message}
|
||||
</ErrorText>
|
||||
</>
|
||||
);
|
||||
if (!gym) {
|
||||
return (
|
||||
<>
|
||||
<BackButton to={`/gyms/${id}`} className="mb-4" />
|
||||
<ErrorText>{t('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('groupAnnouncements')} />
|
||||
{announcements.length === 0 ? (
|
||||
<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('noAnnouncements')}</p>
|
||||
</div>
|
||||
) : (
|
||||
<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 justify-between gap-3">
|
||||
<span className="min-w-0 truncate text-[0.9rem] font-bold">{a.title}</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>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
<Modal
|
||||
open={composerOpen}
|
||||
onClose={() => setComposerOpen(false)}
|
||||
title={t('announcementsTitle')}
|
||||
>
|
||||
<GymAnnouncementsSection key={gym.id} gym={gym} />
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -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 <p className="text-[0.875rem] text-dim">{t('noPhotos')}</p>;
|
||||
}
|
||||
const [first, ...rest] = photos;
|
||||
const preview = 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('photosMore', { 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('gallerySection')}
|
||||
</span>
|
||||
<span className="shrink-0 text-[0.72rem] font-semibold tabular-nums text-dim">
|
||||
{t('tilePhotos', { count: photos.length })}
|
||||
</span>
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
/* 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 <p className="text-[0.875rem] text-dim">{t('noEquipment')}</p>;
|
||||
}
|
||||
/* 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 (
|
||||
<div className="grid grid-cols-1 gap-2 sm:grid-cols-2">
|
||||
{gym.equipment.map((e) => (
|
||||
<div
|
||||
key={e.id}
|
||||
className="flex items-center justify-between gap-2 rounded-[10px] border border-line bg-card/50 px-3 py-2.5 text-[0.85rem] font-semibold"
|
||||
>
|
||||
<span className="min-w-0 truncate">{formatGymEquipment(e, i18n.language)}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<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-2 content-center gap-1.5">
|
||||
{preview.length === 0 ? (
|
||||
<div className="col-span-2 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) => (
|
||||
<span
|
||||
key={e.id}
|
||||
className="min-w-0 truncate rounded-[8px] border border-line bg-input/50 px-1.5 py-1 text-[0.65rem] font-semibold text-dim"
|
||||
>
|
||||
{formatGymEquipment(e, i18n.language)}
|
||||
</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('groupEquipment')}
|
||||
</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 } = useQuery({
|
||||
queryKey: ['admin-announcements', gymId],
|
||||
queryFn: () =>
|
||||
api<{ announcements: AdminAnnouncement[] }>(
|
||||
`/admin/announcements?gymId=${encodeURIComponent(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('noAnnouncements')}</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('groupAnnouncements')}
|
||||
</span>
|
||||
<span className="shrink-0 text-[0.72rem] font-semibold tabular-nums text-dim">
|
||||
{t('tileAnnouncementsCount', { count: announcements.length })}
|
||||
</span>
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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 <Loading />;
|
||||
@@ -914,19 +950,18 @@ export default function GymDetail() {
|
||||
{/* GODZINY: cały wiersz bezpośrednio pod hero (jak w apce) */}
|
||||
<HoursBand gym={gym} />
|
||||
|
||||
{/* DWIE KOLUMNY (widok odczytu identyczny jak w apce; edycja w grupach menu) */}
|
||||
{/* 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('gallerySection')} />
|
||||
<GalleryMosaic gym={gym} />
|
||||
</Card>
|
||||
)}
|
||||
<Card>
|
||||
<SectionHeader title={t('groupEquipment')} description={t('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">
|
||||
@@ -990,27 +1025,9 @@ export default function GymDetail() {
|
||||
<ExceptionsEditor gymId={gym.id} />
|
||||
</div>
|
||||
</Modal>
|
||||
<Modal open={galleryOpen} onClose={() => setGalleryOpen(false)} title={t('manageGallery')}>
|
||||
<GallerySection key={gym.id} gym={gym} onChanged={() => void invalidate()} />
|
||||
</Modal>
|
||||
<Modal
|
||||
open={equipmentOpen}
|
||||
onClose={() => setEquipmentOpen(false)}
|
||||
title={t('manageEquipment')}
|
||||
className="sm:max-w-2xl"
|
||||
>
|
||||
<EquipmentSection key={gym.id} gym={gym} onChanged={() => void invalidate()} />
|
||||
</Modal>
|
||||
<Modal open={ownersOpen} onClose={() => setOwnersOpen(false)} title={t('manageOwners')}>
|
||||
<OwnersSection key={gym.id} gym={gym} onChanged={() => void invalidate()} />
|
||||
</Modal>
|
||||
<Modal
|
||||
open={announcementsOpen}
|
||||
onClose={() => setAnnouncementsOpen(false)}
|
||||
title={t('announcementsTitle')}
|
||||
>
|
||||
<GymAnnouncementsSection key={gym.id} gym={gym} />
|
||||
</Modal>
|
||||
{gym.kind === 'REAL' && (
|
||||
<GymQrModal
|
||||
open={qrOpen}
|
||||
@@ -1035,7 +1052,7 @@ export default function GymDetail() {
|
||||
}
|
||||
|
||||
/* Awaryjne ogłoszenia w imieniu siłowni (gdy właściciel nie może sam). */
|
||||
function GymAnnouncementsSection({ gym }: { gym: Gym }) {
|
||||
export function GymAnnouncementsSection({ gym }: { gym: Gym }) {
|
||||
const { t } = useTranslation('gyms');
|
||||
const queryClient = useQueryClient();
|
||||
const { data, isLoading } = useQuery({
|
||||
@@ -1224,7 +1241,7 @@ function AddSpecFields({
|
||||
return null;
|
||||
}
|
||||
|
||||
function EquipmentSection({ gym, onChanged }: { gym: Gym; onChanged: () => 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<unknown> {
|
||||
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('');
|
||||
|
||||
220
admin/src/pages/gyms/GymEquipmentPage.tsx
Normal file
220
admin/src/pages/gyms/GymEquipmentPage.tsx
Normal file
@@ -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 (
|
||||
<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): 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<Gym>(`/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 = (
|
||||
<Select
|
||||
size="sm"
|
||||
value={String(rangeDays)}
|
||||
onChange={(e) => setRangeDays(Number(e.target.value))}
|
||||
aria-label={t('equipmentPage.usage.rangeAria')}
|
||||
>
|
||||
{RANGE_OPTIONS.map((d) => (
|
||||
<option key={d} value={String(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)
|
||||
return (
|
||||
<>
|
||||
<BackButton to={`/gyms/${id}`} className="mb-4" />
|
||||
<ErrorText>
|
||||
{t('common:errorPrefix')}
|
||||
{(error as Error).message}
|
||||
</ErrorText>
|
||||
</>
|
||||
);
|
||||
if (!gym) {
|
||||
return (
|
||||
<>
|
||||
<BackButton to={`/gyms/${id}`} className="mb-4" />
|
||||
<ErrorText>{t('notFound')}</ErrorText>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const equipment = gym.equipment;
|
||||
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('groupEquipment')} description={t('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('noEquipment')}</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 gap-2 sm:grid-cols-2">
|
||||
{equipment.map((e) => (
|
||||
<div
|
||||
key={e.id}
|
||||
className="flex items-center justify-between gap-2 rounded-[10px] border border-line bg-card/50 px-3 py-2.5 text-[0.85rem] font-semibold"
|
||||
>
|
||||
<span className="min-w-0 truncate">{formatGymEquipment(e, i18n.language)}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{gym.kind === 'REAL' && <EquipmentUsageHeatmap gymId={gym.id} rangeDays={rangeDays} />}
|
||||
|
||||
<Modal
|
||||
open={editOpen}
|
||||
onClose={() => setEditOpen(false)}
|
||||
title={t('manageEquipment')}
|
||||
className="sm:max-w-2xl"
|
||||
>
|
||||
<EquipmentSection
|
||||
key={gym.id}
|
||||
gym={gym}
|
||||
onChanged={() => {
|
||||
void queryClient.invalidateQueries({ queryKey: ['gym', id] });
|
||||
}}
|
||||
/>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
118
admin/src/pages/gyms/GymGalleryPage.tsx
Normal file
118
admin/src/pages/gyms/GymGalleryPage.tsx
Normal file
@@ -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<Gym>(`/admin/gyms/${id}`),
|
||||
enabled: !!id,
|
||||
});
|
||||
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [preview, setPreview] = useState<GymPhoto | null>(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 <Loading />;
|
||||
if (error)
|
||||
return (
|
||||
<>
|
||||
<BackButton to={`/gyms/${id}`} className="mb-4" />
|
||||
<ErrorText>
|
||||
{t('common:errorPrefix')}
|
||||
{(error as Error).message}
|
||||
</ErrorText>
|
||||
</>
|
||||
);
|
||||
if (!gym) {
|
||||
return (
|
||||
<>
|
||||
<BackButton to={`/gyms/${id}`} className="mb-4" />
|
||||
<ErrorText>{t('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('gallerySection')} />
|
||||
{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('noPhotos')}</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 open={editOpen} onClose={() => setEditOpen(false)} title={t('manageGallery')}>
|
||||
<GallerySection
|
||||
key={gym.id}
|
||||
gym={gym}
|
||||
onChanged={() => {
|
||||
void queryClient.invalidateQueries({ queryKey: ['gym', id] });
|
||||
}}
|
||||
/>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -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(
|
||||
<MemoryRouter initialEntries={['/gyms/g1']}>
|
||||
<MemoryRouter initialEntries={[initialPath]}>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<Topbar />
|
||||
<Routes>
|
||||
<Route path="/gyms/:id" element={<GymDetail />} />
|
||||
<Route path="/gyms/:id/equipment" element={<GymEquipmentPage />} />
|
||||
</Routes>
|
||||
</QueryClientProvider>
|
||||
</MemoryRouter>,
|
||||
@@ -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ą
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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' });
|
||||
|
||||
Reference in New Issue
Block a user