fix date inputs

This commit is contained in:
2025-11-13 16:24:19 +03:00
parent a29aa896e0
commit 529893be8b
3 changed files with 60 additions and 40 deletions

View File

@@ -1,43 +1,33 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment import { FormItemProps, Form, DatePicker } from "antd";
// @ts-nocheck import dayjs from "dayjs";
import { UI_DATE_FORMAT } from "@/lib/constants"; import type { DatePickerProps } from "antd";
import { DatePicker } from "antd"; import { UI_DATE_FORMAT, SERVER_DATE_FORMAT } from "utils/constants.ts";
import { SizeType } from "antd/es/config-provider/SizeContext";
import { Dayjs } from "dayjs";
import { CSSProperties, FocusEventHandler, KeyboardEventHandler } from "react";
export interface ProDatePickerProps { export default function ProDateFormInput({
style?: CSSProperties; formItemProps,
format?: string; pickerProps,
defaultValue?: Dayjs; }: {
value?: Dayjs; formItemProps: FormItemProps;
size?: SizeType; pickerProps: DatePickerProps;
disabled?: boolean; }) {
onChange?: (value: Dayjs | null, dateString: string) => void;
placeholder?: string;
picker?: "date";
ref?: any;
onBlur?: FocusEventHandler<HTMLInputElement>;
onKeyDown?: KeyboardEventHandler;
className?: string;
getPopupContainer?: (trigger: HTMLElement) => HTMLElement;
defaultOpen?: boolean;
allowClear?: boolean;
}
function ProDatePicker(props: ProDatePickerProps) {
return ( return (
<DatePicker <Form.Item
allowClear={false} getValueProps={(value) => ({
format={UI_DATE_FORMAT} value: value ? dayjs(value, SERVER_DATE_FORMAT) : undefined,
style={{ width: "100%" }} })}
disabled={props.disabled} normalize={(value) =>
onChange={props.onChange} value ? `${dayjs(value).format(SERVER_DATE_FORMAT)}` : undefined
suffixIcon={null} }
{...props} {...formItemProps}
/> >
<DatePicker
format={{
format: UI_DATE_FORMAT,
type: "mask",
}}
{...pickerProps}
/>
</Form.Item>
); );
} }
export default ProDatePicker;

View File

@@ -0,0 +1,28 @@
import { FormItemProps, Form, TimePicker } from "antd";
import type { TimePickerProps } from "antd";
import dayjs from "dayjs";
import { UI_TIME_FORMAT } from "utils/constants.ts";
export default function TimeFormInput({
formItemProps,
pickerProps,
}: {
formItemProps: FormItemProps;
pickerProps: TimePickerProps;
}) {
return (
<Form.Item
{...formItemProps}
getValueProps={(value) => ({
value: value ? dayjs(value, UI_TIME_FORMAT) : null,
})}
normalize={(value) =>
value ? `${dayjs(value).format(UI_TIME_FORMAT)}` : ""
}
{...formItemProps}
>
<TimePicker format={UI_TIME_FORMAT} {...pickerProps} />
</Form.Item>
);
}

View File

@@ -47,7 +47,9 @@ export const THEME_STORAGE_KEY = "themeKey";
export const USER_EMAIL = "userEmail"; export const USER_EMAIL = "userEmail";
export const DEFAULT_LANGUAGE = "selectedLang"; export const DEFAULT_LANGUAGE = "selectedLang";
export const UI_DATE_FORMAT = "YYYY-MM-DD"; export const SERVER_DATE_FORMAT = "YYYY-MM-DD";
export const UI_DATE_FORMAT = "YYYY/MM/DD";
export const UI_TIME_FORMAT = "HH:mm";
export const CONTACTS_URL = "LT"; export const CONTACTS_URL = "LT";
export const FILTER_PARAMS = ""; export const FILTER_PARAMS = "";
@@ -103,4 +105,4 @@ export const LOGIN_URL = `${API_BASE_URL}login`;
export const SEND_OTP_URL = `${API_BASE_URL}sendOtp`; export const SEND_OTP_URL = `${API_BASE_URL}sendOtp`;
export const CONFIRM_OTP_URL = `${API_BASE_URL}confirmOtp`; export const CONFIRM_OTP_URL = `${API_BASE_URL}confirmOtp`;
export const PAYMENT_CONFIRMATION_URL = `https://menu.fascano.com/payment/confirmation`; export const PAYMENT_CONFIRMATION_URL = `https://menu.fascano.com/payment/confirmation`;
export const DISCOUNT_URL = `${BASE_URL}getDiscount`; export const DISCOUNT_URL = `${BASE_URL}getDiscount`;