O que mudou
Infra (por app):
i18n/locales.ts — lista de locales (pt, en), default pt, labels para o seletor
i18n/request.ts — lê o cookie NEXT_LOCALE, carrega as mensagens
messages/pt.json + messages/en.json — todas as strings extraídas
next.config.ts — envolvido com withNextIntl (operator-pwa: withPWA(withNextIntl(...)))
app/layout.tsx — <html lang={locale}> dinâmico, NextIntlClientProvider
app/language-switcher.tsx — seletor PT | EN (cookie + router.refresh())
23 ficheiros de UI atualizados — todos os textos visíveis agora usam t('...') ou getTranslations.
Datas no relatório passaram de toLocaleString('pt-PT') fixo para useFormatter() do next-intl — localizam-se automaticamente.
Plurais em ICU no sync-chip: {count, plural, one {# pedido...} other {# pedidos...}}.
Resultado dos testes:
pnpm test:e2e — 3/3 ✓
pnpm test:e2e:auth — 4/4 ✓
tsc --noEmit em ambas as apps — limpo ✓
Para adicionar uma língua futura: criar messages/<locale>.json + adicionar o locale a i18n/locales.ts em cada app. O seletor aparece automaticamente.
60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
'use client';
|
|
|
|
import { useEffect, useState } from 'react';
|
|
import Link from 'next/link';
|
|
import { CheckCircle2, Clock } from 'lucide-react';
|
|
import { useTranslations } from 'next-intl';
|
|
import { db } from '@/lib/queue/db';
|
|
import { subscribeBroadcast } from '@/lib/queue/broadcast';
|
|
|
|
export function SentStatus({ cid }: { cid: string }) {
|
|
const t = useTranslations('maintenance');
|
|
const [inQueue, setInQueue] = useState<boolean | null>(null);
|
|
|
|
useEffect(() => {
|
|
async function check() {
|
|
const item = await db.pending.get(cid);
|
|
setInQueue(!!item);
|
|
}
|
|
check();
|
|
|
|
const unsub = subscribeBroadcast((msg) => {
|
|
if (msg.type === 'synced' && msg.clientRequestId === cid) setInQueue(false);
|
|
if (msg.type === 'dead-letter' && msg.clientRequestId === cid) setInQueue(false);
|
|
});
|
|
|
|
return unsub;
|
|
}, [cid]);
|
|
|
|
const pending = inQueue === true;
|
|
|
|
return (
|
|
<main className="mx-auto flex min-h-dvh max-w-lg flex-col items-center justify-center gap-6 p-6 text-center">
|
|
<div className="flex flex-col items-center gap-3">
|
|
{pending ? (
|
|
<Clock className="h-16 w-16 text-orange-400" />
|
|
) : (
|
|
<CheckCircle2 className="h-16 w-16 text-green-500" />
|
|
)}
|
|
<h1 className="text-2xl font-bold">
|
|
{pending ? t('pendingTitle') : t('sentTitle')}
|
|
</h1>
|
|
{cid && (
|
|
<p className="font-mono text-xs text-muted-foreground" data-testid="request-cid">
|
|
{cid}
|
|
</p>
|
|
)}
|
|
<p className="text-sm text-muted-foreground">
|
|
{pending ? t('pendingMessage') : t('sentMessage')}
|
|
</p>
|
|
</div>
|
|
<Link
|
|
href="/"
|
|
className="rounded-xl bg-primary px-8 py-3 font-semibold text-primary-foreground hover:opacity-90"
|
|
>
|
|
{t('backHome')}
|
|
</Link>
|
|
</main>
|
|
);
|
|
}
|