Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: fix form validation in login, signup and forgot password

Ammar Ahmed2ad39048daec
diff --git a/apps/mobile/app/components/auth/forgot-password.tsx b/apps/mobile/app/components/auth/forgot-password.tsx
index 85ced9c76..331d3c508 100644
--- a/apps/mobile/app/components/auth/forgot-password.tsx
+++ b/apps/mobile/app/components/auth/forgot-password.tsx
@@ -27,7 +27,7 @@ import { useThemeColors } from "@notesnook/theme";
import DialogHeader from "../dialog/dialog-header";
import { Button } from "../ui/button";
import { IconButton } from "../ui/icon-button";
-import Input from "../ui/input";
+import FormInput, { createFormRef, validators } from "../ui/input/form-input";
import Seperator from "../ui/seperator";
import Heading from "../ui/typography/heading";
import Paragraph from "../ui/typography/paragraph";
@@ -36,14 +36,17 @@ import { DefaultAppStyles } from "../../utils/styles";
export const ForgotPassword = ({ userEmail }: { userEmail: string }) => {
const { colors } = useThemeColors("sheet");
- const email = useRef<string>(userEmail);
+ const formRef = useRef(
+ createFormRef({
+ email: userEmail || ""
+ })
+ ).current;
const emailInputRef = useRef<TextInput>(null);
- const [error, setError] = useState(false);
const [loading, setLoading] = useState(false);
const [sent, setSent] = useState(false);
const sendRecoveryEmail = async () => {
- if (!email.current || error) {
+ if (formRef.validateField("email")) {
ToastManager.show({
heading: strings.emailRequired(),
type: "error",
@@ -51,6 +54,9 @@ export const ForgotPassword = ({ userEmail }: { userEmail: string }) => {
});
return;
}
+
+ const values = formRef.getValues();
+
setLoading(true);
try {
const lastRecoveryEmailTime = SettingsService.get().lastRecoveryEmailTime;
@@ -60,7 +66,7 @@ export const ForgotPassword = ({ userEmail }: { userEmail: string }) => {
) {
throw new Error(strings.pleaseWaitBeforeSendEmail());
}
- await db.user.recoverAccount(email.current.toLowerCase());
+ await db.user.recoverAccount(values.email.toLowerCase());
SettingsService.set({
lastRecoveryEmailTime: Date.now()
});
@@ -126,22 +132,25 @@ export const ForgotPassword = ({ userEmail }: { userEmail: string }) => {
<DialogHeader title={strings.accountRecovery()} />
<Seperator />
- <Input
+ <FormInput
+ name="email"
+ formRef={formRef}
fwdRef={emailInputRef}
- onChangeText={(value) => {
- email.current = value;
- }}
- defaultValue={email.current}
- onErrorCheck={(e) => setError(e)}
+ loading={loading}
returnKeyLabel={strings.next()}
returnKeyType="next"
autoComplete="email"
- validationType="email"
+ keyboardType="email-address"
autoCorrect={false}
autoCapitalize="none"
- errorMessage={strings.emailInvalid()}
placeholder={strings.email()}
- onSubmit={() => {}}
+ validators={[
+ validators.required(strings.emailRequired()),
+ validators.email(strings.enterAValidEmailAddress())
+ ]}
+ onSubmitEditing={() => {
+ sendRecoveryEmail();
+ }}
/>
<Button
diff --git a/apps/mobile/app/components/auth/login.tsx b/apps/mobile/app/components/auth/login.tsx
index efa44ba28..546048c34 100644
--- a/apps/mobile/app/components/auth/login.tsx
+++ b/apps/mobile/app/components/auth/login.tsx
@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { strings } from "@notesnook/intl";
import { useThemeColors } from "@notesnook/theme";
import { RouteProp, useRoute } from "@react-navigation/native";
-import React, { useEffect, useState } from "react";
+import React, { useEffect, useRef, useState } from "react";
import { TouchableOpacity, View, useWindowDimensions } from "react-native";
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
import { DDS } from "../../services/device-detection";
@@ -38,13 +38,14 @@ import { sleep } from "../../utils/time";
import { Dialog } from "../dialog";
import { Progress } from "../sheets/progress";
import { Button } from "../ui/button";
-import Input from "../ui/input";
+import FormInput, { createFormRef, validators } from "../ui/input/form-input";
import Heading from "../ui/typography/heading";
import Paragraph from "../ui/typography/paragraph";
import { hideAuth } from "./common";
import { ForgotPassword } from "./forgot-password";
import { AuthHeader } from "./header";
import { useLogin } from "./use-login";
+import AppIcon from "../ui/AppIcon";
const LoginSteps = {
emailAuth: 1,
@@ -69,8 +70,8 @@ export const Login = ({
passwordInputRef,
loading,
setLoading,
- setError,
- login
+ login,
+ error
} = useLogin(async () => {
eSendEvent(eUserLoggedIn, true);
await sleep(500);
@@ -93,6 +94,27 @@ export const Login = ({
});
const { width, height } = useWindowDimensions();
const isTablet = width > 600;
+ const formRef = useRef(
+ createFormRef({
+ email: "",
+ password: ""
+ })
+ ).current;
+
+ const canContinue = () => {
+ if (step === LoginSteps.emailAuth) {
+ return !formRef.validateField("email");
+ }
+
+ return formRef.validate();
+ };
+
+ const onContinue = () => {
+ if (loading) return;
+ if (!canContinue()) return;
+ login();
+ };
+
useEffect(() => {
async () => {
setStep(LoginSteps.emailAuth);
@@ -198,27 +220,30 @@ export const Login = ({
gap: DefaultAppStyles.GAP_VERTICAL
}}
>
- <Input
+ <FormInput
+ name="email"
+ formRef={formRef}
fwdRef={emailInputRef}
onChangeText={(value) => {
email.current = value;
}}
testID="input.email"
- onErrorCheck={(e) => setError(e)}
returnKeyLabel="Next"
returnKeyType="next"
autoComplete="email"
- validationType="email"
+ keyboardType="email-address"
marginBottom={0}
autoCorrect={false}
autoCapitalize="none"
- errorMessage={strings.emailInvalid()}
placeholder={strings.email()}
- defaultValue={email.current}
editable={step === LoginSteps.emailAuth && !loading}
- onSubmit={() => {
+ validators={[
+ validators.required(strings.emailRequired()),
+ validators.email(strings.enterAValidEmailAddress())
+ ]}
+ onSubmitEditing={() => {
if (step === LoginSteps.emailAuth) {
- login();
+ onContinue();
} else {
passwordInputRef.current?.focus();
}
@@ -227,7 +252,9 @@ export const Login = ({
{step === LoginSteps.passwordAuth && (
<>
- <Input
+ <FormInput
+ name="password"
+ formRef={formRef}
fwdRef={passwordInputRef}
onChangeText={(value) => {
password.current = value;
@@ -242,9 +269,9 @@ export const Login = ({
placeholder={strings.password()}
marginBottom={0}
editable={!loading}
- defaultValue={password.current}
- onSubmit={() => {
- login();
+ validators={[validators.required(strings.passwordRequired())]}
+ onSubmitEditing={() => {
+ onContinue();
}}
/>
<Button
@@ -273,8 +300,7 @@ export const Login = ({
<Button
loading={loading}
onPress={() => {
- if (loading) return;
- login();
+ onContinue();
}}
style={{
width: "100%"
@@ -328,6 +354,25 @@ export const Login = ({
</Paragraph>
</TouchableOpacity>
) : null}
+
+ {error ? (
+ <Paragraph
+ numberOfLines={4}
+ onPress={() => {}}
+ color={colors.error.accent}
+ style={{
+ textAlign: "center",
+ marginTop: DefaultAppStyles.GAP_VERTICAL
+ }}
+ >
+ <AppIcon
+ color={colors.error.accent}
+ name="alert-circle-outline"
+ size={AppFontSize.sm - 1}
+ />{" "}
+ {error.message}
+ </Paragraph>
+ ) : null}
</View>
</View>
</View>
diff --git a/apps/mobile/app/components/auth/signup.tsx b/apps/mobile/app/components/auth/signup.tsx
index d936ad17c..9b744d703 100644
--- a/apps/mobile/app/components/auth/signup.tsx
+++ b/apps/mobile/app/components/auth/signup.tsx
@@ -30,7 +30,6 @@ import {
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
import { db } from "../../common/database";
import { DDS } from "../../services/device-detection";
-import { ToastManager } from "../../services/event-manager";
import { clearMessage, setEmailVerifyMessage } from "../../services/message";
import Navigation from "../../services/navigation";
import { useUserStore } from "../../stores/use-user-store";
@@ -39,7 +38,7 @@ import { AppFontSize } from "../../utils/size";
import { DefaultAppStyles } from "../../utils/styles";
import { Loading } from "../loading";
import { Button } from "../ui/button";
-import Input from "../ui/input";
+import FormInput, { createFormRef, validators } from "../ui/input/form-input";
import Heading from "../ui/typography/heading";
import Paragraph from "../ui/typography/paragraph";
import { AuthHeader } from "./header";
@@ -47,7 +46,6 @@ import { SignupContext } from "./signup-context";
import { RouteParams } from "../../stores/use-navigation-store";
import SettingsService from "../../services/settings";
import AppIcon from "../ui/AppIcon";
-import isEmail from "validator/lib/isEmail";
const SignupSteps = {
signup: 0,
@@ -64,13 +62,16 @@ export const Signup = ({
}) => {
const [currentStep, setCurrentStep] = useState(SignupSteps.signup);
const { colors } = useThemeColors();
- const email = useRef<string>(undefined);
+ const formRef = useRef(
+ createFormRef({
+ email: "",
+ password: "",
+ confirmPassword: ""
+ })
+ ).current;
const emailInputRef = useRef<TextInput>(null);
const passwordInputRef = useRef<TextInput>(null);
- const password = useRef<string>(undefined);
const confirmPasswordInputRef = useRef<TextInput>(null);
- const confirmPassword = useRef<string>(undefined);
- const [error, setError] = useState(false);
const [errorMessage, setErrorMessage] = useState<string>();
const [loading, setLoading] = useState(false);
const setUser = useUserStore((state) => state.setUser);
@@ -79,34 +80,17 @@ export const Signup = ({
const isTablet = width > 600;
const route = useRoute<RouteProp<RouteParams, "Auth">>();
- const validateInfo = () => {
- if (!password.current || !email.current || !confirmPassword.current) {
- setErrorMessage(strings.allFieldsRequiredDesc());
- return false;
- }
-
- if (!isEmail(email.current)) {
- setErrorMessage(strings.emailInvalid());
- return false;
- }
-
- if (password.current !== confirmPassword.current) {
- setErrorMessage(strings.passwordNotMatched());
- return false;
- }
-
- return true;
- };
-
const signup = async () => {
setErrorMessage(undefined);
- if (!validateInfo() || error) return;
+ if (!formRef.validate()) return;
if (loading) return;
+ const values = formRef.getValues();
+
setLoading(true);
try {
setCurrentStep(SignupSteps.createAccount);
- await db.user.signup(email.current!.toLowerCase(), password.current!);
+ await db.user.signup(values.email.toLowerCase(), values.password);
const user = await db.user.getUser();
setUser(user);
setLastSynced(await db.lastSynced());
@@ -123,12 +107,14 @@ export const Signup = ({
} catch (e) {
setCurrentStep(SignupSteps.signup);
setLoading(false);
- ToastManager.show({
- heading: strings.signupFailed(),
- message: (e as Error).message,
- type: "error",
- context: "local"
- });
+ if (
+ (e as Error).message === "Unable to create an account on this email."
+ ) {
+ formRef.setError("email", (e as Error).message);
+ } else {
+ setErrorMessage((e as Error).message);
+ }
+
return false;
}
};
@@ -223,37 +209,35 @@ export const Signup = ({
alignSelf: "center"
}}
>
- <Input
+ <FormInput
+ name="email"
+ formRef={formRef}
fwdRef={emailInputRef}
- onChangeText={(value) => {
- email.current = value;
- }}
- defaultValue={email.current}
+ loading={loading}
testID="input.email"
- onErrorCheck={(e) => setError(e)}
returnKeyLabel="Next"
returnKeyType="next"
autoComplete="email"
- validationType="email"
+ keyboardType="email-address"
autoCorrect={false}
autoCapitalize="none"
- errorMessage={strings.emailInvalid()}
placeholder={strings.email()}
blurOnSubmit={false}
- onSubmit={() => {
- if (!email.current) return;
+ validators={[
+ validators.required(strings.emailRequired()),
+ validators.email(strings.enterAValidEmailAddress())
+ ]}
+ onSubmitEditing={() => {
passwordInputRef.current?.focus();
}}
/>
- <Input
+ <FormInput
+ name="password"
+ formRef={formRef}
fwdRef={passwordInputRef}
- onChangeText={(value) => {
- password.current = value;
- }}
- defaultValue={password.current}
+ loading={loading}
testID="input.password"
- onErrorCheck={(e) => setError(e)}
returnKeyLabel="Next"
returnKeyType="next"
secureTextEntry
@@ -262,20 +246,18 @@ export const Signup = ({
blurOnSubmit={false}
autoCorrect={false}
placeholder={strings.password()}
- onSubmit={() => {
- if (!password.current) return;
+ validators={[validators.required(strings.passwordRequired())]}
+ onSubmitEditing={() => {
confirmPasswordInputRef.current?.focus();
}}
/>
- <Input
+ <FormInput
+ name="confirmPassword"
+ formRef={formRef}
fwdRef={confirmPasswordInputRef}
- onChangeText={(value) => {
- confirmPassword.current = value;
- }}
- defaultValue={confirmPassword.current}
+ loading={loading}
testID="input.confirmPassword"
- onErrorCheck={(e) => setError(e)}
returnKeyLabel="Signup"
returnKeyType="done"
secureTextEntry
@@ -283,12 +265,16 @@ export const Signup = ({
autoCapitalize="none"
autoCorrect={false}
blurOnSubmit={false}
- validationType="confirmPassword"
- customValidator={() => password.current || ""}
- errorMessage={strings.passwordNotMatched()}
placeholder={strings.confirmPassword()}
marginBottom={12}
- onSubmit={() => {
+ validators={[
+ validators.required(strings.confirmPasswordRequired()),
+ validators.matchField(
+ "password",
+ strings.passwordNotMatched()
+ )
+ ]}
+ onSubmitEditing={() => {
signup();
}}
/>
diff --git a/apps/mobile/app/components/auth/use-login.ts b/apps/mobile/app/components/auth/use-login.ts
index f79fb3e78..a9180e849 100644
--- a/apps/mobile/app/components/auth/use-login.ts
+++ b/apps/mobile/app/components/auth/use-login.ts
@@ -39,7 +39,7 @@ export const useLogin = (
onFinishLogin?: () => void,
sessionExpired = false
) => {
- const [error, setError] = useState(false);
+ const [error, setError] = useState<Error>();
const [loading, setLoading] = useState(false);
const setUser = useUserStore((state) => state.setUser);
const [step, setStep] = useState(LoginSteps.emailAuth);
@@ -142,12 +142,7 @@ export const useLogin = (
const finishWithError = async (e: Error) => {
if (e.message === "invalid_grant") setStep(LoginSteps.emailAuth);
setLoading(false);
- ToastManager.show({
- heading: strings.loginFailed(),
- message: e.message,
- type: "error",
- context: "local"
- });
+ setError(e);
};
const finishLogin = async () => {
diff --git a/apps/mobile/app/components/ui/input/form-input.tsx b/apps/mobile/app/components/ui/input/form-input.tsx
new file mode 100644
index 000000000..d070dd42d
--- /dev/null
+++ b/apps/mobile/app/components/ui/input/form-input.tsx
@@ -0,0 +1,404 @@
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2023 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+import React, { RefObject, useEffect, useMemo, useState } from "react";
+import {
+ ColorValue,
+ TextInput,
+ TextInputProps,
+ TouchableOpacity,
+ View,
+ ViewStyle
+} from "react-native";
+import isEmail from "validator/lib/isEmail";
+import isURL from "validator/lib/isURL";
+import { useThemeColors } from "@notesnook/theme";
+import { defaultBorderRadius, AppFontSize } from "../../../utils/size";
+import { DefaultAppStyles } from "../../../utils/styles";
+import { IconButton } from "../icon-button";
+import Paragraph from "../typography/paragraph";
+import AppIcon from "../AppIcon";
+
+export type FormValues = Record<string, string>;
+export type FormErrors = Partial<Record<string, string>>;
+export type FieldValidator = (
+ value: string,
+ values: FormValues
+) => string | undefined;
+export type ValidationSchema = Partial<Record<string, FieldValidator[]>>;
+
+export interface FormRef {
+ values: FormValues;
+ errors: FormErrors;
+ setValue: (name: string, value: string) => void;
+ getValue: (name: string) => string;
+ getValues: () => FormValues;
+ setError: (name: string, error?: string) => void;
+ getError: (name: string) => string | undefined;
+ clearErrors: () => void;
+ registerField: (name: string, validators?: FieldValidator[]) => void;
+ unregisterField: (name: string) => void;
+ validateField: (name: string) => string | undefined;
+ validate: () => boolean;
+ subscribe: (listener: () => void) => () => void;
+}
+
+export function createFormRef(initialValues: FormValues = {}): FormRef {
+ const listeners = new Set<() => void>();
+ const values: FormValues = { ...initialValues };
+ const errors: FormErrors = {};
+ const schema: ValidationSchema = {};
+
+ const notify = () => {
+ listeners.forEach((listener) => listener());
+ };
+
+ return {
+ values,
+ errors,
+ setValue(name, value) {
+ values[name] = value;
+ if (errors[name]) delete errors[name];
+ notify();
+ },
+ getValue(name) {
+ return values[name] ?? "";
+ },
+ getValues() {
+ return { ...values };
+ },
+ setError(name, error) {
+ if (!error) {
+ delete errors[name];
+ } else {
+ errors[name] = error;
+ }
+ notify();
+ },
+ getError(name) {
+ return errors[name];
+ },
+ clearErrors() {
+ Object.keys(errors).forEach((key) => delete errors[key]);
+ notify();
+ },
+ registerField(name, validators = []) {
+ schema[name] = validators;
+ if (values[name] === undefined) values[name] = "";
+ },
+ unregisterField(name) {
+ delete schema[name];
+ delete errors[name];
+ notify();
+ },
+ validateField(name) {
+ const fieldValidators = schema[name] || [];
+ const value = values[name] ?? "";
+ for (const validator of fieldValidators) {
+ const error = validator(value, values);
+ if (error) {
+ errors[name] = error;
+ notify();
+ return error;
+ }
+ }
+ delete errors[name];
+ notify();
+ return undefined;
+ },
+ validate() {
+ const nextErrors = validateForm(values, schema);
+ Object.keys(errors).forEach((key) => delete errors[key]);
+ Object.keys(nextErrors).forEach((key) => {
+ errors[key] = nextErrors[key];
+ });
+ notify();
+ return !hasFormErrors(nextErrors);
+ },
+ subscribe(listener) {
+ listeners.add(listener);
+ return () => {
+ listeners.delete(listener);
+ };
+ }
+ };
+}
+
+export function validateForm(
+ values: FormValues,
+ schema: ValidationSchema
+): FormErrors {
+ const errors: FormErrors = {};
+
+ Object.keys(schema).forEach((field) => {
+ const fieldValidators = schema[field] || [];
+ const value = values[field] ?? "";
+ for (const validator of fieldValidators) {
+ const error = validator(value, values);
+ if (error) {
+ errors[field] = error;
+ break;
+ }
+ }
+ });
+
+ return errors;
+}
+
+export function hasFormErrors(errors: FormErrors) {
+ return Object.keys(errors).length > 0;
+}
+
+export const validators = {
+ required:
+ (message = "This field is required") =>
+ (value: string) =>
+ value?.trim() ? undefined : message,
+
+ email:
+ (message = "Please enter a valid email") =>
+ (value: string) =>
+ !value?.trim() || isEmail(value.trim()) ? undefined : message,
+
+ minLength: (length: number, message?: string) => (value: string) =>
+ !value || value.length >= length
+ ? undefined
+ : message || `Must be at least ${length} characters`,
+
+ url:
+ (message = "Please enter a valid URL") =>
+ (value: string) =>
+ !value?.trim() || isURL(value.trim(), { allow_underscores: true })
+ ? undefined
+ : message,
+
+ matchField:
+ (fieldName: string, message = "Values do not match") =>
+ (value: string, values: FormValues) =>
+ value === values[fieldName] ? undefined : message
+};
+
+interface FormInputProps extends TextInputProps {
+ name: string;
+ formRef: FormRef;
+ validators?: FieldValidator[];
+ fwdRef?: RefObject<TextInput | null>;
+ loading?: boolean;
+ error?: string;
+ customColor?: ColorValue;
+ marginBottom?: number;
+ marginRight?: number;
+ button?: {
+ icon: string;
+ color: ColorValue;
+ onPress: () => void;
+ testID?: string;
+ size?: number;
+ };
+ buttons?: React.ReactNode;
+ buttonLeft?: React.ReactNode;
+ height?: number;
+ fontSize?: number;
+ inputStyle?: TextInputProps["style"];
+ containerStyle?: ViewStyle;
+ wrapperStyle?: ViewStyle;
+}
+
+export function FormInput({
+ name,
+ formRef,
+ validators: fieldValidators = [],
+ fwdRef,
+ loading,
+ error,
+ secureTextEntry,
+ customColor,
+ marginBottom = 10,
+ marginRight,
+ button,
+ buttonLeft,
+ buttons,
+ height = 45,
+ fontSize = AppFontSize.sm,
+ inputStyle = {},
+ containerStyle = {},
+ wrapperStyle = {},
+ onFocus,
+ onBlur,
+ onPress,
+ onChangeText,
+ ...restProps
+}: FormInputProps) {
+ const { colors, isDark } = useThemeColors();
+ const [focused, setFocused] = useState(false);
+ const [secureEntry, setSecureEntry] = useState(true);
+ const [, setVersion] = useState(0);
+
+ useEffect(() => {
+ formRef.registerField(name, fieldValidators);
+ const unsubscribe = formRef.subscribe(() => {
+ setVersion((v) => v + 1);
+ });
+
+ return () => {
+ unsubscribe();
+ formRef.unregisterField(name);
+ };
+ }, [fieldValidators, formRef, name]);
+
+ const value = formRef.getValue(name);
+ const fieldError = error || formRef.getError(name);
+
+ const borderColor = useMemo(() => {
+ if (fieldError) return colors.error.accent;
+ if (focused) return customColor || colors.selected.border;
+ return colors.primary.border;
+ }, [colors, customColor, fieldError, focused]);
+
+ const style: ViewStyle = {
+ borderWidth: 1,
+ borderRadius: defaultBorderRadius,
+ borderColor,
+ flexDirection: "row",
+ justifyContent: "space-between",
+ alignItems: "center",
+ paddingHorizontal: DefaultAppStyles.GAP,
+ ...containerStyle
+ };
+
+ const textStyle: TextInputProps["style"] = {
+ paddingHorizontal: 0,
+ fontSize,
+ color:
+ onPress && loading ? colors.primary.accent : colors.primary.paragraph,
+ flexGrow: 1,
+ flexShrink: 1,
+ paddingBottom: DefaultAppStyles.GAP_VERTICAL,
+ paddingTop: DefaultAppStyles.GAP_VERTICAL,
+ fontFamily: "Inter-Regular",
+ ...(inputStyle as ViewStyle)
+ };
+
+ const handleChangeText = (nextValue: string) => {
+ formRef.setValue(name, nextValue);
+ onChangeText?.(nextValue);
+ };
+
+ return (
+ <View
+ importantForAccessibility="yes"
+ style={{
+ marginBottom,
+ marginRight,
+ ...wrapperStyle
+ }}
+ >
+ <TouchableOpacity
+ disabled={!loading}
+ onPress={onPress}
+ activeOpacity={1}
+ style={style}
+ >
+ {buttonLeft}
+
+ <TextInput
+ {...restProps}
+ value={value}
+ ref={fwdRef}
+ editable={!loading && restProps.editable !== false}
+ onChangeText={handleChangeText}
+ onFocus={(e) => {
+ setFocused(true);
+ onFocus?.(e);
+ }}
+ onBlur={(e) => {
+ setFocused(false);
+ onBlur?.(e);
+ }}
+ keyboardAppearance={isDark ? "dark" : "light"}
+ style={textStyle}
+ secureTextEntry={secureTextEntry && secureEntry}
+ placeholderTextColor={colors.primary.placeholder}
+ />
+
+ <View
+ style={{
+ flexDirection: "row",
+ justifyContent: "center",
+ height: 35 > height ? height : 35,
+ alignItems: "center"
+ }}
+ >
+ {secureTextEntry && (
+ <IconButton
+ name="eye"
+ size={20}
+ top={10}
+ bottom={10}
+ onPress={() => {
+ fwdRef?.current?.blur();
+ setSecureEntry(!secureEntry);
+ }}
+ style={{
+ width: 25,
+ marginLeft: 5
+ }}
+ color={
+ secureEntry ? colors.secondary.icon : colors.primary.accent
+ }
+ />
+ )}
+
+ {buttons}
+
+ {button && (
+ <IconButton
+ testID={button.testID}
+ name={button.icon}
+ size={button.size || AppFontSize.xl}
+ top={10}
+ bottom={10}
+ onPress={button.onPress}
+ color={button.color}
+ style={{
+ marginRight: -8
+ }}
+ />
+ )}
+ </View>
+ </TouchableOpacity>
+
+ {fieldError ? (
+ <Paragraph
+ size={AppFontSize.xs}
+ style={{ marginTop: 5, color: colors.error.icon }}
+ >
+ <AppIcon
+ color={colors.error.accent}
+ name="alert-circle-outline"
+ size={AppFontSize.sm - 1}
+ />{" "}
+ {fieldError}
+ </Paragraph>
+ ) : null}
+ </View>
+ );
+}
+
+export default FormInput;
diff --git a/apps/mobile/app/components/ui/input/index.tsx b/apps/mobile/app/components/ui/input/index.tsx
index bca8d6a88..19da9fde2 100644
--- a/apps/mobile/app/components/ui/input/index.tsx
+++ b/apps/mobile/app/components/ui/input/index.tsx
@@ -121,8 +121,8 @@ const Input = ({
const color = error
? colors.error.border
: focus
- ? customColor || colors.selected.border
- : colors.primary.border;
+ ? customColor || colors.selected.border
+ : colors.primary.border;
const validate = async (value: string) => {
if (!validationType) return;
diff --git a/packages/intl/locale/en.po b/packages/intl/locale/en.po
index 4316660c9..a16f04684 100644
--- a/packages/intl/locale/en.po
+++ b/packages/intl/locale/en.po
@@ -1770,6 +1770,10 @@ msgstr "Confirm new password"
msgid "Confirm password"
msgstr "Confirm password"
+#: src/strings.ts:2661
+msgid "Confirm password required"
+msgstr "Confirm password required"
+
#: src/strings.ts:1487
msgid "Confirm pin"
msgstr "Confirm pin"
@@ -4540,6 +4544,10 @@ msgstr "Password not entered"
msgid "Password protection"
msgstr "Password protection"
+#: src/strings.ts:2660
+msgid "Password required"
+msgstr "Password required"
+
#: src/strings.ts:809
msgid "Password updated"
msgstr "Password updated"
@@ -4647,6 +4655,7 @@ msgid "Please enable automatic backups to avoid losing important data."
msgstr "Please enable automatic backups to avoid losing important data."
#: src/strings.ts:1512
+#: src/strings.ts:2662
msgid "Please enter a valid email address"
msgstr "Please enter a valid email address"
@@ -7662,8 +7671,8 @@ msgid "Your support request has been forwarded"
msgstr "Your support request has been forwarded"
#: src/strings.ts:2062
-msgid "Your support request has been forwarded to our support team. We will get back to you via email at {email}. If this email is not reachable or incorrect, please send us an email directly at [email protected]."
-msgstr "Your support request has been forwarded to our support team. We will get back to you via email at {email}. If this email is not reachable or incorrect, please send us an email directly at [email protected]."
+msgid "Your support request has been forwarded to our support team. We will get back to you via email as soon as possible. If you don't receive an email from us within 24-48 hours, please send us an email directly at [email protected]."
+msgstr "Your support request has been forwarded to our support team. We will get back to you via email as soon as possible. If you don't receive an email from us within 24-48 hours, please send us an email directly at [email protected]."
#: src/strings.ts:956
msgid "Your tags"
diff --git a/packages/intl/locale/pseudo-LOCALE.po b/packages/intl/locale/pseudo-LOCALE.po
index 709e5ab2a..2d924d193 100644
--- a/packages/intl/locale/pseudo-LOCALE.po
+++ b/packages/intl/locale/pseudo-LOCALE.po
@@ -1759,6 +1759,10 @@ msgstr ""
msgid "Confirm password"
msgstr ""
+#: src/strings.ts:2661
+msgid "Confirm password required"
+msgstr ""
+
#: src/strings.ts:1487
msgid "Confirm pin"
msgstr ""
@@ -4514,6 +4518,10 @@ msgstr ""
msgid "Password protection"
msgstr ""
+#: src/strings.ts:2660
+msgid "Password required"
+msgstr ""
+
#: src/strings.ts:809
msgid "Password updated"
msgstr ""
@@ -4621,6 +4629,7 @@ msgid "Please enable automatic backups to avoid losing important data."
msgstr ""
#: src/strings.ts:1512
+#: src/strings.ts:2662
msgid "Please enter a valid email address"
msgstr ""
@@ -7604,7 +7613,7 @@ msgid "Your support request has been forwarded"
msgstr ""
#: src/strings.ts:2062
-msgid "Your support request has been forwarded to our support team. We will get back to you via email at {email}. If this email is not reachable or incorrect, please send us an email directly at [email protected]."
+msgid "Your support request has been forwarded to our support team. We will get back to you via email as soon as possible. If you don't receive an email from us within 24-48 hours, please send us an email directly at [email protected]."
msgstr ""
#: src/strings.ts:956
diff --git a/packages/intl/src/strings.ts b/packages/intl/src/strings.ts
index ddfce1b9a..eca1169f3 100644
--- a/packages/intl/src/strings.ts
+++ b/packages/intl/src/strings.ts
@@ -2656,5 +2656,8 @@ Use this if changes from other devices are not appearing on this device. This wi
t`Invalid recovery key. Make sure to input your account recovery key, not a 2FA recovery code.`,
featureNotAvailable: () => t`This feature is not available on this plan.`,
valueMustBeBetween: (min: number, max: number) =>
- t`Value must be between ${min} and ${max}`
+ t`Value must be between ${min} and ${max}`,
+ passwordRequired: () => t`Password required`,
+ confirmPasswordRequired: () => t`Confirm password required`,
+ enterAValidEmailAddress: () => t`Please enter a valid email address`
};