diff --git a/src/pages/ConciergePage.tsx b/src/pages/ConciergePage.tsx index f87e95dafe30..46f17e76c083 100644 --- a/src/pages/ConciergePage.tsx +++ b/src/pages/ConciergePage.tsx @@ -7,6 +7,7 @@ import {withOnyx} from 'react-native-onyx'; import ReportActionsSkeletonView from '@components/ReportActionsSkeletonView'; import ReportHeaderSkeletonView from '@components/ReportHeaderSkeletonView'; import ScreenWrapper from '@components/ScreenWrapper'; +import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import type {AuthScreensParamList} from '@libs/Navigation/types'; @@ -31,6 +32,7 @@ type ConciergePageProps = ConciergePageOnyxProps & StackScreenProps { if (session && 'authToken' in session) { @@ -56,7 +58,7 @@ function ConciergePage({session}: ConciergePageProps) { return ( - + diff --git a/src/pages/home/HeaderView.tsx b/src/pages/home/HeaderView.tsx index 4282eb689d22..2ca54d3a54d7 100644 --- a/src/pages/home/HeaderView.tsx +++ b/src/pages/home/HeaderView.tsx @@ -1,7 +1,7 @@ import React, {memo} from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import {useOnyx, withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import Badge from '@components/Badge'; import Button from '@components/Button'; import CaretWrapper from '@components/CaretWrapper'; @@ -19,6 +19,7 @@ import TaskHeaderActionButton from '@components/TaskHeaderActionButton'; import Text from '@components/Text'; import Tooltip from '@components/Tooltip'; import useLocalize from '@hooks/useLocalize'; +import usePolicy from '@hooks/usePolicy'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; @@ -34,18 +35,7 @@ import ROUTES from '@src/ROUTES'; import type * as OnyxTypes from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; -type HeaderViewOnyxProps = { - /** Personal details of all the users */ - personalDetails: OnyxEntry; - - /** Parent report */ - parentReport: OnyxEntry; - - /** The current policy of the report */ - policy: OnyxEntry; -}; - -type HeaderViewProps = HeaderViewOnyxProps & { +type HeaderViewProps = { /** Toggles the navigationMenu open and closed */ onNavigationMenuButtonClicked: () => void; @@ -62,9 +52,13 @@ type HeaderViewProps = HeaderViewOnyxProps & { shouldUseNarrowLayout?: boolean; }; -function HeaderView({report, personalDetails, parentReport, parentReportAction, policy, reportID, onNavigationMenuButtonClicked, shouldUseNarrowLayout = false}: HeaderViewProps) { +function HeaderView({report, parentReportAction, reportID, onNavigationMenuButtonClicked, shouldUseNarrowLayout = false}: HeaderViewProps) { const [isDeleteTaskConfirmModalVisible, setIsDeleteTaskConfirmModalVisible] = React.useState(false); const [invoiceReceiverPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : -1}`); + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID || report?.reportID || '-1'}`); + const policy = usePolicy(report?.policyID); + const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); const {translate} = useLocalize(); const theme = useTheme(); @@ -144,163 +138,161 @@ function HeaderView({report, personalDetails, parentReport, parentReportAction, dataSet={{dragArea: true}} > - - {isLoading ? ( - - ) : ( - <> - {shouldUseNarrowLayout && ( - + ) : ( + + {shouldUseNarrowLayout && ( + + - - - - - - - )} - - ReportUtils.navigateToDetailsPage(report)} - style={[styles.flexRow, styles.alignItemsCenter, styles.flex1]} - disabled={shouldDisableDetailPage} - accessibilityLabel={title} - role={CONST.ROLE.BUTTON} + + + + + + )} + + ReportUtils.navigateToDetailsPage(report)} + style={[styles.flexRow, styles.alignItemsCenter, styles.flex1]} + disabled={shouldDisableDetailPage} + accessibilityLabel={title} + role={CONST.ROLE.BUTTON} + > + {shouldShowSubscript ? ( + + ) : ( + + + + )} + - {shouldShowSubscript ? ( - + + + {!isEmptyObject(parentNavigationSubtitleData) && ( + - ) : ( - - - )} - - - - - {!isEmptyObject(parentNavigationSubtitleData) && ( - - )} - {shouldShowSubtitle() && ( + {shouldShowSubtitle() && ( + + {subtitle} + + )} + {isChatRoom && !!reportDescription && isEmptyObject(parentNavigationSubtitleData) && ( + { + if (ReportUtils.canEditReportDescription(report, policy)) { + Navigation.navigate(ROUTES.REPORT_DESCRIPTION.getRoute(reportID)); + return; + } + Navigation.navigate(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(reportID)); + }} + style={[styles.alignSelfStart, styles.mw100]} + accessibilityLabel={translate('reportDescriptionPage.roomDescription')} + > - {subtitle} + {reportDescription} - )} - {isChatRoom && !!reportDescription && isEmptyObject(parentNavigationSubtitleData) && ( - { - if (ReportUtils.canEditReportDescription(report, policy)) { - Navigation.navigate(ROUTES.REPORT_DESCRIPTION.getRoute(reportID)); - return; - } - Navigation.navigate(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(reportID)); - }} - style={[styles.alignSelfStart, styles.mw100]} - accessibilityLabel={translate('reportDescriptionPage.roomDescription')} - > - - {reportDescription} - - - )} - {isPolicyExpenseChat && !!policyDescription && isEmptyObject(parentNavigationSubtitleData) && ( - { - if (ReportUtils.canEditPolicyDescription(policy)) { - Navigation.navigate(ROUTES.WORKSPACE_PROFILE_DESCRIPTION.getRoute(report.policyID ?? '-1')); - return; - } - Navigation.navigate(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(reportID)); - }} - style={[styles.alignSelfStart, styles.mw100]} - accessibilityLabel={translate('workspace.editor.descriptionInputLabel')} - > - - {policyDescription} - - - )} - - {brickRoadIndicator === CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR && ( - - - + )} - - - {ReportUtils.isChatUsedForOnboarding(report) && SubscriptionUtils.isUserOnFreeTrial() && ( - + {isPolicyExpenseChat && !!policyDescription && isEmptyObject(parentNavigationSubtitleData) && ( + { + if (ReportUtils.canEditPolicyDescription(policy)) { + Navigation.navigate(ROUTES.WORKSPACE_PROFILE_DESCRIPTION.getRoute(report.policyID ?? '-1')); + return; + } + Navigation.navigate(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(reportID)); + }} + style={[styles.alignSelfStart, styles.mw100]} + accessibilityLabel={translate('workspace.editor.descriptionInputLabel')} + > + + {policyDescription} + + )} - {isTaskReport && !shouldUseNarrowLayout && ReportUtils.isOpenTaskReport(report, parentReportAction) && } - {canJoin && !shouldUseNarrowLayout && joinButton} + {brickRoadIndicator === CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR && ( + + + + )} + + + {ReportUtils.isChatUsedForOnboarding(report) && SubscriptionUtils.isUserOnFreeTrial() && ( + + )} + {isTaskReport && !shouldUseNarrowLayout && ReportUtils.isOpenTaskReport(report, parentReportAction) && } + {canJoin && !shouldUseNarrowLayout && joinButton} - { - setIsDeleteTaskConfirmModalVisible(false); - Task.deleteTask(report); - }} - onCancel={() => setIsDeleteTaskConfirmModalVisible(false)} - title={translate('task.deleteTask')} - prompt={translate('task.deleteConfirmation')} - confirmText={translate('common.delete')} - cancelText={translate('common.cancel')} - danger - shouldEnableNewFocusManagement - /> - - )} - + + { + setIsDeleteTaskConfirmModalVisible(false); + Task.deleteTask(report); + }} + onCancel={() => setIsDeleteTaskConfirmModalVisible(false)} + title={translate('task.deleteTask')} + prompt={translate('task.deleteConfirmation')} + confirmText={translate('common.delete')} + cancelText={translate('common.cancel')} + danger + shouldEnableNewFocusManagement + /> + + )} {!isLoading && canJoin && shouldUseNarrowLayout && {joinButton}} @@ -309,16 +301,4 @@ function HeaderView({report, personalDetails, parentReport, parentReportAction, HeaderView.displayName = 'HeaderView'; -export default memo( - withOnyx({ - parentReport: { - key: ({report}) => `${ONYXKEYS.COLLECTION.REPORT}${report.parentReportID ?? report?.reportID}`, - }, - policy: { - key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '-1'}`, - }, - personalDetails: { - key: ONYXKEYS.PERSONAL_DETAILS_LIST, - }, - })(HeaderView), -); +export default memo(HeaderView);