import { Text } from "react-native"; import { Controller, useForm } from "react-hook-form"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import { FormInput } from "@/components/auth/FormInput"; import { PasswordInput } from "@/components/auth/PasswordInput"; import { MessageDisplay } from "@/components/auth/MessageDisplay"; import { AuthButton } from "@/components/auth/AuthButton"; const signInSchema = z.object({ emailAddress: z .string() .trim() .min(1, "Email is required") .pipe(z.email("Enter a valid email address")), password: z .string() .min(1, "Password is required") .max(128, "Password is too long"), }); type SignInValues = z.infer; interface SignInFormProps { errorMessage: string; successMessage: string; isLoading: boolean; onSignInSubmit: (values: { emailAddress: string; password: string; }) => void | Promise; } export const SignInForm = ({ errorMessage, successMessage, isLoading, onSignInSubmit, }: SignInFormProps) => { const { control, handleSubmit } = useForm({ resolver: zodResolver(signInSchema), defaultValues: { emailAddress: "", password: "" }, mode: "onBlur", reValidateMode: "onBlur", shouldUnregister: false, }); const submit = (vals: SignInValues) => onSignInSubmit({ emailAddress: vals.emailAddress.trim().toLowerCase(), password: vals.password, }); return ( <> ( <> {error ? ( {error.message} ) : null} )} /> ( <> handleSubmit(submit)()} /> {error ? ( {error.message} ) : null} )} /> {errorMessage ? ( ) : null} {successMessage ? ( ) : null} {isLoading ? "Signing in..." : "Sign In"} ); };