Skip to content

Commit

Permalink
Merge pull request #46696 from bernhardoj/fix/46204-login-is-cleared-…
Browse files Browse the repository at this point in the history
…when-resizing
  • Loading branch information
francoisl authored Aug 5, 2024
2 parents aa3804e + 498019c commit 3580ec4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/pages/signin/LoginForm/BaseLoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ 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, Credentials} from '@src/types/onyx';
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';
Expand All @@ -47,19 +47,15 @@ type BaseLoginFormOnyxProps = {

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

/** The credentials of the logged in person */
credentials: OnyxEntry<Credentials>;
};

type BaseLoginFormProps = WithToggleVisibilityViewProps & BaseLoginFormOnyxProps & LoginFormProps;

function BaseLoginForm({account, credentials, closeAccount, blurOnSubmit = false, isVisible}: BaseLoginFormProps, ref: ForwardedRef<InputHandle>) {
function BaseLoginForm({account, login, onLoginChanged, closeAccount, blurOnSubmit = false, isVisible}: BaseLoginFormProps, ref: ForwardedRef<InputHandle>) {
const styles = useThemeStyles();
const {isOffline} = useNetwork();
const {translate} = useLocalize();
const input = useRef<BaseTextInputRef | null>(null);
const [login, setLogin] = useState(() => Str.removeSMSDomain(credentials?.login ?? ''));
const [formError, setFormError] = useState<TranslationPaths | undefined>();
const prevIsVisible = usePrevious(isVisible);
const firstBlurred = useRef(false);
Expand Down Expand Up @@ -101,7 +97,7 @@ function BaseLoginForm({account, credentials, closeAccount, blurOnSubmit = false
*/
const onTextInput = useCallback(
(text: string) => {
setLogin(text);
onLoginChanged(text);
if (firstBlurred.current) {
validate(text);
}
Expand All @@ -115,7 +111,7 @@ function BaseLoginForm({account, credentials, closeAccount, blurOnSubmit = false
CloseAccount.setDefaultData();
}
},
[account, closeAccount, input, setLogin, validate],
[account, closeAccount, input, onLoginChanged, validate],
);

function getSignInWithStyles() {
Expand Down Expand Up @@ -338,7 +334,6 @@ BaseLoginForm.displayName = 'BaseLoginForm';
export default withToggleVisibilityView(
withOnyx<BaseLoginFormProps, BaseLoginFormOnyxProps>({
account: {key: ONYXKEYS.ACCOUNT},
credentials: {key: ONYXKEYS.CREDENTIALS},
closeAccount: {key: ONYXKEYS.FORMS.CLOSE_ACCOUNT_FORM},
})(forwardRef(BaseLoginForm)),
);
6 changes: 6 additions & 0 deletions src/pages/signin/LoginForm/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
type LoginFormProps = {
/** The login input value */
login: string;

/** A callback to notify that the login input value is changed */
onLoginChanged: (login: string) => void;

/** Function used to scroll to the top of the page */
scrollPageToTop?: () => void;

Expand Down
4 changes: 4 additions & 0 deletions src/pages/signin/SignInPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ function SignInPage({credentials, account, activeClients = [], preferredLocale,
* if we need to clear their sign in details so they can enter a login */
const [hasInitiatedSAMLLogin, setHasInitiatedSAMLLogin] = useState(false);

const [login, setLogin] = useState(() => Str.removeSMSDomain(credentials?.login ?? ''));

const isClientTheLeader = !!activeClients && ActiveClientManager.isClientTheLeader();
// We need to show "Another login page is opened" message if the page isn't active and visible
// eslint-disable-next-line rulesdir/no-negated-variables
Expand Down Expand Up @@ -283,6 +285,8 @@ function SignInPage({credentials, account, activeClients = [], preferredLocale,
<LoginForm
ref={loginFormRef}
isVisible={shouldShowLoginForm}
login={login}
onLoginChanged={setLogin}
blurOnSubmit={account?.validated === false}
scrollPageToTop={signInPageLayoutRef.current?.scrollPageToTop}
/>
Expand Down

0 comments on commit 3580ec4

Please sign in to comment.