-
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
fix: incorrect page is displayed when refreshing the page #54680
Changes from all commits
025c78b
c98a3a5
7a83b03
13d0c65
d70595e
4ed9e5a
ca4b1e7
728ac39
e49143e
f429543
15c3b56
669eb15
c986d69
f44a299
c0ad5d2
45c2e9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,7 +1,8 @@ | ||||||
import React, {useState} from 'react'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @truph01 for my understanding, can you explain why that regression occured and how did we fix it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. asking cause I'm not a fan of introducing new props unless there is no other option There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The modal defined in:
utilizes animation for sliding in and out. Consequently, even if we consistently set the
the modal doesn’t appear instantly. Instead, its container remains visible momentarily due to the animation transition. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense to me, thanks a lot |
||||||
import React, {useEffect, useState} from 'react'; | ||||||
import type {ValueOf} from 'type-fest'; | ||||||
import Button from '@components/Button'; | ||||||
import DelegateNoAccessWrapper from '@components/DelegateNoAccessWrapper'; | ||||||
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; | ||||||
import HeaderPageLayout from '@components/HeaderPageLayout'; | ||||||
import {FallbackAvatar} from '@components/Icon/Expensicons'; | ||||||
import MenuItem from '@components/MenuItem'; | ||||||
|
@@ -15,26 +16,31 @@ import {formatPhoneNumber} from '@libs/LocalePhoneNumber'; | |||||
import Navigation from '@libs/Navigation/Navigation'; | ||||||
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; | ||||||
import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; | ||||||
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; | ||||||
import {getPersonalDetailByEmail} from '@libs/PersonalDetailsUtils'; | ||||||
import CONST from '@src/CONST'; | ||||||
import ROUTES from '@src/ROUTES'; | ||||||
import type SCREENS from '@src/SCREENS'; | ||||||
import DelegateMagicCodeModal from './DelegateMagicCodeModal'; | ||||||
|
||||||
type ConfirmDelegatePageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.DELEGATE.DELEGATE_CONFIRM>; | ||||||
|
||||||
function ConfirmDelegatePage({route}: ConfirmDelegatePageProps) { | ||||||
function ConfirmDelegatePage({route, navigation}: ConfirmDelegatePageProps) { | ||||||
const {translate} = useLocalize(); | ||||||
|
||||||
const styles = useThemeStyles(); | ||||||
const login = route.params.login; | ||||||
const role = route.params.role as ValueOf<typeof CONST.DELEGATE_ROLE>; | ||||||
const showValidateActionModal = route.params.showValidateActionModal === 'true'; | ||||||
const {isOffline} = useNetwork(); | ||||||
const [shouldDisableModalAnimation, setShouldDisableModalAnimation] = useState(true); | ||||||
const [shouldShowLoading, setShouldShowLoading] = useState(showValidateActionModal ?? false); | ||||||
|
||||||
const [isValidateCodeActionModalVisible, setIsValidateCodeActionModalVisible] = useState(showValidateActionModal ?? false); | ||||||
useEffect(() => { | ||||||
navigation.setParams({showValidateActionModal: String(isValidateCodeActionModalVisible)}); | ||||||
}, [isValidateCodeActionModalVisible, navigation]); | ||||||
|
||||||
const personalDetails = PersonalDetailsUtils.getPersonalDetailByEmail(login); | ||||||
const personalDetails = getPersonalDetailByEmail(login); | ||||||
const avatarIcon = personalDetails?.avatar ?? FallbackAvatar; | ||||||
const formattedLogin = formatPhoneNumber(login ?? ''); | ||||||
const displayName = personalDetails?.displayName ?? formattedLogin; | ||||||
|
@@ -49,51 +55,57 @@ function ConfirmDelegatePage({route}: ConfirmDelegatePageProps) { | |||||
text={translate('delegate.addCopilot')} | ||||||
style={styles.mt6} | ||||||
pressOnEnter | ||||||
onPress={() => setIsValidateCodeActionModalVisible(true)} | ||||||
onPress={() => { | ||||||
setShouldDisableModalAnimation(false); | ||||||
setIsValidateCodeActionModalVisible(true); | ||||||
}} | ||||||
/> | ||||||
); | ||||||
|
||||||
return ( | ||||||
<HeaderPageLayout | ||||||
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_DELEGATE_ROLE.getRoute(login, role))} | ||||||
title={translate('delegate.addCopilot')} | ||||||
testID={ConfirmDelegatePage.displayName} | ||||||
footer={submitButton} | ||||||
childrenContainerStyles={[styles.pt3, styles.gap6]} | ||||||
keyboardShouldPersistTaps="handled" | ||||||
> | ||||||
<DelegateNoAccessWrapper accessDeniedVariants={[CONST.DELEGATE.DENIED_ACCESS_VARIANTS.DELEGATE]}> | ||||||
<Text style={[styles.ph5]}>{translate('delegate.confirmCopilot')}</Text> | ||||||
<MenuItem | ||||||
avatarID={personalDetails?.accountID ?? -1} | ||||||
iconType={CONST.ICON_TYPE_AVATAR} | ||||||
icon={avatarIcon} | ||||||
title={displayName} | ||||||
description={formattedLogin} | ||||||
interactive={false} | ||||||
/> | ||||||
<MenuItemWithTopDescription | ||||||
title={translate('delegate.role', {role})} | ||||||
description={translate('delegate.accessLevel')} | ||||||
helperText={translate('delegate.roleDescription', {role})} | ||||||
onPress={() => Navigation.navigate(ROUTES.SETTINGS_DELEGATE_ROLE.getRoute(login, role, ROUTES.SETTINGS_DELEGATE_CONFIRM.getRoute(login, role)))} | ||||||
shouldShowRightIcon | ||||||
/> | ||||||
<DelegateMagicCodeModal | ||||||
shouldHandleNavigationBack | ||||||
login={login} | ||||||
role={role} | ||||||
onClose={() => { | ||||||
if (!showValidateActionModal) { | ||||||
<> | ||||||
<HeaderPageLayout | ||||||
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_DELEGATE_ROLE.getRoute(login, role))} | ||||||
title={translate('delegate.addCopilot')} | ||||||
testID={ConfirmDelegatePage.displayName} | ||||||
footer={submitButton} | ||||||
childrenContainerStyles={[styles.pt3, styles.gap6]} | ||||||
keyboardShouldPersistTaps="handled" | ||||||
> | ||||||
<DelegateNoAccessWrapper accessDeniedVariants={[CONST.DELEGATE.DENIED_ACCESS_VARIANTS.DELEGATE]}> | ||||||
<Text style={[styles.ph5]}>{translate('delegate.confirmCopilot')}</Text> | ||||||
<MenuItem | ||||||
avatarID={personalDetails?.accountID ?? CONST.DEFAULT_NUMBER_ID} | ||||||
iconType={CONST.ICON_TYPE_AVATAR} | ||||||
icon={avatarIcon} | ||||||
title={displayName} | ||||||
description={formattedLogin} | ||||||
interactive={false} | ||||||
/> | ||||||
<MenuItemWithTopDescription | ||||||
title={translate('delegate.role', {role})} | ||||||
description={translate('delegate.accessLevel')} | ||||||
helperText={translate('delegate.roleDescription', {role})} | ||||||
onPress={() => Navigation.navigate(ROUTES.SETTINGS_DELEGATE_ROLE.getRoute(login, role, ROUTES.SETTINGS_DELEGATE_CONFIRM.getRoute(login, role)))} | ||||||
shouldShowRightIcon | ||||||
/> | ||||||
<DelegateMagicCodeModal | ||||||
// We should disable the animation initially and only enable it when the user manually opens the modal | ||||||
// to ensure it appears immediately when refreshing the page. | ||||||
disableAnimation={shouldDisableModalAnimation} | ||||||
shouldHandleNavigationBack | ||||||
login={login} | ||||||
role={role} | ||||||
onClose={() => { | ||||||
setShouldShowLoading(false); | ||||||
setIsValidateCodeActionModalVisible(false); | ||||||
return; | ||||||
} | ||||||
Navigation.navigate(ROUTES.SETTINGS_SECURITY); | ||||||
}} | ||||||
isValidateCodeActionModalVisible={isValidateCodeActionModalVisible} | ||||||
/> | ||||||
</DelegateNoAccessWrapper> | ||||||
</HeaderPageLayout> | ||||||
}} | ||||||
isValidateCodeActionModalVisible={isValidateCodeActionModalVisible} | ||||||
/> | ||||||
</DelegateNoAccessWrapper> | ||||||
</HeaderPageLayout> | ||||||
{shouldShowLoading && <FullScreenLoadingIndicator />} | ||||||
</> | ||||||
); | ||||||
} | ||||||
|
||||||
|
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.
@truph01 can you please put a comment here explaining why this is needed ? the git blame will not explain to others why we needed this
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.
I just added comment