82 lines
2.4 KiB
TypeScript
82 lines
2.4 KiB
TypeScript
import { Card, ErrorText, Field, Input, Select, WeekPicker } from '../../../components/ui';
|
|
|
|
/* Meta planu: tytuł, długość, tydzień startu (+ hint) — siatka pól, błędy inline. */
|
|
export function PlanMetaForm({
|
|
title,
|
|
onTitleChange,
|
|
onTitleBlur,
|
|
titleError,
|
|
weeksCount,
|
|
onWeeksCountChange,
|
|
startDate,
|
|
onStartDateChange,
|
|
startWeekError,
|
|
showStartWeek,
|
|
}: {
|
|
title: string;
|
|
onTitleChange: (v: string) => void;
|
|
onTitleBlur?: () => void;
|
|
titleError?: string;
|
|
weeksCount: number;
|
|
onWeeksCountChange: (n: number) => void;
|
|
startDate: string;
|
|
onStartDateChange: (v: string) => void;
|
|
startWeekError?: string;
|
|
showStartWeek: boolean;
|
|
}) {
|
|
const titleField = (
|
|
<Field label="Tytuł">
|
|
<Input
|
|
value={title}
|
|
onChange={(e) => onTitleChange(e.target.value)}
|
|
onBlur={onTitleBlur}
|
|
placeholder="np. Plan masowy 8-tygodniowy"
|
|
aria-invalid={titleError ? true : undefined}
|
|
/>
|
|
{titleError && <ErrorText>{titleError}</ErrorText>}
|
|
</Field>
|
|
);
|
|
const weeksField = (
|
|
<Field label="Długość (tygodnie)">
|
|
<Select value={weeksCount} onChange={(e) => onWeeksCountChange(parseInt(e.target.value))}>
|
|
{[1, 2, 3, 4, 5, 6, 7, 8].map((n) => (
|
|
<option key={n} value={n}>
|
|
{n}
|
|
</option>
|
|
))}
|
|
</Select>
|
|
</Field>
|
|
);
|
|
|
|
return (
|
|
<Card>
|
|
{/* desktop: równe kolumny — po lewej kalendarz startu, po prawej inputy pod siebie;
|
|
mobile (i tryb edycji bez startu): jedno pod drugim / dwa obok siebie */}
|
|
{showStartWeek ? (
|
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4 items-start">
|
|
<Field label="Tydzień startu">
|
|
<WeekPicker value={startDate} onChange={onStartDateChange} />
|
|
{startWeekError && <ErrorText>{startWeekError}</ErrorText>}
|
|
</Field>
|
|
<div className="grid gap-4">
|
|
{titleField}
|
|
{weeksField}
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
|
{titleField}
|
|
{weeksField}
|
|
</div>
|
|
)}
|
|
{showStartWeek && (
|
|
<p className="mt-3 text-dim text-[0.875rem]">
|
|
Opcjonalnie zaznacz tydzień startu — plan zostanie od razu aktywowany (start =
|
|
poniedziałek zaznaczonego tygodnia), a daty dni treningowych wyliczone automatycznie. Bez
|
|
tygodnia plan pozostanie szkicem.
|
|
</p>
|
|
)}
|
|
</Card>
|
|
);
|
|
}
|