fix: one status tile list for both admin cards; clear the copied timer on unmount

- The mail import's status tiles (which, labels, tones) were written out
  in the desktop and the mobile card alike; statTiles in the shared model
  holds them, each card keeps its own look.
- The journey share link set 'copied' back two seconds after a copy even
  when the dialog had closed, which also broke a client test run (window
  gone at teardown). useCopied, the trip share's hook, moves to hooks/ and
  serves both; it clears its timer on unmount.
- PlanLlmConfig is not exported: only the union is used outside.
This commit is contained in:
Maurice
2026-11-13 21:16:17 +01:00
parent 6ac7bd2d96
commit dfbe23e5b8
9 changed files with 134 additions and 50 deletions
@@ -1,7 +1,6 @@
import {
AlertTriangle,
CheckCircle,
Clock,
Copy,
Inbox,
Loader2,
@@ -11,6 +10,7 @@ import {
Upload,
Webhook,
XCircle,
type LucideIcon,
} from 'lucide-react';
import type { ReactNode } from 'react';
import { useTranslation } from '../../../i18n';
@@ -33,11 +33,13 @@ import { useToast } from '../../shared/Toast';
import {
TRANSPORTS,
problemText,
statTiles,
statusFacts,
transportInfo,
transportLabel,
type MailAdminForm,
type MailAdminProblem,
type StatTone,
} from './mailIngestAdminModel';
import { useMailIngestAdmin, type MailIngestAdmin } from './useMailIngestAdmin';
@@ -169,8 +171,6 @@ function WebhookFields({ admin, form, t, error }: FieldsProps) {
);
}
type StatTone = 'neutral' | 'success' | 'warning' | 'danger';
const STAT_TONE: Record<StatTone, { icon: string; value: string }> = {
neutral: { icon: 'bg-surface-tertiary text-content-muted', value: 'text-content' },
success: { icon: 'bg-success-soft text-success', value: 'text-content' },
@@ -185,7 +185,7 @@ function StatTile({
value,
tone,
}: {
icon: typeof Mail;
icon: LucideIcon;
label: string;
value: number;
tone: StatTone;
@@ -229,15 +229,9 @@ function StatusBlock({ admin, t, locale }: { admin: MailIngestAdmin; t: T; local
</span>
</div>
<div className="grid grid-cols-4 gap-1.5 max-md:grid-cols-2">
<StatTile icon={Mail} label={t('mailAdmin.status.mails')} value={facts.mails} tone="neutral" />
<StatTile icon={CheckCircle} label={t('mailAdmin.status.added')} value={facts.added} tone="success" />
<StatTile icon={Clock} label={t('mailAdmin.status.waiting')} value={facts.waiting} tone="warning" />
<StatTile
icon={XCircle}
label={t('mailAdmin.status.failed')}
value={facts.failed}
tone={facts.failed > 0 ? 'danger' : 'neutral'}
/>
{statTiles(facts, t).map(({ key, ...tile }) => (
<StatTile key={key} {...tile} />
))}
</div>
{status.last_error && (
<p className="m-0 flex items-start gap-1.5 rounded-lg bg-warning-soft px-3 py-2 text-caption leading-snug text-warning">
@@ -1,4 +1,4 @@
// FE-ADMIN-MAILINGEST-001 to FE-ADMIN-MAILINGEST-007
// FE-ADMIN-MAILINGEST-001 to FE-ADMIN-MAILINGEST-008
import type { MailIngestAdminStatusResponse } from '@trek/shared';
import { describe, expect, it } from 'vitest';
import {
@@ -10,6 +10,7 @@ import {
formOf,
problemText,
problemsOf,
statTiles,
statusFacts,
transportInfo,
transportLabel,
@@ -105,4 +106,16 @@ describe('mailIngestAdminModel', () => {
'mailAdmin.transport.webhookInfo',
]);
});
it('FE-ADMIN-MAILINGEST-008: the status tiles in order, the failed one red only when something failed', () => {
const t = ((key: string) => key) as never;
const tiles = statTiles({ mails: 4, added: 2, waiting: 1, failed: 0 }, t);
expect(tiles.map(({ key, label, value, tone }) => [key, label, value, tone])).toEqual([
['mails', 'mailAdmin.status.mails', 4, 'neutral'],
['added', 'mailAdmin.status.added', 2, 'success'],
['waiting', 'mailAdmin.status.waiting', 1, 'warning'],
['failed', 'mailAdmin.status.failed', 0, 'neutral'],
]);
expect(statTiles({ mails: 1, added: 0, waiting: 0, failed: 1 }, t)[3].tone).toBe('danger');
});
});
@@ -1,4 +1,5 @@
import type { MailIngestAdminStatusResponse, MailIngestImapTls } from '@trek/shared';
import { CheckCircle, Clock, Mail, XCircle, type LucideIcon } from 'lucide-react';
import type { TranslationFn } from '../../../types';
/**
@@ -129,6 +130,34 @@ export function statusFacts(status: MailIngestAdminStatusResponse): {
};
}
/** How a status tile is coloured; each card maps it onto its own tokens. */
export type StatTone = 'neutral' | 'success' | 'warning' | 'danger';
/** One number of the status card. */
export interface StatTile {
key: 'mails' | 'added' | 'waiting' | 'failed';
icon: LucideIcon;
label: string;
value: number;
tone: StatTone;
}
/** The day's numbers as the status tiles show them, in order, on desktop and mobile alike. */
export function statTiles(facts: ReturnType<typeof statusFacts>, t: TranslationFn): StatTile[] {
return [
{ key: 'mails', icon: Mail, label: t('mailAdmin.status.mails'), value: facts.mails, tone: 'neutral' },
{ key: 'added', icon: CheckCircle, label: t('mailAdmin.status.added'), value: facts.added, tone: 'success' },
{ key: 'waiting', icon: Clock, label: t('mailAdmin.status.waiting'), value: facts.waiting, tone: 'warning' },
{
key: 'failed',
icon: XCircle,
label: t('mailAdmin.status.failed'),
value: facts.failed,
tone: facts.failed > 0 ? 'danger' : 'neutral',
},
];
}
/** A problem in the admin's words; a switch of literal keys so the i18n check sees each one. */
export function problemText(problem: MailAdminProblem, t: TranslationFn): string {
switch (problem) {