Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

1.1 KB
Raw Blame
import React from 'react'
import { SavedSegmentPublic, SavedSegment } from '../filtering/segments'
import { parseNaiveDate, formatDayShort } from '../util/date'

type SegmentAuthorshipProps = {
  className?: string
  showOnlyPublicData: boolean
  segment: SavedSegmentPublic | SavedSegment
}

export function SegmentAuthorship({
  className,
  showOnlyPublicData,
  segment
}: SegmentAuthorshipProps) {
  const authorLabel =
    showOnlyPublicData === true
      ? null
      : (segment.owner_name ?? '(Removed User)')

  const { updated_at, inserted_at } = segment
  const showUpdatedAt = updated_at !== inserted_at

  return (
    <span className={className}>
      <span>
        {`Created on ${formatDayShort(parseNaiveDate(inserted_at))}`}
        {!showUpdatedAt && !!authorLabel && ` by ${authorLabel}`}
      </span>
      {showUpdatedAt && (
        <>
          {' • '}
          <span>
            {`last updated on ${formatDayShort(parseNaiveDate(updated_at))}`}
            {!!authorLabel && ` by ${authorLabel}`}
          </span>
        </>
      )}
    </span>
  )
}