import type { TurnstileInstance } from '@marsidev/react-turnstile'; import { Turnstile } from '@marsidev/react-turnstile'; import { useNavigate } from '@tanstack/react-router'; import { useRef, useState } from 'react'; import { toast } from 'sonner'; import NixOSLogo from '@/assets/nixos.svg?react'; import { Button } from '@/components/ui/button'; import { Field, FieldGroup, FieldLabel, } from '@/components/ui/field'; import { Input } from '@/components/ui/input'; import { useGetMagicLink } from '@/hooks/data/useGetMagicLink'; import { cn } from '@/lib/utils'; export function LoginForm({ className, ...props }: React.ComponentProps<'div'>) { const formRef = useRef(null); const turnstileRef = useRef(null); const [token, setToken] = useState(null); const { mutateAsync, isPending } = useGetMagicLink(); const navigate = useNavigate(); const handleSubmit = (event: React.FormEvent) => { event.preventDefault(); const formData = new FormData(formRef.current!); const email = formData.get('email')! as string; mutateAsync({ email, turnstile_token: token! }).then(() => { void navigate({ to: '/magicLinkSent', search: { email } }); }).catch((error) => { console.error(error); toast.error('请求登录链接失败'); turnstileRef.current?.reset(); }); }; return (
Nix CN Meetup #2

欢迎来到 Nix CN Meetup #2

参会登记Email
{ setToken(token); }} />
); }