Skip to content

Commit a52eb1a

Browse files
authored
fix(HNT-1379): fix saving prospects with datePublished value (#1265)
- ensures datePublished value is converted to YYYY-MM-DD value prior to form submission (required by graph input)
1 parent 6589a1a commit a52eb1a

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/curated-corpus/components/ApprovedItemForm/ApprovedItemForm.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ describe('The ApprovedItemForm component', () => {
9595
{ name: 'Two Authors', sortOrder: 2 },
9696
],
9797
publisher: 'Amazing Inventions',
98+
datePublished: '2025-12-11 09:30:00',
9899
topic: Topics.HealthFitness,
99100
source: CorpusItemSource.Prospect,
100101
status: CuratedStatus.Recommendation,
@@ -196,6 +197,16 @@ describe('The ApprovedItemForm component', () => {
196197
const syndicated = screen.getByLabelText(/Syndicated/);
197198
expect(syndicated).toBeInTheDocument();
198199
expect(syndicated).toHaveProperty('checked', item.isSyndicated);
200+
201+
// hidden fields
202+
const datePublished = screen.getByLabelText(/datePublished/);
203+
expect(datePublished).toBeInTheDocument();
204+
// make sure the date time value is converted to just a date
205+
expect(datePublished).toHaveValue('2025-12-11');
206+
207+
const source = screen.getByLabelText(/source/);
208+
expect(source).toBeInTheDocument();
209+
expect(source).toHaveValue(item.source);
199210
});
200211

201212
it('should render the ImageUpload component', () => {

src/curated-corpus/components/ApprovedItemForm/ApprovedItemForm.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useEffect, useMemo, useState } from 'react';
2+
import { DateTime } from 'luxon';
23
import {
34
Box,
45
CircularProgress,
@@ -103,7 +104,11 @@ export const ApprovedItemForm: React.FC<
103104
publisher: approvedItem.publisher,
104105
// A read-only value we may get back from the Pocket Graph
105106
// for some stories + all collections and syndicated items.
106-
datePublished: approvedItem.datePublished ?? null,
107+
datePublished: approvedItem.datePublished
108+
? DateTime.fromJSDate(new Date(approvedItem.datePublished)).toFormat(
109+
'yyyy-MM-dd',
110+
)
111+
: null,
107112
language: approvedItem.language ?? '',
108113
topic: approvedItem.topic ?? '',
109114
curationStatus: isRecommendation
@@ -550,13 +555,11 @@ export const ApprovedItemForm: React.FC<
550555
</Grid>
551556
<Box display="none">
552557
<TextField
553-
type="hidden"
554558
id="source"
555559
label="source"
556560
{...formik.getFieldProps('source')}
557561
/>
558562
<TextField
559-
type="hidden"
560563
id="datePublished"
561564
label="datePublished"
562565
{...formik.getFieldProps('datePublished')}

0 commit comments

Comments
 (0)