Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 8 additions & 21 deletions src/pages/signin/LoginForm/BaseLoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import {Str} from 'expensify-common';
import type {ForwardedRef} from 'react';
import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react';
import {InteractionManager, View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import DotIndicatorMessage from '@components/DotIndicatorMessage';
import FormAlertWithSubmitButton from '@components/FormAlertWithSubmitButton';
import AppleSignIn from '@components/SignInButtons/AppleSignIn';
Expand Down Expand Up @@ -34,24 +33,16 @@ import CONFIG from '@src/CONFIG';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import type {CloseAccountForm} from '@src/types/form';
import type {Account} from '@src/types/onyx';
import htmlDivElementRef from '@src/types/utils/htmlDivElementRef';
import viewRef from '@src/types/utils/viewRef';
import type LoginFormProps from './types';
import type {InputHandle} from './types';

type BaseLoginFormOnyxProps = {
/** The details about the account that the user is signing in with */
account: OnyxEntry<Account>;
type BaseLoginFormProps = WithToggleVisibilityViewProps & LoginFormProps;

/** Message to display when user successfully closed their account */
closeAccount: OnyxEntry<CloseAccountForm>;
};

type BaseLoginFormProps = WithToggleVisibilityViewProps & BaseLoginFormOnyxProps & LoginFormProps;

function BaseLoginForm({account, login, onLoginChanged, closeAccount, blurOnSubmit = false, isVisible}: BaseLoginFormProps, ref: ForwardedRef<InputHandle>) {
function BaseLoginForm({login, onLoginChanged, blurOnSubmit = false, isVisible}: BaseLoginFormProps, ref: ForwardedRef<InputHandle>) {
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
const [closeAccount] = useOnyx(ONYXKEYS.FORMS.CLOSE_ACCOUNT_FORM);
const styles = useThemeStyles();
const {isOffline} = useNetwork();
const {translate} = useLocalize();
Expand All @@ -62,6 +53,7 @@ function BaseLoginForm({account, login, onLoginChanged, closeAccount, blurOnSubm
const isFocused = useIsFocused();
const isLoading = useRef(false);
const {shouldUseNarrowLayout, isInNarrowPaneModal} = useResponsiveLayout();
const accountMessage = account?.message === 'unlinkLoginForm.succesfullyUnlinkedLogin' ? translate(account.message) : account?.message ?? '';

/**
* Validate the input value and set the error for formError
Expand Down Expand Up @@ -276,7 +268,7 @@ function BaseLoginForm({account, login, onLoginChanged, closeAccount, blurOnSubm
style={[styles.mv2]}
type="success"
// eslint-disable-next-line @typescript-eslint/naming-convention,@typescript-eslint/prefer-nullish-coalescing
messages={{0: closeAccount?.success ? closeAccount.success : account?.message || ''}}
messages={{0: closeAccount?.success ? closeAccount.success : accountMessage}}
/>
)}
{
Expand Down Expand Up @@ -331,9 +323,4 @@ function BaseLoginForm({account, login, onLoginChanged, closeAccount, blurOnSubm

BaseLoginForm.displayName = 'BaseLoginForm';

export default withToggleVisibilityView(
withOnyx<BaseLoginFormProps, BaseLoginFormOnyxProps>({
account: {key: ONYXKEYS.ACCOUNT},
closeAccount: {key: ONYXKEYS.FORMS.CLOSE_ACCOUNT_FORM},
})(forwardRef(BaseLoginForm)),
);
export default withToggleVisibilityView(forwardRef(BaseLoginForm));
2 changes: 1 addition & 1 deletion src/pages/signin/LoginForm/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {InputHandle} from './types';
import type LoginFormProps from './types';

function LoginForm({scrollPageToTop, ...rest}: LoginFormProps, ref: ForwardedRef<InputHandle>) {
const loginFormRef = useRef<InputHandle>();
const loginFormRef = useRef<InputHandle>(null);

useImperativeHandle(ref, () => ({
isInputFocused: loginFormRef.current ? loginFormRef.current.isInputFocused : () => false,
Expand Down