Skip to content

Commit 3580ec4

Browse files
authored
Merge pull request #46696 from bernhardoj/fix/46204-login-is-cleared-when-resizing
2 parents aa3804e + 498019c commit 3580ec4

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/pages/signin/LoginForm/BaseLoginForm.tsx

+4-9
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import CONST from '@src/CONST';
3535
import type {TranslationPaths} from '@src/languages/types';
3636
import ONYXKEYS from '@src/ONYXKEYS';
3737
import type {CloseAccountForm} from '@src/types/form';
38-
import type {Account, Credentials} from '@src/types/onyx';
38+
import type {Account} from '@src/types/onyx';
3939
import htmlDivElementRef from '@src/types/utils/htmlDivElementRef';
4040
import viewRef from '@src/types/utils/viewRef';
4141
import type LoginFormProps from './types';
@@ -47,19 +47,15 @@ type BaseLoginFormOnyxProps = {
4747

4848
/** Message to display when user successfully closed their account */
4949
closeAccount: OnyxEntry<CloseAccountForm>;
50-
51-
/** The credentials of the logged in person */
52-
credentials: OnyxEntry<Credentials>;
5350
};
5451

5552
type BaseLoginFormProps = WithToggleVisibilityViewProps & BaseLoginFormOnyxProps & LoginFormProps;
5653

57-
function BaseLoginForm({account, credentials, closeAccount, blurOnSubmit = false, isVisible}: BaseLoginFormProps, ref: ForwardedRef<InputHandle>) {
54+
function BaseLoginForm({account, login, onLoginChanged, closeAccount, blurOnSubmit = false, isVisible}: BaseLoginFormProps, ref: ForwardedRef<InputHandle>) {
5855
const styles = useThemeStyles();
5956
const {isOffline} = useNetwork();
6057
const {translate} = useLocalize();
6158
const input = useRef<BaseTextInputRef | null>(null);
62-
const [login, setLogin] = useState(() => Str.removeSMSDomain(credentials?.login ?? ''));
6359
const [formError, setFormError] = useState<TranslationPaths | undefined>();
6460
const prevIsVisible = usePrevious(isVisible);
6561
const firstBlurred = useRef(false);
@@ -101,7 +97,7 @@ function BaseLoginForm({account, credentials, closeAccount, blurOnSubmit = false
10197
*/
10298
const onTextInput = useCallback(
10399
(text: string) => {
104-
setLogin(text);
100+
onLoginChanged(text);
105101
if (firstBlurred.current) {
106102
validate(text);
107103
}
@@ -115,7 +111,7 @@ function BaseLoginForm({account, credentials, closeAccount, blurOnSubmit = false
115111
CloseAccount.setDefaultData();
116112
}
117113
},
118-
[account, closeAccount, input, setLogin, validate],
114+
[account, closeAccount, input, onLoginChanged, validate],
119115
);
120116

121117
function getSignInWithStyles() {
@@ -338,7 +334,6 @@ BaseLoginForm.displayName = 'BaseLoginForm';
338334
export default withToggleVisibilityView(
339335
withOnyx<BaseLoginFormProps, BaseLoginFormOnyxProps>({
340336
account: {key: ONYXKEYS.ACCOUNT},
341-
credentials: {key: ONYXKEYS.CREDENTIALS},
342337
closeAccount: {key: ONYXKEYS.FORMS.CLOSE_ACCOUNT_FORM},
343338
})(forwardRef(BaseLoginForm)),
344339
);

src/pages/signin/LoginForm/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
type LoginFormProps = {
2+
/** The login input value */
3+
login: string;
4+
5+
/** A callback to notify that the login input value is changed */
6+
onLoginChanged: (login: string) => void;
7+
28
/** Function used to scroll to the top of the page */
39
scrollPageToTop?: () => void;
410

src/pages/signin/SignInPage.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ function SignInPage({credentials, account, activeClients = [], preferredLocale,
161161
* if we need to clear their sign in details so they can enter a login */
162162
const [hasInitiatedSAMLLogin, setHasInitiatedSAMLLogin] = useState(false);
163163

164+
const [login, setLogin] = useState(() => Str.removeSMSDomain(credentials?.login ?? ''));
165+
164166
const isClientTheLeader = !!activeClients && ActiveClientManager.isClientTheLeader();
165167
// We need to show "Another login page is opened" message if the page isn't active and visible
166168
// eslint-disable-next-line rulesdir/no-negated-variables
@@ -283,6 +285,8 @@ function SignInPage({credentials, account, activeClients = [], preferredLocale,
283285
<LoginForm
284286
ref={loginFormRef}
285287
isVisible={shouldShowLoginForm}
288+
login={login}
289+
onLoginChanged={setLogin}
286290
blurOnSubmit={account?.validated === false}
287291
scrollPageToTop={signInPageLayoutRef.current?.scrollPageToTop}
288292
/>

0 commit comments

Comments
 (0)