Silownie: lustrzany pasek godzin pod hero w adminie (widok odczytu jak w apce) + badge dzis w pasku tygodnia
This commit is contained in:
@@ -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 (
|
||||
<div className="flex flex-col gap-1">
|
||||
{availability.map((day, i) => (
|
||||
<Card className="mb-5 p-4 sm:p-5">
|
||||
{hasHours && (
|
||||
<>
|
||||
<SectionHeader title={t('hours')} />
|
||||
<div className="grid grid-cols-7 gap-1 sm:gap-1.5">
|
||||
{availability.map((day, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className={`min-w-0 rounded-[10px] px-1 py-2 text-center sm:px-2 ${
|
||||
day ? 'bg-accent/10' : 'bg-input/50'
|
||||
} ${i === todayIdx ? 'outline outline-1 outline-accent/50' : ''}`}
|
||||
>
|
||||
<div
|
||||
className={`truncate text-[0.74rem] font-semibold sm:text-[0.78rem] ${
|
||||
day ? 'text-accent-text' : 'text-dim/60'
|
||||
}`}
|
||||
>
|
||||
{/* telefon: skrót dnia + zwarty zakres; desktop: pełna nazwa + pełne godziny */}
|
||||
<span className="uppercase tracking-wide sm:hidden">{dayShort(i)}</span>
|
||||
<span className="hidden items-center justify-center gap-1.5 sm:flex">
|
||||
{dayFull(i)}
|
||||
{i === todayIdx && (
|
||||
<span className="rounded-full bg-accent px-1.5 py-0.5 text-[0.58rem] font-extrabold uppercase tracking-wide text-accent-ink">
|
||||
{t('today')}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
className={`truncate text-[0.66rem] font-semibold tabular-nums sm:text-[0.8rem] ${
|
||||
day ? 'text-ink' : 'text-dim/50'
|
||||
}`}
|
||||
>
|
||||
<span className="sm:hidden">{day ? formatDayRange(day) : '—'}</span>
|
||||
<span className="hidden sm:block">
|
||||
{day ? `${day.start}–${day.end}` : t('closed')}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{exceptions.length > 0 && (
|
||||
<div
|
||||
key={i}
|
||||
className={`flex items-center justify-between gap-3 rounded-[10px] px-3 py-1.5 text-[0.85rem] ${
|
||||
i === todayIdx ? 'bg-accent/10 outline outline-1 outline-accent/40' : ''
|
||||
className={`flex flex-wrap items-center gap-2 ${
|
||||
hasHours ? 'mt-4 border-t border-line pt-3.5' : ''
|
||||
}`}
|
||||
>
|
||||
<span className={`flex items-center gap-2 ${day ? 'font-semibold' : 'text-dim/70'}`}>
|
||||
{dayFull(i)}
|
||||
{i === todayIdx && (
|
||||
<span className="rounded-full bg-accent px-2 py-0.5 text-[0.62rem] font-extrabold uppercase tracking-wide text-accent-ink">
|
||||
{t('today')}
|
||||
<span className="text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
|
||||
{t('exceptions')}
|
||||
</span>
|
||||
{exceptions.map((ex) => (
|
||||
<span
|
||||
key={ex.id}
|
||||
className="inline-flex items-center gap-1.5 rounded-[10px] border border-dashed border-danger/40 bg-danger/7 px-2.5 py-1 text-[0.78rem]"
|
||||
>
|
||||
<CalendarX className="h-3 w-3 shrink-0 text-danger" />
|
||||
<b className="tabular-nums">{fmtDate(ex.date)}</b>
|
||||
<span className="text-dim">
|
||||
{ex.availability ? `${ex.availability.start}–${ex.availability.end}` : t('closed')}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
<span className={`tabular-nums ${day ? 'font-semibold' : 'text-dim/60'}`}>
|
||||
{fmt(day)}
|
||||
</span>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -851,6 +911,9 @@ export default function GymDetail() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 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) */}
|
||||
<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">
|
||||
@@ -873,14 +936,6 @@ export default function GymDetail() {
|
||||
<PresenceTelemetry gymId={gym.id} rangeDays={presenceRange} />
|
||||
</Card>
|
||||
)}
|
||||
<Card>
|
||||
<SectionHeader title={t('hours')} />
|
||||
<HoursList gym={gym} />
|
||||
<div className="mt-4 mb-2 text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
|
||||
{t('exceptions')}
|
||||
</div>
|
||||
<ExceptionsList gymId={gym.id} />
|
||||
</Card>
|
||||
<Card>
|
||||
<SectionHeader title={t('data')} />
|
||||
<div className="grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5 text-[0.85rem]">
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
],
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -99,7 +99,14 @@ function HoursBand({ gym }: { gym: Gym }) {
|
||||
>
|
||||
{/* telefon: skrót dnia + zwarty zakres; desktop: pełna nazwa + pełne godziny */}
|
||||
<span className="uppercase tracking-wide sm:hidden">{dayShort(i)}</span>
|
||||
<span className="hidden sm:block">{dayFull(i)}</span>
|
||||
<span className="hidden items-center justify-center gap-1.5 sm:flex">
|
||||
{dayFull(i)}
|
||||
{i === todayIdx && (
|
||||
<span className="rounded-full bg-accent px-1.5 py-0.5 text-[0.58rem] font-extrabold uppercase tracking-wide text-accent-ink">
|
||||
{t('common:fmt.today')}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
className={`truncate text-[0.66rem] font-semibold tabular-nums sm:text-[0.8rem] ${
|
||||
|
||||
Reference in New Issue
Block a user