Files
ipal-kit/src/modules/stats/admin/StatsWidget.tsx
T
Radosław SmolińskiandClaude Opus 5.5 6b46bc0c14 Admin panel in English and Polish, reworded per docs/dev/admin-ux.md
- admin-i18n module: AdminText { en, pl }, component texts under the ipal
  namespace (project translations win), en + pl admin languages when the
  project sets none (project's supportedLanguages wins)
- every plugin label, description, option, tab and group as { en, pl };
  explicit labels instead of auto-labels; sentence case; glossary terms
- visible renames (slugs, names, data unchanged): Cookie banner, Form
  messages, Privacy group, Search engines, Maintenance, Spam protection,
  E-mail sending, stats nav link Overview (hidden without access)
- Polish visitor defaults by page locale: cookie banner, form messages,
  validators, lightbox, accessibility widget; {field} uses the label
- fixes: e-mail status banner used Turnstile wording; developer words and
  env var names out of editor messages; stats numbers/dates in the admin
  language; test e-mail no longer says ipal-kit
- test/adminUx.test.ts: length limits, en + pl present, no developer words

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-27 15:46:25 +01:00

49 lines
1.7 KiB
TypeScript

import type { Payload, PayloadRequest } from 'payload'
import type { StatsI18n } from './statsI18n.js'
import { canReadStats } from './canReadStats.js'
import { loadStats } from './loadStats.js'
import { num, statsI18n, tr } from './statsI18n.js'
import { STATS_CSS, VisitsChart } from './VisitsChart.js'
type Props = {
adminRoute?: string
/** Injected by Payload into admin server components. */
i18n?: StatsI18n
payload?: Payload
req?: PayloadRequest
timeZone?: string
user?: unknown
}
/**
* Dashboard card (admin.components.beforeDashboard): visits per day for the
* last 30 days with a link to the full view. For users the stats-visits
* collection lets read (admins by default); renders nothing on
* any error (DB not ready, collection missing).
*/
export async function StatsWidget({ adminRoute = '/admin', i18n: i18nProp, payload, req, timeZone = 'Europe/Warsaw', user }: Props) {
if (!payload || !(await canReadStats(payload, req, user))) {return null}
const i18n = statsI18n(i18nProp ?? (req?.i18n as StatsI18n | undefined))
let stats
try {
stats = await loadStats(payload, { timeZone })
} catch {
return null
}
return (
<section className="ipal-stats" style={{ marginBottom: '2rem' }}>
<style>{STATS_CSS}</style>
<h2 style={{ marginBottom: '0.25rem' }}>{tr(i18n, 'statsVisitsPerDay')}</h2>
<p style={{ color: 'var(--theme-elevation-500)', margin: '0 0 0.75rem' }}>
{tr(i18n, 'statsWidgetSummary', { views: num(i18n, stats.totals.views), visits: num(i18n, stats.totals.visits) })} ·{' '}
<a href={`${adminRoute.replace(/\/$/, '')}/stats`}>{tr(i18n, 'statsWidgetLink')}</a>
</p>
<VisitsChart days={stats.days} i18n={i18n} />
</section>
)
}
export default StatsWidget