From 2ef06b3a8c1ec07accbfed0a25274793a818bc49 Mon Sep 17 00:00:00 2001 From: Siddharth Date: Fri, 10 Nov 2023 13:01:50 +0530 Subject: [PATCH] chore: reset state in form --- .../components/phone-auth/phone-auth-form.tsx | 26 +++++++------------ apps/consent/app/login/email-login-form.tsx | 2 ++ apps/consent/app/login/verification/form.tsx | 4 +++ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/apps/consent/app/components/phone-auth/phone-auth-form.tsx b/apps/consent/app/components/phone-auth/phone-auth-form.tsx index 1ed7585655..2c3aade057 100644 --- a/apps/consent/app/components/phone-auth/phone-auth-form.tsx +++ b/apps/consent/app/components/phone-auth/phone-auth-form.tsx @@ -41,21 +41,6 @@ interface AuthFormProps { countryCodes: any } -const initialState: GetCaptchaChallengeResponse = { - error: false, - message: null, - responsePayload: { - id: null, - challenge: null, - formData: { - login_challenge: null, - phone: null, - remember: false, - channel: null, - }, - }, -} - const PhoneAuthForm: React.FC = ({ login_challenge, countryCodes, @@ -64,12 +49,18 @@ const PhoneAuthForm: React.FC = ({ const [phoneNumber, setPhoneNumber] = useState("") const [state, formAction] = useFormState( getCaptchaChallenge, - initialState, + { + error: false, + message: null, + responsePayload: null, + }, ) if (state.error) { toast.error(state.message) state.error = false + state.message = null + state.responsePayload = null } const handlePhoneNumberChange = (value?: E164Number | undefined) => { @@ -111,6 +102,9 @@ const PhoneAuthForm: React.FC = ({ toast.error("Invalid Captcha Request") } + state.error = false + state.message = null + state.responsePayload = null return null } diff --git a/apps/consent/app/login/email-login-form.tsx b/apps/consent/app/login/email-login-form.tsx index c9fd88f3df..0c0fdaad82 100644 --- a/apps/consent/app/login/email-login-form.tsx +++ b/apps/consent/app/login/email-login-form.tsx @@ -31,6 +31,8 @@ const EmailLoginForm = ({ login_challenge }: LoginProps) => { if (state.error) { toast.error(state.message) state.error = false + state.message = null + state.responsePayload = null } return ( diff --git a/apps/consent/app/login/verification/form.tsx b/apps/consent/app/login/verification/form.tsx index ff371ac860..54ef1bf104 100644 --- a/apps/consent/app/login/verification/form.tsx +++ b/apps/consent/app/login/verification/form.tsx @@ -46,12 +46,16 @@ const VerificationForm: React.FC = ({ if (stateVerificationCode.error) { toast.error(stateVerificationCode.message) + stateVerificationCode.error = false stateVerificationCode.message = null + stateVerificationCode.responsePayload = null } if (stateTwoFA.error) { toast.error(stateTwoFA.message) + stateTwoFA.error = false stateTwoFA.message = null + stateTwoFA.responsePayload = null } return (