Skip to content

Commit 0599f27

Browse files
committed
Fix metadata date not being updated
The backend would report "Not able to parse date string 2021-06-15T13:33: ParseException: Unparseable date: "2021-06-15T13:33"". This fixes that, by making sure the date stored in redux is a proper ISO date again.
1 parent 2e54223 commit 0599f27

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/main/Metadata.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useMemo, useState } from "react";
1+
import React, { useCallback, useEffect, useMemo, useState } from "react";
22

33
import { css } from "@emotion/react";
44
import { BREAKPOINTS, calendarStyle, selectFieldStyle, titleStyle, titleStyleBold } from "../cssStyles";
@@ -286,10 +286,22 @@ const FieldContent: React.FC<{ field: MetadataField, readonly?: boolean }> = ({
286286
}
287287
};
288288

289+
const handleDateConversion = useCallback((value: string) => {
290+
let returnValue = value;
291+
if (field && (field.type === "date" || field.type === "time")) {
292+
if (returnValue !== "") { // Empty string is allowed
293+
returnValue = new Date(returnValue).toJSON();
294+
}
295+
}
296+
return returnValue;
297+
// eslint-disable-next-line react-hooks/exhaustive-deps
298+
}, [field?.type]);
299+
289300
// Set value in store, but debounced
290301
const debouncedCommit = useMemo(
291302
() =>
292303
debounce((newValue: string) => {
304+
newValue = handleDateConversion(newValue);
293305
if (newValue !== field.value) {
294306
dispatch(
295307
setFieldValue({
@@ -299,7 +311,7 @@ const FieldContent: React.FC<{ field: MetadataField, readonly?: boolean }> = ({
299311
);
300312
}
301313
}, 500),
302-
[dispatch, field.id, field.value],
314+
[dispatch, field.id, field.value, handleDateConversion],
303315
);
304316

305317
useEffect(() => {

0 commit comments

Comments
 (0)