forked from owid/owid-grapher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGdocsDateline.tsx
53 lines (49 loc) · 1.76 KB
/
GdocsDateline.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Col } from "antd"
import { Dayjs } from "dayjs"
import { dayjs, OwidGdocErrorMessage, OwidGdoc } from "@ourworldindata/utils"
import React from "react"
import DatePicker from "./DatePicker.js"
import { getPropertyMostCriticalError } from "./gdocsValidation.js"
import { GdocsErrorHelp } from "./GdocsErrorHelp.js"
export const GdocsPublishedAt = <T extends OwidGdoc>({
gdoc,
setCurrentGdoc,
errors,
}: {
gdoc: T
setCurrentGdoc: (gdoc: T) => void
errors?: OwidGdocErrorMessage[]
}) => {
const { publishedAt } = gdoc
const onChangePublishedAt = (publishedAt: Dayjs | null) => {
setCurrentGdoc({
...gdoc,
publishedAt: publishedAt?.toDate() || null,
})
}
const publishedAtError = getPropertyMostCriticalError("publishedAt", errors)
return (
<Col span={8}>
<label htmlFor="publishedAt">Publication date</label>
<DatePicker
onChange={onChangePublishedAt}
value={publishedAt ? dayjs(publishedAt) : undefined}
format="ddd, MMM D, YYYY"
id="publishedAt"
status={publishedAtError?.type}
// The "Today" button has been disabled because it sets
// the time to the current time. This time change makes
// it all the way to the atom feed, which is then
// interpreted by MailChimp's RSS-to-Email as a new
// article.
showToday={false}
/>
<GdocsErrorHelp
error={publishedAtError}
help={
"Used in default dateline. Visible in the citation block. Also used to sort articles in lists."
}
/>
</Col>
)
}