From 8caed6bfbef66ef0030f4ac298710d17ce51d8fc Mon Sep 17 00:00:00 2001 From: Adam Iskounen <44589599+iskounen@users.noreply.github.com> Date: Tue, 8 Oct 2024 13:22:55 -0400 Subject: [PATCH] feat(DIA-898): use shared password field for sign-up and login [WIP] (#10904) * feat: use shared password field for sign-up and login * used forwardRef to pass an input ref --- .../Auth2/components/PasswordInput.tsx | 49 ++++++++++++++++ .../Auth2/scenes/LoginPasswordStep.tsx | 58 ++----------------- .../Auth2/scenes/SignUpPasswordStep.tsx | 53 ++--------------- 3 files changed, 61 insertions(+), 99 deletions(-) create mode 100644 src/app/Scenes/Onboarding/Auth2/components/PasswordInput.tsx diff --git a/src/app/Scenes/Onboarding/Auth2/components/PasswordInput.tsx b/src/app/Scenes/Onboarding/Auth2/components/PasswordInput.tsx new file mode 100644 index 00000000000..b6ce2275fbc --- /dev/null +++ b/src/app/Scenes/Onboarding/Auth2/components/PasswordInput.tsx @@ -0,0 +1,49 @@ +import { Input, useTheme } from "@artsy/palette-mobile" +import { LoginPasswordStepFormValues } from "app/Scenes/Onboarding/Auth2/scenes/LoginPasswordStep" +import { SignUpPasswordStepFormValues } from "app/Scenes/Onboarding/Auth2/scenes/SignUpPasswordStep" +import { FormikContextType, useFormikContext } from "formik" +import { forwardRef } from "react" + +export const PasswordInput = forwardRef((_props, ref) => { + const { + dirty, + errors, + handleChange, + handleSubmit, + validateForm, + values, + }: FormikContextType = + useFormikContext() + + const { color } = useTheme() + + return ( + { + handleChange("password")(text) + }} + onSubmitEditing={() => { + if (dirty && !!values.password) { + handleSubmit() + } + }} + onBlur={validateForm} + /> + ) +}) diff --git a/src/app/Scenes/Onboarding/Auth2/scenes/LoginPasswordStep.tsx b/src/app/Scenes/Onboarding/Auth2/scenes/LoginPasswordStep.tsx index 0a90a270c08..c730de2f8d4 100644 --- a/src/app/Scenes/Onboarding/Auth2/scenes/LoginPasswordStep.tsx +++ b/src/app/Scenes/Onboarding/Auth2/scenes/LoginPasswordStep.tsx @@ -7,8 +7,8 @@ import { Spacer, Text, Touchable, - useTheme, } from "@artsy/palette-mobile" +import { PasswordInput } from "app/Scenes/Onboarding/Auth2/components/PasswordInput" import { useAuthNavigation, useAuthScreen, @@ -20,7 +20,7 @@ import { Formik, useFormikContext } from "formik" import { useRef } from "react" import * as Yup from "yup" -interface LoginPasswordStepFormValues { +export interface LoginPasswordStepFormValues { password: string } @@ -31,7 +31,6 @@ export const LoginPasswordStep: React.FC = () => { return ( initialValues={{ password: "" }} - validateOnChange={true} validationSchema={Yup.object().shape({ password: Yup.string().required("Password field is required"), })} @@ -84,24 +83,12 @@ export const LoginPasswordStep: React.FC = () => { } const LoginPasswordStepForm: React.FC = () => { - const { - dirty, - errors, - handleChange, - handleSubmit, - isSubmitting, - isValid, - resetForm, - setErrors, - touched, - validateForm, - values, - } = useFormikContext() + const { handleSubmit, isSubmitting, isValid, resetForm } = + useFormikContext() const navigation = useAuthNavigation() const screen = useAuthScreen() const passwordRef = useRef(null) - const { color } = useTheme() useInputAutofocus({ screenName: "LoginPasswordStep", @@ -121,44 +108,11 @@ const LoginPasswordStepForm: React.FC = () => { Welcome back to Artsy - 0 || touched.password ? errors.password : undefined} - placeholderTextColor={color("black30")} - ref={passwordRef} - returnKeyType="done" - secureTextEntry - // textContentType="oneTimeCode" - // We need to to set textContentType to password here - // enable autofill of login details from the device keychain. - textContentType="password" - testID="password" - title="Password" - value={values.password} - onChangeText={(text) => { - // Hide error when the user starts to type again - if (errors.password) { - setErrors({ - password: undefined, - }) - validateForm() - } - handleChange("password")(text) - }} - onSubmitEditing={() => { - if (dirty && !!values.password) { - handleSubmit() - } - }} - onBlur={validateForm} - /> + - diff --git a/src/app/Scenes/Onboarding/Auth2/scenes/SignUpPasswordStep.tsx b/src/app/Scenes/Onboarding/Auth2/scenes/SignUpPasswordStep.tsx index b0276c5fb8e..3445f708a15 100644 --- a/src/app/Scenes/Onboarding/Auth2/scenes/SignUpPasswordStep.tsx +++ b/src/app/Scenes/Onboarding/Auth2/scenes/SignUpPasswordStep.tsx @@ -1,13 +1,5 @@ -import { - BackButton, - Button, - Flex, - Input, - LinkText, - Spacer, - Text, - useTheme, -} from "@artsy/palette-mobile" +import { BackButton, Button, Flex, Input, LinkText, Spacer, Text } from "@artsy/palette-mobile" +import { PasswordInput } from "app/Scenes/Onboarding/Auth2/components/PasswordInput" import { useAuthNavigation, useAuthScreen, @@ -18,7 +10,7 @@ import { Formik, useFormikContext } from "formik" import React, { useRef } from "react" import * as Yup from "yup" -interface SignUpPasswordStepFormValues { +export interface SignUpPasswordStepFormValues { password: string } @@ -57,20 +49,11 @@ export const SignUpPasswordStep: React.FC = () => { } const SignUpPasswordStepForm: React.FC = () => { - const { - errors, - handleChange, - handleSubmit, - isSubmitting, - isValid, - setErrors, - values, - resetForm, - } = useFormikContext() + const { handleSubmit, isSubmitting, isValid, resetForm } = + useFormikContext() const navigation = useAuthNavigation() const screen = useAuthScreen() - const { color } = useTheme() const passwordRef = useRef(null) useInputAutofocus({ @@ -91,31 +74,7 @@ const SignUpPasswordStepForm: React.FC = () => { Welcome to Artsy - { - // Hide error when the user starts to type again - if (errors.password) { - setErrors({ - password: undefined, - }) - } - handleChange("password")(text) - }} - onSubmitEditing={handleSubmit} - /> +