summaryrefslogtreecommitdiffstats
path: root/src/components/MetaItems/Dates/Dates.tsx
blob: 04dff3a4cfef9b705175aea4bec4fdcedb3c78e2 (plain)
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
54
55
56
import { MetaKind } from '@ts/types/app';
import { settings } from '@utils/config';
import { getFormattedDate } from '@utils/helpers/format';
import { useRouter } from 'next/router';
import { useIntl } from 'react-intl';
import { MetaItem } from '..';

const Dates = ({
  publication,
  update,
  kind,
}: {
  publication: string;
  update: string;
  kind: MetaKind;
}) => {
  const intl = useIntl();
  const { locale } = useRouter();
  const validLocale = locale ? locale : settings.locales.defaultLocale;

  const publicationDate = getFormattedDate(publication, validLocale);
  const updateDate = getFormattedDate(update, validLocale);

  return (
    <>
      <MetaItem
        title={intl.formatMessage({
          defaultMessage: 'Published on:',
          description: 'Dates: publication date meta label',
        })}
        values={[
          <time key={publication} dateTime={publication}>
            {publicationDate}
          </time>,
        ]}
        kind={kind}
      />
      {publicationDate !== updateDate && (
        <MetaItem
          title={intl.formatMessage({
            defaultMessage: 'Updated on:',
            description: 'Dates: update date meta label',
          })}
          values={[
            <time key={update} dateTime={update}>
              {updateDate}
            </time>,
          ]}
          kind={kind}
        />
      )}
    </>
  );
};

export default Dates;