refactor(shared-error-page): update error page to use translation keys for dynamic content

This commit is contained in:
beilunyang
2025-10-22 01:04:10 +08:00
parent 7398b73f3f
commit 1ffe920d47
6 changed files with 62 additions and 60 deletions
@@ -188,7 +188,6 @@ export function SharedEmailPageClient({
return tShared("sharedMailbox")
}
})()}
showCta={true}
ctaText={tShared("createOwnEmail")}
/>
+5 -7
View File
@@ -1,4 +1,3 @@
import { getTranslations } from "next-intl/server"
import { getSharedEmail, getSharedEmailMessages } from "@/lib/shared-data"
import { SharedErrorPage } from "@/components/emails/shared-error-page"
import { SharedEmailPageClient } from "./page-client"
@@ -12,7 +11,6 @@ interface PageProps {
export default async function SharedEmailPage({ params }: PageProps) {
const { token } = await params
const tShared = await getTranslations("emails.shared")
// 服务端获取数据
const email = await getSharedEmail(token)
@@ -20,11 +18,11 @@ export default async function SharedEmailPage({ params }: PageProps) {
if (!email) {
return (
<SharedErrorPage
title={tShared("emailNotFound")}
subtitle={tShared("linkExpired")}
error={tShared("linkInvalid")}
description={tShared("linkInvalidDescription")}
ctaText={tShared("createOwnEmail")}
titleKey="emailNotFound"
subtitleKey="linkExpired"
errorKey="linkInvalid"
descriptionKey="linkInvalidDescription"
ctaTextKey="createOwnEmail"
/>
)
}
@@ -37,7 +37,6 @@ export function SharedMessagePageClient({ message }: SharedMessagePageClientProp
: message.emailExpiresAt
? `${tShared("expiresAt")}: ${new Date(message.emailExpiresAt).toLocaleString()}`
: tShared("sharedMessage")}
showCta={true}
ctaText={tShared("createOwnEmail")}
/>
+5 -7
View File
@@ -1,4 +1,3 @@
import { getTranslations } from "next-intl/server"
import { getSharedMessage } from "@/lib/shared-data"
import { SharedErrorPage } from "@/components/emails/shared-error-page"
import { SharedMessagePageClient } from "./page-client"
@@ -12,7 +11,6 @@ interface PageProps {
export default async function SharedMessagePage({ params }: PageProps) {
const { token } = await params
const tShared = await getTranslations("emails.shared")
// 服务端获取数据
const message = await getSharedMessage(token)
@@ -20,11 +18,11 @@ export default async function SharedMessagePage({ params }: PageProps) {
if (!message) {
return (
<SharedErrorPage
title={tShared("messageNotFound")}
subtitle={tShared("linkExpired")}
error={tShared("linkInvalid")}
description={tShared("linkInvalidDescription")}
ctaText={tShared("createOwnEmail")}
titleKey="messageNotFound"
subtitleKey="linkExpired"
errorKey="linkInvalid"
descriptionKey="linkInvalidDescription"
ctaTextKey="createOwnEmail"
/>
)
}
+28 -14
View File
@@ -1,34 +1,48 @@
"use client"
import { useTranslations } from "next-intl"
import { AlertCircle } from "lucide-react"
import { Card } from "@/components/ui/card"
import { BrandHeader } from "@/components/ui/brand-header"
import { FloatingLanguageSwitcher } from "@/components/layout/floating-language-switcher"
interface SharedErrorPageProps {
title: string
subtitle: string
error: string
description: string
ctaText: string
titleKey: string
subtitleKey: string
errorKey: string
descriptionKey: string
ctaTextKey: string
}
export function SharedErrorPage({ title, subtitle, error, description, ctaText }: SharedErrorPageProps) {
export function SharedErrorPage({
titleKey,
subtitleKey,
errorKey,
descriptionKey,
ctaTextKey,
}: SharedErrorPageProps) {
const tShared = useTranslations("emails.shared")
const resolvedTitle = tShared(titleKey)
const resolvedSubtitle = tShared(subtitleKey)
const resolvedError = tShared(errorKey)
const resolvedDescription = tShared(descriptionKey)
const resolvedCtaText = tShared(ctaTextKey)
return (
<div className="min-h-screen bg-gray-50 dark:bg-gray-900">
<div className="min-h-screen bg-gray-50 dark:bg-gray-900 flex flex-col justify-center items-center">
<div className="container mx-auto p-4 max-w-4xl">
<BrandHeader
title={title}
subtitle={subtitle}
showCta={true}
ctaText={ctaText}
title={resolvedTitle}
subtitle={resolvedSubtitle}
ctaText={resolvedCtaText}
/>
<div className="text-center">
<div className="text-center mt-6">
<Card className="max-w-md mx-auto p-8 text-center space-y-4">
<AlertCircle className="h-12 w-12 mx-auto text-destructive" />
<h2 className="text-2xl font-bold">{error}</h2>
<h2 className="text-2xl font-bold">{resolvedError}</h2>
<p className="text-gray-500">
{description}
{resolvedDescription}
</p>
</Card>
</div>
+14 -20
View File
@@ -8,17 +8,13 @@ import { ExternalLink, Mail } from "lucide-react"
interface BrandHeaderProps {
title?: string
subtitle?: string
showCta?: boolean
ctaText?: string
ctaHref?: string
}
export function BrandHeader({
title,
subtitle,
showCta = true,
ctaText,
ctaHref = "https://moemail.app"
}: BrandHeaderProps) {
const t = useTranslations("emails.shared.brand")
@@ -29,7 +25,7 @@ export function BrandHeader({
<div className="text-center space-y-4 lg:pb-4">
<div className="flex justify-center pt-2">
<Link
href={ctaHref}
href="https://moemail.app"
className="flex items-center gap-3 hover:opacity-80 transition-opacity group"
>
<div className="relative w-12 h-12">
@@ -96,21 +92,19 @@ export function BrandHeader({
</p>
</div>
{showCta && (
<div className="flex justify-center">
<Button
asChild
size="lg"
className="gap-2 bg-primary hover:bg-primary/90 text-white px-8 min-h-10 h-auto py-1"
>
<Link href={ctaHref} target="_blank" rel="noopener noreferrer">
<Mail className="w-5 h-5" />
{displayCtaText}
<ExternalLink className="w-4 h-4" />
</Link>
</Button>
</div>
)}
<div className="flex justify-center">
<Button
asChild
size="lg"
className="gap-2 bg-primary hover:bg-primary/90 text-white px-8 min-h-10 h-auto py-1"
>
<Link href="/" target="_blank" rel="noopener noreferrer">
<Mail className="w-5 h-5" />
{displayCtaText}
<ExternalLink className="w-4 h-4" />
</Link>
</Button>
</div>
</div>
)
}