'use client'; import { getAuthMethodConfig, testEmailSend, updateAuthMethodConfig, } from '@/services/admin/authMethod'; 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'; import { LogsTable } from '../log'; export default function Page() { const t = useTranslations('email'); const ref = useRef>({}); const [email, setEmail] = useState(); const { data, refetch, isFetching } = useQuery({ queryKey: ['getAuthMethodConfig', 'email'], queryFn: async () => { const { data } = await getAuthMethodConfig({ method: 'email', }); ref.current = data.data as API.AuthMethodConfig; return data.data; }, }); async function updateConfig(key: string, value: unknown) { if (data?.[key] === value) return; try { await updateAuthMethodConfig({ ...ref.current, [key]: value, } as API.UpdateAuthMethodConfigRequest); toast.success(t('saveSuccess')); refetch(); } catch (error) { toast.error(t('saveFailed')); } } return ( {t('settings')} {t('template')} {t('logs')}

{t('enableDescription')}

updateConfig('enabled', checked)} />

{t('emailVerificationDescription')}

updateConfig('config', { ...data?.config, enable_verify: checked }) } />

{t('emailSuffixWhitelistDescription')}

updateConfig('config', { ...data?.config, enable_domain_suffix: checked }) } />

{t('whitelistSuffixesDescription')}