From 824180ab6640f5456448bb32507df711481b4f52 Mon Sep 17 00:00:00 2001 From: cade Date: Sat, 1 Jun 2024 12:56:30 -0700 Subject: [PATCH] fix sign in error form reset --- app/_components/forgot-password-form.tsx | 15 +++++++++--- app/_components/sign-in-form.tsx | 16 ++++++++++--- app/_components/sign-up-form.tsx | 30 ++++++++++++++++++++---- app/_mutations/forgot-password.ts | 12 +++++----- app/_mutations/sign-in.ts | 14 +++++++---- app/_mutations/sign-up.ts | 30 +++++++++++++++++++----- 6 files changed, 90 insertions(+), 27 deletions(-) diff --git a/app/_components/forgot-password-form.tsx b/app/_components/forgot-password-form.tsx index 99192d50..46781a2c 100644 --- a/app/_components/forgot-password-form.tsx +++ b/app/_components/forgot-password-form.tsx @@ -6,12 +6,21 @@ import forgotPassword from '@/_mutations/forgot-password'; import { useActionState } from 'react'; const ForgotPasswordForm = () => { - const [state, action] = useActionState(forgotPassword, null); + const [state, action] = useActionState(forgotPassword, { + defaultValues: { email: '' }, + error: '', + }); return (
- - {state?.error &&

{state.error}

} + + {state.error &&

{state.error}

} diff --git a/app/_components/sign-in-form.tsx b/app/_components/sign-in-form.tsx index deb5566c..9303e929 100644 --- a/app/_components/sign-in-form.tsx +++ b/app/_components/sign-in-form.tsx @@ -10,13 +10,23 @@ interface SignInFormProps { } const SignInForm = ({ next }: SignInFormProps) => { - const [state, action] = useActionState(signIn.bind(null, { next }), null); + const [state, action] = useActionState(signIn.bind(null, { next }), { + defaultValues: { email: '', password: '' }, + error: '', + }); return ( - +
{ Forgot password?
- {state?.error &&

{state.error}

} + {state.error &&

{state.error}

} diff --git a/app/_components/sign-up-form.tsx b/app/_components/sign-up-form.tsx index 4635ecac..6da098af 100644 --- a/app/_components/sign-up-form.tsx +++ b/app/_components/sign-up-form.tsx @@ -10,23 +10,43 @@ interface SignUpFormProps { } const SignUpForm = ({ next }: SignUpFormProps) => { - const [state, action] = useActionState(signUp.bind(null, { next }), null); + const [state, action] = useActionState(signUp.bind(null, { next }), { + defaultValues: { email: '', firstName: '', lastName: '', password: '' }, + error: '', + }); return (
- - + +
- + - {state?.error &&

{state.error}

} + {state.error &&

{state.error}

}