import { PLACE_CONTRIB_FIELDS, type PlaceContribField, type PlaceContribLogResponse, type PlaceContribLogResult, } from '@trek/shared'; import { ChevronLeft, ChevronRight } from 'lucide-react'; import { useEffect, useState } from 'react'; import { useTranslation } from '../../i18n'; import { placeContribRepo } from '../../repo/placeContribRepo'; import { PillSelect } from '../shared/dialogParts'; import { fs } from '../shared/DialogShell'; import { fieldLabel } from './placeContribModel'; const PER_PAGE = 20; const RESULTS: PlaceContribLogResult[] = ['accepted', 'duplicate', 'rejected', 'withheld', 'retracted']; const RESULT_LOOK: Record = { accepted: 'bg-success-soft text-success', duplicate: 'bg-surface-tertiary text-content-muted', rejected: 'bg-danger-soft text-danger', withheld: 'bg-surface-tertiary text-content-muted', retracted: 'bg-warning-soft text-warning', }; /** * What this installation sent, newest first: the place, the field, a short * form of the value and what the service made of it. Read only while the fold * is open, a page at a time. */ export default function PlaceContribLog() { const { t, locale } = useTranslation(); const [page, setPage] = useState(1); const [result, setResult] = useState('all'); const [field, setField] = useState('all'); const [data, setData] = useState(null); const [failed, setFailed] = useState(false); useEffect(() => { const controller = new AbortController(); setFailed(false); placeContribRepo .log( { page, perPage: PER_PAGE, ...(result === 'all' ? {} : { result }), ...(field === 'all' ? {} : { field }), }, controller.signal ) .then(setData, () => { if (!controller.signal.aborted) setFailed(true); }); return () => controller.abort(); }, [page, result, field]); const pages = data ? Math.max(1, Math.ceil(data.total / PER_PAGE)) : 1; const day = new Intl.DateTimeFormat(locale, { day: 'numeric', month: 'short' }); return (
quiet label={t('admin.contribute.log.result')} value={result} onChange={(v) => { setResult(v); setPage(1); }} options={[ { value: 'all', label: t('admin.contribute.log.allResults') }, ...RESULTS.map((r) => ({ value: r, label: t(`admin.contribute.result.${r}`) })), ]} /> quiet label={t('admin.contribute.log.field')} value={field} onChange={(v) => { setField(v); setPage(1); }} options={[ { value: 'all', label: t('admin.contribute.log.allFields') }, ...PLACE_CONTRIB_FIELDS.map((f) => ({ value: f, label: fieldLabel(t, f) })), ]} />
{failed && (

{t('admin.contribute.log.failed')}

)} {data && data.entries.length === 0 && (

{t('admin.contribute.log.empty')}

)} {data && data.entries.length > 0 && (
    {data.entries.map((e) => (
  • {day.format(new Date(`${e.day}T12:00:00`))} {e.placeName} {e.valueSummary && ( {e.valueSummary} )} {fieldLabel(t, e.field)} {t(`admin.contribute.result.${e.result}`)}
  • ))}
)} {data && pages > 1 && (
{page} / {pages}
)}
); }