diff --git a/src/apps/content-editor/src/app/components/Editor/Field/Field.tsx b/src/apps/content-editor/src/app/components/Editor/Field/Field.tsx
index f06aafeec9..81fae3c451 100644
--- a/src/apps/content-editor/src/app/components/Editor/Field/Field.tsx
+++ b/src/apps/content-editor/src/app/components/Editor/Field/Field.tsx
@@ -889,24 +889,6 @@ export const Field = ({
);
case "date":
- /**
- * Every time this parent compenent re-renders it creates a new function
- * invalidating the FieldTypeData components referential prop check,
- * causing it to re-render as well. This `onChange` handler doesn't need
- * to change once created.
- */
- const onDateChange = useCallback(
- (value, name, datatype) => {
- /**
- * Flatpickr emits a utc timestamp, offset from users local time.
- * Legacy behavior did not send utc but sent the value as is selected by the user
- * this ensures that behavior is maintained.
- */
- onChange(value, name, datatype);
- },
- [onChange]
- );
-
return (
onDateChange(date, name, datatype)}
+ onChange={(date) => {
+ onChange(
+ date ? moment(date).format("yyyy-MM-DD") : null,
+ name,
+ datatype
+ );
+ }}
error={errors && Object.values(errors)?.some((error) => !!error)}
/>
diff --git a/src/shell/components/FieldTypeDate/index.tsx b/src/shell/components/FieldTypeDate/index.tsx
index 26d6d4676d..d7fec6415f 100644
--- a/src/shell/components/FieldTypeDate/index.tsx
+++ b/src/shell/components/FieldTypeDate/index.tsx
@@ -9,6 +9,7 @@ import Button from "@mui/material/Button";
import { Typography, Stack, Box, TextField } from "@mui/material";
import format from "date-fns/format";
import CalendarTodayRoundedIcon from "@mui/icons-material/CalendarTodayRounded";
+import moment from "moment";
export interface FieldTypeDateProps extends DatePickerProps {
name: string;
@@ -18,6 +19,7 @@ export interface FieldTypeDateProps extends DatePickerProps {
timePicker?: React.ReactNode;
};
onClear?: () => void;
+ valueFormatPreview?: string;
}
const parseDateInput = (input: string): Date | null => {
@@ -56,7 +58,14 @@ const parseDateInput = (input: string): Date | null => {
};
export const FieldTypeDate = memo(
- ({ required, error, slots, onClear, ...props }: FieldTypeDateProps) => {
+ ({
+ required,
+ error,
+ slots,
+ onClear,
+ valueFormatPreview,
+ ...props
+ }: FieldTypeDateProps) => {
const textFieldRef = useRef(null);
const [isOpen, setIsOpen] = useState(false);
@@ -195,6 +204,12 @@ export const FieldTypeDate = memo(
Clear
+ {(valueFormatPreview || props.value) && (
+
+ Stored as{" "}
+ {valueFormatPreview ?? moment(props.value).format("yyyy-MM-DD")}
+
+ )}
);
}
diff --git a/src/shell/components/FieldTypeDateTime/index.tsx b/src/shell/components/FieldTypeDateTime/index.tsx
index 9e44c4eb25..9ec561d6f4 100644
--- a/src/shell/components/FieldTypeDateTime/index.tsx
+++ b/src/shell/components/FieldTypeDateTime/index.tsx
@@ -79,6 +79,9 @@ export const FieldTypeDateTime = ({
name={name}
required={required}
value={dateString ? moment(dateString).toDate() : null}
+ valueFormatPreview={
+ dateString && timeString ? `${dateString} ${timeString}` : null
+ }
onChange={(date) => {
if (date) {
onChange(
@@ -222,11 +225,6 @@ export const FieldTypeDateTime = ({
),
}}
/>
- {dateString && timeString && (
-
- Stored as {dateString} {timeString}
-
- )}
>
);
};