Plany: zapis planu jako akcja 'Zatwierdź plan' w menu kontekstowym (stopka zostawia Anuluj)
This commit is contained in:
@@ -12,7 +12,7 @@ import {
|
||||
useExercises,
|
||||
type PlanWeekInput,
|
||||
} from '../../api/queries';
|
||||
import { CalendarX } from 'lucide-react';
|
||||
import { CalendarX, Check } from 'lucide-react';
|
||||
import {
|
||||
BackButton,
|
||||
Button,
|
||||
@@ -73,6 +73,8 @@ export default function PlanEditor() {
|
||||
? `/plans/${planIdParam}`
|
||||
: '/plans';
|
||||
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
const requestExit = () => {
|
||||
if (editor.dirty) setConfirmExit(true);
|
||||
else navigate(backPath);
|
||||
@@ -93,6 +95,15 @@ 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)
|
||||
actions: [
|
||||
{
|
||||
label: 'Zatwierdź plan',
|
||||
icon: Check,
|
||||
onClick: () => save(),
|
||||
disabled: saving,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// Inicjalizacja trybu edycji po załadowaniu danych (useEffect, nie setState during render)
|
||||
@@ -103,7 +114,6 @@ export default function PlanEditor() {
|
||||
}, [isEdit, planData, editor]);
|
||||
|
||||
const [error, setError] = useState('');
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [activeWeek, setActiveWeek] = useState(0);
|
||||
const [resultsOpenKey, setResultsOpenKey] = useState<string | null>(null);
|
||||
const [confirmExit, setConfirmExit] = useState(false);
|
||||
@@ -403,11 +413,8 @@ export default function PlanEditor() {
|
||||
<span className="text-warn"> · {weekCountLabel(totals.emptyWeeks)} bez ćwiczeń</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex gap-3">
|
||||
<Button onClick={save} disabled={saving} className="flex-1">
|
||||
{saving ? 'Zapisywanie…' : isEdit ? 'Zapisz zmiany' : 'Utwórz plan'}
|
||||
</Button>
|
||||
<Button variant="secondary" onClick={requestExit} className="shrink-0">
|
||||
<div className="flex justify-end">
|
||||
<Button variant="secondary" onClick={requestExit} className="w-full sm:w-auto">
|
||||
Anuluj
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -51,8 +51,7 @@ function mockApi(capture: Capture) {
|
||||
if (url.includes('/auth/refresh'))
|
||||
return jsonResponse(401, { error: { code: 'UNAUTHORIZED', message: 'no cookie' } });
|
||||
if (url.includes('/me/active-session')) return jsonResponse(200, { session: null });
|
||||
if (url.endsWith('/me'))
|
||||
return jsonResponse(200, { user: USER, memberships: [] });
|
||||
if (url.endsWith('/me')) return jsonResponse(200, { user: USER, memberships: [] });
|
||||
if (url.includes('/exercises')) return jsonResponse(200, { exercises: EXERCISES });
|
||||
if (url.includes('/dashboard'))
|
||||
return jsonResponse(200, {
|
||||
@@ -155,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: 'Utwórz plan' }));
|
||||
await user.click(screen.getByRole('button', { name: 'Zatwierdź plan' }));
|
||||
await waitFor(() =>
|
||||
expect(capture.createPlanBody).toMatchObject({
|
||||
title: 'Plan testowy',
|
||||
@@ -208,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: 'Utwórz plan' }));
|
||||
await user.click(screen.getByRole('button', { name: 'Zatwierdź plan' }));
|
||||
await waitFor(() => expect(capture.createPlanBody).toBeDefined());
|
||||
expect(capture.createPlanBody).not.toHaveProperty('startDate');
|
||||
});
|
||||
|
||||
@@ -54,7 +54,9 @@ test('mobile: tworzenie planu — bezpieczny tap dnia, bottom sheet, edycja seri
|
||||
await page.getByRole('button', { name: '+ dodaj ćwiczenie…' }).click();
|
||||
await page.getByRole('option', { name: /Wyciskanie/ }).click();
|
||||
await page.getByPlaceholder('np. Plan masowy 8-tygodniowy').fill('Plan mobile');
|
||||
await page.getByRole('button', { name: 'Utwórz plan' }).click();
|
||||
// „Zatwierdź plan" w grupie „Akcje" dolnego paska
|
||||
await page.getByRole('button', { name: 'Akcje' }).click();
|
||||
await page.getByRole('button', { name: 'Zatwierdź plan' }).click();
|
||||
|
||||
// po utworzeniu — szczegóły planu (mock zwraca „Plan e2e”)
|
||||
await expect(page.getByRole('heading', { name: 'Plan e2e' })).toBeVisible();
|
||||
|
||||
@@ -43,7 +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();
|
||||
await page.getByRole('button', { name: 'Utwórz plan' }).click();
|
||||
// akcja główna w menu kontekstowym (lg+: inline w nagłówku)
|
||||
await page.getByRole('button', { name: 'Zatwierdź plan' }).click();
|
||||
|
||||
// po utworzeniu — szczegóły planu (aktywowany z datą startu)
|
||||
await expect(page.getByRole('heading', { name: 'Plan e2e' })).toBeVisible();
|
||||
@@ -58,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: 'Utwórz plan' }).click();
|
||||
await page.getByRole('button', { name: 'Zatwierdź plan' }).click();
|
||||
await expect(page.getByText('Podaj tytuł planu').first()).toBeVisible();
|
||||
|
||||
// podsumowanie stopki: 0 dni · 0 ćwiczeń · 0 serii + ostrzeżenie o pustych tygodniach
|
||||
|
||||
@@ -82,6 +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"
|
||||
|
||||
await expect(page.getByRole('heading', { name: 'Plan dla podopiecznego' })).toBeVisible();
|
||||
// dodaj dzień (Poniedziałek)
|
||||
|
||||
@@ -377,7 +377,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: 'Utwórz plan' }));
|
||||
await user.click(screen.getByRole('button', { name: 'Zatwierdź plan' }));
|
||||
// błąd pod polem tytułu + w stopce
|
||||
expect(screen.getAllByText('Podaj tytuł planu').length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user