From 0fa25621295cc2e5adf130ab147d1904dfa1aecf Mon Sep 17 00:00:00 2001 From: javayhu Date: Tue, 18 Mar 2025 11:43:11 +0800 Subject: [PATCH] refactor: enhance localization and component structure in settings - Updated English and Chinese localization files to improve newsletter subscription labels and team references. - Renamed route for notifications from `SettingsNotification` to `SettingsNotifications` for consistency. - Refactored `DashboardPage`, `SettingsBillingPage`, and `SettingsAccountPage` to streamline layout and improve responsiveness. - Introduced `SettingsNotificationPage` to handle notification settings with a dedicated component. - Enhanced various settings components to accept `className` props for better styling flexibility. --- messages/en.json | 5 ++- messages/zh.json | 5 ++- .../[locale]/(dashborad)/dashboard/page.tsx | 9 ++---- .../(dashborad)/settings/account/page.tsx | 22 ++++++------- .../(dashborad)/settings/billing/page.tsx | 9 ++---- .../{notification => notifications}/page.tsx | 8 ++--- src/components/dashboard/sidebar-main.tsx | 4 ++- .../conditional-update-password-card.tsx | 11 +++++-- .../settings/account/delete-account-card.tsx | 9 ++++-- .../settings/account/reset-password-card.tsx | 9 ++++-- .../settings/account/update-avatar-card.tsx | 13 +++++--- .../settings/account/update-name-card.tsx | 9 ++++-- .../settings/account/update-password-card.tsx | 9 ++++-- .../notification/newsletter-form-card.tsx | 31 ++++++++++--------- src/config.tsx | 2 +- src/mail/components/email-layout.tsx | 6 ++-- src/routes.ts | 2 +- 17 files changed, 91 insertions(+), 72 deletions(-) rename src/app/[locale]/(dashborad)/settings/{notification => notifications}/page.tsx (77%) diff --git a/messages/en.json b/messages/en.json index 12902d9..9ea47d6 100644 --- a/messages/en.json +++ b/messages/en.json @@ -378,8 +378,7 @@ "newsletter": { "title": "Newsletter Subscription", "description": "Manage your newsletter subscription preferences", - "checkboxLabel": "Subscribe to newsletter", - "checkboxDescription": "Receive updates, news, and special offers via email", + "label": "Subscribe to newsletter", "hint": "You can change your subscription preferences at any time", "emailRequired": "Email is required to subscribe to the newsletter", "subscribeSuccess": "Successfully subscribed to the newsletter", @@ -395,7 +394,7 @@ }, "Mail": { "common": { - "team": "MkSaaS Team", + "team": "{name} Team", "copyright": "©️ {year} All Rights Reserved." }, "verifyEmail": { diff --git a/messages/zh.json b/messages/zh.json index 8caf74f..3a7e910 100644 --- a/messages/zh.json +++ b/messages/zh.json @@ -373,8 +373,7 @@ "newsletter": { "title": "订阅", "description": "管理您的邮件列表订阅偏好", - "checkboxLabel": "订阅邮件列表", - "checkboxDescription": "通过邮件接收更新、新闻和特别优惠", + "label": "订阅邮件列表", "hint": "您可以随时更改订阅偏好", "emailRequired": "订阅邮件列表需要邮箱", "subscribeSuccess": "成功订阅邮件列表", @@ -390,7 +389,7 @@ }, "Mail": { "common": { - "team": "MkSaaS 团队", + "team": "{name} 团队", "copyright": "©️ {year} 版权所有。" }, "verifyEmail": { diff --git a/src/app/[locale]/(dashborad)/dashboard/page.tsx b/src/app/[locale]/(dashborad)/dashboard/page.tsx index 58585e9..3fed3e4 100644 --- a/src/app/[locale]/(dashborad)/dashboard/page.tsx +++ b/src/app/[locale]/(dashborad)/dashboard/page.tsx @@ -14,13 +14,8 @@ export default function DashboardPage() { return ( <> -
-
-
-
-
-
-
+ +
); diff --git a/src/app/[locale]/(dashborad)/settings/account/page.tsx b/src/app/[locale]/(dashborad)/settings/account/page.tsx index eb985ef..f8d7bb0 100644 --- a/src/app/[locale]/(dashborad)/settings/account/page.tsx +++ b/src/app/[locale]/(dashborad)/settings/account/page.tsx @@ -1,8 +1,8 @@ import { DashboardHeader } from '@/components/dashboard/dashboard-header'; -import { UpdateAvatarCard } from '@/components/settings/account/update-avatar-card'; -import { UpdateNameCard } from '@/components/settings/account/update-name-card'; import { ConditionalUpdatePasswordCard } from '@/components/settings/account/conditional-update-password-card'; import { DeleteAccountCard } from '@/components/settings/account/delete-account-card'; +import { UpdateAvatarCard } from '@/components/settings/account/update-avatar-card'; +import { UpdateNameCard } from '@/components/settings/account/update-name-card'; import { useTranslations } from 'next-intl'; export default function SettingsAccountPage() { @@ -19,20 +19,16 @@ export default function SettingsAccountPage() { }, ]; - - return ( <> - -
-
-
- - - - -
+ +
+
+ + + +
diff --git a/src/app/[locale]/(dashborad)/settings/billing/page.tsx b/src/app/[locale]/(dashborad)/settings/billing/page.tsx index 21651dc..8efc7f5 100644 --- a/src/app/[locale]/(dashborad)/settings/billing/page.tsx +++ b/src/app/[locale]/(dashborad)/settings/billing/page.tsx @@ -18,13 +18,8 @@ export default function SettingsBillingPage() { return ( <> -
-
-
-
-
-
-
+ +
); diff --git a/src/app/[locale]/(dashborad)/settings/notification/page.tsx b/src/app/[locale]/(dashborad)/settings/notifications/page.tsx similarity index 77% rename from src/app/[locale]/(dashborad)/settings/notification/page.tsx rename to src/app/[locale]/(dashborad)/settings/notifications/page.tsx index f702d37..6218bf2 100644 --- a/src/app/[locale]/(dashborad)/settings/notification/page.tsx +++ b/src/app/[locale]/(dashborad)/settings/notifications/page.tsx @@ -20,11 +20,9 @@ export default function SettingsNotificationPage() { <> -
-
-
- -
+
+
+
diff --git a/src/components/dashboard/sidebar-main.tsx b/src/components/dashboard/sidebar-main.tsx index 089af13..1722a55 100644 --- a/src/components/dashboard/sidebar-main.tsx +++ b/src/components/dashboard/sidebar-main.tsx @@ -49,7 +49,9 @@ export function SidebarMain() { {item.items?.length ? ( diff --git a/src/components/settings/account/conditional-update-password-card.tsx b/src/components/settings/account/conditional-update-password-card.tsx index bbcecf4..bd0a48d 100644 --- a/src/components/settings/account/conditional-update-password-card.tsx +++ b/src/components/settings/account/conditional-update-password-card.tsx @@ -4,6 +4,11 @@ import { UpdatePasswordCard } from '@/components/settings/account/update-passwor import { ResetPasswordCard } from '@/components/settings/account/reset-password-card'; import { authClient } from '@/lib/auth-client'; import { useEffect, useState } from 'react'; +import { cn } from '@/lib/utils'; + +interface ConditionalUpdatePasswordCardProps { + className?: string; +} /** * Conditionally renders either: @@ -11,7 +16,7 @@ import { useEffect, useState } from 'react'; * - ResetPasswordCard: if the user only has social login providers and has an email * - Nothing: if the user has no credential provider and no email */ -export function ConditionalUpdatePasswordCard() { +export function ConditionalUpdatePasswordCard({ className }: ConditionalUpdatePasswordCardProps) { const { data: session } = authClient.useSession(); const [hasCredentialProvider, setHasCredentialProvider] = useState(false); const [isLoading, setIsLoading] = useState(true); @@ -53,13 +58,13 @@ export function ConditionalUpdatePasswordCard() { // If user has credential provider, show UpdatePasswordCard if (hasCredentialProvider) { - return ; + return ; } // If user doesn't have credential provider but has an email, show ResetPasswordCard // The forgot password flow requires an email address if (session?.user?.email) { - return ; + return ; } // If user has no credential provider and no email, don't show anything diff --git a/src/components/settings/account/delete-account-card.tsx b/src/components/settings/account/delete-account-card.tsx index 3d67ba8..3f1f4bf 100644 --- a/src/components/settings/account/delete-account-card.tsx +++ b/src/components/settings/account/delete-account-card.tsx @@ -20,17 +20,22 @@ import { } from '@/components/ui/alert-dialog'; import { useLocaleRouter } from '@/i18n/navigation'; import { authClient } from '@/lib/auth-client'; +import { cn } from '@/lib/utils'; import { useTranslations } from 'next-intl'; import { useState } from 'react'; import { toast } from 'sonner'; +interface DeleteAccountCardProps { + className?: string; +} + /** * Delete user account * * This component allows users to permanently delete their account. * It includes a confirmation dialog to prevent accidental deletions. */ -export function DeleteAccountCard() { +export function DeleteAccountCard({ className }: DeleteAccountCardProps) { const t = useTranslations('Dashboard.sidebar.settings.items.account'); const [isDeleting, setIsDeleting] = useState(false); const [showConfirmation, setShowConfirmation] = useState(false); @@ -76,7 +81,7 @@ export function DeleteAccountCard() { }; return ( - + {t('deleteAccount.title')} diff --git a/src/components/settings/account/reset-password-card.tsx b/src/components/settings/account/reset-password-card.tsx index ae696d3..9e21a7e 100644 --- a/src/components/settings/account/reset-password-card.tsx +++ b/src/components/settings/account/reset-password-card.tsx @@ -11,8 +11,13 @@ import { } from '@/components/ui/card'; import { useLocaleRouter } from '@/i18n/navigation'; import { authClient } from '@/lib/auth-client'; +import { cn } from '@/lib/utils'; import { useTranslations } from 'next-intl'; +interface ResetPasswordCardProps { + className?: string; +} + /** * Reset Password Card * @@ -31,7 +36,7 @@ import { useTranslations } from 'next-intl'; * * This effectively adds a credential provider to their account, enabling email/password login. */ -export function ResetPasswordCard() { +export function ResetPasswordCard({ className }: ResetPasswordCardProps) { const router = useLocaleRouter(); const t = useTranslations('Dashboard.sidebar.settings.items.account'); const { data: session } = authClient.useSession(); @@ -46,7 +51,7 @@ export function ResetPasswordCard() { }; return ( - + {t('setupPassword.title')} diff --git a/src/components/settings/account/update-avatar-card.tsx b/src/components/settings/account/update-avatar-card.tsx index e2960e9..a52d112 100644 --- a/src/components/settings/account/update-avatar-card.tsx +++ b/src/components/settings/account/update-avatar-card.tsx @@ -12,16 +12,21 @@ import { CardTitle } from '@/components/ui/card'; import { authClient } from '@/lib/auth-client'; +import { cn } from '@/lib/utils'; import { uploadFileFromBrowser } from '@/storage'; import { User2Icon } from 'lucide-react'; import { useTranslations } from 'next-intl'; import { useEffect, useState } from 'react'; import { toast } from 'sonner'; +interface UpdateAvatarCardProps { + className?: string; +} + /** * Update the user's avatar */ -export function UpdateAvatarCard() { +export function UpdateAvatarCard({ className }: UpdateAvatarCardProps) { const t = useTranslations('Dashboard.sidebar.settings.items.account'); const [isUploading, setIsUploading] = useState(false); const [error, setError] = useState(''); @@ -123,7 +128,7 @@ export function UpdateAvatarCard() { }; return ( - + {t('avatar.title')} @@ -133,7 +138,7 @@ export function UpdateAvatarCard() { -
+
{/* avatar */} @@ -144,7 +149,7 @@ export function UpdateAvatarCard() { {/* upload button */}