Email for professionals and teams
Translate webhooks
Hieu Nguyen (Jack)379be2955bed
diff --git a/src/app/(admin)/webhooks/deliveries.tsx b/src/app/(admin)/webhooks/deliveries.tsxindex c9a03d3..afc05dc 100644--- a/src/app/(admin)/webhooks/deliveries.tsx+++ b/src/app/(admin)/webhooks/deliveries.tsx@@ -2,6 +2,7 @@import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";import { RotateCw } from "lucide-react";+import { useLanguage } from "@/components/language-provider";import { Badge } from "@/components/ui/badge";import { Button } from "@/components/ui/button";import type { WebhookDelivery } from "./types";@@ -23,6 +24,7 @@ const STATUS_STYLES: Record<WebhookDelivery["status"], string> = {};export function WebhookDeliveries({ webhookId }: { webhookId: string }) {+ const { t } = useLanguage();const qc = useQueryClient();const deliveries = useQuery({queryKey: ["webhook-deliveries", webhookId],@@ -40,11 +42,11 @@ export function WebhookDeliveries({ webhookId }: { webhookId: string }) {});if (deliveries.isLoading) {- return <p className="text-sm text-neutral-500">Loading deliveries…</p>;+ return <p className="text-sm text-neutral-500">{t("webhooks.loadingDeliveries")}</p>;}if (!deliveries.data?.length) {- return <p className="text-sm text-neutral-500">No deliveries recorded yet.</p>;+ return <p className="text-sm text-neutral-500">{t("webhooks.noDeliveries")}</p>;}return (@@ -52,12 +54,12 @@ export function WebhookDeliveries({ webhookId }: { webhookId: string }) {<table className="w-full min-w-[820px] text-left text-sm"><thead className="bg-neutral-50 text-xs uppercase tracking-wide text-neutral-500"><tr>- <th className="px-3 py-2 font-medium">Event</th>- <th className="px-3 py-2 font-medium">Status</th>- <th className="px-3 py-2 font-medium">Attempts</th>- <th className="px-3 py-2 font-medium">Response</th>- <th className="px-3 py-2 font-medium">Last attempt</th>- <th className="px-3 py-2 font-medium">Next retry</th>+ <th className="px-3 py-2 font-medium">{t("webhooks.col.event")}</th>+ <th className="px-3 py-2 font-medium">{t("webhooks.col.status")}</th>+ <th className="px-3 py-2 font-medium">{t("webhooks.col.attempts")}</th>+ <th className="px-3 py-2 font-medium">{t("webhooks.col.response")}</th>+ <th className="px-3 py-2 font-medium">{t("webhooks.col.lastAttempt")}</th>+ <th className="px-3 py-2 font-medium">{t("webhooks.col.nextRetry")}</th><th className="px-3 py-2 font-medium" /></tr></thead>@@ -72,7 +74,7 @@ export function WebhookDeliveries({ webhookId }: { webhookId: string }) {</td><td className="px-3 py-2"><Badge className={STATUS_STYLES[delivery.status]}>- {DELIVERY_STATUS_LABELS[delivery.status] ?? delivery.status}+ {DELIVERY_STATUS_LABELS[delivery.status] ? t(DELIVERY_STATUS_LABELS[delivery.status]) : delivery.status}</Badge></td><td className="px-3 py-2 whitespace-nowrap">@@ -109,7 +111,7 @@ export function WebhookDeliveries({ webhookId }: { webhookId: string }) {disabled={retry.isPending}onClick={() => retry.mutate(delivery.id)}>- <RotateCw className="h-3 w-3" /> Retry+ <RotateCw className="h-3 w-3" /> {t("webhooks.retry")}</Button>)}</td>diff --git a/src/app/(admin)/webhooks/page.tsx b/src/app/(admin)/webhooks/page.tsxindex 53229ac..ae90bb5 100644--- a/src/app/(admin)/webhooks/page.tsx+++ b/src/app/(admin)/webhooks/page.tsx@@ -4,6 +4,7 @@ import { mobilePrimaryActionClass } from "@/components/page-header-utils";import { useState } from "react";import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";import { Activity, Plus, RefreshCw, Send, Trash2 } from "lucide-react";+import { useLanguage } from "@/components/language-provider";import { Badge } from "@/components/ui/badge";import { Button } from "@/components/ui/button";import { Card, CardContent } from "@/components/ui/card";@@ -30,6 +31,7 @@ import {import { WebhookDeliveries } from "./deliveries";export default function WebhooksPage() {+ const { t } = useLanguage();const qc = useQueryClient();const [dialogOpen, setDialogOpen] = useState(false);const [url, setUrl] = useState("");@@ -89,9 +91,9 @@ export default function WebhooksPage() {<div className="space-y-6"><div className="flex flex-wrap items-end justify-between gap-4"><div>- <h1 className="text-2xl font-semibold">Webhooks</h1>+ <h1 className="text-2xl font-semibold">{t("webhooks.title")}</h1><p className="mt-1 text-sm text-neutral-500">- Deliver message events to your own endpoints, with automatic retries.+ {t("webhooks.description")}</p></div><Button@@ -101,23 +103,22 @@ export default function WebhooksPage() {setDialogOpen(true);}}>- <Plus className="h-4 w-4" /> Add endpoint+ <Plus className="h-4 w-4" /> {t("webhooks.add")}</Button></div>{secret && (<Card><CardContent className="pt-6 text-sm">- <p className="font-medium">Signing secret — shown once</p>+ <p className="font-medium">{t("webhooks.secretTitle")}</p><p className="mt-1 text-neutral-500">- Verify the <code>X-Email-Platform-Signature</code> header (HMAC-SHA256 of the raw- body) with this secret.+ {t("webhooks.secretHint", { header: "\u0001" }).split("\u0001").flatMap((part, index) => index === 0 ? [part] : [<code key={index}>X-Email-Platform-Signature</code>, part])}</p><code className="mt-2 block break-all rounded-lg bg-neutral-100 p-2 text-xs">{secret}</code><Button variant="outline" size="sm" className="mt-3" onClick={() => setSecret(null)}>- Dismiss+ {t("webhooks.dismiss")}</Button></CardContent></Card>@@ -129,7 +130,7 @@ export default function WebhooksPage() {) : !webhooks.data?.length ? (<Card><CardContent className="pt-6 text-sm text-neutral-500">- No endpoints yet. Add one to start receiving events.+ {t("webhooks.none")}</CardContent></Card>) : (@@ -151,40 +152,40 @@ export default function WebhooksPage() {</div></div><div className="flex items-center gap-2 rounded-full">- <span className="text-xs font-medium text-neutral-600">{hook.enabled ? "Enabled" : "Disabled"}</span>+ <span className="text-xs font-medium text-neutral-600">{hook.enabled ? t("webhooks.enabled") : t("webhooks.disabled")}</span><Switchchecked={hook.enabled}onCheckedChange={() => toggle.mutate(hook)}- aria-label={`${hook.enabled ? "Disable" : "Enable"} ${hook.url}`}+ aria-label={t(hook.enabled ? "webhooks.toggleLabel.disable" : "webhooks.toggleLabel.enable", { url: hook.url })}/></div></div><div className="mt-5 grid grid-cols-2 overflow-hidden rounded-2xl bg-neutral-50 sm:grid-cols-5"><div className="px-4 py-3"><span className="block text-lg font-semibold text-neutral-900">{hook.stats.total}</span>- <span className="block text-xs text-neutral-500">Deliveries</span>+ <span className="block text-xs text-neutral-500">{t("webhooks.stat.deliveries")}</span></div><div className="px-4 py-3"><span className={`block text-lg font-semibold ${hook.stats.delivered ? "text-green-600" : "text-neutral-400"}`}>{hook.stats.delivered}</span>- <span className="block text-xs text-neutral-500">Delivered</span>+ <span className="block text-xs text-neutral-500">{t("webhooks.stat.delivered")}</span></div><div className="px-4 py-3"><span className={`block text-lg font-semibold ${hook.stats.pending ? "text-amber-600" : "text-neutral-400"}`}>{hook.stats.pending}</span>- <span className="block text-xs text-neutral-500">In flight</span>+ <span className="block text-xs text-neutral-500">{t("webhooks.stat.inFlight")}</span></div><div className="px-4 py-3"><span className={`block text-lg font-semibold ${hook.stats.failing ? "text-red-600" : "text-neutral-400"}`}>{hook.stats.failing}</span>- <span className="block text-xs text-neutral-500">Failed</span>+ <span className="block text-xs text-neutral-500">{t("webhooks.stat.failed")}</span></div><div className="px-4 py-3"><span className="block text-lg font-semibold text-neutral-500">{hook.maxAttempts}</span>- <span className="block text-xs text-neutral-500">Max attempts</span>+ <span className="block text-xs text-neutral-500">{t("webhooks.stat.maxAttempts")}</span></div></div>@@ -195,12 +196,12 @@ export default function WebhooksPage() {onClick={() => setExpanded(expanded === hook.id ? null : hook.id)}><Activity className="h-4 w-4" />- {expanded === hook.id ? "Hide delivery history" : "Delivery history"}+ {expanded === hook.id ? t("webhooks.hideHistory") : t("webhooks.history")}</Button><div className="ml-auto flex flex-wrap items-center gap-2">{testResult[hook.id] && (<p className="mr-1 text-sm text-neutral-600">- Test delivery: <span className="font-medium">{testResult[hook.id]}</span>+ {t("webhooks.testDelivery", { result: testResult[hook.id] })}</p>)}<Button@@ -209,25 +210,25 @@ export default function WebhooksPage() {onClick={() => runTest.mutate(hook.id)}disabled={runTest.isPending}>- <Send className="h-4 w-4" /> Test+ <Send className="h-4 w-4" /> {t("webhooks.test")}</Button><Buttonvariant="ghost"size="sm"onClick={() => {- if (window.confirm("Rotate this signing secret? The previous secret will stop signing new deliveries immediately.")) rotate.mutate(hook.id);+ if (window.confirm(t("webhooks.rotateConfirm"))) rotate.mutate(hook.id);}}disabled={rotate.isPending}>- <RefreshCw className="h-4 w-4" /> Rotate secret+ <RefreshCw className="h-4 w-4" /> {t("webhooks.rotate")}</Button><Buttonvariant="ghost"size="sm"onClick={() => remove.mutate(hook.id)}- aria-label={`Delete ${hook.url}`}+ aria-label={t("webhooks.deleteLabel", { url: hook.url })}>- <Trash2 className="h-4 w-4" /> Delete+ <Trash2 className="h-4 w-4" /> {t("common.delete")}</Button></div></div>@@ -245,9 +246,9 @@ export default function WebhooksPage() {<Dialog open={dialogOpen} onOpenChange={setDialogOpen}><DialogContent className="max-h-[calc(100vh-4rem)] overflow-y-auto"><DialogHeader>- <DialogTitle>Add endpoint</DialogTitle>+ <DialogTitle>{t("webhooks.add")}</DialogTitle><DialogDescription>- Failed deliveries retry automatically with exponential backoff.+ {t("webhooks.addDescription")}</DialogDescription></DialogHeader><form@@ -258,7 +259,7 @@ export default function WebhooksPage() {}}><div className="space-y-2">- <Label htmlFor="hook-url">Endpoint URL</Label>+ <Label htmlFor="hook-url">{t("webhooks.endpointUrl")}</Label><Inputid="hook-url"type="url"@@ -268,24 +269,24 @@ export default function WebhooksPage() {/></div><div className="space-y-2">- <Label htmlFor="hook-description">Description</Label>+ <Label htmlFor="hook-description">{t("webhooks.descriptionLabel")}</Label><Inputid="hook-description"value={description}- placeholder="Optional"+ placeholder={t("webhooks.optional")}onChange={(e) => setDescription(e.target.value)}/></div><div className="space-y-2">- <Label>Events</Label>+ <Label>{t("webhooks.events")}</Label>{WEBHOOK_EVENTS.map((event) => (<labelkey={event.value}className="flex cursor-pointer items-center justify-between rounded-lg border border-neutral-200 px-3 py-2"><span>- <span className="block text-sm font-medium">{event.label}</span>- <span className="block text-xs text-neutral-500">{event.hint}</span>+ <span className="block text-sm font-medium">{t(event.labelKey)}</span>+ <span className="block text-xs text-neutral-500">{t(event.hintKey)}</span></span><inputtype="checkbox"@@ -297,7 +298,7 @@ export default function WebhooksPage() {))}</div><div className="space-y-2">- <Label htmlFor="hook-attempts">Max attempts</Label>+ <Label htmlFor="hook-attempts">{t("webhooks.stat.maxAttempts")}</Label><Inputid="hook-attempts"type="number"@@ -312,13 +313,13 @@ export default function WebhooksPage() {<div className="flex justify-end gap-2"><Button type="button" variant="outline" onClick={() => setDialogOpen(false)}>- Cancel+ {t("common.cancel")}</Button><Button type="submit" disabled={create.isPending || events.length === 0}><RefreshCwclassName={create.isPending ? "h-4 w-4 animate-spin" : "hidden"}/>- Create+ {t("webhooks.create")}</Button></div></form>diff --git a/src/app/(admin)/webhooks/utils.ts b/src/app/(admin)/webhooks/utils.tsindex c431889..1e9231a 100644--- a/src/app/(admin)/webhooks/utils.ts+++ b/src/app/(admin)/webhooks/utils.ts@@ -1,3 +1,5 @@+import type { TranslationKey } from "@/lib/i18n/types";+import { defaultTranslator } from "@/lib/i18n/utils";import { authFetch } from "@/lib/auth/client";import { formatUserDate } from "@/lib/time/utils";import type {@@ -8,24 +10,24 @@ import type {WebhookEvent,} from "./types";-export const WEBHOOK_EVENTS: { value: WebhookEvent; label: string; hint: string }[] = [- { value: "message.inbound", label: "Inbound message", hint: "A message was received and stored" },- { value: "message.outbound", label: "Outbound message", hint: "A message was sent" },- { value: "message.failed", label: "Delivery failure", hint: "An outbound message failed" },+export const WEBHOOK_EVENTS: { value: WebhookEvent; labelKey: TranslationKey; hintKey: TranslationKey }[] = [+ { value: "message.inbound", labelKey: "webhooks.event.inbound", hintKey: "webhooks.event.inboundHint" },+ { value: "message.outbound", labelKey: "webhooks.event.outbound", hintKey: "webhooks.event.outboundHint" },+ { value: "message.failed", labelKey: "webhooks.event.failed", hintKey: "webhooks.event.failedHint" },];export const DELIVERY_STATUS_LABELS = {- pending: "Pending",- delivered: "Delivered",- failed: "Failed",- retrying: "Retrying",- exhausted: "Gave up",-} as const;+ pending: "webhooks.status.pending",+ delivered: "webhooks.status.delivered",+ failed: "webhooks.status.failed",+ retrying: "webhooks.status.retrying",+ exhausted: "webhooks.status.exhausted",+} as const satisfies Record<string, TranslationKey>;async function readJson<T>(res: Response): Promise<T> {const json = (await res.json()) as T & { error?: unknown };if (!res.ok) {- throw new Error(typeof json.error === "string" ? json.error : "Request failed");+ throw new Error(typeof json.error === "string" ? json.error : defaultTranslator("domains.requestFailed"));}return json;}diff --git a/src/lib/i18n/en.json b/src/lib/i18n/en.jsonindex 5fc5310..f17eb07 100644--- a/src/lib/i18n/en.json+++ b/src/lib/i18n/en.json@@ -1237,5 +1237,54 @@"ses.domainHint": "Verified sender identity in SES","ses.sandboxHint": "Account-wide restriction","ses.sandboxDetail": "In the sandbox SES delivers only to verified addresses. Request production access in the SES console before sending to anyone else.",- "ses.addCnames": "Add these CNAME records where this domain's DNS is hosted, then check status."+ "ses.addCnames": "Add these CNAME records where this domain's DNS is hosted, then check status.",+ "webhooks.event.inbound": "Inbound message",+ "webhooks.event.inboundHint": "A message was received and stored",+ "webhooks.event.outbound": "Outbound message",+ "webhooks.event.outboundHint": "A message was sent",+ "webhooks.event.failed": "Delivery failure",+ "webhooks.event.failedHint": "An outbound message failed",+ "webhooks.status.pending": "Pending",+ "webhooks.status.delivered": "Delivered",+ "webhooks.status.failed": "Failed",+ "webhooks.status.retrying": "Retrying",+ "webhooks.status.exhausted": "Gave up",+ "webhooks.title": "Webhooks",+ "webhooks.description": "Deliver message events to your own endpoints, with automatic retries.",+ "webhooks.add": "Add endpoint",+ "webhooks.secretTitle": "Signing secret — shown once",+ "webhooks.secretHint": "Verify the {header} header (HMAC-SHA256 of the raw body) with this secret.",+ "webhooks.dismiss": "Dismiss",+ "webhooks.none": "No endpoints yet. Add one to start receiving events.",+ "webhooks.enabled": "Enabled",+ "webhooks.disabled": "Disabled",+ "webhooks.toggleLabel.disable": "Disable {url}",+ "webhooks.toggleLabel.enable": "Enable {url}",+ "webhooks.stat.deliveries": "Deliveries",+ "webhooks.stat.delivered": "Delivered",+ "webhooks.stat.inFlight": "In flight",+ "webhooks.stat.failed": "Failed",+ "webhooks.stat.maxAttempts": "Max attempts",+ "webhooks.hideHistory": "Hide delivery history",+ "webhooks.history": "Delivery history",+ "webhooks.testDelivery": "Test delivery: {result}",+ "webhooks.test": "Test",+ "webhooks.rotateConfirm": "Rotate this signing secret? The previous secret will stop signing new deliveries immediately.",+ "webhooks.rotate": "Rotate secret",+ "webhooks.deleteLabel": "Delete {url}",+ "webhooks.addDescription": "Failed deliveries retry automatically with exponential backoff.",+ "webhooks.endpointUrl": "Endpoint URL",+ "webhooks.descriptionLabel": "Description",+ "webhooks.optional": "Optional",+ "webhooks.events": "Events",+ "webhooks.create": "Create",+ "webhooks.col.event": "Event",+ "webhooks.col.status": "Status",+ "webhooks.col.attempts": "Attempts",+ "webhooks.col.response": "Response",+ "webhooks.col.lastAttempt": "Last attempt",+ "webhooks.col.nextRetry": "Next retry",+ "webhooks.loadingDeliveries": "Loading deliveries…",+ "webhooks.noDeliveries": "No deliveries recorded yet.",+ "webhooks.retry": "Retry"}diff --git a/src/lib/i18n/pt-BR.json b/src/lib/i18n/pt-BR.jsonindex 9bd1720..700f8bd 100644--- a/src/lib/i18n/pt-BR.json+++ b/src/lib/i18n/pt-BR.json@@ -1237,5 +1237,54 @@"ses.domainHint": "Identidade de remetente verificada no SES","ses.sandboxHint": "Restrição em toda a conta","ses.sandboxDetail": "No sandbox, o SES entrega apenas a endereços verificados. Solicite acesso de produção no console do SES antes de enviar a outras pessoas.",- "ses.addCnames": "Adicione estes registros CNAME onde o DNS deste domínio está hospedado e depois verifique o status."+ "ses.addCnames": "Adicione estes registros CNAME onde o DNS deste domínio está hospedado e depois verifique o status.",+ "webhooks.event.inbound": "Mensagem recebida",+ "webhooks.event.inboundHint": "Uma mensagem foi recebida e armazenada",+ "webhooks.event.outbound": "Mensagem enviada",+ "webhooks.event.outboundHint": "Uma mensagem foi enviada",+ "webhooks.event.failed": "Falha de entrega",+ "webhooks.event.failedHint": "Uma mensagem enviada falhou",+ "webhooks.status.pending": "Pendente",+ "webhooks.status.delivered": "Entregue",+ "webhooks.status.failed": "Falhou",+ "webhooks.status.retrying": "Tentando novamente",+ "webhooks.status.exhausted": "Desistiu",+ "webhooks.title": "Webhooks",+ "webhooks.description": "Entregue eventos de mensagens aos seus próprios endpoints, com novas tentativas automáticas.",+ "webhooks.add": "Adicionar endpoint",+ "webhooks.secretTitle": "Segredo de assinatura — exibido uma vez",+ "webhooks.secretHint": "Verifique o cabeçalho {header} (HMAC-SHA256 do corpo bruto) com este segredo.",+ "webhooks.dismiss": "Dispensar",+ "webhooks.none": "Nenhum endpoint ainda. Adicione um para começar a receber eventos.",+ "webhooks.enabled": "Ativado",+ "webhooks.disabled": "Desativado",+ "webhooks.toggleLabel.disable": "Desativar {url}",+ "webhooks.toggleLabel.enable": "Ativar {url}",+ "webhooks.stat.deliveries": "Entregas",+ "webhooks.stat.delivered": "Entregues",+ "webhooks.stat.inFlight": "Em andamento",+ "webhooks.stat.failed": "Falhas",+ "webhooks.stat.maxAttempts": "Máximo de tentativas",+ "webhooks.hideHistory": "Ocultar histórico de entregas",+ "webhooks.history": "Histórico de entregas",+ "webhooks.testDelivery": "Entrega de teste: {result}",+ "webhooks.test": "Testar",+ "webhooks.rotateConfirm": "Girar este segredo de assinatura? O segredo anterior deixará de assinar novas entregas imediatamente.",+ "webhooks.rotate": "Girar segredo",+ "webhooks.deleteLabel": "Excluir {url}",+ "webhooks.addDescription": "As entregas com falha são repetidas automaticamente com espera exponencial.",+ "webhooks.endpointUrl": "URL do endpoint",+ "webhooks.descriptionLabel": "Descrição",+ "webhooks.optional": "Opcional",+ "webhooks.events": "Eventos",+ "webhooks.create": "Criar",+ "webhooks.col.event": "Evento",+ "webhooks.col.status": "Status",+ "webhooks.col.attempts": "Tentativas",+ "webhooks.col.response": "Resposta",+ "webhooks.col.lastAttempt": "Última tentativa",+ "webhooks.col.nextRetry": "Próxima tentativa",+ "webhooks.loadingDeliveries": "Carregando entregas…",+ "webhooks.noDeliveries": "Nenhuma entrega registrada ainda.",+ "webhooks.retry": "Tentar novamente"}