-
Notifications
You must be signed in to change notification settings - Fork 581
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(auth2): More smoothing out of auth screens (#10895)
* refactor(auth): switch to standard formik mode * fix(auth2): fix weird keyboard performance issues * refactor(auth2): more smoothing out * test(auth2): stub out test files * chore(auth2): be sure to dismiss keyboard after each step
- Loading branch information
Showing
23 changed files
with
365 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
describe("AuthApp", () => { | ||
it("renders correctly", () => { | ||
// TODO | ||
}) | ||
}) |
5 changes: 5 additions & 0 deletions
5
src/app/Scenes/Onboarding/Auth2/__tests__/AuthContext.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
describe("AuthContext", () => { | ||
it("renders correctly", () => { | ||
// TODO | ||
}) | ||
}) |
5 changes: 5 additions & 0 deletions
5
src/app/Scenes/Onboarding/Auth2/__tests__/AuthScenes.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
describe("AuthScenes", () => { | ||
it("renders correctly", () => { | ||
// TODO | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/app/Scenes/Onboarding/Auth2/components/__tests__/AuthScreen.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
describe("AuthScreen", () => { | ||
it("renders correctly", () => { | ||
// TODO | ||
}) | ||
}) |
5 changes: 5 additions & 0 deletions
5
src/app/Scenes/Onboarding/Auth2/hooks/__tests__/useAuthNavigation.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
describe("useAuthNavigation", () => { | ||
it("renders correctly", () => { | ||
// TODO | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ import { | |
} from "app/Scenes/Onboarding/Auth2/hooks/useAuthNavigation" | ||
import { useInputAutofocus } from "app/Scenes/Onboarding/Auth2/hooks/useInputAutofocus" | ||
import { GlobalStore } from "app/store/GlobalStore" | ||
import { FormikProvider, useFormik, useFormikContext } from "formik" | ||
import { Formik, useFormikContext } from "formik" | ||
import { useRef } from "react" | ||
import * as Yup from "yup" | ||
|
||
|
@@ -16,38 +16,36 @@ interface ForgotPasswordStepFormValues { | |
export const ForgotPasswordStep: React.FC = () => { | ||
const navigation = useAuthNavigation() | ||
|
||
const formik = useFormik<ForgotPasswordStepFormValues>({ | ||
initialValues: { email: "" }, | ||
onSubmit: async ({ email }, { setErrors, resetForm }) => { | ||
const res = await GlobalStore.actions.auth.forgotPassword({ | ||
email, | ||
}) | ||
if (!res) { | ||
// For security purposes, we are returning a generic error message | ||
setErrors({ | ||
email: | ||
"Couldn’t send reset password link. Please try again, or contact [email protected]", | ||
}) | ||
} else { | ||
navigation.navigate({ | ||
name: "ForgotPasswordStep", | ||
params: { requestedPasswordReset: true }, | ||
return ( | ||
<Formik<ForgotPasswordStepFormValues> | ||
initialValues={{ email: "" }} | ||
onSubmit={async ({ email }, { setErrors, resetForm }) => { | ||
const res = await GlobalStore.actions.auth.forgotPassword({ | ||
email, | ||
}) | ||
|
||
resetForm() | ||
} | ||
}, | ||
validationSchema: Yup.object().shape({ | ||
email: Yup.string() | ||
.email("Please provide a valid email address") | ||
.required("Email field is required"), | ||
}), | ||
}) | ||
|
||
return ( | ||
<FormikProvider value={formik}> | ||
if (!res) { | ||
setErrors({ | ||
email: | ||
"Couldn’t send reset password link. Please try again, or contact [email protected]", | ||
}) | ||
} else { | ||
navigation.navigate({ | ||
name: "ForgotPasswordStep", | ||
params: { requestedPasswordReset: true }, | ||
}) | ||
|
||
resetForm() | ||
} | ||
}} | ||
validationSchema={Yup.object().shape({ | ||
email: Yup.string() | ||
.email("Please provide a valid email address") | ||
.required("Email field is required"), | ||
})} | ||
> | ||
<ForgotPasswordStepForm /> | ||
</FormikProvider> | ||
</Formik> | ||
) | ||
} | ||
|
||
|
@@ -145,7 +143,7 @@ const ForgotPasswordStepForm: React.FC = () => { | |
|
||
<Button | ||
variant="fillDark" | ||
onPress={() => navigation.navigate({ name: "WelcomeStep" })} | ||
onPress={() => navigation.navigate({ name: "LoginWelcomeStep" })} | ||
block | ||
haptic="impactMedium" | ||
testID="returnToLoginButton" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,11 @@ import { | |
useAuthScreen, | ||
} from "app/Scenes/Onboarding/Auth2/hooks/useAuthNavigation" | ||
import { useInputAutofocus } from "app/Scenes/Onboarding/Auth2/hooks/useInputAutofocus" | ||
import { waitForSubmit } from "app/Scenes/Onboarding/Auth2/utils/waitForSubmit" | ||
import { GlobalStore } from "app/store/GlobalStore" | ||
import { FormikProvider, useFormik, useFormikContext } from "formik" | ||
import { Formik, useFormikContext } from "formik" | ||
import { useRef, useState } from "react" | ||
import { Keyboard } from "react-native" | ||
import * as Yup from "yup" | ||
|
||
interface LoginOTPStepFormValues { | ||
|
@@ -26,34 +28,39 @@ interface LoginOTPStepFormValues { | |
export const LoginOTPStep: React.FC = () => { | ||
const screen = useAuthScreen() | ||
|
||
const formik = useFormik<LoginOTPStepFormValues>({ | ||
initialValues: { otp: "" }, | ||
onSubmit: async ({ otp }, { setErrors, resetForm }) => { | ||
const res = await GlobalStore.actions.auth.signIn({ | ||
oauthProvider: "email", | ||
oauthMode: "email", | ||
email: screen.params?.email, | ||
password: screen.params?.password, | ||
otp: otp.trim(), | ||
}) | ||
|
||
if (res === "invalid_otp") { | ||
setErrors({ otp: "Invalid two-factor authentication code" }) | ||
} else if (res !== "success") { | ||
setErrors({ otp: "Something went wrong. Please try again, or contact [email protected]" }) | ||
} | ||
|
||
if (res === "success") { | ||
resetForm() | ||
} | ||
}, | ||
validationSchema: Yup.string().test("otp", "This field is required", (value) => value !== ""), | ||
}) | ||
|
||
return ( | ||
<FormikProvider value={formik}> | ||
<Formik<LoginOTPStepFormValues> | ||
initialValues={{ otp: "" }} | ||
validateOnChange={false} | ||
validationSchema={Yup.object().shape({ | ||
otp: Yup.string().required("This field is required"), | ||
})} | ||
onSubmit={async ({ otp }, { setErrors, resetForm }) => { | ||
Keyboard.dismiss() | ||
|
||
const res = await GlobalStore.actions.auth.signIn({ | ||
oauthProvider: "email", | ||
oauthMode: "email", | ||
email: screen.params?.email, | ||
password: screen.params?.password, | ||
otp: otp.trim(), | ||
}) | ||
|
||
await waitForSubmit() | ||
|
||
if (res === "invalid_otp") { | ||
setErrors({ otp: "Invalid two-factor authentication code" }) | ||
} else if (res !== "success") { | ||
setErrors({ otp: "Something went wrong. Please try again, or contact [email protected]" }) | ||
} | ||
|
||
if (res === "success") { | ||
resetForm() | ||
} | ||
}} | ||
> | ||
<LoginOTPStepForm /> | ||
</FormikProvider> | ||
</Formik> | ||
) | ||
} | ||
|
||
|
Oops, something went wrong.