Skip to content

Commit

Permalink
chore: reset state in form
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth committed Nov 10, 2023
1 parent b16773d commit 2ef06b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
26 changes: 10 additions & 16 deletions apps/consent/app/components/phone-auth/phone-auth-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<AuthFormProps> = ({
login_challenge,
countryCodes,
Expand All @@ -64,12 +49,18 @@ const PhoneAuthForm: React.FC<AuthFormProps> = ({
const [phoneNumber, setPhoneNumber] = useState<string>("")
const [state, formAction] = useFormState<GetCaptchaChallengeResponse, FormData>(
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) => {
Expand Down Expand Up @@ -111,6 +102,9 @@ const PhoneAuthForm: React.FC<AuthFormProps> = ({
toast.error("Invalid Captcha Request")
}

state.error = false
state.message = null
state.responsePayload = null
return null
}

Expand Down
2 changes: 2 additions & 0 deletions apps/consent/app/login/email-login-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 4 additions & 0 deletions apps/consent/app/login/verification/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ const VerificationForm: React.FC<VerificationFormProps> = ({

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 (
Expand Down

0 comments on commit 2ef06b3

Please sign in to comment.