fix(dates): use AdminDatePicker everywhere + mode-aware default placeholder
- The project create-modal start/end dates used raw <input type="date">; converted to <AdminDatePicker> so every date field in the app now goes through the shared component (react-datepicker on desktop, native on touch). - AdminDatePicker now defaults its placeholder by mode (date 'dd.mm.rrrr', month 'mm.rrrr', time 'hh:mm') so empty date fields always show a format hint; explicit placeholders (e.g. 'Od'/'Do' range filters) still override. - Dropped WarehouseReceiptForm's ad-hoc 'dd.mm.yyyy' so it inherits the unified Czech default. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -58,6 +58,7 @@ interface NativeInputProps {
|
|||||||
minDate?: string;
|
minDate?: string;
|
||||||
maxDate?: string;
|
maxDate?: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
placeholder?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const modeToInputType: Record<string, string> = {
|
const modeToInputType: Record<string, string> = {
|
||||||
@@ -73,6 +74,7 @@ function NativeInput({
|
|||||||
minDate,
|
minDate,
|
||||||
maxDate,
|
maxDate,
|
||||||
disabled,
|
disabled,
|
||||||
|
placeholder,
|
||||||
}: NativeInputProps) {
|
}: NativeInputProps) {
|
||||||
const type = modeToInputType[mode] || "date";
|
const type = modeToInputType[mode] || "date";
|
||||||
// For time inputs, min/max must be in HH:mm format, not date format
|
// For time inputs, min/max must be in HH:mm format, not date format
|
||||||
@@ -95,6 +97,7 @@ function NativeInput({
|
|||||||
value={value || ""}
|
value={value || ""}
|
||||||
onChange={(e) => onChange(e.target.value)}
|
onChange={(e) => onChange(e.target.value)}
|
||||||
className="admin-form-input"
|
className="admin-form-input"
|
||||||
|
placeholder={placeholder}
|
||||||
required={required}
|
required={required}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
min={minProp}
|
min={minProp}
|
||||||
@@ -126,6 +129,12 @@ export default function AdminDatePicker({
|
|||||||
}: AdminDatePickerProps) {
|
}: AdminDatePickerProps) {
|
||||||
const useNative = isTouchDevice();
|
const useNative = isTouchDevice();
|
||||||
|
|
||||||
|
// Mode-aware default placeholder so empty date fields always show a format
|
||||||
|
// hint (callers can still override, e.g. "Od"/"Do" on range filters).
|
||||||
|
const effectivePlaceholder =
|
||||||
|
placeholder ??
|
||||||
|
(mode === "time" ? "hh:mm" : mode === "month" ? "mm.rrrr" : "dd.mm.rrrr");
|
||||||
|
|
||||||
if (useNative) {
|
if (useNative) {
|
||||||
return (
|
return (
|
||||||
<NativeInput
|
<NativeInput
|
||||||
@@ -136,6 +145,7 @@ export default function AdminDatePicker({
|
|||||||
minDate={minDate}
|
minDate={minDate}
|
||||||
maxDate={maxDate}
|
maxDate={maxDate}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
placeholder={effectivePlaceholder}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -181,7 +191,7 @@ export default function AdminDatePicker({
|
|||||||
const customInput = (
|
const customInput = (
|
||||||
<CustomInput
|
<CustomInput
|
||||||
required={required}
|
required={required}
|
||||||
placeholder={placeholder}
|
placeholder={effectivePlaceholder}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -191,7 +201,7 @@ export default function AdminDatePicker({
|
|||||||
onChange: handleChange,
|
onChange: handleChange,
|
||||||
locale: "cs",
|
locale: "cs",
|
||||||
customInput,
|
customInput,
|
||||||
placeholderText: placeholder,
|
placeholderText: effectivePlaceholder,
|
||||||
minDate: parseMinMax(minDate),
|
minDate: parseMinMax(minDate),
|
||||||
maxDate: parseMinMax(maxDate),
|
maxDate: parseMinMax(maxDate),
|
||||||
popperPlacement: "bottom-start" as const,
|
popperPlacement: "bottom-start" as const,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { motion } from "framer-motion";
|
|||||||
import ConfirmModal from "../components/ConfirmModal";
|
import ConfirmModal from "../components/ConfirmModal";
|
||||||
import FormModal from "../components/FormModal";
|
import FormModal from "../components/FormModal";
|
||||||
import FormField from "../components/FormField";
|
import FormField from "../components/FormField";
|
||||||
|
import AdminDatePicker from "../components/AdminDatePicker";
|
||||||
|
|
||||||
import { formatDate, czechPlural } from "../utils/formatters";
|
import { formatDate, czechPlural } from "../utils/formatters";
|
||||||
import SortIcon from "../components/SortIcon";
|
import SortIcon from "../components/SortIcon";
|
||||||
@@ -530,23 +531,21 @@ export default function Projects() {
|
|||||||
|
|
||||||
<div className="admin-form-row">
|
<div className="admin-form-row">
|
||||||
<FormField label="Začátek">
|
<FormField label="Začátek">
|
||||||
<input
|
<AdminDatePicker
|
||||||
type="date"
|
mode="date"
|
||||||
value={createForm.start_date}
|
value={createForm.start_date}
|
||||||
onChange={(e) =>
|
onChange={(val) =>
|
||||||
setCreateForm({ ...createForm, start_date: e.target.value })
|
setCreateForm({ ...createForm, start_date: val })
|
||||||
}
|
}
|
||||||
className="admin-form-input"
|
|
||||||
/>
|
/>
|
||||||
</FormField>
|
</FormField>
|
||||||
<FormField label="Konec">
|
<FormField label="Konec">
|
||||||
<input
|
<AdminDatePicker
|
||||||
type="date"
|
mode="date"
|
||||||
value={createForm.end_date}
|
value={createForm.end_date}
|
||||||
onChange={(e) =>
|
onChange={(val) =>
|
||||||
setCreateForm({ ...createForm, end_date: e.target.value })
|
setCreateForm({ ...createForm, end_date: val })
|
||||||
}
|
}
|
||||||
className="admin-form-input"
|
|
||||||
/>
|
/>
|
||||||
</FormField>
|
</FormField>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -378,7 +378,6 @@ export default function WarehouseReceiptForm() {
|
|||||||
delivery_note_date: val,
|
delivery_note_date: val,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
placeholder="dd.mm.yyyy"
|
|
||||||
/>
|
/>
|
||||||
</FormField>
|
</FormField>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user