more simple error message + important code comments

pull/4829/head
unuunn 3 weeks ago
parent 8f40c4ea26
commit 99d55f7a13

@ -2,7 +2,7 @@ import dayjs from "dayjs";
import toast from "react-hot-toast";
import { cn } from "@/lib/utils";
// ISO 8601 (almost)
// must be compatible with JS Date.parse(), we use ISO 8601 (almost)
const DATE_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
// convert Date to datetime string.
@ -24,25 +24,13 @@ const DateTimeInput: React.FC<Props> = ({ value, onChange }) => {
onBlur={(e) => {
const inputValue = e.target.value;
if (inputValue) {
// note: inputValue must be compatible with JS Date.parse()
const date = dayjs(inputValue).toDate();
// Check if the date is valid.
if (!isNaN(date.getTime())) {
onChange(date);
} else {
toast.error(
<span>
Invalid datetime.<br/>
Use a{" "}
<a
class="underline text-primary hover:text-primary/80"
href="https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Date#datestring" target="_blank">
Date.parse()
</a>
-compatible format,<br/>
e.g., <code>2023-12-31 23:59:59</code><br/>
or <code>31/12/2023, 23:59:59</code>.
</span>
);
toast.error("Invalid datetime format. Use format: 2023-12-31 23:59:59");
e.target.value = formatDate(value);
}
}

Loading…
Cancel
Save