import { useTRPC } from '@/integrations/trpc/react'; import { pushModal } from '@/modals'; import { zodResolver } from '@hookform/resolvers/zod'; import { zSignInEmail } from '@openpanel/validation'; import { useMutation, useQueryClient } from '@tanstack/react-query'; import { useNavigate, useRouter } from '@tanstack/react-router'; import { type SubmitHandler, useForm } from 'react-hook-form'; import { toast } from 'sonner'; import type { z } from 'zod'; import { InputWithLabel } from '../forms/input-with-label'; import { Button } from '../ui/button'; const validator = zSignInEmail; type IForm = z.infer; export function SignInEmailForm({ isLastUsed }: { isLastUsed?: boolean }) { const trpc = useTRPC(); const mutation = useMutation( trpc.auth.signInEmail.mutationOptions({ async onSuccess() { toast.success('Successfully signed in'); window.location.href = '/'; }, onError(error) { toast.error(error.message); }, }), ); const form = useForm({ resolver: zodResolver(validator), defaultValues: { email: '', password: '', }, }); const onSubmit: SubmitHandler = (values) => { mutation.mutate({ ...values, }); }; return (
{isLastUsed && ( Used last time )}
); }