diff --git a/admin/src/pages/gyms/GymDetail.tsx b/admin/src/pages/gyms/GymDetail.tsx index 9682c8c..c125fbe 100644 --- a/admin/src/pages/gyms/GymDetail.tsx +++ b/admin/src/pages/gyms/GymDetail.tsx @@ -3,6 +3,7 @@ import { useNavigate, useParams } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { useQuery, useQueryClient } from '@tanstack/react-query'; import { + CalendarX, Crown, Dumbbell, Image as ImageIcon, @@ -63,39 +64,98 @@ import { Textarea, } from '../../components/ui'; import { AvailabilityEditor } from '../../components/AvailabilityEditor'; -import { dayFull, normalizeAvailability, TIME_SLOTS } from '../../lib/availability'; +import { + dayFull, + dayShort, + formatDayRange, + normalizeAvailability, + TIME_SLOTS, +} from '../../lib/availability'; import { fmtDate, fmtNumber } from '../../lib/format'; -/* Lista godzin otwarcia: wiersz na dzień (czytelna w wąskiej kolumnie), „dziś” wyróżnione. */ -function HoursList({ gym }: { gym: Gym }) { +/* 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: + siedem dni, „dziś” wyróżnione, dni otwarte akcentowo; na telefonie skróty. + Wyjątki tylko do odczytu — ich dodawanie/usuwanie zostaje w modalu Edycja. */ +function HoursBand({ gym }: { gym: Gym }) { const { t } = useTranslation('gyms'); const availability = normalizeAvailability(gym.availability); const todayIdx = (new Date().getDay() + 6) % 7; - const fmt = (r: { start: string; end: string } | null) => - r ? `${r.start}–${r.end}` : t('closed'); + const { data } = useQuery({ + queryKey: ['gym-exceptions', gym.id], + queryFn: () => api<{ exceptions: GymException[] }>(`/admin/gyms/${gym.id}/exceptions`), + }); + const exceptions = data?.exceptions ?? []; + const hasHours = availability.some(Boolean); + if (!hasHours && exceptions.length === 0) return null; return ( -
- {availability.map((day, i) => ( + + {hasHours && ( + <> + +
+ {availability.map((day, i) => ( +
+
+ {/* telefon: skrót dnia + zwarty zakres; desktop: pełna nazwa + pełne godziny */} + {dayShort(i)} + + {dayFull(i)} + {i === todayIdx && ( + + {t('today')} + + )} + +
+
+ {day ? formatDayRange(day) : '—'} + + {day ? `${day.start}–${day.end}` : t('closed')} + +
+
+ ))} +
+ + )} + {exceptions.length > 0 && (
- - {dayFull(i)} - {i === todayIdx && ( - - {t('today')} + + {t('exceptions')} + + {exceptions.map((ex) => ( + + + {fmtDate(ex.date)} + + {ex.availability ? `${ex.availability.start}–${ex.availability.end}` : t('closed')} - )} - - - {fmt(day)} - + + ))}
- ))} -
+ )} + ); } @@ -851,6 +911,9 @@ 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) */}
@@ -873,14 +936,6 @@ export default function GymDetail() { )} - - - -
- {t('exceptions')} -
- -
diff --git a/admin/test/e2e/admin.spec.ts b/admin/test/e2e/admin.spec.ts index 2b80d95..975c53f 100644 --- a/admin/test/e2e/admin.spec.ts +++ b/admin/test/e2e/admin.spec.ts @@ -25,6 +25,10 @@ test('kliknięcie w siłownię otwiera podstronę z detalami', async ({ page }) await page.getByRole('link', { name: 'Fit Factory' }).click(); await expect(page).toHaveURL(/\/gyms\/gym-1$/); await expect(page.getByRole('heading', { name: 'Fit Factory' })).toBeVisible(); + // pasek godzin w całym wierszu pod hero (widok odczytu jak w apce) + wyjątek harmonogramu + await expect(page.getByRole('heading', { name: 'Godziny otwarcia' })).toBeVisible(); + await expect(page.getByText('06:00–22:00')).toBeVisible(); + await expect(page.getByText('10:00–14:00')).toBeVisible(); // menu kontekstowe podstrony detalu nie dziedziczy akcji ze strony listy (brak ikony ➕) await expect(page.getByRole('button', { name: 'Dodawanie' })).not.toBeVisible(); }); diff --git a/admin/test/e2e/mock-api.ts b/admin/test/e2e/mock-api.ts index 07f690f..ca0dc52 100644 --- a/admin/test/e2e/mock-api.ts +++ b/admin/test/e2e/mock-api.ts @@ -588,12 +588,22 @@ export function mockApi(page: Page, opts: MockApiOptions = {}) { return route.fulfill({ status: 405 }); }); - // Wyjątki harmonogramu — pusta lista (detail siłowni odświeża widok godzin). + // Wyjątki harmonogramu — jeden wyjątek dla gym-1 (pokrywa chipy wyjątków pod paskiem godzin). page.route('**/api/v1/admin/gyms/*/exceptions*', (route) => route.fulfill({ status: 200, contentType: 'application/json', - body: JSON.stringify({ exceptions: [] }), + body: JSON.stringify({ + exceptions: [ + { + id: 'ex-1', + gymId: 'gym-1', + date: '2026-12-24', + availability: { start: '10:00', end: '14:00' }, + createdAt: '2026-12-01T00:00:00.000Z', + }, + ], + }), }), ); diff --git a/app/src/pages/gyms/GymDetail.tsx b/app/src/pages/gyms/GymDetail.tsx index 9eb0b98..d03f7d0 100644 --- a/app/src/pages/gyms/GymDetail.tsx +++ b/app/src/pages/gyms/GymDetail.tsx @@ -99,7 +99,14 @@ function HoursBand({ gym }: { gym: Gym }) { > {/* telefon: skrót dnia + zwarty zakres; desktop: pełna nazwa + pełne godziny */} {dayShort(i)} - {dayFull(i)} + + {dayFull(i)} + {i === todayIdx && ( + + {t('common:fmt.today')} + + )} +