Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix login is cleared when resizing window #46696

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
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
Loading