-
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
[CP Staging] fix: onboarding modal is not displayed in web #54329
Changes from 4 commits
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 |
---|---|---|
|
@@ -73,7 +73,7 @@ | |
function getReportID(route: ReportScreenNavigationProps['route']): string { | ||
// The report ID is used in an onyx key. If it's an empty string, onyx will return | ||
// a collection instead of an individual report. | ||
return String(route.params?.reportID || 0); | ||
Check failure on line 76 in src/pages/home/ReportScreen.tsx GitHub Actions / Changed files ESLint check
|
||
} | ||
|
||
/** | ||
|
@@ -94,14 +94,14 @@ | |
if (!parentReportActions || !parentReportActionID) { | ||
return; | ||
} | ||
return parentReportActions[parentReportActionID ?? '0']; | ||
Check failure on line 97 in src/pages/home/ReportScreen.tsx GitHub Actions / Changed files ESLint check
|
||
} | ||
|
||
function ReportScreen({route, currentReportID = '', navigation}: ReportScreenProps) { | ||
const styles = useThemeStyles(); | ||
const {translate} = useLocalize(); | ||
const reportIDFromRoute = getReportID(route); | ||
const reportActionIDFromRoute = route?.params?.reportActionID ?? ''; | ||
Check failure on line 104 in src/pages/home/ReportScreen.tsx GitHub Actions / Changed files ESLint check
|
||
const isFocused = useIsFocused(); | ||
const prevIsFocused = usePrevious(isFocused); | ||
const firstRenderRef = useRef(true); | ||
|
@@ -112,13 +112,14 @@ | |
const {isOffline} = useNetwork(); | ||
const {shouldUseNarrowLayout, isInNarrowPaneModal} = useResponsiveLayout(); | ||
const {activeWorkspaceID} = useActiveWorkspace(); | ||
const lastAccessedReportIDRef = useRef<string>(); | ||
|
||
const [modal] = useOnyx(ONYXKEYS.MODAL); | ||
const [isComposerFullSize] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportIDFromRoute}`, {initialValue: false}); | ||
const [accountManagerReportID] = useOnyx(ONYXKEYS.ACCOUNT_MANAGER_REPORT_ID, {initialValue: ''}); | ||
// If accountManagerReportID is an empty string, using ?? can crash the app. | ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
const [accountManagerReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${accountManagerReportID || '-1'}`); | ||
Check failure on line 122 in src/pages/home/ReportScreen.tsx GitHub Actions / Changed files ESLint check
|
||
const [userLeavingStatus] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_USER_IS_LEAVING_ROOM}${reportIDFromRoute}`, {initialValue: false}); | ||
const [reportOnyx, reportResult] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`, {allowStaleData: true}); | ||
const [reportMetadata = defaultReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportIDFromRoute}`, {initialValue: defaultReportMetadata}); | ||
|
@@ -126,9 +127,9 @@ | |
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, initialValue: {}}); | ||
const [betas] = useOnyx(ONYXKEYS.BETAS); | ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
const [parentReportAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportOnyx?.parentReportID || -1}`, { | ||
Check failure on line 130 in src/pages/home/ReportScreen.tsx GitHub Actions / Changed files ESLint check
|
||
canEvict: false, | ||
selector: (parentReportActions) => getParentReportAction(parentReportActions, reportOnyx?.parentReportActionID ?? ''), | ||
Check failure on line 132 in src/pages/home/ReportScreen.tsx GitHub Actions / Changed files ESLint check
|
||
}); | ||
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP); | ||
const [workspaceTooltip] = useOnyx(ONYXKEYS.NVP_WORKSPACE_TOOLTIP); | ||
|
@@ -151,6 +152,10 @@ | |
return; | ||
} | ||
|
||
if (lastAccessedReportIDRef.current) { | ||
return; | ||
} | ||
|
||
const lastAccessedReportID = ReportUtils.findLastAccessedReport(!canUseDefaultRooms, !!route.params.openOnAdminRoom, activeWorkspaceID)?.reportID; | ||
|
||
// It's possible that reports aren't fully loaded yet | ||
|
@@ -160,6 +165,7 @@ | |
} | ||
|
||
Log.info(`[ReportScreen] no reportID found in params, setting it to lastAccessedReportID: ${lastAccessedReportID}`); | ||
lastAccessedReportIDRef.current = lastAccessedReportID; | ||
navigation.setParams({reportID: lastAccessedReportID}); | ||
}, [activeWorkspaceID, canUseDefaultRooms, navigation, route, finishedLoadingApp]); | ||
|
||
|
@@ -190,7 +196,7 @@ | |
() => | ||
reportOnyx && { | ||
lastReadTime: reportOnyx.lastReadTime, | ||
reportID: reportOnyx.reportID ?? '', | ||
Check failure on line 199 in src/pages/home/ReportScreen.tsx GitHub Actions / Changed files ESLint check
|
||
policyID: reportOnyx.policyID, | ||
lastVisibleActionCreated: reportOnyx.lastVisibleActionCreated, | ||
statusNum: reportOnyx.statusNum, | ||
|
@@ -274,12 +280,12 @@ | |
const hasHelpfulErrors = Object.keys(report?.errorFields ?? {}).some((key) => key !== 'notFound'); | ||
const shouldHideReport = !hasHelpfulErrors && !ReportUtils.canAccessReport(report, policies, betas); | ||
|
||
const transactionThreadReportID = ReportActionsUtils.getOneTransactionThreadReportID(reportID ?? '', reportActions ?? [], isOffline); | ||
Check failure on line 283 in src/pages/home/ReportScreen.tsx GitHub Actions / Changed files ESLint check
|
||
const [transactionThreadReportActions = {}] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`); | ||
const combinedReportActions = ReportActionsUtils.getCombinedReportActions(reportActions, transactionThreadReportID ?? null, Object.values(transactionThreadReportActions)); | ||
const lastReportAction = [...combinedReportActions, parentReportAction].find((action) => ReportUtils.canEditReportAction(action) && !ReportActionsUtils.isMoneyRequestAction(action)); | ||
const isSingleTransactionView = ReportUtils.isMoneyRequest(report) || ReportUtils.isTrackExpenseReport(report); | ||
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID ?? '-1'}`]; | ||
Check failure on line 288 in src/pages/home/ReportScreen.tsx GitHub Actions / Changed files ESLint check
|
||
const isTopMostReportId = currentReportID === reportIDFromRoute; | ||
const didSubscribeToReportLeavingEvents = useRef(false); | ||
|
||
|
@@ -321,7 +327,7 @@ | |
} | ||
|
||
useEffect(() => { | ||
if (!transactionThreadReportID || !route?.params?.reportActionID || !ReportUtils.isOneTransactionThread(linkedAction?.childReportID ?? '-1', reportID ?? '', linkedAction)) { | ||
Check failure on line 330 in src/pages/home/ReportScreen.tsx GitHub Actions / Changed files ESLint check
|
||
return; | ||
} | ||
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(route?.params?.reportID)); | ||
|
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.
While the param is updating in the route, this
useEffect
can be triggered again, andnavigation.setParams
is called again with the outdated state that can cause the navigation stack to be overridden to the old state.