Plany: akcje Wstecz/Dalej/Zapisz w menu kontekstowym topbar, nazwa tygodnia pod silownia (stopka tylko podsumowanie)
This commit is contained in:
@@ -14,15 +14,15 @@ import {
|
||||
useExercises,
|
||||
type PlanBody,
|
||||
} from '../../api/queries';
|
||||
import { CalendarX, Check } from 'lucide-react';
|
||||
import { CalendarX, Check, ChevronLeft, ChevronRight } from 'lucide-react';
|
||||
import {
|
||||
BackButton,
|
||||
Button,
|
||||
Card,
|
||||
ConfirmDialog,
|
||||
EmptyState,
|
||||
ErrorText,
|
||||
Field,
|
||||
Input,
|
||||
isPastWeek,
|
||||
Select,
|
||||
Skeleton,
|
||||
@@ -144,6 +144,22 @@ export default function PlanEditor() {
|
||||
else navigate(backPath);
|
||||
};
|
||||
|
||||
// Walidacja kroku 1 (potrzebna w akcji topbar — przed useTopbar):
|
||||
// pusty tytuł lub tydzień startu w przeszłości blokują „Dalej”. Krok 2 → 3 zawsze.
|
||||
const startWeekError =
|
||||
!isEdit && editor.startDate && isPastWeek(editor.startDate)
|
||||
? 'Tydzień startu nie może być w przeszłości'
|
||||
: '';
|
||||
const step1Valid = editor.title.trim() !== '' && !startWeekError;
|
||||
const goToStep = (n: number) => {
|
||||
if (n <= step) {
|
||||
setStep(n);
|
||||
return;
|
||||
}
|
||||
if (n === 2 && step1Valid) setStep(2);
|
||||
if (n === 3 && step1Valid) setStep(3);
|
||||
};
|
||||
|
||||
useTopbar({
|
||||
title: isTraineeMode
|
||||
? isEdit
|
||||
@@ -159,10 +175,30 @@ export default function PlanEditor() {
|
||||
: '/plans',
|
||||
// mobile „<” w dolnym pasku topmenu: potwierdzenie przy niezapisanych zmianach
|
||||
onBack: editor.dirty ? requestExit : undefined,
|
||||
// akcja główna w menu kontekstowym (grupa ⋯; na lg+ inline w nagłówku)
|
||||
// nawigacja wizarda + zapis w menu kontekstowym (grupa ⋯; na lg+ inline w nagłówku)
|
||||
actions: [
|
||||
...(step > 1
|
||||
? [
|
||||
{
|
||||
label: 'Wstecz',
|
||||
icon: ChevronLeft,
|
||||
variant: 'secondary' as const,
|
||||
onClick: () => setStep(step - 1),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...(step < 3
|
||||
? [
|
||||
{
|
||||
label: 'Dalej',
|
||||
icon: ChevronRight,
|
||||
onClick: () => goToStep(step + 1),
|
||||
disabled: step === 1 && !step1Valid,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
label: 'Zatwierdź plan',
|
||||
label: isEdit ? 'Zapisz zmiany' : 'Zapisz',
|
||||
icon: Check,
|
||||
onClick: () => save(),
|
||||
disabled: saving,
|
||||
@@ -188,23 +224,8 @@ export default function PlanEditor() {
|
||||
const exercises = exData?.exercises ?? [];
|
||||
const loading = isEdit && !editor.initialized;
|
||||
|
||||
// Walidacja inline: tytuł (po touch) + tydzień startu w przeszłości
|
||||
// Walidacja inline: tytuł (po touch)
|
||||
const titleError = titleTouched && !editor.title.trim() ? 'Podaj tytuł planu' : '';
|
||||
const startWeekError =
|
||||
!isEdit && editor.startDate && isPastWeek(editor.startDate)
|
||||
? 'Tydzień startu nie może być w przeszłości'
|
||||
: '';
|
||||
|
||||
// Krok 1 blokuje przejście: pusty tytuł lub start w przeszłości. Krok 2 → 3 zawsze.
|
||||
const step1Valid = editor.title.trim() !== '' && !startWeekError;
|
||||
const goToStep = (n: number) => {
|
||||
if (n <= step) {
|
||||
setStep(n);
|
||||
return;
|
||||
}
|
||||
if (n === 2 && step1Valid) setStep(2);
|
||||
if (n === 3 && step1Valid) setStep(3);
|
||||
};
|
||||
|
||||
// Podsumowanie stopki: dni/ćwiczenia/serie + tygodnie bez ćwiczeń (nie blokuje)
|
||||
const totals = useMemo(() => {
|
||||
@@ -393,7 +414,7 @@ export default function PlanEditor() {
|
||||
|
||||
{step === 2 && (
|
||||
<>
|
||||
{/* Wybór siłowni (informacyjny) — z członkostw właściciela planu */}
|
||||
{/* Wybór siłowni (informacyjny) + opcjonalna nazwa aktywnego tygodnia */}
|
||||
<Card className="mb-4">
|
||||
<Field label="Siłownia">
|
||||
{gymOptions.length > 0 ? (
|
||||
@@ -423,6 +444,14 @@ export default function PlanEditor() {
|
||||
</p>
|
||||
)}
|
||||
</Field>
|
||||
<Field label={`Nazwa tygodnia ${activeWi + 1} (opcjonalnie)`}>
|
||||
<Input
|
||||
value={week.customName}
|
||||
onChange={(e) => editor.setWeekAlias(activeWi, e.target.value)}
|
||||
placeholder="np. Deload"
|
||||
maxLength={40}
|
||||
/>
|
||||
</Field>
|
||||
</Card>
|
||||
|
||||
{/* Zakładki tygodni (sticky pod topbarem): każdy tydzień z osobna,
|
||||
@@ -458,8 +487,6 @@ export default function PlanEditor() {
|
||||
onCopyPrev={() => editor.copyPrevWeek(activeWi)}
|
||||
canClear={weekDays.length > 0 || !week.detached}
|
||||
onClear={() => setClearWeekIdx(activeWi)}
|
||||
alias={week.customName}
|
||||
onAliasChange={(v) => editor.setWeekAlias(activeWi, v)}
|
||||
>
|
||||
<DayPicker
|
||||
days={weekDays}
|
||||
@@ -536,33 +563,16 @@ export default function PlanEditor() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* sticky stopka; na mobile pod stałym dolnym paskiem topmenu (+ safe-area) */}
|
||||
{/* sticky stopka: tylko belka podsumowania (akcje Wstecz/Dalej/Zapisz są w menu kontekstowym topbar);
|
||||
na mobile pod stałym dolnym paskiem topmenu (+ safe-area) */}
|
||||
<div className="sticky bottom-0 -mx-4 px-4 py-3 bg-bg/95 backdrop-blur border-t border-line mt-2 md:-mx-8 md:px-8 max-md:bottom-[calc(43px+max(0.5rem,env(safe-area-inset-bottom)))]">
|
||||
{error && <ErrorText>{error}</ErrorText>}
|
||||
<div className="flex flex-col gap-2 sm:flex-row sm:items-center">
|
||||
<div className="text-dim text-[0.8125rem]">
|
||||
{dayCountLabel(totals.days)} · {exerciseCountLabel(totals.exercises)} ·{' '}
|
||||
{setCountLabel(totals.sets)}
|
||||
{totals.emptyWeeks > 0 && (
|
||||
<span className="text-warn"> · {weekCountLabel(totals.emptyWeeks)} bez ćwiczeń</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2 sm:ml-auto">
|
||||
{step > 1 && (
|
||||
<Button variant="secondary" onClick={() => setStep(step - 1)}>
|
||||
Wstecz
|
||||
</Button>
|
||||
)}
|
||||
{step < 3 ? (
|
||||
<Button onClick={() => goToStep(step + 1)} disabled={step === 1 && !step1Valid}>
|
||||
Dalej
|
||||
</Button>
|
||||
) : (
|
||||
<Button onClick={() => save()} disabled={saving}>
|
||||
{isEdit ? 'Zapisz zmiany' : 'Zapisz'}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<div className="text-dim text-[0.8125rem]">
|
||||
{dayCountLabel(totals.days)} · {exerciseCountLabel(totals.exercises)} ·{' '}
|
||||
{setCountLabel(totals.sets)}
|
||||
{totals.emptyWeeks > 0 && (
|
||||
<span className="text-warn"> · {weekCountLabel(totals.emptyWeeks)} bez ćwiczeń</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { Copy, Trash2 } from 'lucide-react';
|
||||
import { Badge, Button, Card, Field, H2, Input, type BadgeColor } from '../../../components/ui';
|
||||
import { Badge, Button, Card, H2, type BadgeColor } from '../../../components/ui';
|
||||
|
||||
/* Panel tygodnia (zamiast akordeonu): nagłówek z badge podsumowania + akcje,
|
||||
opcjonalny alias tygodnia, treść zawsze widoczna — przełączanie tygodni
|
||||
odbywa się przez zakładki. */
|
||||
treść zawsze widoczna — przełączanie tygodni odbywa się przez zakładki. */
|
||||
export function WeekPanel({
|
||||
index,
|
||||
summary,
|
||||
@@ -12,8 +11,6 @@ export function WeekPanel({
|
||||
onCopyPrev,
|
||||
canClear,
|
||||
onClear,
|
||||
alias,
|
||||
onAliasChange,
|
||||
children,
|
||||
}: {
|
||||
index: number;
|
||||
@@ -22,9 +19,6 @@ export function WeekPanel({
|
||||
onCopyPrev: () => void;
|
||||
canClear: boolean;
|
||||
onClear: () => void;
|
||||
/** Opcjonalny alias tygodnia (np. „Deload"); undefined = pole ukryte. */
|
||||
alias?: string;
|
||||
onAliasChange?: (v: string) => void;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
@@ -47,18 +41,6 @@ export function WeekPanel({
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{alias !== undefined && onAliasChange && (
|
||||
<div className="mt-4 max-w-xs">
|
||||
<Field label="Nazwa tygodnia (opcjonalnie)">
|
||||
<Input
|
||||
value={alias}
|
||||
onChange={(e) => onAliasChange(e.target.value)}
|
||||
placeholder="np. Deload"
|
||||
maxLength={40}
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
)}
|
||||
<div className="mt-4">{children}</div>
|
||||
</Card>
|
||||
);
|
||||
|
||||
@@ -154,7 +154,7 @@ describe('PlanEditor — data startu i menu kontekstowe', () => {
|
||||
const title = screen.getByPlaceholderText('np. Plan masowy 8-tygodniowy');
|
||||
await user.type(title, 'Plan testowy');
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Zatwierdź plan' }));
|
||||
await user.click(screen.getByRole('button', { name: 'Zapisz' }));
|
||||
await waitFor(() =>
|
||||
expect(capture.createPlanBody).toMatchObject({
|
||||
title: 'Plan testowy',
|
||||
@@ -207,7 +207,7 @@ describe('PlanEditor — data startu i menu kontekstowe', () => {
|
||||
|
||||
const title = screen.getByPlaceholderText('np. Plan masowy 8-tygodniowy');
|
||||
await user.type(title, 'Plan szkic');
|
||||
await user.click(screen.getByRole('button', { name: 'Zatwierdź plan' }));
|
||||
await user.click(screen.getByRole('button', { name: 'Zapisz' }));
|
||||
await waitFor(() => expect(capture.createPlanBody).toBeDefined());
|
||||
expect(capture.createPlanBody).not.toHaveProperty('startDate');
|
||||
});
|
||||
@@ -224,7 +224,9 @@ describe('PlanEditor — data startu i menu kontekstowe', () => {
|
||||
await user.type(screen.getByPlaceholderText('np. Plan masowy 8-tygodniowy'), 'Plan wizard');
|
||||
expect(screen.getByRole('button', { name: 'Dalej' })).toBeEnabled();
|
||||
// 1 tydzień — podsumowanie bez lustrzanych tygodni
|
||||
const weeksField = screen.getByText('Długość (tygodnie)').closest('[data-slot="field"]') as HTMLElement;
|
||||
const weeksField = screen
|
||||
.getByText('Długość (tygodnie)')
|
||||
.closest('[data-slot="field"]') as HTMLElement;
|
||||
await user.selectOptions(within(weeksField).getByRole('combobox'), '1');
|
||||
await user.click(screen.getByRole('button', { name: 'Dalej' }));
|
||||
|
||||
@@ -239,7 +241,7 @@ describe('PlanEditor — data startu i menu kontekstowe', () => {
|
||||
await user.click(screen.getByRole('button', { name: 'dodaj ćwiczenie…' }));
|
||||
await user.click(await screen.findByRole('option', { name: /Przysiady/ }));
|
||||
const aliasField = screen
|
||||
.getByText('Nazwa tygodnia (opcjonalnie)')
|
||||
.getByText('Nazwa tygodnia 1 (opcjonalnie)')
|
||||
.closest('[data-slot="field"]') as HTMLElement;
|
||||
await user.type(within(aliasField).getByRole('textbox'), 'Deload');
|
||||
|
||||
@@ -252,7 +254,9 @@ describe('PlanEditor — data startu i menu kontekstowe', () => {
|
||||
const summaryCard = screen
|
||||
.getByText('Łącznie: 1 dzień · 1 ćwiczenie · 1 seria')
|
||||
.closest('[data-slot="card"]') as HTMLElement;
|
||||
expect(within(summaryCard).getByText('Pon · 1 dzień · 1 ćwiczenie · 1 seria')).toBeInTheDocument();
|
||||
expect(
|
||||
within(summaryCard).getByText('Pon · 1 dzień · 1 ćwiczenie · 1 seria'),
|
||||
).toBeInTheDocument();
|
||||
|
||||
// zapis — body z gymId i customName
|
||||
await user.click(screen.getByRole('button', { name: 'Zapisz' }));
|
||||
|
||||
@@ -30,8 +30,9 @@ test('mobile: tworzenie planu — bezpieczny tap dnia, bottom sheet, edycja seri
|
||||
await login(page);
|
||||
await openNewPlan(page);
|
||||
|
||||
// dodaj dzień (Poniedziałek) — krok 2 po tytule i przejściu „Dalej”
|
||||
// dodaj dzień (Poniedziałek) — krok 2 po tytule i przejściu „Dalej” (grupa „Akcje”)
|
||||
await page.getByPlaceholder('np. Plan masowy 8-tygodniowy').fill('Plan');
|
||||
await page.getByRole('button', { name: 'Akcje' }).click();
|
||||
await page.getByRole('button', { name: 'Dalej' }).click();
|
||||
await page.getByRole('button', { name: 'Pon' }).click();
|
||||
|
||||
@@ -55,9 +56,9 @@ test('mobile: tworzenie planu — bezpieczny tap dnia, bottom sheet, edycja seri
|
||||
await page.getByRole('button', { name: 'Pon' }).click();
|
||||
await page.getByRole('button', { name: 'dodaj ćwiczenie…' }).click();
|
||||
await page.getByRole('option', { name: /Wyciskanie/ }).click();
|
||||
// „Zatwierdź plan" w grupie „Akcje" dolnego paska
|
||||
// „Zapisz" w grupie „Akcje" dolnego paska
|
||||
await page.getByRole('button', { name: 'Akcje' }).click();
|
||||
await page.getByRole('button', { name: 'Zatwierdź plan' }).click();
|
||||
await page.getByRole('button', { name: 'Zapisz' }).click();
|
||||
|
||||
// po utworzeniu — szczegóły planu (mock zwraca „Plan e2e”)
|
||||
await expect(page.getByRole('heading', { name: 'Plan e2e' })).toBeVisible();
|
||||
@@ -71,6 +72,7 @@ test('mobile 320px: brak poziomego scrolla w edytorze', async ({ page }) => {
|
||||
|
||||
// dodaj dzień + ćwiczenie (krok 2) — tabela serii (min-w) nie może przelewać strony
|
||||
await page.getByPlaceholder('np. Plan masowy 8-tygodniowy').fill('Plan');
|
||||
await page.getByRole('button', { name: 'Akcje' }).click();
|
||||
await page.getByRole('button', { name: 'Dalej' }).click();
|
||||
await page.getByRole('button', { name: 'Pon' }).click();
|
||||
await page.getByRole('button', { name: 'dodaj ćwiczenie…' }).click();
|
||||
|
||||
@@ -43,8 +43,8 @@ test('formularz nowego planu ma wybór tygodnia startu i przycisk „Wstecz” w
|
||||
await page.getByPlaceholder('np. Plan masowy 8-tygodniowy').fill('Plan e2e');
|
||||
await page.getByRole('button', { name: 'Następny miesiąc' }).click();
|
||||
await page.getByRole('button', { name: '20', exact: true }).click();
|
||||
// akcja główna w menu kontekstowym (lg+: inline w nagłówku)
|
||||
await page.getByRole('button', { name: 'Zatwierdź plan' }).click();
|
||||
// akcja zapisu w menu kontekstowym (lg+: inline w nagłówku)
|
||||
await page.getByRole('button', { name: 'Zapisz' }).click();
|
||||
|
||||
// po utworzeniu — szczegóły planu (aktywowany z datą startu)
|
||||
await expect(page.getByRole('heading', { name: 'Plan e2e' })).toBeVisible();
|
||||
@@ -59,7 +59,7 @@ test('walidacja tytułu i podsumowanie stopki', async ({ page }) => {
|
||||
await expect(page.getByRole('heading', { name: 'Nowy plan' })).toBeVisible();
|
||||
|
||||
// pusty tytuł → błąd inline pod polem (i w stopce — pierwszy w DOM)
|
||||
await page.getByRole('button', { name: 'Zatwierdź plan' }).click();
|
||||
await page.getByRole('button', { name: 'Zapisz' }).click();
|
||||
await expect(page.getByText('Podaj tytuł planu').first()).toBeVisible();
|
||||
|
||||
// podsumowanie stopki: 0 dni · 0 ćwiczeń · 0 serii + ostrzeżenie o pustych tygodniach
|
||||
|
||||
@@ -82,7 +82,7 @@ test('edytor planu podopiecznego: „Wstaw wyniki" prefylluje serie z ostatniej
|
||||
}) => {
|
||||
await openTraineePlansTab(page);
|
||||
await page.getByRole('button', { name: 'Utwórz plan' }).click();
|
||||
// (lista: akcja tworzenia w topbarze) — w edytorze zapis = „Zatwierdź plan"
|
||||
// (lista: akcja tworzenia w topbarze) — w edytorze zapis = „Zapisz" (menu kontekstowe)
|
||||
|
||||
await expect(page.getByRole('heading', { name: 'Plan dla podopiecznego' })).toBeVisible();
|
||||
// dodaj dzień (Poniedziałek) — krok 2 po tytule i przejściu „Dalej”
|
||||
|
||||
@@ -193,7 +193,9 @@ function jsonResponse(status: number, body: unknown) {
|
||||
});
|
||||
}
|
||||
|
||||
function mockApi(opts: { plans?: unknown[]; capture?: { createBody?: Record<string, unknown> } } = {}) {
|
||||
function mockApi(
|
||||
opts: { plans?: unknown[]; capture?: { createBody?: Record<string, unknown> } } = {},
|
||||
) {
|
||||
const plans = opts.plans ?? PLANS;
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
@@ -386,7 +388,7 @@ describe('PlanEditor — tryb podopiecznego', () => {
|
||||
renderAt(`/trainees/${TRAINEE_ID}/plans/new`);
|
||||
|
||||
await screen.findByRole('heading', { name: 'Plan dla podopiecznego' });
|
||||
await user.click(screen.getByRole('button', { name: 'Zatwierdź plan' }));
|
||||
await user.click(screen.getByRole('button', { name: 'Zapisz' }));
|
||||
// błąd pod polem tytułu + w stopce
|
||||
expect(screen.getAllByText('Podaj tytuł planu').length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
@@ -441,7 +443,9 @@ describe('PlanEditor — wizard 3-etapowy (tryb podopiecznego)', () => {
|
||||
await screen.findByRole('heading', { name: 'Plan dla podopiecznego' });
|
||||
await user.type(screen.getByPlaceholderText('np. Plan masowy 8-tygodniowy'), 'Plan wizard');
|
||||
// 1 tydzień — podsumowanie bez lustrzanych tygodni
|
||||
const weeksField = screen.getByText('Długość (tygodnie)').closest('[data-slot="field"]') as HTMLElement;
|
||||
const weeksField = screen
|
||||
.getByText('Długość (tygodnie)')
|
||||
.closest('[data-slot="field"]') as HTMLElement;
|
||||
await user.selectOptions(within(weeksField).getByRole('combobox'), '1');
|
||||
await user.click(screen.getByRole('button', { name: 'Dalej' }));
|
||||
|
||||
@@ -450,7 +454,9 @@ describe('PlanEditor — wizard 3-etapowy (tryb podopiecznego)', () => {
|
||||
const gymField = screen.getByText('Siłownia').closest('[data-slot="field"]') as HTMLElement;
|
||||
const gymSelect = within(gymField).getByRole('combobox');
|
||||
expect(within(gymSelect).getByRole('option', { name: 'Bez siłowni' })).toBeInTheDocument();
|
||||
expect(within(gymSelect).getByRole('option', { name: 'Siłownia Podopiecznej' })).toBeInTheDocument();
|
||||
expect(
|
||||
within(gymSelect).getByRole('option', { name: 'Siłownia Podopiecznej' }),
|
||||
).toBeInTheDocument();
|
||||
await user.selectOptions(gymSelect, 'gym-1');
|
||||
|
||||
// dzień + ćwiczenie + alias tygodnia
|
||||
@@ -458,7 +464,7 @@ describe('PlanEditor — wizard 3-etapowy (tryb podopiecznego)', () => {
|
||||
await user.click(screen.getByRole('button', { name: 'dodaj ćwiczenie…' }));
|
||||
await user.click(await screen.findByRole('option', { name: /Przysiady/ }));
|
||||
const aliasField = screen
|
||||
.getByText('Nazwa tygodnia (opcjonalnie)')
|
||||
.getByText('Nazwa tygodnia 1 (opcjonalnie)')
|
||||
.closest('[data-slot="field"]') as HTMLElement;
|
||||
await user.type(within(aliasField).getByRole('textbox'), 'Deload');
|
||||
|
||||
@@ -470,7 +476,9 @@ describe('PlanEditor — wizard 3-etapowy (tryb podopiecznego)', () => {
|
||||
const summaryCard = screen
|
||||
.getByText('Łącznie: 1 dzień · 1 ćwiczenie · 1 seria')
|
||||
.closest('[data-slot="card"]') as HTMLElement;
|
||||
expect(within(summaryCard).getByText('Pon · 1 dzień · 1 ćwiczenie · 1 seria')).toBeInTheDocument();
|
||||
expect(
|
||||
within(summaryCard).getByText('Pon · 1 dzień · 1 ćwiczenie · 1 seria'),
|
||||
).toBeInTheDocument();
|
||||
|
||||
// zapis (krok 3) — body z gymId i customName
|
||||
await user.click(screen.getByRole('button', { name: 'Zapisz' }));
|
||||
|
||||
Reference in New Issue
Block a user