From b95b60bc93ffe7a0c276d911699e6b12a955521f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Fri, 19 Jan 2024 17:55:15 +0000 Subject: [PATCH] feat: Capture epoch time in DateInput --- .../src/@planx/components/DateInput/Public.test.tsx | 1 + .../src/@planx/components/DateInput/Public.tsx | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/editor.planx.uk/src/@planx/components/DateInput/Public.test.tsx b/editor.planx.uk/src/@planx/components/DateInput/Public.test.tsx index 036379744c..80fd208b36 100644 --- a/editor.planx.uk/src/@planx/components/DateInput/Public.test.tsx +++ b/editor.planx.uk/src/@planx/components/DateInput/Public.test.tsx @@ -87,6 +87,7 @@ test("recovers previously submitted date when clicking the back button even if a expect(handleSubmit).toHaveBeenCalledWith({ data: { [dataField]: "2010-05-22", + [dataField + ".epoch"]: 1274486400, }, }); }); diff --git a/editor.planx.uk/src/@planx/components/DateInput/Public.tsx b/editor.planx.uk/src/@planx/components/DateInput/Public.tsx index 8e94227670..24ba4d1064 100644 --- a/editor.planx.uk/src/@planx/components/DateInput/Public.tsx +++ b/editor.planx.uk/src/@planx/components/DateInput/Public.tsx @@ -12,7 +12,7 @@ import InputRow from "ui/shared/InputRow"; import { object } from "yup"; import { DESCRIPTION_TEXT, ERROR_MESSAGE } from "../shared/constants"; -import { getPreviouslySubmittedData, makeData } from "../shared/utils"; +import { getPreviouslySubmittedData } from "../shared/utils"; export type Props = PublicProps; @@ -22,7 +22,16 @@ const DateInputPublic: React.FC = (props) => { date: getPreviouslySubmittedData(props) ?? "", }, onSubmit: (values) => { - props.handleSubmit?.(makeData(props, values.date)); + props.handleSubmit?.({ + data: props.fn + ? { + // Capture user data as ISO 8601 + [props.fn]: values.date, + // Capture user data as epoch time (for use in calculate component) + [props.fn + ".epoch"]: new Date(values.date).valueOf() / 1000, + } + : undefined + }); }, validateOnBlur: false, validateOnChange: false,