diff --git a/app/src/pages/plans/PlanEditor.tsx b/app/src/pages/plans/PlanEditor.tsx index a0a0719..8c1071d 100644 --- a/app/src/pages/plans/PlanEditor.tsx +++ b/app/src/pages/plans/PlanEditor.tsx @@ -20,7 +20,6 @@ import { Card, ConfirmDialog, EmptyState, - ErrorText, Field, Input, isPastWeek, @@ -29,15 +28,10 @@ import { Tabs, type BadgeColor, } from '../../components/ui'; +import { useToast } from '../../components/toast'; import { cn } from '../../lib/utils'; import { exerciseAvailableAtGym } from '../../lib/equipment'; -import { - DAY_NAMES, - dayCountLabel, - exerciseCountLabel, - setCountLabel, - weekCountLabel, -} from '../../lib/labels'; +import { DAY_NAMES, dayCountLabel, exerciseCountLabel } from '../../lib/labels'; import { useTopbar } from '../../topbar'; import { displayedDaysOf, type EditorDay, type EditorWeek } from './plan-editor/types'; import { usePlanEditorState } from './plan-editor/usePlanEditorState'; @@ -221,7 +215,7 @@ export default function PlanEditor() { } }, [isEdit, planData, editor]); - const [error, setError] = useState(''); + const { push } = useToast(); const [activeWeek, setActiveWeek] = useState(0); const [resultsOpenKey, setResultsOpenKey] = useState(null); const [confirmExit, setConfirmExit] = useState(false); @@ -245,28 +239,6 @@ export default function PlanEditor() { // Walidacja inline: tytuł (po touch) const titleError = titleTouched && !editor.title.trim() ? 'Podaj tytuł planu' : ''; - // Podsumowanie stopki: dni/ćwiczenia/serie + tygodnie bez ćwiczeń (nie blokuje) - const totals = useMemo(() => { - let days = 0; - let exerciseTotal = 0; - let sets = 0; - let emptyWeeks = 0; - editor.weeks.forEach((_, i) => { - const weekDays = displayedDaysOf(editor.weeks, i); - days += weekDays.length; - let weekExercises = 0; - weekDays.forEach((d) => { - weekExercises += d.exercises.length; - d.exercises.forEach((e) => { - sets += e.sets.length; - }); - }); - exerciseTotal += weekExercises; - if (weekExercises === 0) emptyWeeks += 1; - }); - return { days, exercises: exerciseTotal, sets, emptyWeeks }; - }, [editor.weeks]); - // Guard niezapisanych zmian: F5/odświeżenie + wyjście (Anuluj/Wstecz/mobile „<”) useEffect(() => { if (!editor.dirty) return; @@ -311,14 +283,13 @@ export default function PlanEditor() { }; const save = async () => { - setError(''); setTitleTouched(true); if (!editor.title.trim()) { - setError('Podaj tytuł planu'); + push('Podaj tytuł planu', 'error'); return; } if (editor.weeks.length !== editor.weeksCount) { - setError(`Plan ma ${editor.weeksCount} tygodni — zdefiniuj je wszystkie`); + push(`Plan ma ${editor.weeksCount} tygodni — zdefiniuj je wszystkie`, 'error'); return; } const body: PlanBody = { @@ -350,7 +321,7 @@ export default function PlanEditor() { // Tydzień startu: bieżący lub przyszły (WeekPicker blokuje minione; guard zapasowy). if (editor.startDate) { if (isPastWeek(editor.startDate)) { - setError('Tydzień startu nie może być w przeszłości'); + push('Tydzień startu nie może być w przeszłości', 'error'); return; } body.startDate = editor.startDate; @@ -372,7 +343,7 @@ export default function PlanEditor() { } navigate(`/plans/${planIdParam}`); } catch (err) { - setError(err instanceof Error ? err.message : 'Błąd zapisu'); + push(err instanceof Error ? err.message : 'Błąd zapisu', 'error'); } finally { setSaving(false); } @@ -583,27 +554,6 @@ export default function PlanEditor() { /> )} - {/* sticky stopka: podsumowanie tylko na kroku 2 (krok 1 = brak dni, krok 3 = PlanSummary); - błędy zapisu zawsze. Akcje Dalej/Zapisz + „<” są w menu kontekstowym topbar; - na mobile pod stałym dolnym paskiem topmenu (50px = pt-2 + wiersz 34px + pb) + safe-area */} - {(step === 2 || error) && ( -
- {error && {error}} - {step === 2 && ( -
- {dayCountLabel(totals.days)} · {exerciseCountLabel(totals.exercises)} ·{' '} - {setCountLabel(totals.sets)} - {totals.emptyWeeks > 0 && ( - - {' '} - · {weekCountLabel(totals.emptyWeeks)} bez ćwiczeń - - )} -
- )} -
- )} - setConfirmExit(false)}