diff --git a/web/src/components/DateTimeInput.tsx b/web/src/components/DateTimeInput.tsx index 0f70da3f4..beb0d06f6 100644 --- a/web/src/components/DateTimeInput.tsx +++ b/web/src/components/DateTimeInput.tsx @@ -1,34 +1,34 @@ import dayjs from "dayjs"; -import { isEqual } from "lodash-es"; import toast from "react-hot-toast"; import { cn } from "@/utils"; +const DATE_TIME_FORMAT = "M/D/YYYY, H:mm:ss"; + // convert Date to datetime string. -const formatDate = (date: Date | undefined): string => { - return dayjs(date).format("M/D/YYYY, H:mm:ss"); +const formatDate = (date: Date): string => { + return dayjs(date).format(DATE_TIME_FORMAT); }; interface Props { - value: Date | undefined; - originalValue: Date | undefined; + value: Date; onChange: (date: Date) => void; } -const DateTimeInput: React.FC = ({ value, originalValue, onChange }) => { +const DateTimeInput: React.FC = ({ value, onChange }) => { return ( { const inputValue = e.target.value; if (inputValue) { - const date = new Date(inputValue); + const date = dayjs(inputValue, DATE_TIME_FORMAT, true).toDate(); + // Check if the date is valid. if (!isNaN(date.getTime())) { onChange(date); } else { @@ -37,7 +37,7 @@ const DateTimeInput: React.FC = ({ value, originalValue, onChange }) => { } } }} - placeholder="M/D/YYYY, H:mm:ss" + placeholder={DATE_TIME_FORMAT} /> ); }; diff --git a/web/src/components/MemoEditor/index.tsx b/web/src/components/MemoEditor/index.tsx index aa8ac7b3e..031114d41 100644 --- a/web/src/components/MemoEditor/index.tsx +++ b/web/src/components/MemoEditor/index.tsx @@ -74,8 +74,6 @@ const MemoEditor = observer((props: Props) => { }); const [createTime, setCreateTime] = useState(); const [updateTime, setUpdateTime] = useState(); - const [originalCreateTime, setOriginalCreateTime] = useState(); - const [originalUpdateTime, setOriginalUpdateTime] = useState(); const [hasContent, setHasContent] = useState(false); const [isVisibilitySelectorOpen, setIsVisibilitySelectorOpen] = useState(false); const editorRef = useRef(null); @@ -125,8 +123,6 @@ const MemoEditor = observer((props: Props) => { handleEditorFocus(); setCreateTime(memo.createTime); setUpdateTime(memo.updateTime); - setOriginalCreateTime(memo.createTime); - setOriginalUpdateTime(memo.updateTime); setState((prevState) => ({ ...prevState, memoVisibility: memo.visibility, @@ -550,14 +546,18 @@ const MemoEditor = observer((props: Props) => { {memoName && (
- {!isEqual(createTime, updateTime) && ( + {!isEqual(createTime, updateTime) && updateTime && ( <> Updated - + + + )} + {createTime && ( + <> + Created + )} - Created - ID