mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 23:50:08 +00:00
94ac7673a5
The settings pages had grown into a mix of styles: folds, dialogs behind rows, full-width rows next to boxed ones, pills for every figure and buttons in four sizes. Every page now uses the same kit. - Cards keep their tinted head band; every part of a card is a rounded block with its own small head (SettingsBlock), and rows sit in rounded boxes. - Nothing folds and nothing hides behind a dialog: the MCP config, OAuth scopes, mail how-to, AI privacy note and addon sub-options are all shown. - Each page is split into two columns balanced by length (SettingsColumns). - Long explanations moved into an info mark next to the label (HintMark). - One button size everywhere (text-control); tab names are one word. - Admin: the old Settings tab is split into Security and Services (?tab=settings still opens Security, and the phone keeps its single Settings section for both); the Integration group is gone, live flights and mail import sit next to the addons they configure. - Addons: one card per type with rows, no search, filter or fold. - Quota, TREK API facts, mail import status and Google's daily limit are compact lines and strips instead of tiles and pills. - Language is a select; routing has its own card under the defaults; storage saves from the foot of its categories card. - Unused keys, FoldSummary and the page-width wrapper are removed.
102 lines
4.3 KiB
TypeScript
102 lines
4.3 KiB
TypeScript
import React from 'react'
|
|
import { useTranslation } from '../../i18n'
|
|
import { RefreshCw, ClipboardList, Loader2 } from 'lucide-react'
|
|
import { fs } from '../shared/DialogShell'
|
|
import { SETTINGS_BUTTON, SettingsCard, SettingsHint, StatusPill } from '../Settings/settingsKit'
|
|
import { useAuditLog } from './useAuditLog'
|
|
|
|
interface AuditLogPanelProps {
|
|
serverTimezone?: string
|
|
}
|
|
|
|
const TH = 'whitespace-nowrap px-3.5 py-2.5 text-start font-geist font-bold uppercase tracking-[.08em] text-content-faint'
|
|
const TD = 'px-3.5 py-2.5 align-top'
|
|
const CODE = 'font-geist tabular-nums'
|
|
|
|
export default function AuditLogPanel({ serverTimezone }: AuditLogPanelProps): React.ReactElement {
|
|
const { t } = useTranslation()
|
|
const { entries, total, loading, loadFirstPage, loadMore, fmtTime, fmtDetails, userLabel } = useAuditLog(serverTimezone)
|
|
|
|
let body: React.ReactNode
|
|
if (loading && entries.length === 0) {
|
|
body = (
|
|
<div className="flex items-center justify-center gap-2 py-10 text-content-faint" style={fs(12.5, 'body')}>
|
|
<Loader2 size={15} className="animate-spin" />
|
|
<span>{t('common.loading')}</span>
|
|
</div>
|
|
)
|
|
} else if (entries.length === 0) {
|
|
body = <SettingsHint className="py-6 text-center">{t('admin.audit.empty')}</SettingsHint>
|
|
} else {
|
|
body = (
|
|
<div className={`overflow-x-auto rounded-[12px] border border-edge-faint bg-surface-card transition-opacity ${loading ? 'opacity-60' : ''}`}>
|
|
<table className="w-full min-w-[720px] border-collapse">
|
|
<thead>
|
|
<tr className="border-b border-edge-faint bg-surface-secondary" style={fs(9.5)}>
|
|
<th className={TH}>{t('admin.audit.col.time')}</th>
|
|
<th className={TH}>{t('admin.audit.col.user')}</th>
|
|
<th className={TH}>{t('admin.audit.col.action')}</th>
|
|
<th className={TH}>{t('admin.audit.col.resource')}</th>
|
|
<th className={TH}>{t('admin.audit.col.ip')}</th>
|
|
<th className={TH}>{t('admin.audit.col.details')}</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody className="divide-y divide-edge-faint" style={fs(12, 'body')}>
|
|
{entries.map((e) => (
|
|
<tr key={e.id} className="hover:bg-surface-secondary">
|
|
<td className={`${TD} ${CODE} whitespace-nowrap text-content-muted`}>{fmtTime(e.created_at)}</td>
|
|
<td className={`${TD} font-medium text-content`}>
|
|
{/* A table cell ignores max-width under auto layout, so the box inside truncates. */}
|
|
<span className="block max-w-[180px] truncate" title={userLabel(e)}>{userLabel(e)}</span>
|
|
</td>
|
|
<td className={`${TD} whitespace-nowrap`}>
|
|
<span className={`${CODE} inline-block rounded-[6px] bg-surface-tertiary px-1.5 py-[1px] text-content`}>{e.action}</span>
|
|
</td>
|
|
<td className={`${TD} ${CODE} max-w-[160px] break-all text-content-muted`}>{e.resource || '—'}</td>
|
|
<td className={`${TD} ${CODE} whitespace-nowrap text-content-muted`}>{e.ip || '—'}</td>
|
|
<td className={`${TD} ${CODE} max-w-[300px] break-all text-content-faint`}>{fmtDetails(e.details)}</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<SettingsCard
|
|
icon={ClipboardList}
|
|
title={t('admin.tabs.audit')}
|
|
hint={t('admin.audit.subtitle')}
|
|
// The count only once there is one: never "0 of 0" while the first page loads.
|
|
badge={total > 0 ? <StatusPill>{t('admin.audit.showing', { count: entries.length, total })}</StatusPill> : undefined}
|
|
action={
|
|
<button
|
|
type="button"
|
|
disabled={loading}
|
|
onClick={() => loadFirstPage()}
|
|
className={SETTINGS_BUTTON}
|
|
>
|
|
<RefreshCw size={14} strokeWidth={2.2} className={loading ? 'animate-spin' : ''} />
|
|
{t('admin.audit.refresh')}
|
|
</button>
|
|
}
|
|
>
|
|
{body}
|
|
|
|
{entries.length < total && (
|
|
<div className="flex justify-center">
|
|
<button
|
|
type="button"
|
|
disabled={loading}
|
|
onClick={() => loadMore()}
|
|
className={SETTINGS_BUTTON}
|
|
>
|
|
{t('admin.audit.loadMore')}
|
|
</button>
|
|
</div>
|
|
)}
|
|
</SettingsCard>
|
|
)
|
|
}
|