mirror of
https://github.com/perfect-panel/ppanel-web.git
synced 2026-02-06 03:30:25 -05:00
116 lines
3.8 KiB
TypeScript
116 lines
3.8 KiB
TypeScript
'use client';
|
|
|
|
import { getVerifyConfig, updateVerifyConfig } from '@/services/admin/system';
|
|
import { useQuery } from '@tanstack/react-query';
|
|
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 { EnhancedInput } from '@workspace/ui/custom-components/enhanced-input';
|
|
import { useTranslations } from 'next-intl';
|
|
import { toast } from 'sonner';
|
|
|
|
export default function Verify() {
|
|
const t = useTranslations('system.verify');
|
|
|
|
const { data, refetch } = useQuery({
|
|
queryKey: ['getVerifyConfig'],
|
|
queryFn: async () => {
|
|
const { data } = await getVerifyConfig();
|
|
return data.data;
|
|
},
|
|
});
|
|
|
|
async function updateConfig(key: string, value: unknown) {
|
|
if (data?.[key] === value) return;
|
|
try {
|
|
await updateVerifyConfig({
|
|
...data,
|
|
[key]: value,
|
|
} as API.VerifyConfig);
|
|
toast.success(t('saveSuccess'));
|
|
refetch();
|
|
} catch (error) {
|
|
/* empty */
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Table>
|
|
<TableBody>
|
|
<TableRow>
|
|
<TableCell>
|
|
<Label>{t('turnstileSiteKey')}</Label>
|
|
<p className='text-muted-foreground text-xs'>{t('turnstileSiteKeyDescription')}</p>
|
|
</TableCell>
|
|
<TableCell className='text-right'>
|
|
<EnhancedInput
|
|
placeholder={t('inputPlaceholder')}
|
|
defaultValue={data?.turnstile_site_key}
|
|
onValueBlur={(value) => updateConfig('turnstile_site_key', value)}
|
|
/>
|
|
</TableCell>
|
|
</TableRow>
|
|
<TableRow>
|
|
<TableCell>
|
|
<Label>{t('turnstileSecret')}</Label>
|
|
<p className='text-muted-foreground text-xs'>{t('turnstileSecretDescription')}</p>
|
|
</TableCell>
|
|
<TableCell className='text-right'>
|
|
<EnhancedInput
|
|
placeholder={t('inputPlaceholder')}
|
|
defaultValue={data?.turnstile_secret}
|
|
onValueBlur={(value) => updateConfig('turnstile_secret', value)}
|
|
/>
|
|
</TableCell>
|
|
</TableRow>
|
|
<TableRow>
|
|
<TableCell>
|
|
<Label>{t('registrationVerificationCode')}</Label>
|
|
<p className='text-muted-foreground text-xs'>
|
|
{t('registrationVerificationCodeDescription')}
|
|
</p>
|
|
</TableCell>
|
|
<TableCell className='text-right'>
|
|
<Switch
|
|
checked={data?.enable_register_verify}
|
|
onCheckedChange={(checked) => {
|
|
updateConfig('enable_register_verify', checked);
|
|
}}
|
|
/>
|
|
</TableCell>
|
|
</TableRow>
|
|
<TableRow>
|
|
<TableCell>
|
|
<Label>{t('loginVerificationCode')}</Label>
|
|
<p className='text-muted-foreground text-xs'>{t('loginVerificationCodeDescription')}</p>
|
|
</TableCell>
|
|
<TableCell className='text-right'>
|
|
<Switch
|
|
checked={data?.enable_login_verify}
|
|
onCheckedChange={(checked) => {
|
|
updateConfig('enable_login_verify', checked);
|
|
}}
|
|
/>
|
|
</TableCell>
|
|
</TableRow>
|
|
<TableRow>
|
|
<TableCell>
|
|
<Label>{t('resetPasswordVerificationCode')}</Label>
|
|
<p className='text-muted-foreground text-xs'>
|
|
{t('resetPasswordVerificationCodeDescription')}
|
|
</p>
|
|
</TableCell>
|
|
<TableCell className='text-right'>
|
|
<Switch
|
|
checked={data?.enable_reset_password_verify}
|
|
onCheckedChange={(checked) => {
|
|
updateConfig('enable_reset_password_verify', checked);
|
|
}}
|
|
/>
|
|
</TableCell>
|
|
</TableRow>
|
|
</TableBody>
|
|
</Table>
|
|
);
|
|
}
|