'use client'; import { getAuthMethodConfig, updateAuthMethodConfig } from '@/services/admin/authMethod'; 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 { DicesIcon } from 'lucide-react'; import { useTranslations } from 'next-intl'; import { uid } from 'radash'; import { toast } from 'sonner'; export default function Page() { const t = useTranslations('device'); const { data, refetch } = useQuery({ queryKey: ['getAuthMethodConfig', 'device'], queryFn: async () => { const { data } = await getAuthMethodConfig({ method: 'device', }); return data.data; }, }); async function updateConfig(key: keyof API.UpdateAuthMethodConfigRequest, value: unknown) { try { await updateAuthMethodConfig({ ...data, [key]: value, } as API.UpdateAuthMethodConfigRequest); toast.success(t('saveSuccess')); refetch(); } catch (error) { toast.error(t('saveFailed')); } } return (

{t('enableDescription')}

updateConfig('enabled', checked)} />

{t('showAdsDescription')}

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

{t('blockVirtualMachineDescription')}

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

{t('enableSecurityDescription')}

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

{t('communicationKeyDescription')}

{ updateConfig('config', { ...data?.config, security_secret: value, }); }} suffix={
{ const id = uid(32).toLowerCase(); const formatted = `${id.slice(0, 8)}-${id.slice(8, 12)}-${id.slice(12, 16)}-${id.slice(16, 20)}-${id.slice(20)}`; updateConfig('config', { ...data?.config, security_secret: formatted, }); }} className='cursor-pointer' />
} />
); }