import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { KeyRound, Search, ShieldCheck, ShieldOff } from 'lucide-react-native'; import { router } from 'expo-router'; import { useMemo, useState } from 'react'; import { Pressable, Text, TextInput, View } from 'react-native'; import { ListCard } from '@/src/components/list-card'; import { ScreenShell } from '@/src/components/screen-shell'; import { listAccounts, setAccountSchedulable, testAccount } from '@/src/services/admin'; export default function AccountsScreen() { const [search, setSearch] = useState(''); const keyword = useMemo(() => search.trim(), [search]); const queryClient = useQueryClient(); const accountsQuery = useQuery({ queryKey: ['accounts', keyword], queryFn: () => listAccounts(keyword), }); const toggleMutation = useMutation({ mutationFn: ({ accountId, schedulable }: { accountId: number; schedulable: boolean }) => setAccountSchedulable(accountId, schedulable), onSuccess: () => queryClient.invalidateQueries({ queryKey: ['accounts'] }), }); const items = accountsQuery.data?.items ?? []; const errorMessage = accountsQuery.error instanceof Error ? accountsQuery.error.message : ''; return ( {items.length === 0 ? ( ) : ( items.map((account) => ( router.push(`/accounts/${account.id}`)}> {account.schedulable ? : } {account.schedulable ? '可调度' : '暂停调度'} { event.stopPropagation(); testAccount(account.id).catch(() => undefined); }} > 测试 { event.stopPropagation(); toggleMutation.mutate({ accountId: account.id, schedulable: !account.schedulable, }); }} > 切换 )) )} ); }