From 4acf7b1837a1dcb839e398007e402d3b3544a895 Mon Sep 17 00:00:00 2001 From: "web@ppanel" Date: Wed, 15 Jan 2025 15:49:11 +0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(auth):=20Add=20SMS=20and=20ema?= =?UTF-8?q?il=20configuration=20options=20to=20global=20store=20and=20upda?= =?UTF-8?q?te=20localization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/dashboard/auth-control/email/page.tsx | 276 ++++++++++-------- .../dashboard/auth-control/general/page.tsx | 45 --- apps/admin/config/use-global.tsx | 20 ++ apps/admin/locales/cs-CZ/auth-control.json | 9 +- apps/admin/locales/cs-CZ/email.json | 20 +- apps/admin/locales/de-DE/auth-control.json | 9 +- apps/admin/locales/de-DE/email.json | 20 +- apps/admin/locales/en-US/auth-control.json | 9 +- apps/admin/locales/en-US/email.json | 20 +- apps/admin/locales/es-ES/auth-control.json | 9 +- apps/admin/locales/es-ES/email.json | 20 +- apps/admin/locales/es-MX/auth-control.json | 9 +- apps/admin/locales/es-MX/email.json | 20 +- apps/admin/locales/fa-IR/auth-control.json | 9 +- apps/admin/locales/fa-IR/email.json | 20 +- apps/admin/locales/fi-FI/auth-control.json | 9 +- apps/admin/locales/fi-FI/email.json | 20 +- apps/admin/locales/fr-FR/auth-control.json | 9 +- apps/admin/locales/fr-FR/email.json | 20 +- apps/admin/locales/hi-IN/auth-control.json | 9 +- apps/admin/locales/hi-IN/email.json | 20 +- apps/admin/locales/hu-HU/auth-control.json | 9 +- apps/admin/locales/hu-HU/email.json | 20 +- apps/admin/locales/ja-JP/auth-control.json | 9 +- apps/admin/locales/ja-JP/email.json | 20 +- apps/admin/locales/ko-KR/auth-control.json | 9 +- apps/admin/locales/ko-KR/email.json | 20 +- apps/admin/locales/no-NO/auth-control.json | 9 +- apps/admin/locales/no-NO/email.json | 20 +- apps/admin/locales/pl-PL/auth-control.json | 9 +- apps/admin/locales/pl-PL/email.json | 20 +- apps/admin/locales/pt-BR/auth-control.json | 9 +- apps/admin/locales/pt-BR/email.json | 20 +- apps/admin/locales/ro-RO/auth-control.json | 9 +- apps/admin/locales/ro-RO/email.json | 20 +- apps/admin/locales/ru-RU/auth-control.json | 9 +- apps/admin/locales/ru-RU/email.json | 20 +- apps/admin/locales/th-TH/auth-control.json | 9 +- apps/admin/locales/th-TH/email.json | 20 +- apps/admin/locales/tr-TR/auth-control.json | 9 +- apps/admin/locales/tr-TR/email.json | 20 +- apps/admin/locales/uk-UA/auth-control.json | 9 +- apps/admin/locales/uk-UA/email.json | 20 +- apps/admin/locales/vi-VN/auth-control.json | 9 +- apps/admin/locales/vi-VN/email.json | 20 +- apps/admin/locales/zh-CN/auth-control.json | 9 +- apps/admin/locales/zh-CN/email.json | 20 +- apps/admin/locales/zh-HK/auth-control.json | 9 +- apps/admin/locales/zh-HK/email.json | 20 +- apps/admin/services/admin/index.ts | 2 +- apps/admin/services/admin/typings.d.ts | 26 +- apps/admin/services/common/typings.d.ts | 24 +- 52 files changed, 675 insertions(+), 385 deletions(-) diff --git a/apps/admin/app/dashboard/auth-control/email/page.tsx b/apps/admin/app/dashboard/auth-control/email/page.tsx index 86b315b..db5f9ae 100644 --- a/apps/admin/app/dashboard/auth-control/email/page.tsx +++ b/apps/admin/app/dashboard/auth-control/email/page.tsx @@ -3,25 +3,28 @@ import { getEmailSmtpConfig, testEmailSmtp, updateEmailSmtpConfig } from '@/services/admin/system'; import { useQuery } from '@tanstack/react-query'; import { Button } from '@workspace/ui/components/button'; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from '@workspace/ui/components/card'; import { Label } from '@workspace/ui/components/label'; import { Switch } from '@workspace/ui/components/switch'; import { Table, TableBody, TableCell, TableRow } from '@workspace/ui/components/table'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@workspace/ui/components/tabs'; +import { Textarea } from '@workspace/ui/components/textarea'; import { HTMLEditor } from '@workspace/ui/custom-components/editor'; import { EnhancedInput } from '@workspace/ui/custom-components/enhanced-input'; import { useTranslations } from 'next-intl'; import { useRef, useState } from 'react'; import { toast } from 'sonner'; -interface ConfigProps { - data?: Record & API.EmailSmtpConfig; - updateConfig: (key: string, value: unknown) => Promise; - isFetching?: boolean; -} - export default function Page() { const t = useTranslations('email'); const ref = useRef>({}); + const [email, setEmail] = useState(); const { data, refetch, isFetching } = useQuery({ queryKey: ['getEmailSmtpConfig'], @@ -42,10 +45,9 @@ export default function Page() { toast.success(t('saveSuccess')); refetch(); } catch (error) { - /* empty */ + toast.error(t('saveFailed')); } } - const [email, setEmail] = useState(); return ( @@ -54,126 +56,154 @@ export default function Page() { {t('emailTemplate')} {t('emailLogs')} - -
- - - - {[ - { - key: 'email_smtp_host', - label: t('smtpServerAddress'), - description: t('smtpServerAddressDescription'), - }, - { - key: 'email_smtp_port', - label: t('smtpServerPort'), - description: t('smtpServerPortDescription'), - type: 'number', - }, - { - key: 'email_smtp_ssl', - label: t('smtpEncryptionMethod'), - description: t('smtpEncryptionMethodDescription'), - component: 'switch', - }, - { - key: 'email_smtp_user', - label: t('smtpAccount'), - description: t('smtpAccountDescription'), - }, - { - key: 'email_smtp_pass', - label: t('smtpPassword'), - description: t('smtpPasswordDescription'), - type: 'password', - }, - { - key: 'email_smtp_from', - label: t('senderAddress'), - description: t('senderAddressDescription'), - }, - ].map(({ key, label, description, type = 'text', component = 'input' }) => ( - - - -

{description}

-
- - {component === 'input' ? ( - updateConfig(key, value)} - /> - ) : ( - updateConfig(key, checked)} - /> - )} - -
- ))} - - - -

{t('sendTestEmailDescription')}

+ +
+ + {[ + { + key: 'email_enabled', + label: t('enable'), + description: t('enableDescription'), + component: 'switch', + }, + { + key: 'enable_email_verify', + label: t('emailVerification'), + description: t('emailVerificationDescription'), + component: 'switch', + }, + { + key: 'enable_email_domain_suffix', + label: t('emailSuffixWhitelist'), + description: t('emailSuffixWhitelistDescription'), + component: 'switch', + }, + { + key: 'email_domain_suffix_list', + label: t('whitelistSuffixes'), + description: t('whitelistSuffixesDescription'), + component: 'textarea', + }, + { + key: 'email_smtp_host', + label: t('smtpServerAddress'), + description: t('smtpServerAddressDescription'), + }, + { + key: 'email_smtp_port', + label: t('smtpServerPort'), + description: t('smtpServerPortDescription'), + type: 'number', + }, + { + key: 'email_smtp_ssl', + label: t('smtpEncryptionMethod'), + description: t('smtpEncryptionMethodDescription'), + component: 'switch', + }, + { + key: 'email_smtp_user', + label: t('smtpAccount'), + description: t('smtpAccountDescription'), + }, + { + key: 'email_smtp_pass', + label: t('smtpPassword'), + description: t('smtpPasswordDescription'), + type: 'password', + }, + { + key: 'email_smtp_from', + label: t('senderAddress'), + description: t('senderAddressDescription'), + }, + ].map(({ key, label, description, type = 'text', component = 'input' }) => ( + + + +

{description}

- - setEmail(value as string)} - /> - + + {component === 'input' ? ( + updateConfig(key, value)} + /> + ) : component === 'switch' ? ( + updateConfig(key, checked)} + /> + ) : ( +