-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fixed getting two magic codes upon signing in once #30849
Merged
madmax330
merged 20 commits into
Expensify:main
from
samilabud:getting_two_magic_codes_upon_signing_once_30181
Apr 16, 2024
Merged
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
283cf90
Fixed getting two magic codes upon signing in once
samilabud 172c9af
Fixed prettier after fixed conficts / after merge
samilabud f0012ab
Added recovery mode feature to code form, fixed bugs: both loading st…
samilabud b50afa8
Fixed two factor auth bug
samilabud 12421b3
Fixed form text when changing from magic code to recovery code or two…
samilabud 2b5248b
Fixed merge issues
samilabud 2db7bc5
Merge branch 'main' into getting_two_magic_codes_upon_signing_once_30181
samilabud 628467e
Fixed merge conflics and issues
samilabud e0413db
Fixed lint issue
samilabud 7941b59
Merge branch 'main' into getting_two_magic_codes_upon_signing_once_30181
samilabud c423527
Removed keyboard validation that dismiss the device keyboard if shown…
samilabud 8859a8d
Merge branch 'main' into getting_two_magic_codes_upon_signing_once_30181
samilabud 7841b30
Merge branch 'main' into getting_two_magic_codes_upon_signing_once_30181
samilabud 05a0e88
Fixed animation image increasing the content height when SAML is enabled
samilabud 9c8b20b
Merge branch 'main' into getting_two_magic_codes_upon_signing_once_30181
samilabud 280d5ef
Merge branch 'main' into getting_two_magic_codes_upon_signing_once_30181
samilabud f8bbc25
Undo the change to fix animation image increasing the content height …
samilabud 5445370
Fixed lint error
samilabud 892e016
Merge branch 'main' into getting_two_magic_codes_upon_signing_once_30181
samilabud 93cda52
Fixed styles to work withoud fixed height
samilabud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,67 @@ | ||
import React, {useEffect} from 'react'; | ||
import {Keyboard, View} from 'react-native'; | ||
import React from 'react'; | ||
import {View} from 'react-native'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
import Button from '@components/Button'; | ||
import FormHelpMessage from '@components/FormHelpMessage'; | ||
import Text from '@components/Text'; | ||
import useKeyboardState from '@hooks/useKeyboardState'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useNetwork from '@hooks/useNetwork'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import useWindowDimensions from '@hooks/useWindowDimensions'; | ||
import * as ErrorUtils from '@libs/ErrorUtils'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import * as Session from '@userActions/Session'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import ROUTES from '@src/ROUTES'; | ||
import type {Account, Credentials} from '@src/types/onyx'; | ||
import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
import ChangeExpensifyLoginLink from './ChangeExpensifyLoginLink'; | ||
import Terms from './Terms'; | ||
import type {Account} from '@src/types/onyx'; | ||
import ValidateCodeForm from './ValidateCodeForm'; | ||
|
||
type ChooseSSOOrMagicCodeOnyxProps = { | ||
/** The credentials of the logged in person */ | ||
credentials: OnyxEntry<Credentials>; | ||
|
||
/** The details about the account that the user is signing in with */ | ||
account: OnyxEntry<Account>; | ||
}; | ||
|
||
type ChooseSSOOrMagicCodeProps = ChooseSSOOrMagicCodeOnyxProps & { | ||
/** Function that returns whether the user is using SAML or magic codes to log in */ | ||
setIsUsingMagicCode: (value: boolean) => void; | ||
/** Determines if user is switched to using recovery code instead of 2fa code */ | ||
isUsingRecoveryCode: boolean; | ||
|
||
/** Function to change `isUsingRecoveryCode` state when user toggles between 2fa code and recovery code */ | ||
setIsUsingRecoveryCode: (value: boolean) => void; | ||
}; | ||
|
||
function ChooseSSOOrMagicCode({credentials, account, setIsUsingMagicCode}: ChooseSSOOrMagicCodeProps) { | ||
function ChooseSSOOrMagicCode({account, isUsingRecoveryCode, setIsUsingRecoveryCode}: ChooseSSOOrMagicCodeProps) { | ||
const styles = useThemeStyles(); | ||
const {isKeyboardShown} = useKeyboardState(); | ||
const {translate} = useLocalize(); | ||
const {isOffline} = useNetwork(); | ||
const {isSmallScreenWidth} = useWindowDimensions(); | ||
|
||
// This view doesn't have a field for user input, so dismiss the device keyboard if shown | ||
useEffect(() => { | ||
if (!isKeyboardShown) { | ||
return; | ||
} | ||
Keyboard.dismiss(); | ||
}, [isKeyboardShown]); | ||
const loginTextAfterMagicCode = isUsingRecoveryCode ? translate('validateCodeForm.enterRecoveryCode') : translate('validateCodeForm.enterAuthenticatorCode'); | ||
const loginText = account?.requiresTwoFactorAuth ? loginTextAfterMagicCode : translate('samlSignIn.orContinueWithMagicCode'); | ||
|
||
return ( | ||
<> | ||
<View> | ||
<Text style={[styles.loginHeroBody, styles.mb5, styles.textNormal, !isSmallScreenWidth ? styles.textAlignLeft : {}]}>{translate('samlSignIn.welcomeSAMLEnabled')}</Text> | ||
<Button | ||
isDisabled={isOffline} | ||
success | ||
large | ||
style={[styles.mv3]} | ||
text={translate('samlSignIn.useSingleSignOn')} | ||
isLoading={account?.isLoading} | ||
onPress={() => { | ||
Navigation.navigate(ROUTES.SAML_SIGN_IN); | ||
}} | ||
/> | ||
<View> | ||
<Text style={[styles.loginHeroBody, styles.mb5, styles.textNormal, !isSmallScreenWidth ? styles.textAlignLeft : {}]}>{translate('samlSignIn.welcomeSAMLEnabled')}</Text> | ||
<Button | ||
isDisabled={isOffline} | ||
success | ||
large | ||
style={[styles.mv3]} | ||
text={translate('samlSignIn.useSingleSignOn')} | ||
onPress={() => { | ||
Navigation.navigate(ROUTES.SAML_SIGN_IN); | ||
}} | ||
/> | ||
|
||
<View style={[styles.mt5]}> | ||
<Text style={[styles.loginHeroBody, styles.mb5, styles.textNormal, !isSmallScreenWidth ? styles.textAlignLeft : {}]}> | ||
{translate('samlSignIn.orContinueWithMagicCode')} | ||
</Text> | ||
</View> | ||
|
||
<Button | ||
isDisabled={isOffline} | ||
style={[styles.mv3]} | ||
large | ||
text={translate('samlSignIn.useMagicCode')} | ||
isLoading={account?.isLoading && account?.loadingForm === (account?.requiresTwoFactorAuth ? CONST.FORMS.VALIDATE_TFA_CODE_FORM : CONST.FORMS.VALIDATE_CODE_FORM)} | ||
onPress={() => { | ||
Session.resendValidateCode(credentials?.login); | ||
setIsUsingMagicCode(true); | ||
}} | ||
/> | ||
{!!account && !isEmptyObject(account.errors) && <FormHelpMessage message={ErrorUtils.getLatestErrorMessage(account)} />} | ||
<ChangeExpensifyLoginLink onPress={() => Session.clearSignInData()} /> | ||
</View> | ||
<View style={[styles.mt5, styles.signInPageWelcomeTextContainer]}> | ||
<Terms /> | ||
<View style={[styles.mt5]}> | ||
<Text style={[styles.loginHeroBody, styles.mb5, styles.textNormal, !isSmallScreenWidth ? styles.textAlignLeft : {}]}>{loginText}</Text> | ||
</View> | ||
</> | ||
|
||
<ValidateCodeForm | ||
isVisible | ||
isUsingRecoveryCode={isUsingRecoveryCode} | ||
setIsUsingRecoveryCode={setIsUsingRecoveryCode} | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
ChooseSSOOrMagicCode.displayName = 'ChooseSSOOrMagicCode'; | ||
|
||
export default withOnyx<ChooseSSOOrMagicCodeProps, ChooseSSOOrMagicCodeOnyxProps>({ | ||
credentials: {key: ONYXKEYS.CREDENTIALS}, | ||
account: {key: ONYXKEYS.ACCOUNT}, | ||
})(ChooseSSOOrMagicCode); | ||
export default withOnyx<ChooseSSOOrMagicCodeProps, ChooseSSOOrMagicCodeOnyxProps>({account: {key: ONYXKEYS.ACCOUNT}})(ChooseSSOOrMagicCode); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly does this do? Rather than setting a minHeight on this, can't we just fix the animated image itself so that it doesn't get cut off?
I'm just thinking that there should be a way for the animated image to be a block-like element that gets wrapped in the overall content wrapper, without needing to set an explicit min height to account for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @shawnborton here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes makes sense, but as far I can see, this was created to use a fixed height due to a bug with the footer in mobile screens, I'm afraid of if we use flexbox or another css technique we going to cause a regression, please see these commit where @grgia was trying to fix this issue:
@allroundexperts, I suggest to solve this with the fixed height and in other PR try to fix the CSS issue, please confirm if you agree or if I should try to fix that in this PR.